axis2带请求的日志响应 [英] axis2 Log Response with Request

查看:289
本文介绍了axis2带请求的日志响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Web服务的新手.

I am very new to Web Service.

我公开了一个Web服务,因此客户端正在使用它,但是由于服务的重要性,我们希望记录流入和流出SOAP请求和SOAP响应.

I have one web service exposed, So client is consuming it but due to importance of service we want to Log SOAP Request and SOAP Response flowing IN and OUT.

我正在使用Axis2-1.6.2 这是我到目前为止尝试过的,我编写了一个自定义的Handler和Module类

I am using Axis2-1.6.2 This is what I tried so far, I wrote one custom Handler and Module class

import org.apache.axis2.AxisFault;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.engine.Handler;
import org.apache.axis2.handlers.AbstractHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class LogHandler extends AbstractHandler implements Handler {
    private static final Log log = LogFactory.getLog(LogHandler.class);
    private String name;

    public String getName() {
        System.out.println("LogHandler.getName()");
        return name;
    }

    public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
        log.info(msgContext.getEnvelope().toString());
        System.out.println("LogHandler.invoke()");
        return InvocationResponse.CONTINUE;        
    }

    public void revoke(MessageContext msgContext) {
        System.out.println("LogHandler.revoke()");
        log.info(msgContext.getEnvelope().toString());
    }

    public void setName(String name) {
        System.out.println("LogHandler.setName()");
        this.name = name;
    }
}

我也为上面的处理程序编写了模块

I also wrote Module for above Handler

public class LoggingModule implements Module {
   //implemented methods
}

从Handler上方,我能够记录传入的SOAP请求和传出的SOAP响应.

From above Handler, I am able to Log Incoming SOAP Request and Outgoing SOAP Response.

但是问题是,我一次收到很多请求,因此,如果我编写普通请求和响应,那么在查看日志时,我将无法确定响应是谁.

But the Problem is, I am getting many request at a time, So If i write Plain Request and Response, then while looking at Logs I am not able to identify whose Response is this.

通常记录为写

Request1 SOAP 
Request2 SOAP 
Response1 SOAP
Request3 SOAP
Request4 SOAP
Response2 SOAP

invoke(MessageContext msgContext)当请求进入而响应消失时,将调用此方法.有什么我可以在响应时间被调用的同时获取请求SOAP的.

invoke(MessageContext msgContext) This method is getting invoked while request comes in and response goes out. Is there anything I can get request SOAP while response time it get called.

因此,我想要一些解决方案,在其中我可以将请求SOAP整合到响应SOAP中,因此1 Log既是请求-响应也是完整的.

So, I want some solution where in I can consolidate Request SOAP in Response SOAP, So 1 Log is complete Request-Response both.

如果有人可以提出一些好的解决方案,这将是有帮助的.

If any body can suggest some good solution for it will be helpful.

推荐答案

您正在获取请求并记录了响应,因为您在两个IN/OUT流中都注册了处理程序.

You are getting request and response is logged, because you register your handler in both IN/OUT flows..

说,如果您在流程外注册处理程序,则可以选择相关的请求和响应.也就是说,您可以从响应messgaecontext访问请求消息上下文.从中,您可以阅读您的请求消息.[1]

Say, if you register your handler at out flow, you will be able to pick your relevant request and response. That is, from response messgaecontext, you can access your request message context. from that, you can read your request message.[1]

但是在这里您会看到一个问题,如果您的请求失败,您将无法在流出中捕获它.该日志可能会丢失.

But here you will see an issue, which if your request is failed, you wont be able to capture it in your outflow.That log might miss.

[1] http://vvratha.blogspot.com/2013/05/accessing-request-messagecontext-from.html

这篇关于axis2带请求的日志响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆