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

Re: Dynamic invocation of web service in Route

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.

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 ( 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..
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?
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(
at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(
at org.apache.camel.util.ExchangeHelper.resolveEndpoint(
at org.apache.camel.processor.RecipientListProcessor.resolveEndpoint(
at org.apache.camel.processor.RecipientListProcessor.createProcessorExchangePairs(
at org.apache.camel.processor.MulticastProcessor.process(
at org.apache.camel.processor.RecipientList.sendToRecipientList(
at org.apache.camel.processor.RecipientList.process(
at org.apache.camel.processor.Pipeline.process(
at org.apache.camel.processor.Pipeline.process(
at org.apache.camel.processor.DelegateAsyncProcessor.process(
at routines.system.CamelStat$1$1.process(
at org.apache.camel.processor.DelegateAsyncProcessor.process(
at org.apache.camel.processor.RedeliveryErrorHandler.process(
at org.apache.camel.processor.CamelInternalProcessor.process(
at org.apache.camel.processor.Pipeline.process(
at org.apache.camel.processor.Pipeline.process(
at org.apache.camel.processor.CamelInternalProcessor.process(
at org.apache.camel.component.cxf.CxfConsumer$1.asyncInvoke(
at org.apache.camel.component.cxf.CxfConsumer$1.invoke(
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$
at java.util.concurrent.Executors$ Source)
at Source)
at org.apache.cxf.workqueue.SynchronousExecutor.execute(
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(
at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(
at org.eclipse.jetty.server.handler.ContextHandler.doScope(
at org.eclipse.jetty.server.handler.ScopedHandler.handle(
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(
at org.eclipse.jetty.server.Server.handle(
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(
... 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