Web Service Consumer Anypoint Studio (CE runtime): How to pass params? - web-services

I need to pass params on Web Service/SOAP calls.
I am using Web Service Consumer in Anypoint Studio (needs run on Mule CE - Community Edition), but I received the following message: "Operation messages with more than 1 part are not supported"
Is there a form to call Web Service/SOAP on Mule CE passing params?
Thanks for any help/examples!
EDIT:
Accord comment, I am testing a calculator web service, in SoapUI return result OK, but in mule return 0.
I am passing the params with Set Payload component. I setted the value with "xml request" returned on SoapUI.
Following the XML code.
<ws:consumer-config name="Web_Service_Consumer1" wsdlLocation="http://www.dneonline.com/calculator.asmx?WSDL" service="Calculator" port="CalculatorSoap12" serviceAddress="http://www.dneonline.com/calculator.asmx" doc:name="Web Service Consumer"/>
<flow name="calculadora-soap-publicoFlow">
<poll doc:name="Poll">
<set-payload value="<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/"> <soap:Header/> <soap:Body> <tem:Add> <tem:intA>3</tem:intA> <tem:intB>2</tem:intB> </tem:Add> </soap:Body> </soap:Envelope>" doc:name="Set Payload"/>
</poll>
<ws:consumer config-ref="Web_Service_Consumer1" operation="Add" doc:name="Web Service Consumer"/>
<json:xml-to-json-transformer doc:name="XML to JSON"/>
<logger level="INFO" doc:name="Logger" message="#[message.payload]"/>
</flow>
Where could be the problem? Thanks!

I found how it works.
We need to pass Web Service Consumer it´s just params, does not full XML envelop. Following the value of the Set Payload just params:
<ns0:Add xmlns:ns0="http://tempuri.org/">
<ns0:intA>1</ns0:intA>
<ns0:intB>3</ns0:intB>
</ns0:Add>

Related

Axis web service consumer and Mule 3.6

I'm going to try latest mule runtime to consume an old Axis web service.
Just trying to use "Web service consumer" component without success.
My first try on a method without parameters result in
org.apache.cxf.interceptor.Fault: Failed to load transport: org/mule/transport axis (org.mule.api.registry.ServiceException). Message payload is of type: MuleUniversalConduit$1
at org.mule.module.cxf.transport.MuleUniversalConduit$2.handleMessage(MuleUniversalConduit.java:194) ~[mule-module-cxf-3.6.1.jar:3.6.1]
...
this is my actual config
mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:tls="http://www.mulesoft.org/schema/mule/tls"
xmlns:ws="http://www.mulesoft.org/schema/mule/ws" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.6.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/tls http://www.mulesoft.org/schema/mule/tls/current/mule-tls.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ws http://www.mulesoft.org/schema/mule/ws/current/mule-ws.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd">
<tls:context name="MyWSTLS_Context" doc:name="TLS Context">
<tls:trust-store path="trustStore/truststore.ts" password="secret"/>
<tls:key-store path="trustStore/keystore.jks" password="secret" keyPassword="toosecret"/>
</tls:context>
<ws:consumer-config name="MyWS_WS_getVersion_Consumer" wsdlLocation="Version.wsdl" service="VersionService" port="Version" serviceAddress="axis:http://staging.myws.com/myws/services/Version" doc:name="Web Service Consumer" connectorConfig="HTTPS_MyWSRequest_Configuration"/>
<http:request-config name="HTTPS_MyWSRequest_Configuration" protocol="HTTPS" host="staging.myws.com" port="443" basePath="/MyWS/services" doc:name="HTTP Request Configuration" tlsContext-ref="MyWSTLS_Context"/>
<http:listener-config name="MyWS_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="wsconsumerFlow">
<http:listener config-ref="MyWS_Listener_Configuration" path="/consumer" doc:name="HTTP"/>
<ws:consumer config-ref="MyWS_WS_getVersion_Consumer" operation="getVersion" doc:name="Web Service Consumer"/>
<logger level="INFO" doc:name="Logger"/>
</flow>
</mule>
The service is an rpc style an requires array of strings as parameters.
Any hint appreciated.
The deprecated but still shipped for backwards compatibility transport for axis is getting into your way.
Just change the axis: from the service address, hopefully it should work if there are no other problems.

How to pass a file as SOAP request to Mule SOAP client to consume service

I have a flow which is exposing a webservice :-
<flow name="ServiceFlow" doc:name="ServiceFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" path="mainData" doc:name="HTTP"/>
<cxf:jaxws-service serviceClass="com.test.services.schema.maindata.v1.MainData" doc:name="SOAP"/>
<component class="com.test.services.schema.maindata.v1.Impl.MainDataImpl" doc:name="JavaMain_ServiceImpl"/>
</flow>
This web service have a operation insertDataOperation which takes all the input from SOAP request and insert it in Database...
My SOAP request is as follow :-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://services.test.com/schema/MainData/V1">
<soapenv:Header/>
<soapenv:Body>
<v1:insertDataRequest>
<v1:Id>311</v1:Id>
<v1:Name>ttttt</v1:Name>
<v1:Age>56</v1:Age>
<v1:Designation>eeeee</v1:Designation>
</v1:insertDataRequest>
</soapenv:Body>
</soapenv:Envelope>
Now I have another web service client flow which is consuming this webservice and the flow is :-
<flow name="ClientFlow" doc:name="ClientFlow">
<file:inbound-endpoint responseTimeout="10000" connector-ref="File_Global" doc:name="File" path="E:\backup\test">
<file:filename-regex-filter pattern="SoapRequestInsert.xml" caseSensitive="false"/>
</file:inbound-endpoint>
<file:file-to-string-transformer encoding="UTF-8" mimeType="text/xml" doc:name="File to String"/>
<cxf:jaxws-client doc:name="SOAP" serviceClass="com.test.services.schema.maindata.v1.MainData" operation="insertDataOperation" port="MainDataPort" />
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" path="mainData" doc:name="HTTP"/>
</flow>
Now here I am trying to consume the webservice by using a file inbound endpoint and passing the SOAP request in the file SoapRequestInsert.xml .. But the issue is that I don't get any error but the data is not inserted in database.. I checked the log .. where I found it enters the insert method of webservice implementation class but it doesn't get the input value ... Please help ... I have taken the reference from the following :- Consuming a JAX-WS in a Mule ESB flow
But It's not working .. what should I do to make it consume successfully and insert into DB ??? Pls help
Because the file you are posting contains the whole SOAP envelope you can HTTP POST it as is:
<flow name="ClientFlow" doc:name="ClientFlow">
<file:inbound-endpoint responseTimeout="10000" connector-ref="File_Global" doc:name="File" path="E:\backup\test">
<file:filename-regex-filter pattern="SoapRequestInsert.xml" caseSensitive="false"/>
</file:inbound-endpoint>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" path="mainData" doc:name="HTTP"/>
</flow>
Note that you may need to add the SOAP action header, before the http:outbound-endpoint:
<set-property name="SOAPAction"
value="http://services.test.com/schema/MainData/V1/insertDataOperation" />
The final working solution is as David suggested the flow and by setting SOAPAction before outbound endpoint :-
<set-property name="SOAPAction"
value="http://services.test.com/schema/MainData/V1/insertDataOperation" />

To consume a web service with multiple input arguments in mule

I'm a beginner, I have a mule flow, in which i would like to call SOAP web service operation which has 4 input arguments
"public double calculateInterest(double principal, double year, double rate, int appid)".
I tried using a file or http endpoint where i end up in String array, or object array while using set payload.
the exception thrown is
cannot be cast to java.lang.Double. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of type: String[]
Could somebody suggest the best way to do it.
you can configure file or http inbound, write a java component (remove cxf component), extract parameters from payload, cast in the required type and call web-service method from the component.
see here is an example of a simple webservice :-
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="CE-3.3.0" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd ">
<flow name="getCalculationFlow1" doc:name="getCalculationFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="getCalculation" doc:name="HTTP"/>
<cxf:jaxws-service serviceClass="com.services.getcalculation.v1.GetCalculation" doc:name="SOAP"/>
<component class="com.services.schema.getcalculation.v1.GetCalculationImpl" doc:name="Java"/>
</flow>
</mule>
where com.services.getcalculation.v1.GetCalculation is the webservice class which is generated using Apache CXF from WSDL files and com.services.schema.getcalculation.v1.GetCalculationImpl is the implemantation class of webservice ... hope this help

Consuming a Webservice Using Mule 3.4

I am trying to consume a webservice produced on by following the tutorials in the mule Documentation. have been able to build the webservice successfully, but having issues consuming it. I have two Java Clasess "HelloWorld" and "HelloWorldImpl". This is my flow
<flow name="helloService" doc:name="helloService">
<http:inbound-endpoint address="http://localhost:63081/hello" exchange-pattern="request-response" doc:name="HTTP">
<cxf:jaxws-service serviceClass="com.test.HelloWorld"/>
</http:inbound-endpoint>
<component class="com.test.HelloWorldImpl" doc:name="Java"/>
<cxf:jaxws-client serviceClass="com.test.HelloWorld" operation="sayHi" doc:name="SOAP" />
<outbound-endpoint address="http://localhost:63081/services/greeter" doc:name="Generic"/>
</flow>
What am I doing wrong?
When I access the outbound endpoint I get
Cannot bind to address "http://activate.adobe.com:63081/services/greeter" No component registered on that endpoint
You have to make your endpoint accept all sub-paths and then handle wrong ones with message routing:
Example:
<flow name="jfeed_fill_data">
<http:inbound-endpoint address="http://localhost:1212" />
<choice>
<when evaluator="header" expression="INBOUND:http.request.path=/jcore/insert/feed/">
<component class="main.java.com.joshlabs.jcore.Feed"/>
</when>
<otherwise>
<message-properties-transformer>
<add-message-property key="http.status" value="404"/>
</message-properties-transformer>
<expression-transformer>
<return-argument evaluator="string" expression="{Exception: "Invalid URL"}"/>
</expression-transformer>
</otherwise>
</choice>
</flow>
First issue: How can there be two services running on the same port (63081) on your localhost.
http://localhost:63081/hello
http://localhost:63081/services/greeter
Also As mentioned in your post, the web-service you have created is Hello service with the endpoint
http://localhost:63081/hello
So you web sevice should be as follows.
<flow name="helloService" doc:name="helloService">
<http:inbound-endpoint address="http://localhost:63081/hello" exchange-pattern="request-response" doc:name="HTTP">
<cxf:jaxws-service serviceClass="com.test.HelloWorld"/>
</http:inbound-endpoint>
<component class="com.test.HelloWorldImpl" doc:name="Java"/>
</flow>
In order to consume you can write another flow which has got the cxf:jaxws-client
<flow name="helloclient" >
<some inbound endpoint. >
....
<cxf:jaxws-client serviceClass="com.test.HelloWorld" operation="sayHi" doc:name="SOAP" />
<outbound-endpoint address="http://localhost:63081/hello" doc:name="Generic"/>
.....
</flow>
Hope this helps.
Your inbound endpoint is http://localhost:63081/hello which is the address you should call to consume your webservice.
Also your outbound endpoint seems to point to a address where there is no webservice to consume. Unless you have a second flow in your mule config that you do not show.
You've defined a flow which has a listener on service end-point http://localhost:63081/hello. In this flow request comes in and then it is forwarded using jaxws-client to another service listening at http://localhost:63081/services/greeter.
Now the error message says Cannot bind to address which means it cannot call the end-point. Is there a service running anywhere at the end-point you're trying to send request to? If you want to send request locally as look like from your flow, then you need another flow listening at that end-point similar to one you have but with different http-endpoint

ReplyTo property missing in SOAPHeader

I have created a WS-BPEL workflow that would call an asynchronous web service and wait for a callback response. The carbon application is successfully deployed into BPS as well.
Details on my external Asynchronous web service
1. It requires basic authentication over http.
2. It requires the soap header to be available in the soap envelope.
3. It would process the request and send a callback to the ReplyTo address it receives in the soap header and use the MessageID to correlate the callback.
My deploy.xml file for the BPEL process looks like this ...
<?xml version="1.0" encoding="UTF-8"?>
<deploy xmlns="http://www.apache.org/ode/schemas/dd/2007/03"
xmlns:callback.integration.service="http://callback.integration.service/"
xmlns:epr="http://wso2.org/bps/bpel/endpoint/config"
xmlns:sample="http://wso2.org/bps/sample"
xmlns:ws.integration.service="http://ws.integration.service/">
<process name="sample:Test">
<active>true</active>
<retired>false</retired>
<process-events generate="all"/>
<provide partnerLink="client">
<service name="sample:Test" port="TestPort"/>
</provide>
<provide partnerLink="IntegrationService">
<service name="callback.integration.service:IntegrationCallback" port="IntegrationResponsePort"/>
</provide>
<invoke partnerLink="IntegrationService">
<service name="ws.integration.service:IntegrationService" port="IntegrationRequestPort">
<epr:endpoint endpointReference="IntegrationService.epr"/>
</service>
</invoke>
</process>
</deploy>
The IntegrationService.epr file looks like this ...
<wsa:EndpointReference
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com uep_schema.xsd"
xmlns:wsa="http://www.w3.org/2005/08/addressing"
xmlns:wsdl11="http://schemas.xmlsoap.org/wsdl/">
<wsa:Address>http://http://server:8080/integration/IntegrationService</wsa:Address>
<wsa:Metadata>
<id>SInvokeEPR</id>
<qos>
<enableAddressing />
</qos>
<transport type="http">
<authorization-username>username</authorization-username>
<authorization-password>password</authorization-password>
</transport>
</wsa:Metadata>
</wsa:EndpointReference>
Now when I test the bpel process from carbon service management console, I do get a request to my asynchronous web service. However the soap envelope looks as followed and it is missing a proper ReplyTo address to send the callback.
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:To>http://server:8080/integration/IntegrationService</wsa:To>
<wsa:ReplyTo>
<wsa:Address>http://www.w3.org/2005/08/addressing/none</wsa:Address>
</wsa:ReplyTo>
<wsa:MessageID>urn:uuid:91ac4ebd-b100-440e-a01d-c4a5c0d8a56f</wsa:MessageID>
<wsa:Action>http://ws.integration.service/IntegrationRequestPortType/createTask</wsa:Action>
</soapenv:Header>
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope>
Now my need is to reply to this request with a callback. The callback soap envelope would contain this MessageID so that the callback correlates with the correct process instance.
How do you get the proper ReplyTo address appended to the soap header?
If I assume correctly you use the WSO2 BPS (or something with Apache ODE), you can use this copy in an assign to set the Header by hand. (http://ode.apache.org/extensions/headers-handling.html)
<bpel:copy>
<bpel:from>
<bpel:literal>
<wsa:ReplyTo xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Address>http://localhost:9763/services/SIServerCallback</Address>
</wsa:ReplyTo>
</bpel:literal>
</bpel:from>
<bpel:to variable="ServiceInvokerIARequest" header="ReplyTo">
</bpel:to>
</bpel:copy>