嗨我正在骡子做简单的POC。
我有一个网络服务,我想让它成为客户端。
它是SOAP Web服务,我想向它发送请求,但我没有得到关注。请给我一些想法。
以下是代码:
MULE:
<cxf:configuration name="CXF_Configuration" enableMuleSoapHeaders="true" initializeStaticBusInstance="true" doc:name="CXF Configuration"/>
<flow name="prjvm1" doc:name="prjvm1">
<http:inbound-endpoint address="http://localhost:5678/httpHello" contentType="application/x-www-form-urlencoded" doc:name="HTTP">
<http:body-to-parameter-map-transformer />
</http:inbound-endpoint>
<!-- This logger is just set to show the message accepted from the request -->
<logger level="INFO" message="#[payload]" doc:name="Logger"/>
<cxf:jaxws-client doc:name="VimService"
wsdlLocation="file:/C:/Users/gugla/MuleStudio/workspace/prjvm/bin/service/vService.wsdl"
operation="retrieveServiceContent"
clientClass="com.esxclient.VService"
port="VimPort">
<cxf:jaxb-databinding/>
</cxf:jaxws-client>
<outbound-endpoint address="http://localhost:8080/gep-sped/servicos/ServicoDeCadastroEAgendamento"
doc:name="Generic"
exchange-pattern="request-response"/>
<echo-component doc:name="Echo"/>
</flow>
我遇到了异常,但是在WSDL中有操作
Message : No such operation: retrieveServiceContent. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of type: ManagedObjectReference
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. No such operation: retrieveServiceContent (java.lang.Exception)
org.mule.module.cxf.CxfOutboundMessageProcessor:282 (null)
2. No such operation: retrieveServiceContent. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of type: ManagedObjectReference (org.mule.api.transport.DispatchException)
org.mule.module.cxf.CxfOutboundMessageProcessor:150 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/DispatchException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.Exception: No such operation: retrieveServiceContent
at org.mule.module.cxf.CxfOutboundMessageProcessor.getOperation(CxfOutboundMessageProcessor.java:282)
at org.mule.module.cxf.CxfOutboundMessageProcessor.getMethodFromOperation(CxfOutboundMessageProcessor.java:322)
at org.mule.module.cxf.CxfOutboundMessageProcessor.getMethod(CxfOutboundMessageProcessor.java:259)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
以下是运行中的WSDL:我很困惑,大约4天就可以了,因为我是骡子的新手。
<operation name="RetrieveServiceContent">
<input message="vim2:RetrieveServiceContentRequestMsg" />
<output message="vim2:RetrieveServiceContentResponseMsg" />
<fault name="RuntimeFault" message="vim2:RuntimeFaultFaultMsg"/>
</operation>
答案 0 :(得分:1)
有几种方法可以做到这一点。我更喜欢MuleStudio希望你这样做的方式,因为我从来没有真正开始工作。基本上,每当我创建一个webservice客户端时,我的mule-config看起来像这样:
<custom-transformer class="nl.thorax.someprogram.transformers.SomeRequestTransformer
<https:outbound-endpoint ref="someEndpoint" >
<cxf:jaxws-client
clientClass="nl.thorax.someprogram.someclass"
wsdlLocation="http://somedomain?wsdl
port="somePort"
operation="someOperation"/>
</https:outbound-endpoint>
<custom-transformer class="nl.thorax.someprogram.transformers.SomeResponseTransformer
其中:
现在,我配置调用的方式(并解析响应)是使用POJO。我的第一个变换器SomeRequestTransformer(基于Mule库中的AbstractMessageTransformer)有一些代码如下:
public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException
{
RequestObject request = new RequestObject();
request.setText("Hello!");
message.setPayload(request);
return message;
}
我创建请求,设置变量并将其返回给Mule。 RequestObject是由WSDL2Java生成的类,对应于WSDL中的某些操作。解析响应的方式大致相同。
现在我从经验中知道很多网络服务都没有完全以相同的方式工作。尝试自己实现我的例子。如果这不起作用,请提供您的Mule-Config以及您可能正在使用的任何和所有Java类。
修改强> 我创建了一个实际可行的方法示例。这些文件可以在our website下载。请参阅文件中的注释。当然,您必须手动创建Mule项目。
示例的注意事项:
http://localhost:8088
处创建一个端点供您调用。该流包含一个变换器,它使用预定义的参数创建一个示例调用。然后它尝试连接到Web服务。我在创建模拟服务时使用了SOAPUI使用的默认地址,但当然可以将其更改为您想要的任何内容。 webservice(据说)返回一些回显到用户浏览器中的东西。