如何设置XFIRE 的MTOM?
我写了以下代码:
服务端配置:<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<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="/getlistservice.ws">
<ref bean="GetListService" />
</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="GetListService" class="org.codehaus.xfire.spring.remoting.XFireExporter">
<property name="serviceBean" ref="UserListImpl" />
<property name="serviceClass" value="org.appfuse.webapp.linkedlist.IUserList" />
<property name="inHandlers">
<list>
<ref bean="domInHandler" />
<ref bean="wss4jInHandlerSign" />
</list>
</property>
<property name="properties">
<map>
<entry key="mtom-enabled" value="true" />
</map>
</property> </bean> <bean id="UserListImpl" class="org.appfuse.webapp.linkedlist.UserListImpl" /> <bean id="domInHandler" class="org.codehaus.xfire.util.dom.DOMInHandler" /> <bean id="wss4jInHandlerSign" class="org.codehaus.xfire.security.wss4j.WSS4JInHandler">
<property name="properties">
<props>
<prop key="action">Signature</prop>
<prop key="signaturePropFile">/insecurity.properties</prop>
<prop key="passwordCallbackClass">org.appfuse.webapp.linkedlist.PasswordHandler</prop>
</props>
</property>
</bean>
</beans>
客户端代码:client = new Client(new URL(
"http://localhost:8080/PYPproject/getlistservice.ws?wsdl"));

Properties properties = new Properties();
properties.setProperty(WSHandlerConstants.ACTION,
WSHandlerConstants.SIGNATURE);
// 私钥名字
properties.setProperty(WSHandlerConstants.USER, "pypkey");
// properties文件URL
properties.setProperty(WSHandlerConstants.SIG_PROP_FILE,
"outsecurity.properties");
// callback类
properties.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS,
PasswordHandler.class.getName()); // 绑定
wsOut = new WSS4JOutHandler(properties); client.addOutHandler(new DOMOutHandler());
client.addOutHandler(wsOut);
client.setProperty(“mtom-enabled”, “true”);
                           client.setProperty(HttpTransport.CHUNKING_ENABLED, “true”); String tem = "123456";
Object[] results = client.invoke("addId",new Object[] { tem.getBytes() });
传输byte[]时 抛:
org.codehaus.xfire.fault.XFireFault: [B cannot be cast to javax.activation.DataHandler
at org.codehaus.xfire.fault.XFireFault.createFault(XFireFault.java:89)
at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:83)
at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:114)
at org.codehaus.xfire.client.Client.invoke(Client.java:336)
at org.codehaus.xfire.client.Client.invoke(Client.java:368)
at test.testClient.main(testClient.java:126)
Caused by: java.lang.ClassCastException: [B cannot be cast to javax.activation.DataHandler
at org.codehaus.xfire.aegis.type.mtom.DataHandlerType.createAttachment(DataHandlerType.java:18)
at org.codehaus.xfire.aegis.type.mtom.AbstractXOPType.writeObject(AbstractXOPType.java:89)
at org.codehaus.xfire.aegis.AegisBindingProvider.writeParameter(AegisBindingProvider.java:229)
at org.codehaus.xfire.service.binding.AbstractBinding.writeParameter(AbstractBinding.java:273)
at org.codehaus.xfire.service.binding.WrappedBinding.writeMessage(WrappedBinding.java:90)
at org.codehaus.xfire.soap.SoapSerializer.writeMessage(SoapSerializer.java:80)
at org.codehaus.xfire.util.OutMessageDataSource.createInputStream(OutMessageDataSource.java:92)
at org.codehaus.xfire.util.OutMessageDataSource.<init>(OutMessageDataSource.java:37)
at org.codehaus.xfire.transport.http.CommonsHttpMessageSender.open(CommonsHttpMessageSender.java:171)
at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:121)
at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)
at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)
at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:79)
... 4 more
求教高手~

解决方案 »

  1.   

    自己顶 解决了
    用代理方式访问Service service = new ObjectServiceFactory().create(
    IUserList.class, "IUserList", null, null);

    IUserList userList = (IUserList) new XFireProxyFactory().create(
    service,"http://localhost:8080/PYPproject/getlistservice.ws");
    client = ((XFireProxy) Proxy.getInvocationHandler(userList))
    .getClient();
    client.setProperty("mtom-enabled", "true");
    client.setProperty(HttpTransport.CHUNKING_ENABLED, "true"); Properties properties = new Properties();
    properties.setProperty(WSHandlerConstants.ACTION,
    WSHandlerConstants.SIGNATURE);
    // 私钥名字
    properties.setProperty(WSHandlerConstants.USER, "pypkey");
    // properties文件URL
    properties.setProperty(WSHandlerConstants.SIG_PROP_FILE,
    "outsecurity.properties");
    // callback类
    properties.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS,
    PasswordHandler.class.getName()); // 绑定
    wsOut = new WSS4JOutHandler(properties); client.addOutHandler(new DOMOutHandler());
    client.addOutHandler(wsOut);