0

I am trying to pass a to URI value dynamically with a property value. That property value will be configured already in the cfg file.

When the file name is extracted using CamelFileNameOnly header, it has to get passed to the to Uri endpoint. So that the same name is referred in the code.

Please find my code below:

I have dropped a file with name KevinFile.txt in my server location= D:\Servers\jboss-fuse-6.2.0.redhat-133\data\myLocalFTP (file://data/myLocalFTP)

Config File

local.folder.url=file://data/myLocalFTP 
KevinFile=file://data/KevinFileDirectory 

Camel Route

<route id="awsRoute">
      <from uri="{{local.folder.url}}"/>
      <bean ref="processorClass" method="process"/>
      <log message="myProperty value is ${exchangeProperty.myProperty}"/>    <---Gives the fileName 
      <to uri="{{${exchangeProperty.myProperty}}}"/>       <--This is the spot i am getting error :( 
</route>

ProcessorClass.java

public class ProcessorClass implements Processor{ 
@Override 
        public void process(Exchange exchange) throws Exception { 

                String fileName = (String) exchange.getIn().getHeader("CamelFileNameOnly"); 
                exchange.setProperty("myPropertyNew", fileName); 

        } 
} 
Kenster
  • 23,465
  • 21
  • 80
  • 106
  • 1
    Kevin, I am very confused with what you are trying to accomplish can you try to improve the description a bit with a focus on what your goal is? – Matthew Fontana May 12 '16 at 11:45
  • Hi Mathew, I need to pass the Propery "filename" in 'to uri' component so that it will refer the cfg file with the similar name and put the file in specified location. – Antony Kevin May 18 '16 at 13:56

2 Answers2

0

Ah what your looking for is simply setting the header as a property. You can do that like this:

from("direct:start")
    .setHeader("CamelFileNameOnly").simple("{{myPropertyName}}")
    .to("file://data/myLocalDisk");

You can also simplify this by using the uri syntax available on the file component in this case (Thanks to Sergii for the recommendation). Just make sure you check the camel documentation for each component certain components rely on exchange headers, while others can leverage URI properties.

from("direct:start")
    .to("file://data/myLocalDisk?fileName={{myPropertyName}}");

Its also worth noting that if you have logic that you want to use before setting the header you can have the setHeader call a bean.

from("direct:start")
    .setHeader("CamelFileNameOnly").bean(MyPropertyLogicBean.class, "someMethod({{myPropertyName}})")
    .to("file://data/myLocalDisk");

Use the camel properties component to get this property to resolve.

Reference: http://camel.apache.org/properties.html

Matthew Fontana
  • 3,790
  • 2
  • 30
  • 50
0

If I understand correctly, you need to specify "dynamic" vlue for the constant part of the producer. Instead of <to uri="{{${exchangeProperty.myProperty}}}"/> you can use recipientList or routingSlip:

<recipientList>
    <simple>${exchangeProperty.myProperty}</simple>
</recipientList>

or

<routingSlip>
    <simple>${exchangeProperty.myProperty}</simple>
</routingSlip>
Sergii Pozharov
  • 17,366
  • 4
  • 29
  • 30