Saturday, January 24, 2015

Apache Camel Ampersand URL | Apache Camel - Include an Ampersand in an URL

Camel URL Ampersand Issue

Recently I encountered a problem when I was using the Exec component to run multiple Windows batch files at one go.
All my parameters were put in an XML file, so I had something like:
<exec executable="cmd" argument="/c c:/batch1.bat;c:/batch2.bat"/>
However, with these settings, only the first batch file was executed.
After some search, I changed the configuration to
<exec executable="cmd" argument="/c c:/batch1.bat;&amp;c:/batch2.bat"/>
This time Camel complained it did not recognize some parameters (c:/batch2.bat). This was because Camel treats '&' as URL delimiter.

Use RAW  to Escape Ampersand

I managed to solve it by using the syntax RAW:
<exec executable="cmd" argument="RAW(/c c:/batch1.bat;&amp;c:/batch2.bat)"/>

What I want to mention is that RAW must be used to enclose the whole value of a parameter, not a part. So the following does not work:
<exec executable="cmd" argument="/c RAW(c:/batch1.bat;&amp;c:/batch2.bat)"/>

Check more details here.


Create a Successful Online Store at Bigcommerce! Try it Free Now!

No comments:

Post a Comment