最近学习Mule时遇到一个问题,场景如下,通过公开的Web Service(代码中的TestWS),接受请求参数,使用自定义的Transformer将参数转成访问另一Web Service(代码中的TestWSInterface )的请求参数。
出现以下异常:
Exception stack is:
1. argument type mismatch (java.lang.IllegalArgumentException)
sun.reflect.NativeMethodAccessorImpl:-2 (null)
2. Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=http://localhost:8082/testws/ws/TestWSInterface, connector=CxfConnector{this=c91629, started=true, initialised=true, name='connector.cxf.0', disposed=false, numberOfConcurrentTransactedReceivers=4, createMultipleTransactedReceivers=true, connected=true, supportedProtocols=[cxf, cxf:http, cxf:https, cxf:jms, cxf:vm], serviceOverrides=null}, transformer=[], name='endpoint.http.localhost.8082.testws.ws.TestWSInterface', properties={wsdlLocation=classpath:TestWSInterface.wsdl, operation=testBean, wsdlPort=TestWSImplPort, enableMuleSoapHeaders=true, clientClass=jame.test.ws.TestWSImplService, applyTransformersToProtocol=true}, transactionConfig=Transaction{factory=null, action=NEVER, timeout=0}, filter=null, deleteUnacceptedMessages=false, securityFilter=null, synchronous=true, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8}. Message payload is of type: Stu (org.mule.api.transport.DispatchException)
org.mule.transport.AbstractMessageDispatcher:185 (http://www.mulesource.org/docs/site/current2/apidocs/org/mule/api/transport/DispatchException.html)
-----------------------------
实际要访问的接口和实现类
@WebService
public interface TestWSInterface {
MyBean testBean(@WebParam(name="newBean")NewBean newBean);
}
@WebService(endpointInterface = "com.aaa.test.ws.TestWSInterface")
public class TestWSImpl implements TestWSInterface {
public MyBean testBean(NewBean newBean){
System.out.println(newBean.getId());
System.out.println(newBean.getAdd());
MyBean my = new MyBean();
my.setAge(20);
my.setName("MyBean");
return my;
}
-----------------------------
MULE接收请求参数的接口和实现类
@WebService
public interface TestWS {
@WebResult(name="outStu")
public Stu test(@WebParam(name="inStu")Stu stu);
}
@WebService(serviceName="TestWSService", endpointInterface="com.aaa.mule.test.ws.TestWS")
public class TestWSImpl implements TestWS {
public Stu test(Stu stu) {
System.err.println(stu.getAge());
System.err.println(stu.getName());
return stu;
}
}
-----------------------------
自定义的Transformer
public class CxfTestTransformer extends AbstractTransformer{
public CxfTestTransformer(){
super();
this.registerSourceType(Stu.class);
this.setReturnClass(NewBean.class);
}
@Override
protected Object doTransform(Object src, String encoding)
throws TransformerException {
System.out.println(src);
NewBean newBean = new NewBean();
newBean.setAdd("aaa");
newBean.setId("111");
return newBean;
}
}
-----------------------------
mule-config.xml
<model name="echoSample">
<service name="TestWS">
<inbound>
<cxf:inbound-endpoint address="http://localhost:65082/services/TestWS"/>
</inbound>
<component>
<singleton-object class="com.aaa.mule.test.ws.TestWSImpl"/>
</component>
<outbound>
<pass-through-router>
<cxf:outbound-endpoint
address="http://localhost:8082/testws/ws/TestWSInterface"
clientClass="com.aaa.test.ws.TestWSImplService"
wsdlPort="TestWSImplPort"
wsdlLocation="classpath:TestWSInterface.wsdl"
operation="testBean">
</cxf:outbound-endpoint>
<custom-transformer class="com.aaa.mule.test.ws.filter.CxfTestTransformer"></custom-transformer>
</pass-through-router>
</outbound>
</service>
</model>
-----------------------------
参考了以下文档
http://www.mulesoft.org/documentation/display/MULE2USER/Using+a+Web+Service+Client+as+an+Outbound+Endpoint
clientClass="com.aaa.test.ws.TestWSImplService"为使用 WSDL to
Java
tool生成的客户端类。
望各位能帮忙解决。