One Star

Dynamic invocation of web service in Route

Hello All
Could you please help me on the following:
I am looking for a solution for dynamic invocation of web service in a ESB route. My requirement is, I want to construct the web service URL dynamically/run time based on the response from another service.
Appreciate your help
Thanks
4 REPLIES
One Star

Re: Dynamic invocation of web service in Route

Hi,
what's really your use case? Why you need that (I know it's needed often) the question stays if a simple recipient list or environmental parameter wouldn't be good enough.

If you use the integration route:
In theory - you may use a recipientList component with a simple expression to build the cxf endpoint with new address.
<recipientList>
  <simple>cxf:bean:cxfEndpoint?address=${header.computed_address}&amp;serviceClass=one.of.my.Services&amp;serviceName=...&amp;endpointName=...</simple>
</recipientList>

However - I am not sure if creating a new cxf endpoint for each request wouldn't create some kind of leak, remains to be seen.. If it will creates leaks, you may still go lower and use the http4 component (http://camel.apache.org/http4.html) Smiley Tongue

if you use the DI job:
 you may want to store the service URI as a context variable and use the context variable as the tEsbConsumer URI value..
g
One Star

Re: Dynamic invocation of web service in Route

Thank You Gusto for your response. Your help highly appreciable.
The usecase is - It is a migration project from existing middleware to Talend. In the existing code there is a scenario where the end point urls are coming from the response from another service call and based on the end point urls it has to invoke the particular service.
As you mentioned below I tried the following, but it gives me error. I am using wsdl instead of bean class for service end point. Could you please help to correct the syntax or anything wrong in the below?
"cxf:${header.computed_address}?dataFormat=PAYLOAD&amp;loggingFeatureEnabled=true&amp;wsdlURL=classpath:CC_ContractorLookup.wsdl&amp;serviceNameString={}ContractorService&amp;endpointNameString={}ContractorLookup&amp;defaultOperationNamespace="
I am getting the below error while trying to run the request in a route:
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: cxf:// due to: Failed to resolve endpoint: cxf:// due to: There are 7 parameters that couldn't be set on the endpoint. Check the uri if the parameters are spelt correctly and that they are properties of the endpoint. Unknown parameters=
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:534)
at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:71)
at org.apache.camel.util.ExchangeHelper.resolveEndpoint(ExchangeHelper.java:88)
at org.apache.camel.processor.RecipientListProcessor.resolveEndpoint(RecipientListProcessor.java:223)
at org.apache.camel.processor.RecipientListProcessor.createProcessorExchangePairs(RecipientListProcessor.java:163)
at org.apache.camel.processor.MulticastProcessor.process(MulticastProcessor.java:208)
at org.apache.camel.processor.RecipientList.sendToRecipientList(RecipientList.java:167)
at org.apache.camel.processor.RecipientList.process(RecipientList.java:120)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:91)
at routines.system.CamelStat$1$1.process(CamelStat.java:56)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:91)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
at org.apache.camel.component.cxf.CxfConsumer$1.asyncInvoke(CxfConsumer.java:94)
at org.apache.camel.component.cxf.CxfConsumer$1.invoke(CxfConsumer.java:74)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:107)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319)
at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:65)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1088)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1024)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:370)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)
... 10 more
One Star

Re: Dynamic invocation of web service in Route

Also could you please help me how to use the http4 component in the Talend Route? Any example would help as I am new to Talend.
One Star

Re: Dynamic invocation of web service in Route

Also could you please help me how to use the http4 component in the Talend Route? Any example would help as I am new to Talend.


1. If you're not feeling very skilled / capable with the mediation routes (Camel), you may try to use the Talend Integration job directly, where you can build something like
define a context variable (e.g. service2Url)
tXMLMap (prepare request) --> tEsbConsumer (call a service) --> tExtractXML (get the url) --> tContextLoad (store the url in the context)
    -- onComponentOk --> tFixedflow (prepare parameters) --> tXMLMap (prepare request) --> tEsbConsumer (invoke the 2nd service)
there you can put the expression "context.service2Url" as the destination URL of the seconds service

2. Please check your exception - apparently you've placed some XML encoding ( &amp; ) where direct string was needed ( & ), be careful what is directly used and what is transformed into XML. The Mediation route editor builds Java DSL code from the model. Apparently you don't need to encode the parameter separator.
3. Talend mediation routes are in fact Camel routes (see the link in the previous mail) and http4 component acts as a raw HTTP client. IMHO you should try to use the cxf if possible
Have fun
Gabriel