如何在没有datamapper的情况下调用mule中的soap webservice

时间:2015-03-01 07:30:17

标签: java mule jax-ws esb

如何在没有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。消息有效内容的类型为:ContentLengthInputStream java.lang.ClassCastException:org.apache.commons.httpclient.ContentLengthInputStream无法强制转换为java.lang.String     at com.cdyne.ws.weatherws.GetCityForecastByZIP_WrapperTypeHelper1.createWrapperObject(Unknown Source)     at 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>

2 个答案:

答案 0 :(得分:2)

如果您想从Mule流程调用外部Web服务,并且您的输入是xml(而不是soap信封),则可以使用CXF Web服务客户端( jaxws-client ): - < / p>

<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>

更新的答案: - 好的......您可以做的很简单..您可以通过 http出站端点从输入xml创建SOAP请求并发布外部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出站端点发布请求

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

<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来放置{{1}肥皂要求......

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

此过程很简单,您可以轻松实现。在浏览器中点击网址<weat:ZIP>12004</weat:ZIP>

希望这会对你有所帮助

答案 1 :(得分:1)

使用xslt转换器,通过编写形成soap请求的相应xsl文件,该文件将配置为xslt转换器。

xslt变换器使用定义的Web服务地址调用http-outbound后。