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.
Related
How can I replace the uri with the text from configuration file myprops.cfg?
<route id="camel-http-proxy2">
<from uri="jetty://http://127.0.0.1:5555/mock"/>
</route>
myprops.cfg:
myuri=http://127.0.0.1:555/mock
my try:
<route id="camel-http-proxy2">
<from uri="jetty://${myuri}"/>
</route>
Then the camel read the uri as it is, it doesnt replace it with the value of the property.
another try:
<endpoint id="input1" uri="jetty//${myuri}"/>
<route id="camel-http-proxy2">
<from uri="ref:input1"/>
</route>
error:
org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to validate xml
org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element '{"http://camel.apache.org/schema/blueprint":endpoint}'. One of '{"http://camel.apache.org/schema/blueprint":route}' is expected.
The answer is:
<route id="camel-http-proxy2">
<from uri="jetty://{{myuri}}"/>
</route>
The documentation of camel is not updated I think.
You need to add the config file within the property-placeholder tag.
<cm:property-placeholder id="myblueprint.placeholder" persistent-id="myprops">
You can then reference the property as ${properties:myuri} or {{myuri}}
<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
I'm having a bit of an issue with preventing the original file from being renamed when I throw/catch an Exception in a Processor.
I have a route like this:
<route customId="true" id="localRoute">
<from uri="{{ftp.pull.LOCAL.server}}" />
<process ref="Processor" />
<to uri="{{ftp.push.LOCAL.route}}" />
</route>
The from URI includes the option of: &move=${file:name.noext}.${file:name.ext}.old
And during my Process, I stop the Exchange from being routed to the end under certain conditions and also throw an Exception that I catch using:
<onException>
<exception>com.myException.ThrownException</exception>
<handled><constant>true</constant></handled>
</onException>
Is there any way to prevent the renaming of the original file I'm pulling from if I throw and catch that exception?
(I throw and catch that Exception in order to prevent a file from entering a Idempotent File Repository for other routes. Many routes use this Processor.)
File will be renamed unless you remove the <handled> or mark that as false.
If you handle the exception it won't propagate and your file component thinks that the Camel exchange processed successfully and it will rename the file.
So I think I may have found an answer.
So what I have found out is that by doing a global <onException> block that catches my custom Exception, it will prevent logging a stack trace and entering in a file name into the File Repo for routes that use a Idempotent File Repository. But that global block will not prevent the routes that rename files from renaming the files.
In order to catch the Exception and prevent the logging of the stack trace on routes that rename files, I needed to use the doTry/doCatch blocks. I have to do something like this:
<route customId="true" id="localRoute">
<from uri="{{ftp.pull.LOCAL.server}}" />
<doTry>
<process ref="Processor" />
<doCatch><exception>com.myException.ThrownException</exception></doCatch>
</doTry>
<to uri="{{ftp.push.LOCAL.route}}" />
</route>
So my solution ends up looking like this:
<camelContext xmlns="http://camel.apache.org/schema/spring">
<onException>
<exception>com.myException.ThrownException</exception>
<handled><constant>true</constant></handled>
</onException>
<route customId="true" id="localRoute">
<from uri="{{ftp.pull.LOCAL.server}}" />
<doTry>
<process ref="Processor" />
<doCatch><exception>com.myException.ThrownException</exception></doCatch>
</doTry>
<to uri="{{ftp.push.LOCAL.route}}" />
</route>
<route customId="true" id="otherRoute">
<from uri="{{ftp.pull.OTHER.server}}" />
<setHeader headerName="otherFileRepoKey">
<simple>${file:name}-${file:modified}</simple>
</setHeader>
<idempotentConsumer messageIdRepositoryRef="otherFileStore">
<header>otherFileRepoKey</header>
<process ref="Processor" />
<to uri="{{ftp.push.OTHER.route}}"/>
</idempotentConsumer>
</route>
</camelContext>
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
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.