Hi Does anyone know how to get a file name without extension in camel. using spring xml.
I know ${header.CamelFileNameOnly} will give the full file name like "test.txt".
I would just like to get the name "test" and need to use this name in somewhere else, does anyone know how to do it ?
Use the file-expression language. Your route shall be something like
<camel:route>
<camel:from uri="file://input/orders" />
<camel:setHeader headerName="FileNameWithoutExtension">
<camel:simple>${file:onlyname.noext}</camel:simple>
</camel:setHeader>
</camel:route>
See the Camel documentation
http://camel.apache.org/file-language.html
You can then do use simple language (http://camel.apache.org/simple.html) to grab the only the name part using ${file:onlyname.noext}
Related
I have one requirement, where I need to move multiple files present in one folder to another. This should be done based on filename which should be dynamic.
As Far I have tried out pollenrich and file (antInclude) but in both case I got struck.
<route id="readFile" autoStartup="true">
<from uri="timer://timer1?repeatCount=1"/>
<setHeader headerName="xxx">
<simple>1234</simple>
</setHeader>
<pollEnrich timeout="15000">
<simple>file://{{baseDirectory}}?move={{destinationDirectory}}&antInclude=*_${header.xxx}.txt</simple>
</pollEnrich>
</route>
Note: Header value will be dynamic, using javascript will pull that data and set it in header.
Any help on this would most welcome.
Thank you for all your response,
I achieved it by using pollenrich but tweaking something in pollenrich.
Got CamelBatchsize using pollenrich.
Running into a loop using size.
Using the above code used to move the file. I achieved it.
Thanks.
I just installed both PHPMD and PHPCS with my Project.
Now, I would like to customize them a bit, but can't seem to achieve it.
I get 2 warnings that I would like to remove for all my project:
phpcs: public method name MyTests::my_test_that_should_pass is not in camel caps format
phpmd: the method my_test_that_should_pass is not in camel case
With PHPMD, I tried to change : .composer/vendor/phpmd/phpmd/src/main/resources/rulesets/controversial.xml and set allow-underscore-test to true like mentioned here
With PHPCS, I don't really know how to do it.
Any idea???
https://phpmd.org/rules/controversial.html
PHPCS uses a file called ruleset.xml to allow you to create your own custom standard. The documentation for it is here: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset
If you want a specific standard for your project, you can include a phpcs.xml file at the root of your project. It's exactly the same format as a ruleset.xml file and can even specify which files and folders need checking by default. Documentation for that is here: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-default-configuration-file
I have no idea what coding standard you are using with PHPCS right now, but I'll assume you are using PSR2.
If you run phpcs with the -s option, you'll see an error message with an error code, like this: Method name "MyTests::my_test_that_should_pass" is not in camel caps format (PSR1.Methods.CamelCapsMethodName.NotCamelCaps). The code is the bit you need here.
For your custom standard, you want PSR2, but you don't want the PSR1.Methods.CamelCapsMethodName sniff because you obviously don't want PHPCS checking for camel case. So create a ruleset with this content:
<?xml version="1.0"?>
<ruleset name="MyStandard">
<description>My custom coding standard.</description>
<rule ref="PSR2">
<exclude name="PSR1.Methods.CamelCapsMethodName"/>
</rule>
</ruleset>
Save that file and call it ruleset.xml or phpcs.xml and then run PHPCS using it: phpcs /path/to/code --standard=/path/to/ruleset.xml
Take a look at the annotated ruleset docs I linked at the top of the comment because there is a lot more you can do with those rulesets.
Is it possible to use SpEL when specifying a URI in a route? I've tried this a few ways but doesn't seem to be working.
Would like to do something like:
<from uri="jms:queue:#{ ${mq.dynamic.switch} ? '$mq.dynamic.queue' : '$mq.static.queue'}?connectionFactory=#connectionFactory" />
I'm essentially trying to evaluate a property to determine what queues to leverage when configuring a JMS route.
No that is not possible in <from>. Howerver you can use Camel's property placeholders:
http://camel.apache.org/using-propertyplaceholder.html
And in Camel routes such as <to> you can use "dynamic-to" which allows to use any of the scripting languages such as SpEL also:
http://camel.apache.org/how-to-use-a-dynamic-uri-in-to.html
http://camel.apache.org/languages.html
I have a simple camel route I need to modify. The route looks like this:
from(source.uri)
.unmarshal()
.bean(TransformMessageBean.class, "SomeMethod")
.to(destination.uri)
I want to add another bean method call after the unmarshaling that set's a header value without disrupting the current data flow . Does anyone know of a way to do this? I read that in apache's documentation that a bean's return value is set in the outbound message body. Is there a way to change that to a header?
Thanks in advance!
Certainly! One of the options available is
.setHeader("headerName").method(beanInstance, "methodToGetHeaderValue")
Using this approach, the method (say, methodToGetHeaderValue) on the provided bean instance will return a value, and that will become the value of the header.
There are a number of options available. You can call it with a bean instance, a bean class (like in your example), or even a bean name, all with or without a method name.
In Spring XML DSL, it would be something like
<setHeader headerName="headerName">
<method bean="mybean" method="mymethod" />
</setHeader>
Another way in XML:
<setHeader name="headerName">
<simple>${bean:yourBean.getMethod}</simple>
</setHeader>
The XSD allows to specify customId="true" id="foo" in the route elements. But when reading the route using Spring you get a parse error in Spring. I can't able to understand this bug. Can you please clarify me?
You should not use customId but only id.
The customId is for internal usage when updating routes from XML that the id is auto assigned or assigned by the end user.