XFire截取SOAP报文,并输出到控制台的方法:
方法一(spring没有集成XFire):
1. 在XFire service.xml中配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="">
<service> <name>AddTwoInteger</name> <serviceClass>cal.IAddTwoInteger</serviceClass> <implementationClass>cal.AddTwoIntegerImpl</implementationClass> <style>wrapped</style> <use>literal</use> <scope>application</scope>
<outHandlers> <handler handlerClass="org.codehaus.xfire.util.dom.DOMInHandler"/> <handler handlerClass ="cal.AuthenticationHandler" ></handler > </outHandlers> <inHandlers> <handler handlerClass="org.codehaus.xfire.util.dom.DOMInHandler"/> <handler handlerClass ="cal.AuthenticationHandler" ></handler > </inHandlers> </service> </beans>
|
2. 添加InHandler文件
package cal;
import org.codehaus.xfire.MessageContext; import org.codehaus.xfire.handler.AbstractHandler; import org.jdom.Element; import org.codehaus.xfire.util.dom.DOMInHandler; import org.dom4j.io.DOMReader; import org.w3c.dom.Document;
public class AuthenticationHandler extends AbstractHandler {
public void invoke(MessageContext cfx) throws Exception { Document inputDoc = (Document) cfx.getInMessage().getProperty(DOMInHandler.DOM_MESSAGE); if(inputDoc!=null){ System.out.println("------------input Soap xml-------------"); System.out.println(this.buildDocment(inputDoc).asXML()); } } /** converts a W3C DOM document into a dom4j document */ public org.dom4j.Document buildDocment(org.w3c.dom.Document domDocument) { DOMReader xmlReader = new DOMReader(); return xmlReader.read(domDocument); }
}
|
方法二(spring集成XFire):
1. xfire.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" ""> <beans> <!-- 引入XFire预配置信息 --> <import resource="classpath:org/codehaus/xfire/spring/xfire.xml" /> <!-- 定义访问的url --> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="urlMap"> <map> <entry key="/UserService.ws"> <ref bean="UserService" /> </entry> </map> </property> </bean>
<!-- 使用XFire导出器 --> <bean id="baseWebService" class="org.codehaus.xfire.spring.remoting.XFireExporter" lazy-init="false" abstract="true"> <!-- 引用xfire.xml中定义的工厂 --> <property name="serviceFactory" ref="xfire.serviceFactory" /> <!-- 引用xfire.xml中的xfire实例 --> <property name="xfire" ref="xfire" /> </bean> <bean id="UserService" parent="baseWebService"> <!-- 业务服务bean --> <property name="serviceBean" ref="userService" /> <!-- 业务服务bean的窄接口类 --> <property name="serviceClass" value="com.jy.service.UserService" /> <property name="inHandlers"> <list> <ref bean="domInHandler"/> <ref bean="addressingHandler"/> </list> </property> </bean> <bean id="domInHandler" class="org.codehaus.xfire.util.dom.DOMInHandler"/> <bean id="addressingHandler" class="com.jy.interceptor.SoapInHandler"/> </beans>
|
2. 添加InHandler.java
package com.jy.interceptor;
import org.codehaus.xfire.MessageContext; import org.codehaus.xfire.handler.AbstractHandler; import org.codehaus.xfire.util.dom.DOMInHandler; import org.dom4j.io.DOMReader; import org.w3c.dom.Document;
public class SoapInHandler extends AbstractHandler { public void invoke(MessageContext arg0) throws Exception { Document inputDoc = (Document) arg0.getInMessage().getProperty(DOMInHandler.DOM_MESSAGE); if(inputDoc!=null){ System.out.println("------------input Soap xml-------------"); System.out.println(this.buildDocment(inputDoc).asXML()); } }
/** converts a W3C DOM document into a dom4j document */ public org.dom4j.Document buildDocment(org.w3c.dom.Document domDocument) { DOMReader xmlReader = new DOMReader(); return xmlReader.read(domDocument); }
}
|
相关资料:
阅读(2802) | 评论(0) | 转发(0) |