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

Announcements
Join us in Bucharest on Sept 18th 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 tested your hint but I still have the exact same error, but  I don't think your guess is right because even when I keep just the GET_server, I still have the same error message
0683p000009MAcg.png
Anonymous
Not applicable
Author

You cannot have the cHttp components as POST_Server, GET_Server and DELETE_SERVER. These should be cMessagingEndpoint components. cMessagingEndpoint components allow you to use the direct endpoint. They are generic endpoints that allow you to use any of the Camel Components. The cHttp components are for producing or consuming service calls. Although you are working with services here, you are actually using the Camel direct component to pass the messages from the cDynamicRouter. Therefore you must use the cMessagingEndpoint.
Anonymous
Not applicable
Author

I've already used the cMessagingEndpoint (please see the first message) but this component  allows two applications to communicate by either sending or receiving messages, one endpoint can not do both, so I cannot have "an answer" from the service web, and *I think* that's why only the DELETE method worked for me 
I jest retested with a cMessagingEndpoint component and a GET request: 
: org.apache.camel.main.MainSupport - Apache Camel 2.15.2 starting
: org.springframework.context.support.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@7bc0bd17: 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 singletons in org.springframework.beans.factory.support.Defaul


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

I also tried a "sipmler" way, using a cMessagingRouter component: 
0683p000009MAcl.png
However, the route just behaves weirdly,it  does not work depending on the corresponding logic to the graph.for example: the branch "when2" is called only when the two conditions "when4" and "when5" are false (dspite the fact that in my Rest Client, the http verb is "DELETE".
When I looked into the code, it appers that it's a little bit *messy*, it's not clear which ".when(...)" is related to which ".choice()": 
public void configure() throws java.lang.Exception {
from(uriMap.get("cHttp_3"))
.routeId("Base_cHttp_3")
.choice()
.id("cMessageRouter_1")
.when()
.simple("${header." + org.apache.camel.Exchange.HTTP_METHOD
+ "} == 'GET'")
.setHeader("CamelHttpMethod", constant("GET"))
.to(uriMap.get("cHttp_4"))
.id("cHttp_4")
.choice()
.id("cMessageRouter_2")
.when()
.simple("${header."
+ org.apache.camel.Exchange.HTTP_RESPONSE_CODE
+ "} == 200 ")
.log(org.apache.camel.LoggingLevel.INFO,
"chouetteRoute.cLog_1", "good")
.id("cLog_2")
.when()
.simple("${header."
+ org.apache.camel.Exchange.HTTP_RESPONSE_CODE
+ "} == 200 ")
.log(org.apache.camel.LoggingLevel.ERROR,
"chouetteRoute.cLog_1", "eRREUR")
.id("cLog_9")
.when()
.simple("${header." + org.apache.camel.Exchange.HTTP_METHOD
+ "} == 'POST'")
.setHeader("CamelHttpMethod", constant("POST"))
.setHeader("Content-Type", constant("application/json"))
.to(uriMap.get("cHttp_7"))
.id("cHttp_7")
.choice()
.id("cMessageRouter_4")
.when()
.simple("${header."
+ org.apache.camel.Exchange.HTTP_RESPONSE_CODE
+ "} == 200 ")
.log(org.apache.camel.LoggingLevel.INFO,
"chouetteRoute.cLog_1", "good")
.id("cLog_5")
.when()
.simple("${header."
+ org.apache.camel.Exchange.HTTP_RESPONSE_CODE
+ "} == 404 ")
.log(org.apache.camel.LoggingLevel.ERROR,
"chouetteRoute.cLog_1", "eRREUR")
.id("cLog_6")
.when()
.simple("${header." + org.apache.camel.Exchange.HTTP_METHOD
+ "} == 'DELETE'")
.setHeader("CamelHttpMethod", constant("DELETE"))
.to(uriMap.get("cHttp_1"))
.id("cHttp_1")
.choice()
.id("cMessageRouter_3")
.when()
.simple("${header."
+ org.apache.camel.Exchange.HTTP_RESPONSE_CODE
+ "} == 200 ")
.log(org.apache.camel.LoggingLevel.INFO,
"chouetteRoute.cLog_1", "good")
.id("cLog_3")
.when()
.simple("${header."
+ org.apache.camel.Exchange.HTTP_RESPONSE_CODE
+ "} == 404 ")
.log(org.apache.camel.LoggingLevel.ERROR,
"chouetteRoute.cLog_1", "eRREUR")
.id("cLog_4");
}

 
Anonymous
Not applicable
Author

If you look at the screenshot, you can see that the cMessagingEndpoint is working as it should. That is why you are getting row counts after the cMessagingEndpoint. You are getting confused with the terminology. The cMessagingEndpoint is fine and should stay. 
However, I can now see that the service is expecting the body as an instance of  org.w3c.dom.Document .  Your service (in Eclipse) is expecting XML as its payload. You need to inform it that you are sending JSON. To do this you might want to try going to the advanced settings of your cHttp components that are calling your Eclipse service and create a new header called "Content-Type" and assigning it a value of "application/json".
The error message below explains that the service wants the body as  org.w3c.dom.Document and that is why you are getting this error. You must be really careful to identify the precise error when debugging. This is a completely different error to the one before.
Caused by: org.apache.camel.InvalidPayloadException: No body available of type: org.w3c.dom.Document but has value: org.apache.camel.converter.stream.CachedOutputStream$WrappedInputStream@6c15234e of type: org.apache.camel.converter.stream.CachedOutputStream.WrappedInputStream on: Message: . Caused by: Error during type conversion from type: java.lang.String to the required type: org.w3c.dom.Document with value due org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Contenu non autorisé dans le prologue.. Exchange]. Caused by: due org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Contenu non autorisé dans le prologue.]
Anonymous
Not applicable
Author

I must say that I'm confused since when I request the service directly in the browser, without Talend, I get json data
  0683p000009MAcq.png  
** the new header "Content-Type":"application/json" in the cHttp component Get_client doesn't resolve the problem, still getting the error 


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

Your browser will only ever make a GET call. You are also not sending a payload or a body. When testing REST services that are anything other than GET you really need to use a tool that makes it easy to specify the http verb and supply a payload. Something like Advanced Rest Client (https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo) for Chrome works for me.
Anonymous
Not applicable
Author

I was actually using DHC rest Client to specify the HTTP Verb I want to use, sorry didn't mention it before
I used DHC Rest Client to make a direct POST (without using talend) in the service (in eclipse)   using json data, it works:
0683p000009MAWA.png
Anonymous
Not applicable
Author

You need to copy the exact settings you use in that to get it to work in Talend. I have just looked at that app and noticed that when you click on the JSON link under the payload, it sets the Content-Type up for you. This will need to be set when you run it via any other system.

0683p000009MAKH.png
Anonymous
Not applicable
Author

well, I added a header in the chttp client component, as you can see in the snapshot, in  the POST_server component, the configuration is already set to "application/json"
is there something else I should set?
0683p000009MA4W.png 0683p000009MAcv.png
here's what I got in the debug:
: org.eclipse.jetty.server.AbstractConnector - Started SelectChannelConnector@localhost:8087
: org.apache.camel.spring.SpringCamelContext - Route: base_cHttp_1 started and consuming from: Endpoint
: org.apache.camel.spring.SpringCamelContext - Route: cMessagingEndpoint_1 started and consuming from: Endpoint
: org.apache.camel.spring.SpringCamelContext - Route: cMessagingEndpoint_2 started and consuming from: Endpoint
: org.apache.camel.spring.SpringCamelContext - Route: 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: test2cDynamicRouter-ctx) started in 1.277 seconds
: cDynamicRouter.cLog_1 - Exchange]
:43:7: Le type d'élément "meta" doit se terminer par la balise de fin correspondante "".
: org.apache.camel.processor.DefaultErrorHandler - Failed delivery for (MessageId: ID-LFR204094-53910-1439560830380-0-3 on ExchangeId: ID-LFR204094-53910-1439560830380-0-1). Exhausted after delivery attempt: 1 caught: org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange]
Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId              ProcessorId          Processor                                                                        Elapsed (ms)

                                        ]
                                                   ]
                                                      ]

choice

Exchange
---------------------------------------------------------------------------------------------------------------------------------------
Exchange
]