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
Related
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.
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" />
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
I just have a little experience with Mule ESB 3.5, and I found that most of Mule examples only create SOAP Web Service with one parameter. For example, you can see that in SOAP Web Service Security example.
http://www.mulesoft.org/documentation/display/current/SOAP+Web+Service+Security+Example
So I have one question, acroding to above example, after using CHOICE flow control, how to pass multi parameter to method of SOAP web service.
Some suggests for me is to use object array to pass multi parameter, but I still have no clue at all.
Thanks to David. I just try your suggestion. But I think I should update my question to make it clearly.
Firstly, I create web service
#WebService
public interface Greeter
{
public String greet(String name);
public String welcome( String name1,String name2);
}
Then I have a control flow for web service configuration
<flow name="UnsecureServiceFlow" doc:name="UnsecureServiceFlow">
<http:inbound-endpoint address="http://localhost:63081/services/unsecure" exchange-pattern="request-response" doc:name="HTTP Inbound Endpoint"/>
<cxf:jaxws-service serviceClass="com.mulesoft.mule.example.security.Greeter" doc:name="Unsecure service"/>
<component class="com.mulesoft.mule.example.security.GreeterService" doc:name="Greeter Service" />
</flow>
Next is the sub flow using jax-ws client to call the method of web service
<flow name="SecurityClients" doc:name="SecurityClients">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="63080" path="client" doc:name="HTTP Inbound Endpoint"/>
<set-payload value="#[message.inboundProperties['http.query.params']['name']]" doc:name="Set payload with 'name' query param"/>
<set-variable variableName="clientType" value="#[message.inboundProperties['http.query.params']['clientType']]" doc:name="Set clientType"/>
<choice doc:name="Choice">
<when expression="#[clientType == 'unsecure']">
<flow-ref name="unsecure" doc:name="Invoke unsecure sub-flow"/>
</when>
<when expression="#[clientType == 'usernameToken']">
<flow-ref name="usernameToken" doc:name="Invoke usernameToken sub-flow"/>
</when>
<when expression="#[clientType == 'usernameTokenSigned']">
<flow-ref name="usernameTokenSigned" doc:name="Invoke usernameToken Signed sub-flow"/>
</when>
<when expression="#[clientType == 'usernameTokenEncrypted']">
<flow-ref name="usernameTokenEncrypted" doc:name="Invoke usernameToken Encrypted sub-flow"/>
</when>
<when expression="#[clientType == 'samlToken']">
<flow-ref name="samlToken" doc:name="Invoke samlToken sub-flow"/>
</when>
<when expression="#[clientType == 'samlTokenSigned']">
<flow-ref name="samlTokenSigned" doc:name="Invoke samlToken Signed sub-flow"/>
</when>
<otherwise>
<set-payload value="Client type is not supported" doc:name="Client type is not supported"/>
</otherwise>
</choice>
<set-property propertyName="Content-Type" value="text/plain" doc:name="Set response Content-Type"/>
<catch-exception-strategy doc:name="Catch Exception Strategy">
<set-payload value="There has been an Error processing the request" doc:name="Set Payload"/>
<set-property propertyName="Content-Type" value="text/plain" doc:name="Set response Content-Type"/>
</catch-exception-strategy>
</flow>
<sub-flow name="unsecure" doc:name="unsecure">
<cxf:jaxws-client operation="greet" serviceClass="com.mulesoft.mule.example.security.Greeter" doc:name="Unsecure SOAP client" doc:description="Unsecure SOAP client"/>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="63081" path="services/unsecure" doc:name="Invoke unsecure Web Service"/>
</sub-flow>
It's ok to use that address to invoke greet method, it only has one parameter.
localhost:63080/client?clientType=usernameToken&name=John
However when I change greet method to welcome method, I do not know how to pass more parameter to it or have to change anything , because payload only contains name parameter
Generate the JAX-WS client classes from the remote web service WSDL and use them in a cxf:jaxws-client configuration element.
In your case, you need to set-payload inside each when in order to create the request object that is needed by cxf:jaxws-client.
Suppose that you need to create a org.saml.SamlToken object for the samlToken case, you would do:
<set-payload value="#[st=new org.saml.SamlToken();st.field1=message.inboundProperties.field1; ... ; st]" />
in the when right before flow-ref.
PS. You can use #[message.inboundProperties.clientType] instead of #[message.inboundProperties['http.query.params']['clientType']]
I'am using Mule Community Edition 3.4.
I have a problem with the UntilSuccessful component. The scenario is now exposed:
I have a flow composed by a UntilSuccessful component in which there's a SOAP component that makes a request to a Web Service. In this flow there is an ExcpetionStrategy, too. The problem that I have is that when an exception occurs inside the UntilSuccessful (i.e in the SOAP component) the ExcpetionStrategy is not able to handle it because it (the Exception thrown) is handled by some mechanism inside the UntilSuccessful component.
Because I need to handle the Exception in the ExcpetionStrategy, I thought to build a custom outbound interceptor (inside the SOAP component) that intercept the SOAP response (an exception if it's thrown) and that is able to throw an Exception in order to trigger the ExcpetionStrategy.
Could anyone help me with this problem? I tried to read the documentation but it is sparse and does not explain very well how to build a custom outbound exception.
What I would to do is to save somewhere the name of Exception thrown (i.e if server thrown a NumberFormatException, I would save its name somewhere in order to use it in the ExceptionStrategy)
Below you can see a snippet of mule configuration file:
<flow name="ProvaClient" doc:name="ProvaClient">
<quartz:inbound-endpoint jobName="TalendJob" repeatInterval="5000" repeatCount="0" responseTimeout="10000" doc:name="Quartz">
<quartz:event-generator-job>
<quartz:payload>error</quartz:payload>
</quartz:event-generator-job>
</quartz:inbound-endpoint>
<object-to-string-transformer doc:name="Object to String"/>
<until-successful objectStore-ref="OS_Bean" maxRetries="2" secondsBetweenRetries="2" doc:name="Until Successful" deadLetterQueue-ref="myQueue">
<processor-chain doc:name="Processor Chain: Wait For Web Service Response">
<processor-chain doc:name="Processor Chain: Web Service">
<cxf:jaxws-client operation="getCode" clientClass="it.aizoon.prova.client.ProvaService" port="ProvaPort" enableMuleSoapHeaders="true" doc:name="SOAP">
</cxf:jaxws-client>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="service/prova" method="POST" doc:name="HTTP"/>
</processor-chain>
<logger message="PAYLOAD: #[payload]" level="INFO" doc:name="Logger"/>
</processor-chain>
</until-successful>
<catch-exception-strategy doc:name="Catch Exception Strategy">
<!-- <processor ref="myExceptionHandler_id"/> -->
<logger message="EXCEPTION STRATEGY" level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
</flow>
Here you can see the server which exposes a web service:
<flow name="provaServer" doc:name="provaServer">
<http:inbound-endpoint exchange-pattern="request-response" doc:name="HTTP" host="localhost" path="service/prova" port="8081"/>
<logger message="SERVER" level="INFO" doc:name="Logger"/>
<cxf:jaxws-service serviceClass="it.aizoon.prova.Prova" doc:name="Process SOAP Request" />
<component class="it.aizoon.prova.ProvaImpl" doc:name="Java"/>
</flow>
And here there is the ProvaImpl.java, the implementation of Web Service. How you can see, if the string passed as argument in getCode() function is error, an exception in thrown and I would that it is managed by the exception strategy defined in the client
#WebService(endpointInterface = "it.aizoon.prova.Prova",
serviceName = "Prova")
public class ProvaImpl implements Prova{
#Override
public String getCode(String code) throws NumberFormatException{
// TODO Auto-generated method stub
if(code.equals("error")) throw new NumberFormatException();
String str = "Andato a buon fine!";
return str;
}
}
I would change the approach rather than using an interceptor. If you need to invoke the exception strategy wihout triggering the until-succesful router first, I would move your cxf:jaxws-client etc. to a private flow. To quote Mule in Action 2nd edition on private flows:
This decoupling allows defining processing and error handling
strategies that are local to the private flow.
<flow name="ProvaClient" doc:name="ProvaClient">
...
<until-successful objectStore-ref="OS_Bean"
maxRetries="2" secondsBetweenRetries="2" doc:name="Until Successful"
deadLetterQueue-ref="myQueue">
<processor-chain doc:name="Processor Chain: Wait For Web Service Response">
<processor-chain doc:name="Processor Chain: Web Service">
<flow-ref name="externalCallFlow" />
</processor-chain>
<logger message="PAYLOAD: #[payload]" level="INFO" doc:name="Logger" />
</processor-chain>
</until-successful>
...
</flow>
<flow name="externalCallFlow">
<cxf:jaxws-client operation="getCode"
clientClass="it.aizoon.prova.client.ProvaService" port="ProvaPort"
enableMuleSoapHeaders="true" doc:name="SOAP">
</cxf:jaxws-client>
<http:outbound-endpoint exchange-pattern="request-response"
host="localhost" port="8081" path="service/prova" method="POST"
doc:name="HTTP" />
<catch-exception-strategy doc:name="Catch Exception Strategy">
<!-- Handle exception here locally and return custom exception or error
message for the unil-successful router -->
</catch-exception-strategy>
</flow>
You can then handle exceptions locally and return a custom exception or error
message for the until-successful router to catch using the following attribute: failureExpression="exception-type:java.lang.NumberFormatException"
Here's a dummy example I knocked up to throw a NumberFormatException, log the exception in the exception strategy and retry:
<flow name="test" doc:name="test">
<http:inbound-endpoint address="http://localhost:8081/test"
doc:name="HTTP" />
<until-successful objectStore-ref="OS_Bean"
maxRetries="2" secondsBetweenRetries="2" doc:name="Until Successful">
<processor-chain doc:name="Processor Chain: Wait For Web Service Response">
<processor-chain doc:name="Processor Chain: Web Service">
<flow-ref name="externalCallFlow" doc:name="Flow Reference" />
</processor-chain>
</processor-chain>
</until-successful>
</flow>
<flow name="externalCallFlow" doc:name="externalCallFlow">
<scripting:component>
<scripting:script engine="groovy">
throw new java.lang.NumberFormatException();
</scripting:script>
</scripting:component>
<default-exception-strategy>
<processor-chain>
<logger level="ERROR"
message="NumberFormatException Occurred : #[message.payload.getException().getCause()]" />
<scripting:component>
<scripting:script engine="groovy">
throw message.payload.getException().getCause();
</scripting:script>
</scripting:component>
</processor-chain>
</default-exception-strategy>
</flow>