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

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

问题描述

我遇到了下一个问题:

我想记录登陆我的网络服务(服务器端)的 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"/>

2nd 将该处理程序的使用添加到来自 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天全站免登陆