gpt4 book ai didi

java - 如何在没有datamapper的情况下在Mule中调用soap webservice

转载 作者:行者123 更新时间:2023-12-01 22:26:01 29 4
gpt4 key购买 nike

如何在没有datamapper的情况下在mule中调用soap webservice并且输入是xml。我正在使用社区添加。 & 我的输入是 xml 而不是肥皂信封。

我的 wsdl 位置是 - http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL输入是 -

 <GetCityForecastByZIP>
<zip>12004</zip>
</GetCityForecastByZIP>

流程 -

<flow name="callservice">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="8081" path="mainData/client" doc:name="HTTP" />
<http:outbound-endpoint exchange-pattern="request-response"
host="localhost" port="8082" path="mainData" doc:name="HTTP">
<cxf:jaxws-client doc:name="SOAP"
serviceClass="com.cdyne.ws.weatherws.WeatherSoap" operation="GetCityForecastByZIP"
port="WeatherSoap" />
</http:outbound-endpoint>
</flow>

出现错误org.apache.commons.httpclient.ContentLengthInputStream 无法转换为 java.lang.String。无法通过端点路由事件:org.mule.module.cxf.CxfOutboundMessageProcessor。消息有效负载的类型:ContentLengthInputStreamjava.lang.ClassCastException:org.apache.commons.httpclient.ContentLengthInputStream 无法转换为 java.lang.String 在 com.cdyne.ws.weatherws.GetCityForecastByZIP_WrapperTypeHelper1.createWrapperObject(来源未知) 在 org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor.handleMessage(WrapperClassOutInterceptor.java:100) 在 org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)

请求 xml:-

    <?xml version="1.0" encoding="UTF-8"?>
<file>
<header>
<documentType>CEN_ORD</documentType>
<version>1.0</version>
<createDate>12/20/14 23:44</createDate>
<originator>IKEA</originator>
<timeZone>PST</timeZone>
<dateFormat>MM/dd/yy HH:mm</dateFormat>
<currencyFormat>USD</currencyFormat>
<weightUnits>lbs</weightUnits>
<linearUnits>meter</linearUnits>
<priceBuCode>207</priceBuCode>
<routeBuCode>207</routeBuCode>
<serviceProviderAbbreviation />
<serviceProviderId />
<origin>207STO</origin>
<destination />
</header>
<data>
<deliveryOrder>
<deliveryMethod>LCD zone A next day</deliveryMethod>
<excReturn>FALSE</excReturn>
<operation>cancel</operation>
<deliveryType>HDN</deliveryType>
<totalArticleQuantity>4</totalArticleQuantity>
<totalArticlePackages>5</totalArticlePackages>
<totalArticleWeight>203.087752</totalArticleWeight>
<totalArticleVolume>1.3783</totalArticleVolume>
<sacId />
<businessUnit>
<code>207</code>
<countryCode>US</countryCode>
<languageCode>SWE</languageCode>
<name />
<phone />
<text />
<timeZone />
<daylightSavings />
</businessUnit>
<orderCustomer>
<priceBu>207</priceBu>
<orderNumber>192286415</orderNumber>
<type>LCD</type>
<customerName>Marcus Gorios</customerName>
<attention />
<careOfName />
<addr1>1800 Collins Ave #15b</addr1>
<addr2>Miami-Dade</addr2>
<addr3 />
<city>Miami Beach</city>
<state>FL</state>
<zipCode>33139</zipCode>
<countryCode>US</countryCode>
<dayPhone>7866267105</dayPhone>
<eveningPhone>7866267105</eveningPhone>
<cellPhone>7866267105</cellPhone>
<fax />
<email>ikea@ikea.com</email>
</orderCustomer>
<packages>
<package>
<packageNumber>100052253628</packageNumber>
<packageWeight>40.6175504</packageWeight>
<packageVolume>0.27566</packageVolume>
<palletNumber />
<mixedPallet>N/A</mixedPallet>
</package>
<package>
<packageNumber>100052253629</packageNumber>
<packageWeight>40.6175504</packageWeight>
<packageVolume>0.27566</packageVolume>
<palletNumber />
<mixedPallet>N/A</mixedPallet>
</package>
<package>
<packageNumber>100052253630</packageNumber>
<packageWeight>40.6175504</packageWeight>
<packageVolume>0.27566</packageVolume>
<palletNumber />
<mixedPallet>N/A</mixedPallet>
</package>
<package>
<packageNumber>100052253631</packageNumber>
<packageWeight>40.6175504</packageWeight>
<packageVolume>0.27566</packageVolume>
<palletNumber />
<mixedPallet>N/A</mixedPallet>
</package>
<package>
<packageNumber>100052253632</packageNumber>
<packageWeight>40.6175504</packageWeight>
<packageVolume>0.27566</packageVolume>
<palletNumber />
<mixedPallet>N/A</mixedPallet>
</package>
</packages>
<order>
<priceBu>207</priceBu>
<number>192286415</number>
<createDate>12/20/14</createDate>
<shipmentNo>100052253628</shipmentNo>
<departureNo>-</departureNo>
<departureDate>12/20/14 17:36</departureDate>
<status />
<deliveryDate>12/21/15 17:00</deliveryDate>
<deliveryDateFrom>12/21/15 17:00</deliveryDateFrom>
<deliveryDateTo>12/21/15 21:00</deliveryDateTo>
<cancelDate />
<createUserId />
<vehicleId />
</order>
<orderLines>
<orderLine>
<priceBu>207</priceBu>
<orderNumber />
<lineNumber>0</lineNumber>
<articleNumber>20293460</articleNumber>
<articleQuantity>0</articleQuantity>
<originalArticleQuantity>2</originalArticleQuantity>
<articlePackages />
<articleReferenceNumber />
<isOutOfStore />
<receivedDate />
<storageLocation />
<receiptDate />
<moveVehicleId />
<moveDate />
<languageCode />
<number>20293460</number>
<description>JÄPPLING chr Skinnarp dark brown NA</description>
<weight>65.0357</weight>
<volume>0.4357</volume>
</orderLine>
<orderLine>
<priceBu>207</priceBu>
<orderNumber />
<lineNumber>0</lineNumber>
<articleNumber>60100879</articleNumber>
<articleQuantity>0</articleQuantity>
<originalArticleQuantity>1</originalArticleQuantity>
<articlePackages />
<articleReferenceNumber />
<isOutOfStore />
<receivedDate />
<storageLocation />
<receiptDate />
<moveVehicleId />
<moveDate />
<languageCode />
<number>60100879</number>
<description>TULLSTA S chr Ransta dark gray NA</description>
<weight>28.6598</weight>
<volume>0.336</volume>
</orderLine>
<orderLine>
<priceBu>207</priceBu>
<orderNumber />
<lineNumber>0</lineNumber>
<articleNumber>70219137</articleNumber>
<articleQuantity>0</articleQuantity>
<originalArticleQuantity>1</originalArticleQuantity>
<articlePackages />
<articleReferenceNumber />
<isOutOfStore />
<receivedDate />
<storageLocation />
<receiptDate />
<moveVehicleId />
<moveDate />
<languageCode />
<number>70219137</number>
<description>TROPISK plant 12" tropical plant/assorted NA</description>
<weight>27.99842</weight>
<volume>0.1533</volume>
</orderLine>
<orderLine>
<priceBu>207</priceBu>
<orderNumber />
<lineNumber>0</lineNumber>
<articleNumber>20217305</articleNumber>
<articleQuantity>0</articleQuantity>
<originalArticleQuantity>1</originalArticleQuantity>
<articlePackages />
<articleReferenceNumber />
<isOutOfStore />
<receivedDate />
<storageLocation />
<receiptDate />
<moveVehicleId />
<moveDate />
<languageCode />
<number>20217305</number>
<description>KARDEMUMMA N plnt pot 12 ½" white/asst patterns</description>
<weight>16.358132</weight>
<volume>0.0177</volume>
</orderLine>
</orderLines>
<orderComment>
<priceBu>207</priceBu>
<orderNumber>192286415</orderNumber>
<createDate />
<commentCode>16</commentCode>
<commentValue>NO</commentValue>
<commentText />
<userId />
</orderComment>
<orderComment>
<priceBu>207</priceBu>
<orderNumber>192286415</orderNumber>
<createDate />
<commentCode>MERGED_WITH_ORDER</commentCode>
<commentValue>NO</commentValue>
<commentText />
<userId />
</orderComment>
</deliveryOrder>
</data>
</file>

肥皂信封

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ship="someurl">
<soapenv:Header/>
<soapenv:Body>
<ship:SendShipmentProcessRequest>
<!--Optional:-->
<ship:ShipmentProcessRequest>
<!--Optional:-->
<ship:ShipmentProcess>
<!--Optional:-->
<ship:DocumentType>?</ship:DocumentType>
<!--Optional:-->
<ship:Version>?</ship:Version>
<ship:CreateDate>?</ship:CreateDate>
<!--Optional:-->
<ship:Originator>?</ship:Originator>
<!--Optional:-->
<ship:TimeZone>?</ship:TimeZone>
<!--Optional:-->
<ship:DateFormat>?</ship:DateFormat>
<!--Optional:-->
<ship:CurrencyFormat>?</ship:CurrencyFormat>
<!--Optional:-->
<ship:WeightUnits>?</ship:WeightUnits>
<!--Optional:-->
<ship:LinearUnits>?</ship:LinearUnits>
<!--Optional:-->
<ship:PriceBuCode>?</ship:PriceBuCode>
<!--Optional:-->
<ship:RouteBuCode>?</ship:RouteBuCode>
<!--Optional:-->
<ship:ServiceProviderAbbreviation>?</ship:ServiceProviderAbbreviation>
<!--Optional:-->
<ship:ServiceProviderId>?</ship:ServiceProviderId>
<!--Optional:-->
<ship:Origin>?</ship:Origin>
<!--Optional:-->
<ship:Destination>?</ship:Destination>
<!--Optional:-->
<ship:DeliveryOrders>
<!--Zero or more repetitions:-->
<ship:DeliveryOrder>
<!--Optional:-->
<ship:DeliveryMethod>?</ship:DeliveryMethod>
<!--Optional:-->
<ship:SACId>?</ship:SACId>
<!--Optional:-->
<ship:Operation>?</ship:Operation>
<!--Optional:-->
<ship:DeliveryType>?</ship:DeliveryType>
<ship:IsExchange>?</ship:IsExchange>
<ship:IsMerge>?</ship:IsMerge>
<!--Optional:-->
<ship:MergeOrderNumber>?</ship:MergeOrderNumber>
<ship:TotalArticleQuantity>?</ship:TotalArticleQuantity>
<ship:TotalArticlePackages>?</ship:TotalArticlePackages>
<ship:TotalArticleWeight>?</ship:TotalArticleWeight>
<ship:TotalArticleVolume>?</ship:TotalArticleVolume>
<!--Optional:-->
<ship:BusinessUnit>
<!--Optional:-->
<ship:Code>?</ship:Code>
<!--Optional:-->
<ship:CountryCode>?</ship:CountryCode>
<!--Optional:-->
<ship:LanguageCode>?</ship:LanguageCode>
<!--Optional:-->
<ship:Name>?</ship:Name>
<!--Optional:-->
<ship:Phone>?</ship:Phone>
<!--Optional:-->
<ship:Text>?</ship:Text>
<!--Optional:-->
<ship:TimeZone>?</ship:TimeZone>
<ship:DaylightSavings>?</ship:DaylightSavings>
</ship:BusinessUnit>
<!--Optional:-->
<ship:OrderCustomer>
<!--Optional:-->
<ship:PriceBu>?</ship:PriceBu>
<!--Optional:-->
<ship:OrderNumber>?</ship:OrderNumber>
<!--Optional:-->
<ship:Type>?</ship:Type>
<!--Optional:-->
<ship:CustomerName>?</ship:CustomerName>
<!--Optional:-->
<ship:Addr1>?</ship:Addr1>
<!--Optional:-->
<ship:Addr2>?</ship:Addr2>
<!--Optional:-->
<ship:Addr3>?</ship:Addr3>
<!--Optional:-->
<ship:City>?</ship:City>
<!--Optional:-->
<ship:State>?</ship:State>
<!--Optional:-->
<ship:ZipCode>?</ship:ZipCode>
<!--Optional:-->
<ship:CountryCode>?</ship:CountryCode>
<!--Optional:-->
<ship:DayPhone>?</ship:DayPhone>
<!--Optional:-->
<ship:EveningPhone>?</ship:EveningPhone>
<!--Optional:-->
<ship:CellPhone>?</ship:CellPhone>
<!--Optional:-->
<ship:Fax>?</ship:Fax>
<!--Optional:-->
<ship:Email>?</ship:Email>
</ship:OrderCustomer>
<!--Optional:-->
<ship:OrderSource>
<!--Optional:-->
<ship:OrderNumber>?</ship:OrderNumber>
<!--Optional:-->
<ship:Type>?</ship:Type>
<!--Optional:-->
<ship:FirstName>?</ship:FirstName>
<!--Optional:-->
<ship:LastName>?</ship:LastName>
<!--Optional:-->
<ship:Addr1>?</ship:Addr1>
<!--Optional:-->
<ship:Addr2>?</ship:Addr2>
<!--Optional:-->
<ship:Addr3>?</ship:Addr3>
<!--Optional:-->
<ship:City>?</ship:City>
<!--Optional:-->
<ship:State>?</ship:State>
<!--Optional:-->
<ship:ZipCode>?</ship:ZipCode>
<!--Optional:-->
<ship:CountryCode>?</ship:CountryCode>
<!--Optional:-->
<ship:DayPhone>?</ship:DayPhone>
<!--Optional:-->
<ship:EveningPhone>?</ship:EveningPhone>
<!--Optional:-->
<ship:CellPhone>?</ship:CellPhone>
<!--Optional:-->
<ship:Fax>?</ship:Fax>
<!--Optional:-->
<ship:Email>?</ship:Email>
</ship:OrderSource>
<ship:HasPackages>?</ship:HasPackages>
<!--Optional:-->
<ship:Packages>
<!--Zero or more repetitions:-->
<ship:Package>
<!--Optional:-->
<ship:PackageNumber>?</ship:PackageNumber>
<ship:PackageWeight>?</ship:PackageWeight>
<ship:PackageVolume>?</ship:PackageVolume>
<!--Optional:-->
<ship:PalletNumber>?</ship:PalletNumber>
<!--Optional:-->
<ship:MixedPallet>?</ship:MixedPallet>
</ship:Package>
</ship:Packages>
<!--Optional:-->
<ship:Order>
<!--Optional:-->
<ship:PriceBu>?</ship:PriceBu>
<!--Optional:-->
<ship:Number>?</ship:Number>
<!--Optional:-->
<ship:IdentifierKey>?</ship:IdentifierKey>
<ship:CreateDate>?</ship:CreateDate>
<!--Optional:-->
<ship:BOLNo>?</ship:BOLNo>
<!--Optional:-->
<ship:DepartureNo>?</ship:DepartureNo>
<ship:DepartureDate>?</ship:DepartureDate>
<!--Optional:-->
<ship:Status>?</ship:Status>
<ship:HasDeliveryDate>?</ship:HasDeliveryDate>
<ship:DeliveryDate>?</ship:DeliveryDate>
<ship:DeliveryDateFrom>?</ship:DeliveryDateFrom>
<ship:DeliveryDateTo>?</ship:DeliveryDateTo>
<ship:CancelDate>?</ship:CancelDate>
<!--Optional:-->
<ship:CreateUserId>?</ship:CreateUserId>
<ship:UpdateDate>?</ship:UpdateDate>
<!--Optional:-->
<ship:UpdateUserId>?</ship:UpdateUserId>
<!--Optional:-->
<ship:VehicleId>?</ship:VehicleId>
<ship:HasOrderLines>?</ship:HasOrderLines>
<!--Optional:-->
<ship:OrderLines>
<!--Zero or more repetitions:-->
<ship:OrderLine>
<!--Optional:-->
<ship:PriceBu>?</ship:PriceBu>
<!--Optional:-->
<ship:OrderNumber>?</ship:OrderNumber>
<ship:LineNumber>?</ship:LineNumber>
<!--Optional:-->
<ship:ArticleNumber>?</ship:ArticleNumber>
<ship:ArticleQuantity>?</ship:ArticleQuantity>
<ship:OriginalArticleQuantity>?</ship:OriginalArticleQuantity>
<ship:ArticlePackages>?</ship:ArticlePackages>
<!--Optional:-->
<ship:ArticleReferenceNumber>?</ship:ArticleReferenceNumber>
<ship:IsOutOfStore>?</ship:IsOutOfStore>
<ship:ReceivedDate>?</ship:ReceivedDate>
<!--Optional:-->
<ship:StorageLocation>?</ship:StorageLocation>
<ship:ReceiptDate>?</ship:ReceiptDate>
<!--Optional:-->
<ship:MoveVehicleId>?</ship:MoveVehicleId>
<ship:MoveDate>?</ship:MoveDate>
<!--Optional:-->
<ship:Description>?</ship:Description>
<ship:Weight>?</ship:Weight>
<ship:Volume>?</ship:Volume>
</ship:OrderLine>
</ship:OrderLines>
<ship:HasOrderComments>?</ship:HasOrderComments>
<!--Optional:-->
<ship:OrderComments>
<!--Zero or more repetitions:-->
<ship:OrderComment>
<!--Optional:-->
<ship:PriceBu>?</ship:PriceBu>
<!--Optional:-->
<ship:OrderNumber>?</ship:OrderNumber>
<ship:CreateDate>?</ship:CreateDate>
<!--Optional:-->
<ship:CommentCode>?</ship:CommentCode>
<!--Optional:-->
<ship:CommentText>?</ship:CommentText>
<!--Optional:-->
<ship:UserId>?</ship:UserId>
</ship:OrderComment>
</ship:OrderComments>
</ship:Order>
<ship:HasOrderSourceAddress>?</ship:HasOrderSourceAddress>
<ship:UseSourceAddressLookup>?</ship:UseSourceAddressLookup>
<!--Optional:-->
<ship:SourceAddressLookupCode>?</ship:SourceAddressLookupCode>
</ship:DeliveryOrder>
</ship:DeliveryOrders>
</ship:ShipmentProcess>
</ship:ShipmentProcessRequest>
</ship:SendShipmentProcessRequest>
</soapenv:Body>
</soapenv:Envelope>

最佳答案

如果您想从 Mule 流中调用外部 Web 服务,并且您的输入是 xml(不是肥皂信封),则可以使用 CXF Web 服务客户端 ( jaxws-client ) :-

<flow name="ClientFlow" doc:name="ClientFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="mainData/client" doc:name="HTTP"/>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" path="mainData" doc:name="HTTP">
<cxf:jaxws-client doc:name="SOAP" serviceClass="com.test.services.schema.maindata.v1.MainData" operation="insertDataOperation" port="MainDataPort" />
</http:outbound-endpoint>
</flow>

更新答案:-好的..您可以做的很简单..您可以根据输入xml创建一个SOAP请求,并通过http出站端点发布将其发送到外部Web服务 ..

例如,让我的输入 xml 为:-

    <GetCityForecastByZIP>
<zip>12004</zip>
</GetCityForecastByZIP>

让我的实际 SOAP 请求是:-

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:weat="http://ws.cdyne.com/WeatherWS/">
<soapenv:Header/>
<soapenv:Body>
<weat:GetCityForecastByZIP>
<weat:ZIP>12004</weat:ZIP>
</weat:GetCityForecastByZIP>
</soapenv:Body>
</soapenv:Envelope>

现在我要做的是,在我的流程中创建上述 SOAP 请求,并通过 http 出站端点发布请求

我将提取值<zip>12004</zip>使用 XPATH 从我的输入 xml 中的 变量 并将值放入 <weat:ZIP>12004</weat:ZIP> 中通过以下方式处理 SOAP 请求:-

<flow name="ClientFlow" doc:name="ClientFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="mainData/client" doc:name="HTTP"/>
<set-payload value="&lt;GetCityForecastByZIP&gt;&lt;zip&gt;12004&lt;/zip&gt;&lt;/GetCityForecastByZIP&gt;" doc:name="Set Payload"/>
<set-variable variableName="Id" value="#[xpath('//GetCityForecastByZIP/zip').text]" doc:name="Variable"/>
<set-payload value="&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:weat=&quot;http://ws.cdyne.com/WeatherWS/&quot;&gt;&lt;soapenv:Header/&gt;&lt;soapenv:Body&gt;&lt;weat:GetCityForecastByZIP&gt;&lt;weat:ZIP&gt;#[flowVars['id']]&lt;/weat:ZIP&gt;&lt;/weat:GetCityForecastByZIP&gt;&lt;/soapenv:Body&gt;&lt;/soapenv:Envelope&gt;" doc:name="Set Payload"/>
<http:outbound-endpoint exchange-pattern="request-response" doc:name="HTTP" method="POST" address="http://wsf.cdyne.com/WeatherWS/Weather.asmx" contentType="text/xml"/>
<logger message="Soap Response:- #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
</flow>

现在,让我解释一下我做了什么......

看这里,我有一个 input.xml,我将其设置为 Http 入站端点之后的有效负载。

现在,我使用 xpath #[xpath('//GetCityForecastByZIP/zip').text] 从输入负载中提取了 Id 的值并放入名为 Id 的变量 ..

在下一步中,我将为我的网络服务创建一个 soap 请求,其中我使用其中提取的变量 Id 来代替 <weat:ZIP>12004</weat:ZIP>肥皂请求...

最后,我通过 http 出站端点发布整个 SOAP 请求..

这个过程很简单,您可以轻松实现..点击网址 http://localhost:8081/mainData/client在浏览器中

希望这对您有帮助

关于java - 如何在没有datamapper的情况下在Mule中调用soap webservice,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28791196/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com