本文主要是介绍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);@Overridepublic 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);@Overridepublic 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">处理成功</errorDescription>
这个如何转换为正常的中文打印???
这篇关于axis1.4 soap接口服务端拦截打印请求响应日志的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!