I faced a problem, when I use this spring-camel context I got error about type conversion from String to Long, related to second {{retryCount}}. When I start debugging I realised that BaseTypeConverterRegistry#convertTo method got retryCount value (let say 10) in the first occurence and value "{{retryCount}}" in the second case (delayer component), so I don't know why.
My Spring Camel context:
<propertyPlaceholder location="classpath:camel.properties" id="properties" />
<route id="mojorun">
<from uri="timer://runOnce?delay=0&repeatCount=1" />
<loop>
<spring:constant>{{retryCount}}</spring:constant>
<spring:inOnly uri="bean:mojo?method=shout"/>
<spring:delay>
<spring:constant>{{retryCount}}</spring:constant>
</spring:delay>
</loop>
</route>
Related
I am setting a property of camel exchange in route 1. I am trying to update the same in the second route inside a splitter. but in the second iteration of splitter i am getting the original value that I set in the route 1 instead of the new updated value. Below is the sample i am trying..
<route handleFault="true" streamCache="true" id="route1">
<from uri="cxfrs://bean://test?synchronous=true"/>
<bean ref="testBean" method="setMyProperty"/>// setting initial value for property
<to uri="direct:directCall"/>
</route>
<route handleFault="true" streamCache="true" id="route2">
<from uri="direct:directcall"/>
<log message="Inside Second call..."/>
<split>
<jsonpath>some Json path</jsonpath>
<bean ref="formatConvertor" method ="convertLHMToJSON(${body})"/>
<split>
<jsonpath>some json path</jsonpath>
<bean ref="PropertySetter" method ="setProperty"/> //I am setting new value in this method
</split>
</split>
Inside the beans:
public void setMyProperty(Exchange exchange) {
exchange.setProperty("testProp", "hello");
}
public void setProperty(Exchange exchange) {
sysout(exchange.getProperty("testProp").toString())//this always prints "hello"
String x=exchange.getProperty("testProp")+some other value;// in all iterations of split I am getting 'hello' as the value of the property instead of new value
exchange.setProperty("testProp", x);
sysout(exchange.getProperty("testProp").toString())// this line prints the new value
}
Why the property is not updated? Even i tried setting in headers. same result. Thank you.
You must use a split-aggregate pattern and copy the property value during each iteration of the split from the old exchange to the new exchange because every time when the split iteration happens a new exchange is created from the source message (only carrying the properties & headers set before the split)
recover headers value after split apache camel
I have a route using the Spring DSL as such
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="activemq:queue:worker?mapJmsMessage=false" />
<convertBodyTo type="java.lang.String"/>
<setHeader headerName="CamelHttpMethod">
<constant>POST</constant>
</setHeader>
<to uri="http://localhost/queue" />
</route>
</camelContext>
The message type is an ActiveMQTextMessage. I am able to POST the message to the HTTP URL, but what I get seems to be the toString() output:
ActiveMQTextMessage {commandId = 5, responseRequired = false, message....
I would like to call the getText() method on the ActiveMQTextMessage instance to populate the route, but I cannot figure out how to get that method called. I am quite sure I could get this to work in code, but I need to do everything via XML.
Figured out the problem. I had mapJmsMessage=false set to handle an exception a few days ago. I removed it and suddenly it worked fine.
I am having issues hitting an http end point via camel recipientlist(2.14).
<route id="httpexecutor">
<from uri="direct:httpexecutor" />
<process ref="httpPreprocessor" />
<recipientList>
<simple>${property[inputSearchParameter.url]}</simple>
</recipientList>
</route>
When the url has a + sign(in one of the parameters) then its breaking.
I also tried %2B then it is getting converted to space.
There is a JIRA:
https://issues.apache.org/jira/browse/CAMEL-6176
However when i am using RAW its not working and getting the following trace(seems like RAW is passed to the service):
Caused by: java.net.URISyntaxException: Illegal character in query at index 558: http://someurl?facet=true&binary=true&-fq=nm_task_type%3A%28OTM_QUERY+OR+OTM_CLIENT_QUERY%29&facet.query=%7B%21key%3D%22%5B*+TO+NOW-30%5D%22%7Ddt_created%3A%5B*+TO+NOW-30DAY%5D&facet.query=%7B%21key%3D%22%5BNOW-30DAY+TO+NOW-15DAY%5D%22%7Ddt_created%3A%5BNOW-30DAY+TO+NOW-15DAY%5D&facet.query=%7B%21key%3D%22%5BNOW-15DAY+TO+NOW-7DAY%5D%22%7Ddt_created%3A%5BNOW-15DAY+TO+NOW-7DAY%5D&facet.query=%7B%21key%3D%22%5BNOW-7DAY+TO+NOW-1DAY%5D%22%7Ddt_created%3A%5BNOW-7DAY+TO+NOW-1DAY%5D&facet.query=RAW({!key="[NOW-1DAY TO NOW]"}dt_created:[NOW-1DAY TO NOW+1DAY])&q=*%3A*&rows=0
at java.net.URI$Parser.fail(URI.java:2829)
at java.net.URI$Parser.checkChars(URI.java:3002)
at java.net.URI$Parser.parseHierarchical(URI.java:3092)
at java.net.URI$Parser.parse(URI.java:3034)
at java.net.URI.<init>(URI.java:595)
at org.apache.camel.util.URISupport.createURIWithQuery(URISupport.java:334)
at org.apache.camel.util.URISupport.createRemainingURI(URISupport.java:428)
at org.apache.camel.component.http.HttpComponent.createEndpoint(HttpComponent.java:248)
at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:122)
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:525)
... 52 more
Any help appeciated.
I haven't tested this, but can you set header "CamelHttpPath" to your URL before passing to Camel HTTP component and see if it helps:
<setHeader headerName="CamelHttpPath">
<simple>YOUR_URL</simple>
</setHeader>
I am using Apache Camel blueprints, my route is triggered from a URL at port 8081 on localhost. This route generates a file but the problem is the file is a binary file without the HTML showing.
I then navigate my browser to http://localhost:8081/foo which triggers the URL.
What is it that I don't understand that is causing it to output a binary file rather than a text file? I guess that I must transform the body somehow?
<route id="url1">
<from uri="netty4-http:http://0.0.0.0:8081/foo" />
<to uri="http://www.google.com/?bridgeEndpoint=true" />
<to uri="file:/test"/>
</route>
Update: I think the problem is that the content coming back from www.google.com is gzip. When I look at the bridgeEndpoint parameter in the documentation it mentions something about gzip... now I am not sure, as I tried it on another website and it still doesn't work.
This line in my log might be relevant.
writing body: DefaultFullHttpResponse(decodeResult: success,
version: HTTP/1.1, content: UnpooledUnsafeDirectByteBuf(ridx: 0, widx: 0, cap: 0))
Update: I discover if I do:
<from uri="timer:secondfoo?period=20s" />
Replacing the from, then it works. Hmm... Something flowing from the netty4-http causes problem.
Update: I found something which works! Obsession pays off.
<route id="url1">
<from uri="netty-http:http://0.0.0.0:8081/foo" />
<removeHeaders pattern="*" />
<setBody>
<simple></simple>
</setBody>
<setHeader headerName="CamelHttpMethod">
<constant>GET</constant>
</setHeader>
<to uri="http://www.google.com/?bridgeEndpoint=true" />
<to uri="file:/test"/>
</route>
You can convert the message to a String type then its text based
<route id="url1">
<from uri="netty4-http:http://0.0.0.0:8081/foo" />
<to uri="http://www.google.com/?bridgeEndpoint=true" />
<convertBodyTo type="String"/>
<to uri="file:/test"/>
</route>
How can i call a SOAP web service with an empty message body using Apache Camel?
For example, the final endpoint on a route would be the invocation of a method on my proxy that takes 0 arguments.
EDIT:
example xml configuration:
<route id="someRoute">
<from uri="ref:activemq-queue"/>
<setHeader headerName="operationName">
<constant>invoke</constant>
</setHeader>
<to uri="cxf:bean:someWS"/>
</route>
...
<cxf:cxfEndpoint id="someWS" address="${ws.address}"
serviceClass="com.example.ws.SomeWS"
The problem is that the method 'invoke' on the WS takes 0 arguments, and an exception is thrown stating that 1 argument is being received. Is there a way for me to specify to ignore this received input?
You can set the message body to be null, if the invocation just take 0 argument. null simple expression is added since camel 2.12.3.
<route id="someRoute">
<from uri="ref:activemq-queue"/>
<setBody>
<simple>null</simple>
</setBody>
<setHeader headerName="operationName">
<constant>invoke</constant>
</setHeader>
<to uri="cxf:bean:someWS"/>
</route>
I also needed to set an empty body to Apache Camel xml and the solution below worked for me.
<setBody id="set-empty-body">
<constant/>
</setBody>
Hope this helps to whoever need it.
The xml configuration will fail if the content of the body is not with the correct type of the class required by the method of your bean. By default, it could be an Object and not a String. When the method recieves the body in an incorrect format, it would process a null value, instead of the body of the route. To solve this problem, you will need to convert the body into the expected class of the method of your bean. For example, if the method's argument of the bean is a String, then you could do something like:
<route id="someRoute">
<from uri="ref:activemq-queue"/>
<setHeader headerName="operationName">
<constant>invoke</constant>
</setHeader>
<convertBodyTo type="String"/>
<to uri="cxf:bean:someWS"/>
</route>
For more information about body conversion, you can check the docs: https://camel.apache.org/components/3.14.x/eips/convertBodyTo-eip.html