apache camel hazelcast getting custom header - apache-camel

I am trying to get the header or property which i set before calling hazelcast but i couldn't able to get the custom header which i set.
<route>
<from uri=""/>
<setHeader headerName="CamelHazelcastObjectId">
<constant>123</constant>
</setHeader>
<setHeader headerName="CamelHazelcastOperationType">
<constant>put</constant>
</setHeader>
<setHeader headerName="test">
<constant>test</constant>
</setHeader>
<setProperty propertyName="test">
<constant>test</constant>
</setProperty>
<to uri="hazelcast:map:testMap"/>
</route>
When i trying to retrieve my custom header or property couldn't able to get that
<route>
<from uri="hazelcast:map:testMap"/>
<log message = "printing:::: ${in.header.test} and ${property[test]}"/>
<to uri=""/>
Please help on this.

The camel-hazelcast component is only for storing the message body, not message headers.

Related

Camel blueprint <setHeader headerName="CamelHttpPath" id="_setHeader1"><el>${header.uriPattern}</el></setHeader> waiting for dependencies

I have the following Camel Context.
<camelContext id="_camuatomicservicecontext" xmlns="http://camel.apache.org/schema/blueprint">
<route id="_camuatomicserviceroute1">
<from id="_from1" uri="direct-vm:camuatomicservice">
<description>accepts vm messages directly </description>
</from>
<log id="_log1" message="Camu Atomic Service body = ${body}, header= ${header.uriPattern}"/>
<!-- <to id="_to1" uri="restlet:protocol:localhost:8189/"/> -->
<setHeader headerName="api.key" id="_setHeader1">
<constant>replace later with properties api.key Does not matter for this poc</constant>
</setHeader>
<setHeader headerName="CamelHttpPath" id="_setOutHeader1">
<el>${header.uriPattern}</el>
</setHeader>
<to id="_to1" pattern="InOut" uri="netty4-http:http:localhost:8189/path"/>
<log id="_log2" message="CamuAtomicService Response body ${body}"/>
</route>
</camelContext>
From the documentation I expect the CamelHttpPath header to override the endpoint configuration "/path" such that calling Facade Services can pass the header.uriPattern in and dynamically change the resource they want to access. The bundle worked fine until I added the setHeader for CamelHttpPath and now getting "Waiting for dependencies." I assume I need to install a feature, but Simple EL in other bundles on that server work already so not sure what feature I need to install.
Instead of I used and it worked fine. The choice was farther down in the options.

how to append file content in velocity in apache camel

I am trying to write a simple sample :) on Apache-camel velocity. It is supposed to pick up a file and insert its content in a pre-written text (in .vm file). But it just puts the file name in the place. Here is my scripts.
blueprint.xml
<camelContext id="_context1" xmlns="http://camel.apache.org/schema/blueprint">
<route id="_route1">
<from id="_from1" uri="file:work/velocityFileInput"/>
<setHeader headerName="receiver" id="_setHeader1">
<simple>sir</simple>
</setHeader>
<setHeader headerName="senderName" id="_setHeader1">
<simple>Magfa co.</simple>
</setHeader>
<setHeader headerName="meetingAddress" id="_setHeader1">
<simple> Tehran , Iran</simple>
</setHeader>
<setHeader headerName="senderPersonalName" id="_setHeader1">
<simple>Ehsan Zangeneh</simple>
</setHeader>
<to id="_to1" uri="velocity:email.vm"/>
<log message="${body}"></log>
</route>
</camelContext>
and here is my .vm file content
Hello dear ${headers.receiver},
This letter is sent from ${headers.senderName} to inform you that you are
invited to the meeting in the address of '${headers.meetingAddress}'.
The meeting is about
${in}
Best regards
${headers.senderPersonalName}
instead of ${in}, I also tried ${body} which didnt work.
Try to convert the body to string after retrieving content from URI the file.
Might this work, Your route will be like this
<route id="_route1">
<from id="_from1" uri="file:work/velocityFileInput"/>
<convertBodyTo id="_convertBodyFileContent" type="java.lang.String"/>
<setHeader headerName="receiver" id="_setHeader1">
<simple>sir</simple>
</setHeader>
<setHeader headerName="senderName" id="_setHeader1">
<simple>Magfa co.</simple>
</setHeader>
<setHeader headerName="meetingAddress" id="_setHeader1">
<simple> Tehran , Iran</simple>
</setHeader>
<setHeader headerName="senderPersonalName" id="_setHeader1">
<simple>Ehsan Zangeneh</simple>
</setHeader>
<to id="_to1" uri="velocity:email.vm"/>
<log message="${body}"></log>
</route>
and here is your .vm file content
Hello dear ${headers.receiver},
This letter is sent from ${headers.senderName} to inform you that you are
invited to the meeting in the address of '${headers.meetingAddress}'.
The meeting is about
${body}
Best regards
${headers.senderPersonalName}

Unable to send body,subject in mail from camel spring SMTP component

I'm writing one basic camel application using camel-spring.I'm able to send email but Im not able to send body and subject in it.I have tried several ways but only thing im getting in mail body is file contents.Please provide your inputs if you have any idea.
<route id="notification">
<from uri="file:///home?noop=true" />
<camel:choice>
<camel:when>
<camel:simple>
${file:name} contains '{{data}}'
</camel:simple>
<camel:setHeader headerName="from">
<simple>nikhil#from.com</simple>
</camel:setHeader>
<setHeader headerName="subject">
<constant>Hello subject</constant>
</setHeader>
<setHeader headerName="contentType">
<constant>text/plain;charset=UTF-8</constant>
</setHeader>
<camel:setHeader headerName="body">
<constant>Test body</constant>
</camel:setHeader>
<camel:setBody>
<constant>Test camel set body</constant>
</camel:setBody>
<setBody>
<constant>Test set body</constant>
</setBody>
<camel:setOutHeader headerName="subject">
<simple>subject from outheader</simple>
</camel:setOutHeader>
<setHeader headerName="subject">
<constant>Status of check report extractor</constant>
</setHeader>
<camel:to uri="smtps://smtp.server.com:465?username=user#gmail.com&password=pass&to=receiver#yahoo.com&subject=${subject}"></camel:to>
</camel:when>
</camel:choice>
</route>
I have added all combinations that I have tried,but they are not workingThanks in advance.
Please, give a try to this route.
<route id="notification">
<from uri="file:///home?noop=true" />
<setHeader headerName="from">
<constant>nikhil#from.com</constant>
</setHeader>
<setHeader headerName="subject">
<constant>Hello subject</constant>
</setHeader>
<setHeader headerName="contentType">
<constant>text/plain;charset=UTF-8</constant>
</setHeader>
<setBody>
<constant>Test camel set body</constant>
</setBody>
<to uri="smtps://smtp.server.com:465?username=user#gmail.com&password=pass&to=receiver#yahoo.com&from=${header.from}&subject=${header.subject}&contentType=${header.contentType}"/>
</route>
Then we can check the "when/simple" condition.
Note that all the stored headers in the route may be retrieved with ${header.X}.

Terminate the current camel exchange

I am processing file in cluster environment. The cluster works fine. It is being processed on Only one server.
But on the second server It identifies as duplicates but still execute the form route delete=true
ERROR:
org.apache.camel.component.file.GenericFileOperationFailedException: Cannot delete file:
I am setting header CamelRouteStop to true but the exchange still try's to delete a file, instead of stop executing the route.
All I need is to end the route if it is duplicate.
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="smb:url?delete=true"/>
<idempotentConsumer messageIdRepositoryRef="myRepo">
<header>messageId</header>
<setHeader headerName="fileExist">
<simple>true</simple>
</setHeader>
</idempotentConsumer>
<when>
<simple>${header.fileExist} == null</simple>
<log message="File ${header.CamelFileName} processing/processed by other Nodes - DUPLICATE" loggingLevel="INFO" />
<setHeader headerName="CamelRouteStop">
<simple <simple resultType="java.lang.Boolean">true</simple>>true</simple>
</setHeader>
</when>
</route>
</camelContext>
For CamelRouteStop you need to use setProperty, not setHeader.

How to configure a Servlet to HazelCast route using Camel

I want to build a route something like
<route>
<from uri="servlet:///user?matchOnUriPrefix=true"/>
<to uri="direct:put"/>
</route>
<route>
<from uri="direct:put"/>
<setHeader headerName="CamelHazelcastOperationType">
<constant>put</constant>
</setHeader>
<to uri="hazelcast:map:foo"/>
</route>
ie everything that matches POST:/user/{cachename}/{key1} should take the key1 as key and place the payload under key:key1 to map:{cachename}.
Same thing for
GET:/user/{cachename}/{key1} should take the {key1} as key and retrieve the payload under key1 from map:{cachename}.
Any Help will be highly appreciated.
Thanks,
You should have a number of Camel headers available from the incoming servlet, such as:
CamelHttpMethod = GET
CamelHttpPath = /user/{cachename}/{key1}
You could use code or an expression language to extract the information from there, a very basic example would be:
<setHeader headerName="cachename">
<simple>${header.CamelHttpPath.split("/")[2]}</simple>
</setHeader>
<setHeader headerName="key1">
<simple>${header.CamelHttpPath.split("/")[3]}</simple>
</setHeader>

Resources