Mule:如何从远程客户端使用服务

时间:2014-07-06 17:31:38

标签: eclipse web-services wsdl mule endpoint

我一直在关注本教程,非常适合从WSDL http://training.middlewareschool.com/mule/consuming-wsdl-first-service/使用wb服务。 我一直在尝试通过使用CXF在Eclipse中生成客户端Web服务并在Mule中发布Web服务来执行类似的方法。我的问题是:如果我配置客户端和mule应用程序具有相同的端点(例如:localhost:8082 / ipsoap / test),我如何使Web服务的工作方式与教程相同。 这意味着如果我测试从客户端发送请求到mule(在eclipse中)我应该从mule收到正确的响应。提前感谢您的时间。

简而言之:

1 - 我使用教程中以下链接中的wsdl在eclipse中生成了一个客户端应用程序:http://ws.cdyne.com/ip2geo/ip2geo.asmx?wsdl

2-作为Mule的一个开始,我添加了一个http连接器和一个记录器,并将eclipse中的端点路径更改为我在Mule上的HTTP连接器上设置的路径。因此,当我从Eclipse中的客户端向Mule发送请求时,我可以看到有一个有效负载。

3-我需要有一个应用程序,即我在eclipse中的客户端应用程序,在Mule中使用已发布的服务。现在我认为这是使用CXF组件实现的,但我仍然无法使其工作。事实上,我想知道这是否是使用Mule的一种有效方式,因为我找不到任何关于我想要实现的内容的教程。

所以这是我测试它的方式: enter image description here

我使用了我在Mule中使用的相同端点并收到以下日志:

> INFO  2014-07-07 13:19:46,124
> [[soapservice].connector.http.mule.default.receiver.02]
> org.mule.api.processor.LoggerMessageProcessor: message transformation
> <soapenv:Envelope
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:q0="http://ws.cdyne.com/"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  
> <soapenv:Body>
>     <q0:ResolveIP>
>       <q0:ipAddress>173.194.36.39</q0:ipAddress>
>       <q0:licenseKey/>
>     </q0:ResolveIP>   </soapenv:Body> </soapenv:Envelope>
> 
> ERROR 2014-07-07 13:19:46,134
> [[soapservice].connector.http.mule.default.receiver.02]
> org.mule.exception.DefaultMessagingExceptionStrategy: 
> ******************************************************************************** Message               : wrong number of arguments. Failed to route
> event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor.
> Message payload is of type: String Code                  :
> MULE_ERROR--2
> -------------------------------------------------------------------------------- Exception stack is:
> 1. wrong number of arguments (java.lang.IllegalArgumentException)   sun.reflect.NativeMethodAccessorImpl:-2 (null)
> 2. wrong number of arguments. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of
> type: String (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.IllegalArgumentException: wrong
> number of arguments   at
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)   at
> sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)   at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>     + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

正如您所见,可以看到soap请求,但不会在CXF组件的级别上使用它。这是我的骡子代码:

<flow name="SoapService" doc:name="SoapService">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" path="test/cap.asmx" doc:name="HTTP"/>
        <byte-array-to-string-transformer doc:name="Byte Array to String"/>
        <logger message="message transformation #[message.payload]" level="INFO" doc:name="Logger"/>
        <flow-ref name="RequestResponse" doc:name="Flow Reference"/>
        <logger level="INFO" doc:name="Logger" message="after posting #[message.payload]"/>
        <mulexml:object-to-xml-transformer doc:name="Object to XML"/>
    </flow>
    <flow name="RequestResponse" doc:name="RequestResponse">
        <cxf:jaxws-client operation="ResolveIP" clientClass="pck.IP2Geo" port="IP2GeoSoap" wsdlLocation="file:/C:/Users/12204-hajjam1/workspace/ipgo/src/ipgeo.wsdl" doc:name="soap 2"/>
        <logger message="before posting #[message.payload]" level="INFO" doc:name="Logger"/>
        <http:outbound-endpoint exchange-pattern="request-response" method="POST" address="http://localhost:10387/ip2geo/ip2geo.asmx" doc:name="HTTP"/>
    </flow>

此外,如果我在cxf组件之前添加ip#[{'173.194.36.39',''}](第二个参数可以为空)的set有效负载,则返回一个空元素。然而,响应应该是这样的:

<pck.IPInformation>
<city>Mountain View</city>
<stateProvince>CA</stateProvince>
<country>United States</country>
<organization/>
<latitude>37.4192</latitude>
<longitude>-122.0574</longitude>
<areaCode>0</areaCode>
<timeZone/>
<hasDaylightSavings>false</hasDaylightSavings>
<certainty>90</certainty>
<regionName/>
<countryCode>US</countryCode>
</pck.IPInformation> 

因此,我的问题是消费和检索响应。 我为这个长度道歉,但我一直在努力解决这个问题并且没有找到解决方案。提前谢谢。

1 个答案:

答案 0 :(得分:1)

您应该创建一个消息类的实例,该实例是从WSDL为ResolveIP方法生成的,并将其用作cxf:jaxws-client元素之前的消息有效内容。