chetan singhal
chetan singhal

Reputation: 948

how to call soap webservice in mule without datamapper

how to call soap webservice in mule without datamapper and input is xml. I am using community addition. & my input is xml not soap envelope.

My wsdl location is - http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL Input is -

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

Flow -

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

Getting error org.apache.commons.httpclient.ContentLengthInputStream cannot be cast to java.lang.String. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of type: ContentLengthInputStream java.lang.ClassCastException: org.apache.commons.httpclient.ContentLengthInputStream cannot be cast to java.lang.String at com.cdyne.ws.weatherws.GetCityForecastByZIP_WrapperTypeHelper1.createWrapperObject(Unknown Source) at org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor.handleMessage(WrapperClassOutInterceptor.java:100) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)

Request 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>[email protected]</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>

Soap Envelope

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

Upvotes: 0

Views: 1248

Answers (2)

Mohan
Mohan

Reputation: 520

use xslt transformer,by writing corresponding xsl file which forms soap request which will be configured to xslt transformer.

After xslt transformer call http-outbound with defined web-service address.

Upvotes: 1

Anirban Sen Chowdhary
Anirban Sen Chowdhary

Reputation: 8321

If you want to call an external web service from your Mule flow and if your input is an xml (not soap envelope) , you can use CXF webservice client ( 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>

UPDATED ANSWER :- OK.. what you can do is simple .. you can create a SOAP request out of your input xml and post it to the external webservice through http outbound endpoint..

for example let my input xml is :-

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

and let my actual SOAP request is :-

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

Now what I will do is, I will create the above SOAP request in my flow and post the request through http outbound endpoint

I will extract the value <zip>12004</zip> from my input xml in a variable using XPATH and put the value in <weat:ZIP>12004</weat:ZIP> of SOAP request by the following way :-

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

Now, let me explain what I did...

See here , I have a input.xml which I set here as payload after Http inbound endpoint.

Now, I extracted the value of Id from input payload using xpath #[xpath('//GetCityForecastByZIP/zip').text] and put into the variable called Id ..

In the next step I am creating a soap request for my webservice where I have used the extracted variable Id in it to put in the place of <weat:ZIP>12004</weat:ZIP> of soap request ...

And finally I am posting the entire SOAP request over http outbound endpoint ..

This process is simple and you can achieve it easily .. Hit the url http://localhost:8081/mainData/client in a browser

Hope this will help you

Upvotes: 2

Related Questions