记录webservice接口日志,输入和输出可以记录再一起
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了记录webservice接口日志,输入和输出可以记录再一起,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3953字,纯文字阅读大概需要6分钟。
内容图文
配置文件配置
<? xml version="1.0" encoding="UTF-8" ?> < beans xmlns ="http://www.springframework.org/schema/beans" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" xmlns:context ="http://www.springframework.org/schema/context" xmlns:jaxws ="http://cxf.apache.org/jaxws" xsi:schemaLocation ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd" > < import resource ="classpath:META-INF/cxf/cxf.xml" /> < import resource ="classpath:META-INF/cxf/cxf-extension-soap.xml" /> < import resource ="classpath:META-INF/cxf/cxf-servlet.xml" /> < context:component-scan base-package ="com.test.inf" /> < jaxws:endpoint id ="syncUserService" implementor ="com.test.inf.testServiceImpl " address ="/testInf" > < jaxws:inInterceptors > < bean name ="loggingInInterceptor" class ="org.apache.cxf.interceptor.LoggingInInterceptor" /> < bean name ="webLogInInterceptor" class ="com.test.inf.WebLogInInterceptor" /> </ jaxws:inInterceptors > < jaxws:outInterceptors > < bean name ="loggingOutInterceptor" class ="org.apache.cxf.interceptor.LoggingOutInterceptor" /> < bean name ="webLogOutInterceptor" class ="com.test.inf.WebLogOutInterceptor" /> </ jaxws:outInterceptors > </ jaxws:endpoint > </ beans >
WebLogInInterceptor 为输入拦截器
WebLogOutInterceptor 为输出拦截器
package com.test.inf; import java.io.ByteArrayInputStream; import java.io.InputStream; import org.apache.cxf.helpers.IOUtils; import org.apache.cxf.interceptor.Fault; import org.apache.cxf.message.Message; import org.apache.cxf.phase.AbstractPhaseInterceptor; import org.apache.cxf.phase.Phase; public class WebLogInInterceptor extends AbstractPhaseInterceptor<Message> { public MessageInInterceptor() { super(Phase.RECEIVE); } publicvoid handleMessage(Message message) throws Fault { try { String xml; InputStream is = message.getContent(InputStream.class); String encoding = (String)message.get(Message.ENCODING); xml = IOUtils.toString(is); System.out.println("输入报文为:" + xml); message.setContent(InputStream.class, new ByteArrayInputStream(xml.getBytes(encoding))); message.getExchange().put("idtest", xml); } catch (Exception e) { e.printStackTrace(); } } }
message.setExchage().put("idtest", xml); 将输入信息存储
package com.test.inf; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.OutputStream; import org.apache.cxf.helpers.IOUtils; import org.apache.cxf.interceptor.Fault; import org.apache.cxf.io.CachedOutputStream; import org.apache.cxf.message.Message; import org.apache.cxf.phase.AbstractPhaseInterceptor; import org.apache.cxf.phase.Phase; public class MessageOutInterceptor extends AbstractPhaseInterceptor<Message> { @SuppressWarnings("unused") private String mMessage; public MessageOutInterceptor() { super(Phase.PRE_STREAM); } publicvoid handleMessage(Message message) throws Fault { String xml; try { String inputXML = (String) message.getExchange().get("idtest"); System.out.println("输入信息::::"+inputXML); OutputStream os = message.getContent(OutputStream.class); CachedStream cs = new CachedStream(); message.setContent(OutputStream.class, cs); message.getInterceptorChain().doIntercept(message); CachedOutputStream csnew = (CachedOutputStream) message.getContent(OutputStream.class); InputStream in = csnew.getInputStream(); xml = IOUtils.toString(in); System.out.println("输出信息:" + xml); IOUtils.copy(new ByteArrayInputStream(xml.getBytes()), os); cs.close(); os.flush(); message.setContent(OutputStream.class, os); } catch (Exception e) { e.printStackTrace(); } } }
String inputXML = (String) message.getExchange().get("idtest"); 获取输入信息
原文:http://www.cnblogs.com/lyhappy/p/6729876.html
内容总结
以上是互联网集市为您收集整理的记录webservice接口日志,输入和输出可以记录再一起全部内容,希望文章能够帮你解决记录webservice接口日志,输入和输出可以记录再一起所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。