I'm using Apache Camel. Using XML DSL, I mean something like
<rests id="rests" xmlns="http://camel.apache.org/schema/spring">
<rest id="rest-custom">
<get uri="my_method" method="">
<description>...</description>
<param name="..." ... />
<route>
<process ref="..." />
<to uri="..." />
</route>
</get>
<post uri="another_method" method="" >
<description>...</description>
<param name="..." .../>
<route>
<process ref="..." />
<to uri="..." />
</route>
</post>
...
So if I want new route, I will just add new <get> or <post> and it works fine.
But now I want to add some DEFAULT method. I mean, something like <get uri="*"> and <post uri="*"> in the bottom of all configuration. So if my url doesn't match any from list - it goes to default one and I can handle it with custom processor (this is the behaviour I want).
For now I don't know, how to do it. Tried to handle 404 responses, but still no success. Looks like solution should be simple, but can't find it yet.
I see only one possible use case for such a default: if you got multiple URLs for the same functionality.
If this is the case and your clients don't want or can't switch to a single URL, you could still use URL rewriting on the incoming request before it reaches your Camel application.
If you want to "catch" all unknown URLs (errors), I guess you should use standard Camel error handling (see Error Handler and Exception clause) because these REST DSL blocks are internally converted to standard Camel routes.
Finally found the solution.
<get uri="/?matchOnUriPrefix=true&bridgeEndpoint=true" method="">
<description>Default GET method</description>
<route>
...
</route>
</get>
Parameters matchOnUriPrefix=true&bridgeEndpoint=true did the trick.
Related
<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 do I use Camel File Component Consumer using multiple threads ?
meaning I have this code :
<route id="incomingFile">
<from
uri="file://{{incomingFileBaseFolder}}?filter=#fileFilter&recursive=true&readLock=changed&move=${file:parent}/.backup/${date:now:yyyy}/backup_${exchangeId}_${file:onlyname.noext}.${file:name.ext}&sortBy=file:modified&delay={{incomingFileDelay}}" />
<transacted />
<threads poolSize="10">
<convertBodyTo type="java.lang.String" />
<setHeader headerName="{{incoming_file_backup_date_header_name}}">
<simple>$simple{date:now:yyyy}
</simple>
</setHeader>
<bean ref="saveFile" method="duplicateCeck" />
<to uri="direct:validateFileDirect" />
<to uri="direct:inputFileContentHandle" />
</threads>
</route>
but it does not seems to work on more than one file at a time.
How do I make it happens ?
Remove <transacted/> as it does not support asynchronous routing. Also transactions only works with component/resources that support JTA transactions natively, which typically is only JMS and JDBC.
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>
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.
I'm dealing with a problem how to read a file with Camel in SMX 4.4.2 but only in case when
the read operation cannot be performed in Camel route from.
I need to read data from the file transform it into XML and then return it to the requestor (the requestor hits SMX via REST Service).
I'm having serious problems with reading the file after the REST invokation.
Routes are like these:
<jaxrs:server id="restService" address="http://localhost:9000/REST/"
staticSubresourceResolution="true">
<jaxrs:serviceBeans>
<ref bean="restFtpBean" />
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="restFtpBean" class="poc.rest.RESTFtpProxyService" />
<cxf:rsServer id="rsServer" address="http://localhost:9000/REST/"
serviceClass="poc.rest.RESTFtpProxyService" />
<camel:camelContext xmlns="http://camel.apache.org/schema/spring">
<endpoint id="ftpProvider" uri="ftp://localhost:21/?fileName=test.xml" />
<route>
<from uri="cxfrs://bean://rsServer" />
<to ref="ftpProvider" />
</route>
</camel:camelContext>
In this scenario Camel tries to write to file !
What am I doing wrong ?
Its always advised to learn and get familiar with the EIPs
http://camel.apache.org/content-enricher.html
Your use-case you need to consume a file from within a route, and there is an EIP pattern for that: http://camel.apache.org/content-enricher.html. See the section about using pollEnrich to consume/poll the file.