Is there any way to set header with boolean value for checking contains like this.
<setHeader name="status">
<simple>${headers.type} contains 'client'</simple>
</setHeader>
This should set status as true if type contains client else false.
Check the docs, you need resultType
<setHeader name="status">
<simple resultType="java.lang.Boolean">${headers.type} contains 'client'</simple>
</setHeader>
Related
I'm using ehcache 3.0 and the latest version of Apache camel. I'd like to delete the element from cache after 120 seconds.
Following is the piece of code I'm using to achieve the same
<setHeader headerName="CamelCacheOperation" id="setCamelEhCacheOperation001">
<constant>CamelCacheAdd</constant>
</setHeader>
<setHeader headerName="CamelCacheTimeToLive" id="setCamelCacheTimeToLive001">
<simple resultType="java.lang.Integer">120</simple>
</setHeader>
<setHeader headerName="CamelCacheTimeToIdle" id="setCamelCacheTimeToIdle001">
<simple resultType="java.lang.Integer">120</simple>
</setHeader>
<setHeader headerName="CamelCacheEternal" id="setCamelCacheEternal001">
<simple resultType="java.lang.Integer">0</simple>
</setHeader>
<setHeader headerName="CamelEhcacheAction" id="setCamelEhCacheAction001">
<constant>PUT</constant>
</setHeader>
<setHeader headerName="CamelEhCacheKey" id="setCamelEhCacheAction001">
<simple resultType="java.lang.String">${property[cachekey]}</simple>
</setHeader>
<setHeader headerName="CamelEhcacheValue" id="setCamelEhCacheValue001">
<simple>${body}</simple>
</setHeader>
<to id="putValueToEhCache" uri="ehcache://cache1?keyType=java.lang.String&valueType=java.lang.String"/>
Even after the TTL duration the element is staying in cache. I've been using this as a reference : https://camel.apache.org/cache.html I've been stuck on this for a while now.
Thanks in advance.
CamelCacheTimeToLive is for the old camel-cache component, the new one, camel-ehcache does not handle such header.
To configure cache expiration you need to set-up a custom configuration as explained http://www.ehcache.org/documentation/3.7/expiry.html
I've a small string template (fragment for testing):
{headers.CamelBatchSize}
{headers.CamelFileName}
{headers.CamelFilePath}
{headers.fileCount}
And when I call it:
<setHeader headerName="fileCount">
<simple>${headers.CamelBatchSize}</simple>
</setHeader>
<to uri="string-template:file:notifymail.tm?delimiterStart={&delimiterStop=}" />
The first row is empty (CamelBatchSize) while the others displayed well. Why cannot I use the CamelBatchSize (without putting it into another header variable)? Where am I wrong?
Are you using a Batch-Consumer? https://camel.apache.org/batch-consumer.html
We are trying to send JMS text message over IBM mq using Apache Camel. We are able set few JMS header properties except the JMSPriority. We tried setting int value and used resultType="java.lang.Integer" but unable to alter priority. Any clue would be more than helpful.
<route id="mqSender">
<from uri="direct:mqSender"></from>
<filter>
<simple> ${body} != null</simple>
<setProperty propertyName="originalRequest">
<simple> ${body}</simple>
</setProperty>
<setHeader headerName="JMSCorrelationID">
<simple>${body.messageContextVO.requestID}</simple>
</setHeader>
<setHeader headerName="VersionId">
<simple>${body.metadata["VersionId"]}</simple>
</setHeader>
<setHeader headerName="FunctionId">
<simple>${body.metadata["FunctionId"]}</simple>
</setHeader>
<setHeader headerName="Format">
<simple>${body.metadata["Format"]}</simple>
</setHeader>
<choice>
<when>
<simple>${property.originalRequest.metadata["FetchPriorityValue"]}== "true"</simple>
<transform>
<simple>${body.formattedData}</simple>
</transform>
<setHeader headerName="JMSPriority">
<simple> ${property.originalRequest.priority}</simple>
</setHeader>
<camel:setHeader headerName="CamelJmsDestinationName"><simple>queue:///${property.originalRequest.metadata["queueName"]}?targetClient=1</simple></camel:setHeader>
</when>
</choice>
<log message="${property.originalRequest.metadata[queueName]}"></log>
<recipientList>
<simple>wmq:queue:${property.originalRequest.metadata["queueName"]}?exchangePattern=InOnly</simple>
</recipientList>
<transform>
<simple>${property.originalRequest}</simple>
</transform>
</filter>
<!-- <to uri="bean:trackerUpdateProcessor?method=process" /> -->
</route>
We found solution to make it work. Priority attribute is required to set at header CamelJmsDestinationName
i.e,
<camel:setHeader headerName="CamelJmsDestinationName"><simple>queue:///${property.originalRequest.metadata["queueName"]}?targetClient=1&priority=${dynamicValue}</simple></camel:setHeader>
Sender code checks for value of priority at MQ Destination level in native code. TimeToLive and Priority values needs to set at MQ destination level to work with Camel.
I am not sure about wmq, but for normal jms component (and I believe camel wmq behave the same) to set JMSPriority for specific message endpoint configuration must have option "preserveMessageQos" set to true
Set to true, if you want to send message using the QoS settings specified on the message, instead of the QoS settings on the JMS endpoint. The following three headers are considered JMSPriority, JMSDeliveryMode, and JMSExpiration. You can provide all or only some of them. If not provided, Camel will fall back to use the values from the endpoint instead. So, when using this option, the headers override the values from the endpoint. The explicitQosEnabled option, by contrast, will only use options set on the endpoint, and not values from the message header.
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
I have created a simple cxf web service. following is the body of soap message
<soapenv:Body>
<bean:getRTOEmployeeSalary>
<!--Optional:-->
<bean:arg0>sdf</bean:arg0>
</bean:getRTOEmployeeSalary>
</soapenv:Body>
My requirement is to extract the value of arg0 in my camel context file. i.e. i want to log the value of arg0. Please help me on this
<route routePolicyRef="loggingInInterceptor">
<from uri="cxf:bean:rtoemplyeeService"/>
<setHeader headerName="exchange">
<spel>${exchange}</spel>
</setHeader>
<log message="value of arg0======== "/>
<convertBodyTo type="java.lang.String" id="stringInput"/>
<bean ref="rtoEmpBean" method="getRTOEmployeeSalary" beanType="rtoEmpBean" id="govtRTOEmp"/>
</route>
I need to use the value of arg0 here.
We can use camel provided spring expression language to extract the value from exchange object. Since exchange object also resides in spring container.
below will be code src to extract the value of arg0 in camel context-
<setHeader headerName="arg0">
<spel>#{exchange.in.body.get(0)}</spel>
</setHeader>
This will set the value of arg0 of soap message in a header named arg0.
http://camel.apache.org/spel.html