You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by edvicif <ed...@gmail.com> on 2012/07/16 18:00:50 UTC

Cannot use fileName property for path extension

Hi!

I wanted to use poll enrich to pick up different files from host, based on
the path and filename.
I was thinking to have something like:
file:/?fileName=${in.body}

Where body is an absolute path of the file. I wasn't able to make it work.

I've created a unit test, where I set up three file. One I try to consume
with defining path after the : but the other two example I try to use
relative path.

Based on other topic thread and the camel file language description. Both
the second and third test case should work. Meaning files are copied. On my
machine which is Windows XP using Camel 2.9.2 they are failing.

There is also an interesting entry in the log file:
DEBUG Creating endpoint
uri=[file:///C:/DOCUME%7E1/myuser/LOCALS%7E1/Temp/junit4621650582543353407/?fileName=subfolder%2Ftest2.txt&idempotent=false&noop=true&recursive=false],
path=[/C:/DOCUME~1/myuser/LOCALS~1/Temp/junit4621650582543353407/],
parameters=[{fileName=subfolder/test2.txt, idempotent=false, noop=true,
recursive=false}]

Note the '/' is replaced, with %2F at the fileName section.

I've tried to replicate the test case using spring DSL
In the log file this is what appear:
DEBUG Camel Routes:
[EventDrivenConsumerRoute[Endpoint[file://removed_for_anonimity/?fileName=/source/mytest.txt&idempotent=false&noop=true&recursive=false]
->
Instrumentation:route[DelegateAsync[UnitOfWork(RouteContextProcessor[Channel[sendTo(Endpoint[file://removed_for_anonimity/temp/poll?fileName=test3.txt])]])]]]]

Here slashes wasn't replaced to %2F. But the solution didn't work. Any idea
what I'm messing up?

David

-----
package experiments.camel.file;

import java.io.File;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

public class DynamicFileEndpointsTest extends CamelTestSupport{
  
  
    @Rule
    public TemporaryFolder temporaryFolder = new TemporaryFolder();
    
    @Before
    public void createFileToCopy() throws Exception{
      temporaryFolder.newFolder("subfolder");
      temporaryFolder.newFile("subfolder/test1.txt");
      temporaryFolder.newFile("subfolder/test2.txt");
      temporaryFolder.newFile("subfolder/test3.txt");
      temporaryFolder.newFolder("target");
    }
    
  
  @Override
  protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

      @Override
      public void configure() throws Exception {
        from(temporaryFolder.getRoot().toURI() +
"/subfolder/?fileName=test1.txt&noop=true&idempotent=false")
        .to(new
File(temporaryFolder.getRoot(),"target").toURI().toString());
        
        from(temporaryFolder.getRoot().toURI() +
"?fileName=subfolder/test2.txt&noop=true&idempotent=false&recursive=false")
        .to(new
File(temporaryFolder.getRoot(),"target").toURI().toString());

        from(temporaryFolder.getRoot().toURI() +
"?fileName=subfolder/test3.txt&noop=true&idempotent=false&recursive=true")
        .to(new
File(temporaryFolder.getRoot(),"target").toURI().toString());

      }
    };
  }

  @Test
  public void testTarget1() throws Exception {
    Thread.sleep(2000);
    assertTrue(new File(temporaryFolder.getRoot(),
"target/test1.txt").exists());
  }
  @Test
  public void testTarget2() throws Exception {
    Thread.sleep(2000);
    assertTrue(new File(temporaryFolder.getRoot(),
"target/test2.txt").exists());
  }

  @Test
  public void testTarget3() throws Exception {
    Thread.sleep(2000);
    assertTrue(new File(temporaryFolder.getRoot(),
"target/test3.txt").exists());
  }

}


--
View this message in context: http://camel.465427.n5.nabble.com/Cannot-use-fileName-property-for-path-extension-tp5716085.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Cannot use fileName property for path extension

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

PollEnrich does not currently support dynamic uris with details from
the current Exchange.

We did put that in a red warning box at its eip documentation for pollEnrich
http://camel.apache.org/content-enricher.html

There is a JIRA ticket to improve this in the future. No later than
Camel 3.0, as it requires an API change in the core.
So we are more careful to go down that in the 2.x codebase.

And use the vote in the JIRA ticket to let us know which tickets you
want us to fix first.



On Mon, Jul 16, 2012 at 6:00 PM, edvicif <ed...@gmail.com> wrote:
> Hi!
>
> I wanted to use poll enrich to pick up different files from host, based on
> the path and filename.
> I was thinking to have something like:
> file:/?fileName=${in.body}
>
> Where body is an absolute path of the file. I wasn't able to make it work.
>
> I've created a unit test, where I set up three file. One I try to consume
> with defining path after the : but the other two example I try to use
> relative path.
>
> Based on other topic thread and the camel file language description. Both
> the second and third test case should work. Meaning files are copied. On my
> machine which is Windows XP using Camel 2.9.2 they are failing.
>
> There is also an interesting entry in the log file:
> DEBUG Creating endpoint
> uri=[file:///C:/DOCUME%7E1/myuser/LOCALS%7E1/Temp/junit4621650582543353407/?fileName=subfolder%2Ftest2.txt&idempotent=false&noop=true&recursive=false],
> path=[/C:/DOCUME~1/myuser/LOCALS~1/Temp/junit4621650582543353407/],
> parameters=[{fileName=subfolder/test2.txt, idempotent=false, noop=true,
> recursive=false}]
>
> Note the '/' is replaced, with %2F at the fileName section.
>
> I've tried to replicate the test case using spring DSL
> In the log file this is what appear:
> DEBUG Camel Routes:
> [EventDrivenConsumerRoute[Endpoint[file://removed_for_anonimity/?fileName=/source/mytest.txt&idempotent=false&noop=true&recursive=false]
> ->
> Instrumentation:route[DelegateAsync[UnitOfWork(RouteContextProcessor[Channel[sendTo(Endpoint[file://removed_for_anonimity/temp/poll?fileName=test3.txt])]])]]]]
>
> Here slashes wasn't replaced to %2F. But the solution didn't work. Any idea
> what I'm messing up?
>
> David
>
> -----
> package experiments.camel.file;
>
> import java.io.File;
>
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.test.junit4.CamelTestSupport;
> import org.junit.Before;
> import org.junit.Rule;
> import org.junit.Test;
> import org.junit.rules.TemporaryFolder;
>
> public class DynamicFileEndpointsTest extends CamelTestSupport{
>
>
>     @Rule
>     public TemporaryFolder temporaryFolder = new TemporaryFolder();
>
>     @Before
>     public void createFileToCopy() throws Exception{
>       temporaryFolder.newFolder("subfolder");
>       temporaryFolder.newFile("subfolder/test1.txt");
>       temporaryFolder.newFile("subfolder/test2.txt");
>       temporaryFolder.newFile("subfolder/test3.txt");
>       temporaryFolder.newFolder("target");
>     }
>
>
>   @Override
>   protected RouteBuilder createRouteBuilder() throws Exception {
>     return new RouteBuilder() {
>
>       @Override
>       public void configure() throws Exception {
>         from(temporaryFolder.getRoot().toURI() +
> "/subfolder/?fileName=test1.txt&noop=true&idempotent=false")
>         .to(new
> File(temporaryFolder.getRoot(),"target").toURI().toString());
>
>         from(temporaryFolder.getRoot().toURI() +
> "?fileName=subfolder/test2.txt&noop=true&idempotent=false&recursive=false")
>         .to(new
> File(temporaryFolder.getRoot(),"target").toURI().toString());
>
>         from(temporaryFolder.getRoot().toURI() +
> "?fileName=subfolder/test3.txt&noop=true&idempotent=false&recursive=true")
>         .to(new
> File(temporaryFolder.getRoot(),"target").toURI().toString());
>
>       }
>     };
>   }
>
>   @Test
>   public void testTarget1() throws Exception {
>     Thread.sleep(2000);
>     assertTrue(new File(temporaryFolder.getRoot(),
> "target/test1.txt").exists());
>   }
>   @Test
>   public void testTarget2() throws Exception {
>     Thread.sleep(2000);
>     assertTrue(new File(temporaryFolder.getRoot(),
> "target/test2.txt").exists());
>   }
>
>   @Test
>   public void testTarget3() throws Exception {
>     Thread.sleep(2000);
>     assertTrue(new File(temporaryFolder.getRoot(),
> "target/test3.txt").exists());
>   }
>
> }
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Cannot-use-fileName-property-for-path-extension-tp5716085.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen