You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by German de la Cruz <ge...@gmail.com> on 2012/08/23 02:12:56 UTC

Rename file in endpoint

Hi group!

I've very little experience in Camel (about 8 hours!)

I think it's a very complete framework and very expressive.

I've a rookie doubt (I expect!!)

I've a file endpoint. I've used a chooser to discriminate differents
components to process a message. But, I've a requiremnt of saving the file
for audit purposes. Then, after process the message, I copy it to
differents endpoints (.error, .zip, .b64, .notProcessed) This is only and
example.

But, I'm not sure if files can be unique in name. Then, what I want to do
is to rename the file in the endpoint in an unique way (for example, a
timestamp). In the .error endpoint, I've made it, but, in the rest of the
endpoints I can't!

I've tried to make a second endpoint, in a way to rename the file in the
first one, but I didn't make it.

Any suggestions??

Thanks in advance

German.-

Here the code...

CamelContext context = new DefaultCamelContext();
 context.addRoutes(new RouteBuilder() {
 @Override
public void configure() throws Exception {
                                // I try to rename the file here....
from("file://./var/endpoints/inbound?delete=true")
.to("file://./var/endpoints/processed/");
   // Or here....
from("file://./var/endpoints/processed?delete=true&moveFailed=.error/${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.${file:ext}")
 .choice()
.when().simple("${file:ext} == 'zip'").bean(new Executor(),"publishZip")
 .to("file://./var/endpoints/processed/.zip")
.when().simple("${file:ext} == 'b64'").bean(new Executor(),"publishB64")
 .to("file://./var/endpoints/processed/.b64")
.otherwise()
.to("file://./var/endpoints/processed/.notProcessed");
 }
});
 context.start();

Re: Rename file in endpoint

Posted by German de la Cruz <ge...@gmail.com>.
great!! It works!!

		CamelContext context = new DefaultCamelContext();
		
	
		
		context.addRoutes(new RouteBuilder() {
			
			@Override
			public void configure() throws Exception {
			
//from("file://./var/endpoints/inbound?move=.ok&moveFailed=.error&preMove=.processed")
				from("file://./var/endpoints/inbound?delete=true")
			
.setHeader(Exchange.FILE_NAME,simple("${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.${file:ext}"))
				.to("file://./var/endpoints/processed/");
				
				
				
				from("file://./var/endpoints/processed?delete=true&moveFailed=.error")
					.choice()
						.when().simple("${file:ext} == 'error'").bean(new
Executor(),"publishError")
							.to("file://./var/endpoints/processed/.error")
						.when().simple("${file:ext} == 'zip'").bean(new Executor(),"publish")
							.to("file://./var/endpoints/processed/.zip")
						.when().simple("${file:ext} == 'b64'").bean(new Executor(),"publish")
							.to("file://./var/endpoints/processed/.b64")
						.otherwise()
							.to("file://./var/endpoints/processed/.notProcessed");
			}
		});
		
		context.start();

Thank you very much!



--
View this message in context: http://camel.465427.n5.nabble.com/Rename-file-in-endpoint-tp5717904p5717939.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Rename file in endpoint

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Aug 23, 2012 at 2:52 AM, Willem jiang <wi...@gmail.com> wrote:
> I think you can set the message header of CamelFileName as you want before sending the message to the file endpoint.
>

Yes either set the header CamelFileName   (Exchange.FILE_NAME is a
constant for that same name) with the name of the file you want.

For example to use a bean class MyNamerBean that has a generateUuidName method
.setHeader(Exchange.FILE_NAME, bean(MyNamerBean.class, "generateUuidName"))

public static String generateUuidName(@Header(Exchange.FILE_NAME)
String existingName) {
  // compute new name, and maybe take part of the existing name into
consideration
}

An alternative is to use the fileName option in the endpoint uri, and
use the file language to refer to that bean that computes the unique
file name.
Then you dont have to set the hearer prior.

Some details here
http://camel.apache.org/file-language.html
http://camel.apache.org/file2

And about bean parameter binding, eg such as the @Header used in the bean above
http://camel.apache.org/bean-binding.html
http://camel.apache.org/parameter-binding-annotations.html



> --
> Willem Jiang
>
> FuseSource
> Web: http://www.fusesource.com (http://www.fusesource.com/)
> Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
>           http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
> Twitter: willemjiang
> Weibo: willemjiang
>
>
>
>
>
> On Thursday, August 23, 2012 at 8:12 AM, German de la Cruz wrote:
>
>> Hi group!
>>
>> I've very little experience in Camel (about 8 hours!)
>>
>> I think it's a very complete framework and very expressive.
>>
>> I've a rookie doubt (I expect!!)
>>
>> I've a file endpoint. I've used a chooser to discriminate differents
>> components to process a message. But, I've a requiremnt of saving the file
>> for audit purposes. Then, after process the message, I copy it to
>> differents endpoints (.error, .zip, .b64, .notProcessed) This is only and
>> example.
>>
>> But, I'm not sure if files can be unique in name. Then, what I want to do
>> is to rename the file in the endpoint in an unique way (for example, a
>> timestamp). In the .error endpoint, I've made it, but, in the rest of the
>> endpoints I can't!
>>
>> I've tried to make a second endpoint, in a way to rename the file in the
>> first one, but I didn't make it.
>>
>> Any suggestions??
>>
>> Thanks in advance
>>
>> German.-
>>
>> Here the code...
>>
>> CamelContext context = new DefaultCamelContext();
>> context.addRoutes(new RouteBuilder() {
>> @Override
>> public void configure() throws Exception {
>> // I try to rename the file here....
>> from("file://./var/endpoints/inbound?delete=true")
>> .to("file://./var/endpoints/processed/");
>> // Or here....
>> from("file://./var/endpoints/processed?delete=true&moveFailed=.error/${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.${file:ext}")
>> .choice()
>> .when().simple("${file:ext} == 'zip'").bean(new Executor(),"publishZip")
>> .to("file://./var/endpoints/processed/.zip")
>> .when().simple("${file:ext} == 'b64'").bean(new Executor(),"publishB64")
>> .to("file://./var/endpoints/processed/.b64")
>> .otherwise()
>> .to("file://./var/endpoints/processed/.notProcessed");
>> }
>> });
>> context.start();
>
>
>



-- 
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

Re: Rename file in endpoint

Posted by Willem jiang <wi...@gmail.com>.
I think you can set the message header of CamelFileName as you want before sending the message to the file endpoint.

-- 
Willem Jiang

FuseSource
Web: http://www.fusesource.com (http://www.fusesource.com/)
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang 
Weibo: willemjiang





On Thursday, August 23, 2012 at 8:12 AM, German de la Cruz wrote:

> Hi group!
> 
> I've very little experience in Camel (about 8 hours!)
> 
> I think it's a very complete framework and very expressive.
> 
> I've a rookie doubt (I expect!!)
> 
> I've a file endpoint. I've used a chooser to discriminate differents
> components to process a message. But, I've a requiremnt of saving the file
> for audit purposes. Then, after process the message, I copy it to
> differents endpoints (.error, .zip, .b64, .notProcessed) This is only and
> example.
> 
> But, I'm not sure if files can be unique in name. Then, what I want to do
> is to rename the file in the endpoint in an unique way (for example, a
> timestamp). In the .error endpoint, I've made it, but, in the rest of the
> endpoints I can't!
> 
> I've tried to make a second endpoint, in a way to rename the file in the
> first one, but I didn't make it.
> 
> Any suggestions??
> 
> Thanks in advance
> 
> German.-
> 
> Here the code...
> 
> CamelContext context = new DefaultCamelContext();
> context.addRoutes(new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> // I try to rename the file here....
> from("file://./var/endpoints/inbound?delete=true")
> .to("file://./var/endpoints/processed/");
> // Or here....
> from("file://./var/endpoints/processed?delete=true&moveFailed=.error/${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.${file:ext}")
> .choice()
> .when().simple("${file:ext} == 'zip'").bean(new Executor(),"publishZip")
> .to("file://./var/endpoints/processed/.zip")
> .when().simple("${file:ext} == 'b64'").bean(new Executor(),"publishB64")
> .to("file://./var/endpoints/processed/.b64")
> .otherwise()
> .to("file://./var/endpoints/processed/.notProcessed");
> }
> });
> context.start();