[mule-user] Consuming a Web Service

4 views
Skip to first unread message

suneet Shah

unread,
Dec 23, 2010, 5:56:40 PM12/23/10
to us...@mule.codehaus.org
Hello,

I am trying to consume a web service using the example at :

http://www.mulesoft.org/documentation/display/MULE3USER/Consuming+Web+Services+with+CXF

Based on the example I have made the following entry in mule-config.xml. How do I use this in my application? I looked at using a MuleClient, but that seems to require that you define the endpoint.
Should I be using a MuleClient to utilize this flow or is there some otherway?
The application is set of Spring object.

<flow name="connectorClient">
<cxf:jaxws-client serviceClass="gapps.GoogleAppsConnectorImpl" operation="add"/>
<outbound-endpoint address="http://localhost:8080/idm-esb/idmsrvc/GoogleAppsConnectorService"/>
</flow>

Thanks for your help.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


David Dossot

unread,
Dec 23, 2010, 6:47:30 PM12/23/10
to us...@mule.codehaus.org
If you want to use this flow from within your application (ie not exposed to the outside world), yes, the best is to:
  • add a VM request-response inbound endpoint,
  • make your outbound endpoint request-response,
  • call the VM endpoint with muleClient.send
HTH
D.

suneet Shah

unread,
Dec 23, 2010, 7:01:25 PM12/23/10
to us...@mule.codehaus.org
Thanks David. That helps quite a bit.

One more question related to this. I am looking at a url provided earlier to make to allow for dynamic endpoints?

http://www.mulesoft.org/documentation/display/MULE3USER/Configuring+Endpoints#ConfiguringEndpoints-DynamicEndpoints

<outbound-endpoint address="smtp://user:secret@#[header:OUTBOUND:host]"/>
<http:outbound-endpoint host="localhost" port="#[header:INBOUND:portNumber]" path="orderService"/>

I am assuming that in the above example, that the values are coming from a properties file. Is there any to set this file values programatically? In my case the endpoints will be stored in a database and set through a UI.

Appreciate your help with these.

David Dossot

unread,
Dec 23, 2010, 7:36:13 PM12/23/10
to us...@mule.codehaus.org
Nope, these values are *not* coming from a properties file (else they won't be dynamic as replaced at configuration load time - usually with ${placeholders}).

In your case, simply add properties to the message you pass to Mule and use #[header:...] to retrieve these properties and build URLs on the fly.

D.

suneet Shah

unread,
Dec 23, 2010, 7:58:04 PM12/23/10
to us...@mule.codehaus.org
Thanks for all your help

suneet Shah

unread,
Dec 29, 2010, 4:02:46 PM12/29/10
to us...@mule.codehaus.org
Hi,

I am trying to implement a flow to call a service. However, the call to the service does not occur. I am sure I have errors in my setup, but I am not certain as to where.
Any thoughts on what I need to change?

MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();

ConfigurationBuilder builder = new SpringXmlConfigurationBuilder("mule-service-client-config.xml");
MuleContextBuilder contextBuilder = new DefaultMuleContextBuilder();
MuleContext context = muleContextFactory.createMuleContext(builder, contextBuilder);
context.start();
MuleClient client = new MuleClient(context);
client.dispatch("vm://dispatchConnectorMessage", addReqType, null);

<flow name="connectorClient">
<vm:inbound-endpoint address="vm://dispatchConnectorMessage" exchange-pattern="request-response" >
</vm:inbound-endpoint>

<cxf:jaxws-client serviceClass="spi.gapps.GoogleAppsConnectorImpl" operation="add"/>

exchange-pattern="request-response" />
</flow>


thanks

David Dossot

unread,
Dec 29, 2010, 4:09:39 PM12/29/10
to us...@mule.codehaus.org
Maybe because you do client.dispatch, which doesn't wait for a response leading to an early termination of the whole Mule instance?

What about using send instead?

HTH
D.

PS. Your inbound VM endpoint would look better like that:

<vm:inbound-endpoint path="dispatchConnectorMessage" exchange-pattern="request-response" />

If you use an endpoint from a particular namespace (vm here), better use the specific attributes of the transport instead of the generic address.

suneet Shah

unread,
Dec 30, 2010, 1:02:07 PM12/30/10
to us...@mule.codehaus.org
Thanks David
That worked well. I am not trying to get the dynamic endpoints to work and am having some problems.

Below is my flow definition, client and errors.
How should I be passing in the property?

<flow name="connectorClient">
<vm:inbound-endpoint address="dispatchConnectorMessage" exchange-pattern="request-response" >
</vm:inbound-endpoint>

<cxf:jaxws-client serviceClass="org.spml2.interf.ConnectorService" operation="add"/>

<outbound-endpoint
address="http://localhost:8080/idm-esb/idmsrvc/#[header:OUTBOUND:serviceName]"
exchange-pattern="request-response" />

</flow>

MuleClient client = new MuleClient(context);

log.info("Mule client calling dispatchConnector");

Map msgPropMap = new HashMap();
//msgPropMap.put("header:OUTBOUND:serviceName", "LDAPConnectorService");
msgPropMap.put("OUTBOUND:serviceName", "LDAPConnectorService");

MuleMessage msg = client.send("dispatchConnectorMessage?method=add", addReqType, msgPropMap);

Exception stack is:
1. Expression Evaluator "header" with expression "outbound:serviceName" returned
null but a value was required. (org.mule.api.expression.RequiredValueException)

org.mule.expression.ExpressionUtils:184 (http://www.mulesoft.org/docs/site/cur
rent3/apidocs/org/mule/api/expression/RequiredValueException.html)
2. Failed to route event via endpoint: org.mule.endpoint.DynamicOutboundEndpoint
@11913b3. Message payload is of type: MuleUniversalConduit$2 (org.mule.api.trans
port.DispatchException)
org.mule.endpoint.DynamicOutboundEndpoint:109 (http://www.mulesoft.org/docs/si
te/current3/apidocs/org/mule/api/transport/DispatchException.html)

David Dossot

unread,
Dec 30, 2010, 1:31:54 PM12/30/10
to us...@mule.codehaus.org
msgPropMap.put("OUTBOUND:serviceName", "LDAPConnectorService");

Mmmh, I don't think using the desired scope in the property name works, but I may be wrong.

I would do:

Map<?, ?> msgPropMap = Collections.singletonMap("serviceName", "LDAPConnectorService");
MuleMessage msg = client.send("vm://dispatchConnectorMessage", addReqType, msgPropMap);

with:

       <flow name="connectorClient">

                <vm:inbound-endpoint path="dispatchConnectorMessage" exchange-pattern="request-response" />
                <cxf:jaxws-client serviceClass="org.spml2.interf.ConnectorService" operation="add"/>

               <outbound-endpoint
                       address="http://localhost:8080/idm-esb/idmsrvc/#[header:INBOUND:serviceName]"
                       exchange-pattern="request-response" />
       </flow>

HTH
D.

suneet Shah

unread,
Dec 31, 2010, 12:36:01 AM12/31/10
to us...@mule.codehaus.org
Thanks very much. That worked.

In an earlier message, you had suggested that the vm:endpoint would look better as:

<vm:inbound-endpoint address="dispatchConnectorMessage" exchange-pattern="request-response" >

instead of

<vm:inbound-endpoint address="vm://dispatchConnectorMessage" exchange-pattern="request-response" >

However, when I remove the vm:// I get the exception below. How should I be defining the address for the vm:inbound endpoint?:

PropertyAccessException 1: org.springframework.beans.MethodInvocationException:
Property 'protocol' threw exception; nested exception is java.lang.IllegalArgume
ntException: Address 'dispatchConnectorMessage' for protocol 'vm' should start w
ith vm://
at org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:1
15)
at org.mule.config.spring.SpringXmlConfigurationBuilder.createSpringRegi
stry(SpringXmlConfigurationBuilder.java:116)
at org.mule.config.spring.SpringXmlConfigurationBuilder.doConfigure(Spri
ngXmlConfigurationBuilder.java:73)


Thanks again for all your help with this

suneet Shah

unread,
Dec 31, 2010, 12:58:22 AM12/31/10
to us...@mule.codehaus.org
Hi,

One more question - On my service I have several operations (add, modify, delete, setPassword). Is there a recommended way to map to these operations? Or should I create separate flow for each?
Currently, I have the only one operation defined:

<cxf:jaxws-client serviceClass="org.openiam.spml2.interf.ConnectorService" operation="add"/>

thanks

David Dossot

unread,
Dec 31, 2010, 12:13:59 PM12/31/10
to us...@mule.codehaus.org
In an earlier message, you had suggested that the vm:endpoint would look better as:

<vm:inbound-endpoint address="dispatchConnectorMessage" exchange-pattern="request-response" >

instead of

<vm:inbound-endpoint address="vm://dispatchConnectorMessage" exchange-pattern="request-response" >

No I suggested <vm:inbound-endpoint path="dispatchConnectorMessage" ...

If you use an endpoint from a specific transport schema use the specific attributes instead of the generic address attribute.

D.

suneet Shah

unread,
Dec 31, 2010, 12:44:59 PM12/31/10
to us...@mule.codehaus.org
Thanks David.
I had actually misread your original message - hence the error.

One more question - On my service I have several operations (add, modify, delete, setPassword). Is there a recommended way to map to multiple operations or be able to select which operation gets called based on the request that is coming in? Or should I create separate flow for each?

Currently, I have the only one operation defined: That works fine.

David Dossot

unread,
Dec 31, 2010, 12:58:48 PM12/31/10
to us...@mule.codehaus.org
Try removing the operation attribute from cxf:jaxws-client and use a message property transformer to create an outbound property named "operation" with the value you want. In this message property transformer set the property value to #[header:INBOUND:operation] to transfer a property named "operation" from inbound to outbound scope.

That should do the trick: you should be able to control the flow from your Java code by adding the operation to the props map.

HTH
D.

suneet Shah

unread,
Jan 3, 2011, 12:12:47 AM1/3/11
to us...@mule.codehaus.org
Hi,

I am having some difficulties in setup the message-properties-transformer. Any thoughts on where I am wrong?

My configuration and exception are below:

<message-properties-transformer name="serviceClient" scope="outbound">
<add-message-property key="operation" value="#[header:INBOUND:operation]"/>
</message-properties-transformer>




<flow name="connectorClient">
<vm:inbound-endpoint path="dispatchConnectorMessage" exchange-pattern="request-response" >

</vm:inbound-endpoint>

<cxf:jaxws-client serviceClass="interf.ConnectorService" >
</cxf:jaxws-client>


<outbound-endpoint
address="http://localhost:8080/dm-esb/idmsrvc/#[header:INBOUND:serviceName]"
exchange-pattern="request-response" transformer-refs="serviceClient" >
</outbound-endpoint>

</flow>

2011-01-03 00:08:58,409 [http-8080-1] ERROR AbstractExceptionListener :
********************************************************************************

Message : local part cannot be "null" when creating a QName (java.
lang.IllegalArgumentException)
Code : MULE_ERROR-10999
--------------------------------------------------------------------------------

Exception stack is:
1. local part cannot be "null" when creating a QName (java.lang.IllegalArgumentE
xception)
javax.xml.namespace.QName:246 (null)
2. local part cannot be "null" when creating a QName (java.lang.IllegalArgumentE
xception) (org.mule.api.DefaultMuleException)
org.mule.module.cxf.CxfOutboundMessageProcessor:139 (http://www.mulesoft.org/d
ocs/site/current3/apidocs/org/mule/api/DefaultMuleException.html)
--------------------------------------------------------------------------------

Root Exception stack trace:
java.lang.IllegalArgumentException: local part cannot be "null" when creating a
QName
at javax.xml.namespace.QName.<init>(QName.java:246)
at javax.xml.namespace.QName.<init>(QName.java:190)
at org.mule.module.cxf.CxfOutboundMessageProcessor.getBindingOperationFr
omEndpoint(CxfOutboundMessageProcessor.java:310)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for ev
erything)

David Dossot

unread,
Jan 3, 2011, 12:24:30 PM1/3/11
to us...@mule.codehaus.org
I think it is too late if you place the transformer on the outbound endpoint. Try placing the transformer right after the VM inbound.

D.

suneet Shah

unread,
Jan 3, 2011, 2:26:11 PM1/3/11
to us...@mule.codehaus.org
I tried changing it to the following, but I am still getting the error below.
Any idea on where I am off?

Map<String,String> msgPropMap = new HashMap<String,String>();
msgPropMap.put("serviceName", "LDAPConnectorService");
msgPropMap.put("operation", "add");




MuleMessage msg = client.send("vm://dispatchConnectorMessage", addReqType, msgPropMap);

<flow name="connectorClient">
<vm:inbound-endpoint path="dispatchConnectorMessage" exchange-pattern="request-response" >
</vm:inbound-endpoint>

<message-properties-transformer name="serviceClient" scope="outbound">
<add-message-property key="operation" value="#[header:INBOUND:operation]"/>
</message-properties-transformer>

<cxf:jaxws-client serviceClass="spml2.interf.ConnectorService" >
</cxf:jaxws-client>


<outbound-endpoint
address="http://localhost:8080/idm-esb/idmsrvc/#[header:INBOUND:serviceName]"
exchange-pattern="request-response" >
</outbound-endpoint>

</flow>

2011-01-03 14:21:01,823 [http-8080-1] ERROR AbstractExceptionListener :

David Dossot

unread,
Jan 3, 2011, 2:33:59 PM1/3/11
to us...@mule.codehaus.org
Your config looks good to me: maybe the cxf:jaxws-client needs a default value as it boot time that is going to be overridden at runtime with the message property? Can you try putting "add" back and override with an "operation" property equals to another of the operations you want to use?

HTH
D.

suneet Shah

unread,
Jan 3, 2011, 5:12:44 PM1/3/11
to us...@mule.codehaus.org
Hi David,

I set the operation attribute back, but it looks like the message transformer is not having any effect. I am getting an illegalargument exception indicating that the wrong operation is being called.

<flow name="connectorClient">
<vm:inbound-endpoint path="dispatchConnectorMessage" exchange-pattern="request-response" >
</vm:inbound-endpoint>

<message-properties-transformer name="serviceClient" scope="outbound">
<add-message-property key="operation" value="#[header:INBOUND:operation]"/>
</message-properties-transformer>

<cxf:jaxws-client serviceClass="interf.ConnectorService" operation="modify" >


</cxf:jaxws-client>


<outbound-endpoint
address="http://localhost:8080/idm-esb/idmsrvc/#[header:INBOUND:serviceName]"
exchange-pattern="request-response" >
</outbound-endpoint>

</flow>


java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.cxf.databinding.AbstractWrapperHelper.createWrapperObject(
AbstractWrapperHelper.java:99)
at org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor.handleMe
ssage(WrapperClassOutInterceptor.java:103)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseIntercept
orChain.java:236)

David Dossot

unread,
Jan 3, 2011, 5:27:08 PM1/3/11
to us...@mule.codehaus.org
>:(

Sorry for this.

Do you, by any chance, have the possibility to put a breakpoint in org.mule.module.cxf.CxfOutboundMessageProcessor.getMethod(event) and see why isn't the "operation" property taken into account when finding the target service method?

D.

suneet Shah

unread,
Jan 3, 2011, 5:41:11 PM1/3/11
to us...@mule.codehaus.org
Hi David,

No worries. I appreciate all your help.
I dont have a mule source project setup. However, I can if that would help.

suneet

David Dossot

unread,
Jan 3, 2011, 5:43:34 PM1/3/11
to us...@mule.codehaus.org
Cool - thank you for your patience and investigations.

D.
Reply all
Reply to author
Forward
0 new messages