CAMEL: Adding Properties to a message in Spring DSL - java

I have a simple route in camel, which reads messages from an activemq queue 'A' and writes it to another activemq queue 'B'.I was able to get this to this part to work.
But I need to add a new property to the message before writing it to 'B'. I have tried to add the property 'prop1' to the message using the Spring DSL below, but the property is not being added to the message.
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="activemq:queue:A"/>
<setProperty propertyName="prop1">
<simple>prop1Value</simple>
</setProperty>
<to uri="activemq:queue:B"/>
</route>
</camelContext>
Is this the correct way to add a property to a message in SPRING DSL?

Use a header instead of a property:
<route>
<from uri="activemq:queue:A"/>
<setHeader headerName="prop1">
<constant>prop1Value</constant>
</setHeader>
<to uri="activemq:queue:B"/>
</route>
<route>
<from uri="activemq:queue:B" />
<log message="prop1 = ${header.prop1}" />
</route>
Camel headers are transferred to JMS properties which are transferred back to Camel headers as can be seen looking at the implementation of org.apache.camel.component.jms.JMSBinding. The Camel properties are skipped.

Related

xml transformation using jboss

<bean class="ats.emvo.transform.TransformXml" id="trsnformbean"/>
<camelContext id="cbr-example-context" xmlns="http://camel.apache.org/schema/blueprint">
<route id="_route1">
<from id="_from1" uri="file:///d:/in"/>
<to id="_to2" uri="file:///E:/out"/>
</route>
</camelContext>
i want to Transform XMl to another xml format. assume i have a logic in ats.emvo.transform.TransformXml java file how do i integrated to transform tis in camel context input (file:///d:/in) is xml file and i want to save it as another location as xml. i already add this file as bean class to camel
You can invoke your bean directly in your routing logic. Just make sure your bean is correctly referenced. With Spring XML, the syntax looks like this:
<route id="_route1">
<from id="_from1" uri="file:///d:/in"/>
<bean ref="myBeanName" method="doTransform"/>
<to id="_to2" uri="file:///E:/out"/>
</route>
You may also want to check the Apache Camel documentation on the matter:
http://camel.apache.org/message-translator.html

How to set headers from bean integration method call in a camel route

Help needed on setting headers based on the method call from bean integration.
within my application I am using a custom POJO and there are before I actually send the message over the wire I want to do set the headers on the exchange, but don't want to do it within my bean and rather do it where my spring DSL is written for the route.
I know that usually the value returned from method is sent as body for the message to the next the endpoint but i want to send values returned as header.
I have attached a sample of my route needs to be, and want:
<route id="someRoute">
<from ref="InboundAsyncEndpoint" />
<to uri="bean:validatorBean?method=validateMessageInternals(MyCostomMessagePojo obj)" />
<choice>
<when>
<simple>
${body.getMetaData().getFinalDestinationName()} == 'AMQEndpoint'
</simple>
<to uri="bean:payloadAndHeaderExtractor?extractHeader(MyCostomMessagePojo obj)" />
<to uri="bean:payloadAndHeaderExtractor?extractPayload(MyCostomMessagePojo obj)" /> <!-- i want the headers being set on the exchange from the map that is returnd from the previous bean and method -->
<to uri="activemq:someQueue"
</when>
<otherwise>
...
...
</otherwise>
</choice>
You can do that in the following way:
<setHeader headerName="YOUR_HEADER">
<simple>bean:payloadAndHeaderExtractor?extractHeader(MyCostomMessagePojo obj)</simple>
</setHeader>
Hope this helps.
R.

Camel get response from Route

I am able to called Web Service, now what ever response came from web service, i need to fetch same response in java code so that i am able to further processing.
<camelContext xmlns="http://camel.apache.org/schema/spring" trace="false">
<route id="my_Sample_Camel_Route_with_CXF">
<from uri="file:src/data?noop=true"/>
<log loggingLevel="INFO" message=">>> ${body}"/>
<to uri="cxf://http://www.webservicex.net/stockquote.asmx?wsdlURL=src/main/resources/META-INF/stockquote.wsdl&serviceName={http://www.webserviceX.NET/}StockQuote&portName={http://www.webserviceX.NET/}StockQuoteSoap&dataFormat=MESSAGE"/>
<log loggingLevel="INFO" message=">>> ${body}"/>
</route>
Instead of logging using

Send response to file request?

One of my client put the file request under directory placeorder with below configuration in CAMEL
<route id="FileToJMS">
<from uri="file:target/placeorder" />
<to uri="jms:incomingOrders" />
</route>
Once processing is done from incomingOrders, i want to send the some response to customer who initiated file request. How can i achieve it with CAMEL (probably using request reply or return address pattern). Any ideas?
Like so:
<route id="FileToJMS">
<from uri="file:target/placeorder" />
<to uri="jms:incomingOrders" />
<to uri="mock:response"/>
</route>
replace "mock:response" with whatever component you want to send the response with

camel : File Poller of CSV

I want to do File Poller of CSV, then unmarshaling.like this:
<route>
<from uri="file:///some/path/to/pickup/csvfiles?delete=true&consumer.delay=10000" />
<unmarshal>
<csv />
</unmarshal>
<to uri="bean:myCsvHandler?method=doHandleCsvData" />
</route>
But I also want to get also the file name in my bean.
How do I do this ?
Have doHandleCsvData bind using the Exchange doHandleCsvData(Exchange exchange) then you can get the file name from the headers, extract the body and process the data.

Categories

Resources