axis1.4 soap接口服务端拦截打印请求响应日志

Posted tower888

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了axis1.4 soap接口服务端拦截打印请求响应日志相关的知识,希望对你有一定的参考价值。

 增加handler:

package com.gh.ca.pub.newhandler.io;

import cn.hutool.core.util.RandomUtil;
import com.gh.ca.pub.util.Tools;
import org.apache.axis.AxisFault;
import org.apache.axis.MessageContext;
import org.apache.axis.handlers.BasicHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ReqHandler extends BasicHandler 
    private static final Logger log = LoggerFactory.getLogger(ReqHandler.class);

    @Override
    public void invoke(MessageContext ctx) throws AxisFault 
        String logid = RandomUtil.randomString(6);
        String clientip = Tools.getClientIP();
        long bTime = System.currentTimeMillis();
        String msg = ctx.getRequestMessage().getSOAPPartAsString();
        ctx.setProperty("logid", logid);
        ctx.setProperty("bTime", bTime);
        log.info("REQ: logid:,clientIP:,msg:", logid, clientip, msg);
    

 

package com.gh.ca.pub.newhandler.io;

import org.apache.axis.AxisFault;
import org.apache.axis.MessageContext;
import org.apache.axis.handlers.BasicHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ResHandler extends BasicHandler 
    private static final Logger log = LoggerFactory.getLogger(ResHandler.class);

    @Override
    public void invoke(MessageContext ctx) throws AxisFault 
        String msg = ctx.getResponseMessage().getSOAPPartAsString();
        long eTime = System.currentTimeMillis();
        String logid = (String) ctx.getProperty("logid");
        long bTime = (long) ctx.getProperty("bTime");
        log.info("RSP: logid:,msg: time:", logid, msg, (eTime - bTime));
    


server-config.wsdd增加配置:

注意: JWSHandler必须注释掉,不然配置的ReqHandler, ResHandler无法生效,不会打印日志

<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
 <globalConfiguration>
  <parameter name="sendMultiRefs" value="true"/>
  <parameter name="disablePrettyXML" value="true"/>
  <parameter name="adminPassword" value="admin"/>
  <parameter name="attachments.Directory" value=""/>
  <parameter name="dotNetSoapEncFix" value="true"/>
  <parameter name="enableNamespacePrefixOptimization" value="false"/>
  <parameter name="sendXMLDeclaration" value="true"/>
  <parameter name="sendXsiTypes" value="true"/>
  <parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/>
    <!--
  <requestFlow>
   <handler type="java:org.apache.axis.handlers.JWSHandler">
    <parameter name="scope" value="session"/>
   </handler>
   <handler type="java:org.apache.axis.handlers.JWSHandler">
    <parameter name="scope" value="request"/>
    <parameter name="extension" value=".jwr"/>
   </handler>
  </requestFlow>
   -->
    <requestFlow>
       <handler type="ReqHandler" />
    </requestFlow>
    <responseFlow>
       <handler type="ResHandler" />
    </responseFlow>
 </globalConfiguration>
 <handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder"/>
 <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/>
 <handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>
  
   <handler name="ReqHandler" type="java:com.gh.ca.pub.newhandler.io.ReqHandler" />
   <handler name="ResHandler" type="java:com.gh.ca.pub.newhandler.io.ResHandler" />

  <service name="ChangePasswd" provider="java:RPC" style="rpc"> ....<service/>

 

问题:

响应中打印的soap报文中文不能显示:

<errorDescription xsi:type="xsd:string">&#x5904;&#x7406;&#x6210;&#x529F;</errorDescription>

这个如何转换为正常的中文打印???

 

 

以上是关于axis1.4 soap接口服务端拦截打印请求响应日志的主要内容,如果未能解决你的问题,请参考以下文章

更改 Axis 1.4 生成的 SOAP Java 客户端的超时设置

PHP使用WSDL格式Soap通信

axis1.4客户端调用http形式

移动端自动化之请求拦截

直接从 HTTP 响应打印

过滤器