Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

cDynamicRouter and different endpoints

Hi all, 
I have the route (attached bellow). 
I have to dynamically redirect the messages depending on the Http verb (I tried to do it using another approch but it was an epic fail 0683p000009MAB6.png
used the link
The problem is that only the "DELETE" method is working, and yet I have the error:  

 :1:1: Fin prématurée du fichier.
: org.apache.camel.processor.DefaultErrorHandler - Failed delivery for (MessageId: ID-LFR204094-55535-1439324535115-0-3 on ExchangeId: ID-LFR204094-55535-1439324535115-0-1). Exhausted after delivery attempt: 1 caught: org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange]


while with the GET or POST methods all I have is this error:


 :1:1: Contenu non autorisé dans le prologue.
: org.apache.camel.processor.DefaultErrorHandler - Failed delivery for (MessageId: ID-LFR204094-56301-1439325581670-0-3 on ExchangeId: ID-LFR204094-56301-1439325581670-0-1). Exhausted after delivery attempt: 1 caught: org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange]


I bridged the URLs:

"http://localhost:8081/webMavenChouette?bridgeEndpoint=true&throwExceptionOnFailure=false"


please find attached the snapshots of the route and the bean:
0683p000009MAHp.png 0683p000009MAcR.png
Thank you for your time 
-Regards

Labels (2)
40 Replies
Anonymous
Not applicable
Author

I addedd a cErrorHandler: 
0683p000009MAQr.png
Here's what I got as logs 
: org.eclipse.jetty.server.AbstractConnector - Started SelectChannelConnector@localhost:8084
: org.apache.camel.spring.SpringCamelContext - Route: Base_cHttp_1 started and consuming from: Endpoint
: org.apache.camel.spring.SpringCamelContext - Route: POST_cMessagingEndpoint_1 started and consuming from: Endpoint
: org.apache.camel.spring.SpringCamelContext - Route: GET_cMessagingEndpoint_2 started and consuming from: Endpoint
: org.apache.camel.spring.SpringCamelContext - Route: DELETE_cMessagingEndpoint_3 started and consuming from: Endpoint
: org.apache.camel.spring.SpringCamelContext - Total 4 routes, of which 4 is started.
: org.apache.camel.spring.SpringCamelContext - Apache Camel 2.15.2 (CamelContext: RouteChouetteSplit-ctx) started in 1.790 seconds
: chouetteRoute.cLog_7 - GET CLIENT
: org.apache.commons.httpclient.HttpMethodDirector - I/O exception (java.net.ConnectException) caught when processing request: Connection refused: connect
: org.apache.commons.httpclient.HttpMethodDirector - Retrying request
: org.apache.commons.httpclient.HttpMethodDirector - I/O exception (java.net.ConnectException) caught when processing request: Connection refused: connect
: org.apache.commons.httpclient.HttpMethodDirector - Retrying request
: org.apache.commons.httpclient.HttpMethodDirector - I/O exception (java.net.ConnectException) caught when processing request: Connection refused: connect
: org.apache.commons.httpclient.HttpMethodDirector - Retrying request
: org.slf4j.Logger - Failed delivery for (MessageId: ID-LFR204094-53626-1439369472006-0-2 on ExchangeId: ID-LFR204094-53626-1439369472006-0-1). Exhausted after delivery attempt: 1 caught: java.net.ConnectException: Connection refused: connect
Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId ProcessorId Processor Elapsed (ms)

]

]

Exchange
---------------------------------------------------------------------------------------------------------------------------------------
Exchange
]
Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.(Unknown Source)
at java.net.Socket.(Unknown Source)
at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:122)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
at org.apache.camel.component.http.HttpProducer.executeMethod(HttpProducer.java:244)
at org.apache.camel.component.http.HttpProducer.process(HttpProducer.java:144)
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:129)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
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:448)
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.direct.DirectProducer.process(DirectProducer.java:51)
at org.apache.camel.processor.RoutingSlip$2.doInAsyncProducer(RoutingSlip.java:301)
at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:304)
at org.apache.camel.processor.RoutingSlip.processExchange(RoutingSlip.java:294)
at org.apache.camel.processor.RoutingSlip.doRoutingSlip(RoutingSlip.java:215)
at org.apache.camel.processor.RoutingSlip.process(RoutingSlip.java:146)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
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:448)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
at org.apache.camel.component.jetty.CamelContinuationServlet.service(CamelContinuationServlet.java:162)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:686)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1494)
at org.eclipse.jetty.servlets.MultiPartFilter.doFilter(MultiPartFilter.java:136)
at org.apache.camel.component.jetty.CamelFilterWrapper.doFilter(CamelFilterWrapper.java:43)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1465)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:499)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:428)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
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:489)
at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:949)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1011)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:668)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Unknown Source)

-Regards
Anonymous
Not applicable
Author

well, as it's said in the docs, the  cMessagingEndpoint  allows two applications to communicate by either sending or receiving messages, one endpoint can not do both.  so I replaced it with a cHttp component, as a server (please find the picture attached). 
The route worked one time as expected with no errors, after a restart of my computer, it gives me this errors: 
Démarrage du job testDynamicRouter a 15:12 13/08/2015.: org.apache.camel.main.MainSupport - Apache Camel 2.15.2 starting: org.springframework.context.support.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@38d760bb: startup date ; root of context hierarchy: org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singlet


To see the whole post, download it here
OriginalPost.pdf
Anonymous
Not applicable
Author

What is the difference between the DELETE, GET and POST cHttp components? How are each of them configured? What type of data is sent? Are they set up as Client rather than Server?
Anonymous
Not applicable
Author

Thank you for your answer
the cHttp DELETE , POST  and GET are all set up as "client", they all have the same URI:
URI="http://localhost:8081/webMavenChouette?bridgeEndpoint=true&throwExceptionOnFailure=false"

calling a REST web service. 
The difference is the configuration, the one called "DELETE" uses the methode "DELETE", the one called "POST" uses the methode "POST", the one called "GET" uses the methode "GET".  They will be used to differenciate the processing according to the HTTP verb used
the data sent is json objects. 
-Regards
0683p000009MAcb.png
Anonymous
Not applicable
Author

Have you tested each of the http verbs with the service you are sending them to without this process? It could be a problem with that service.
Anonymous
Not applicable
Author

Actually I've already tested the service itself using a route : 
chttp (server) -> chttp(client) -> cMessageRouter ->2 when branches to test the Exchange.HTTP_RESPONSE_CODE ->cLogs
and it's working just fine with the 3 http verbs
The problem occurs when I introduce the cDynamicRouter. to do the if/else conditions, I used a bean, using the cBeanRegister" component,  which redirects the message 
public String setURI(Document document,@Header(Exchange.SLIP_ENDPOINT) String previous, 
@Header(Exchange.HTTP_METHOD) String httpVerb) {

if (previous != null) {
return null;
}

return "direct:" + httpVerb;

it returns a "direct:GET" (if the request was a GET) that is put in the "GET_server": a chttp server component ; 
please reconsider the snapshots, I renamed the chttp component depending on their configuration. 
0683p000009MAbt.png 0683p000009MATL.png 0683p000009MAZJ.png
Anonymous
Not applicable
Author

Where is the service you are calling running? Is it running in the Studio or in the Karaf? Do you have more than one service; 1 for each verb?
Also, can you add the following code to your routine?
public String setURI(Document document,@Header(Exchange.SLIP_ENDPOINT) String previous, 
@Header(Exchange.HTTP_METHOD) String httpVerb) {

if (previous != null) {
return null;
}

System.out.out.println("direct:"+httpVerb); //<--- This code to see what is produced
return "direct:" + httpVerb;
}
Anonymous
Not applicable
Author

my service is running in eclipse, it's a spring mvc application, with Rest controllers
and the   System.out.out.println("direct:"+httpVerb); prints the http verb I'm using in the request in the Rest Client DHC
==> if it's a GET request then the code prints "direct:GET"
Anonymous
Not applicable
Author

I *think* I might have the answer, but I can't test it here. Looking at your error messages it looks like the service is throwing errors because it is expecting a String but is receiving the body as an instance of java.io.InputStream. To work around this, try putting cProcessor components before your POST_client, GET_client and DELETE_client components. In each of the cProcessor components, put the following code.....
String jsonString = exchange.getIn().getBody(String.class);
exchange.getIn().setBody(jsonString);

What you are doing here is forcing the body to be converted to a String (from an instance of java.io.InputStream) and then putting it back into the "in" message as a String.
This won't necessarily get it to work perfectly, but you should see it get further after this.
Let me know if it works.