如何在AXIS 1.x中记录Log4J SOAP请求和响应? [英] How can I log with Log4J SOAP request and response in AXIS 1.x?

查看:181
本文介绍了如何在AXIS 1.x中记录Log4J SOAP请求和响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到下一个问题:

我想记录落在我的Web服务(服务器端)上的SOAP请求/响应.尝试在wsdd文件中配置我的Web服务.我总是登陆类似下一页的页面:

I want to log the SOAP requests/responses that land on my web service (server side). Trying to configure my web service in the wsdd file. I am always landing on pages like the next one:

如何使用org.apache.axis.handlers.LogHandler

建议将Apeche Axis LogHandler配置为记录请求/响应.这对我来说是无效的,因为a)无法在那里链接log4j,并且b)我无法使其正常工作.

Which recommends to configure the Apeche Axis LogHandler to log the request/response. That is not valid for me, since a)there is no way to link the log4j there, and b)I just am not able to make it work.

有人知道让我的log4j记录请求/响应的方法吗?

Does anyone know a way to make my log4j to log the request/responses?

推荐答案

因此,经过数小时或在互联网上进行谷歌搜索之后,我决定冒险尝试并对自己的处理程序进行编程.比预期容易得多.

So after hours or Googling out there in the web, I decided to get adventurous and program my own handler. Is much easier than expected.

我制作了一个类,该类扩展了抽象类BasicHandler(org.apache.axis.handlers.BasicHandler),并实现了记录请求或响应的invoke方法.这是我的课,我已将其浸洗为SOAPLogHandler:

I made a class that extends the abstract class BasicHandler (org.apache.axis.handlers.BasicHandler), and implements the invoke method loging the request or the response. Here is my class, which I have baptized as SOAPLogHandler :

package com.mypackage.axishandlers;

import org.apache.axis.AxisFault;
import org.apache.axis.MessageContext;
import org.apache.axis.handlers.BasicHandler;
import org.apache.log4j.Logger;

public class SOAPLogHandler extends BasicHandler {

private static Logger LOG= Logger.getLogger(SOAPLogHandler.class);
private static final long serialVersionUID = 1L;

@Override
public void invoke(MessageContext msgContext) throws AxisFault {
    if(msgContext.getResponseMessage() != null && msgContext.getResponseMessage().getSOAPPart() != null) {
        LOG.info(" Response = " + msgContext.getResponseMessage().getSOAPPartAsString());
    } else {
        if(msgContext.getRequestMessage() != null && msgContext.getRequestMessage().getSOAPPartAsString() != null) {
            LOG.info(" Request = " + msgContext.getRequestMessage().getSOAPPartAsString());
        }    
    }
}  }

这个想法是,首先记录请求,然后在处理后记录响应.因此,在 server-config.wsdd (如果在客户端,则为客户端的wsdd文件)中,我们必须添加一个指向该类的处理程序,并将其配置为在请求/响应链:

The idea is, to log first the request, and when processed, log the response. So, in the server-config.wsdd (or the wsdd file from your client if you are in the client side), we have to add a handler pointing to that class, and configure it to uses in the request/response chain:

第一次添加处理程序

 <handler name="log" type="java:com.mypackage.axishandlers.SOAPLogHandler"/>

第二次在http传输的请求/响应中添加该处理程序的使用(着重于日志处理程序)

2nd add the use of that handler to the request/response from the http transport (focus on the log handler)

 <transport name="http">
  <requestFlow>
   <handler type="log"/>
   <handler type="URLMapper"/>
   <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>
  </requestFlow>
  <responseFlow>
   <handler type="log"/>
  </responseFlow>
...
 </transport>

这样,魔术就可以完成了,您应该从请求/响应中收到漂亮的日志!

With that, the magic should be done, and you should receive a pretty log from the request/responses!

免责声明:如果您使用某种类型的SOAP多部分内容,我不确定会发生什么.

Disclaimer: I am not really sure from what will happend if you use some kind of SOAP multipart thing.

这篇关于如何在AXIS 1.x中记录Log4J SOAP请求和响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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