You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by servicemix-user <mo...@gmail.com> on 2010/11/01 06:26:06 UTC

Camel Route - How to avoid Multiple files in target folder

hi

i deployed a camel routing service in servicemix.  here is my code
                       try {
			        context.addRoutes(new RouteBuilder() {				
			         public void configure() {
			             
from("http://localhost/testservice/resources/1").to("file:/target/"); 
			         } });
		           } catch (Exception e) {
				e.printStackTrace();
                  	  }
	                 try{
                	      context.start();
                             Thread.sleep(5000);
                              context.stop();
                 	}catch(Exception e){}

while the program(servicemix) is running it is invoked the web service
(http://localhost/testservice/resources/1) specified in the from() method,
and the output of the xml values are stored inside the target folder. 
 my xml output will be like this, <?xml version=1.1><root> <test>my sample
service </test></root>
 Problem:
   It creates multiple text file along with the xml value inside the targer
folder. when ever i execute the program it will put around 100 text files in
the target folder . i want to store it in a single text file. how do i
overcome this issue.

-- 
View this message in context: http://servicemix.396122.n5.nabble.com/Camel-Route-How-to-avoid-Multiple-files-in-target-folder-tp3244637p3244637.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Camel Route - How to avoid Multiple files in target folder

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Nov 1, 2010 at 2:01 PM, servicemix-user <mo...@gmail.com> wrote:
>
> HI,
> I tried to fetch the output using following code what u gave,
>
> from("http://localhost/testservice/resources/1")
> .setHeader(FileComponent.HEADER_FILE_NAME, constant("output.txt"))
> .to("file:/target/")
>
>
>
> But in Output.txt file have put the same record again and again ( its around
> 30,000 line )
>

That is because you are consuming from http endpoint, which means it
will invoke a GET on the http endpoint and send out a message with
that response.

If you want to expose a http server that other clients can invoke, use
the jetty endpoint instead.
http://camel.apache.org/jetty



>
> <?xml version="1.0" encoding="UTF-8"
> standalone="yes"?><abc><xmlcontent><address>Chennai</address><name>Ramya</name><mobileno>987878</mobileno><phoneno>43423</phoneno><vehicle_colour>red</vehicle_colour><vehicle_no>TN1456</vehicle_no><vehicle_type>maruthi</vehicle_type></xmlcontent></abc><?xml
> version="1.0" encoding="UTF-8"
> standalone="yes"?><abc><xmlcontent><address>Chennai</address><name>Ramya</name><mobileno>987878</mobileno><phoneno>43423</phoneno><vehicle_colour>red</vehicle_colour><vehicle_no>TN1456</vehicle_no><vehicle_type>maruthi</vehicle_type></xmlcontent></abc><?xml
> version="1.0" encoding="UTF-8"
> standalone="yes"?><abc><xmlcontent><address>Chennai</address><name>Ramya</name><mobileno>987878</mobileno><phoneno>43423</phoneno><vehicle_colour>red</vehicle_colour><vehicle_no>TN1456</vehicle_no><vehicle_type>maruthi</vehicle_type></xmlcontent></abc><?xml
> version="1.0" encoding="UTF-8"
> standalone="yes"?><abc><xmlcontent><address>Chennai</address><name>Ramya</name><mobileno>987878</mobileno><phoneno>43423</phoneno><vehicle_colour>red</vehicle_colour><vehicle_no>TN1456</vehicle_no><vehicle_type>maruthi</vehicle_type></xmlcontent></abc>
>
>
>
> Pls give the sample code  and give  ur valuable feedback for this..
>
>
>
> --
> View this message in context: http://servicemix.396122.n5.nabble.com/Camel-Route-How-to-avoid-Multiple-files-in-target-folder-tp3244637p3245001.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>



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

Re: Camel Route - How to avoid Multiple files in target folder

Posted by servicemix-user <mo...@gmail.com>.
why it is creating this much of files or putting the same content in the
single file. what is the reason?

is it the reason of Thread.sleep(5000) time delay?
the problem we find out it is invoking the rest service more than 100 times
with in the time delay we mentioned above. thats y it is creating the
multiple files as wel as multiple content in the same file.

how to over come this issue..

kindly give me your suggestion and the solution.



-- 
View this message in context: http://servicemix.396122.n5.nabble.com/Camel-Route-How-to-avoid-Multiple-files-in-target-folder-tp3244637p3246215.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Camel Route - How to avoid Multiple files in target folder

Posted by servicemix-user <mo...@gmail.com>.
hi
thanks for your reply.
this is our requirement: 
Multiple REST service running on various host. Client send the request to
servicemix and serivcemix will decide which of the service to be called. For
eg System A is the client and sending the request to System B(Servicemix
running). Based on the Client request , the servicemix invoke the SystemC(
Webservice Running) and the output of the xml send back to the same client.

We took loan broker example for the above requirement. In these Client
(System A) can send the request to Servicemix (System B) and service mix
succesfully invoking the related REST Webservice (from System C) and the
output stored in the specifed file(output.txt). we want to send back the
result to the requested client. but we are receiving the output content as
many times. 

Sample code and the output are mentioned below:

This is my RouteBuilder.java file which is running under Servicemix(System
B)
   try {
                                context.addRoutes(new RouteBuilder() {
                                 public void configure() {
                                    
from("http://localhost/testservice/resources/1")
.setHeader(FileComponent.HEADER_FILE_NAME, constant("output.txt"))
.to("file:/target/?autoCreate=false&append=true")

                                 } });
                           } catch (Exception e) {
                                e.printStackTrace();
                   }
                         try{
                     context.start();
                             Thread.sleep(5000);
                              context.stop();
                  }catch(Exception e){}

this is the sample  OUTPUT we are getting in the  OUTPUT.TXT file:-

<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><abc><xmlcontent><address>Chennai</address><name>Ramya</name><mobileno>987878</mobileno><phoneno>43423</phoneno><vehicle_colour>red</vehicle_colour><vehicle_no>TN1456</vehicle_no><vehicle_type>maruthi</vehicle_type></xmlcontent></abc><?xml
version="1.0" encoding="UTF-8"
standalone="yes"?><abc><xmlcontent><address>Chennai</address><name>Ramya</name><mobileno>987878</mobileno><phoneno>43423</phoneno><vehicle_colour>red</vehicle_colour><vehicle_no>TN1456</vehicle_no><vehicle_type>maruthi</vehicle_type></xmlcontent></abc><?xml
version="1.0" encoding="UTF-8"
standalone="yes"?><abc><xmlcontent><address>Chennai</address><name>Ramya</name><mobileno>987878</mobileno><phoneno>43423</phoneno><vehicle_colour>red</vehicle_colour><vehicle_no>TN1456</vehicle_no><vehicle_type>maruthi</vehicle_type></xmlcontent></abc><?xml
version="1.0" encoding="UTF-8"
standalone="yes"?><abc><xmlcontent><address>Chennai</address><name>Ramya</name><mobileno>987878</mobileno><phoneno>43423</phoneno><vehicle_colour>red</vehicle_colour><vehicle_no>TN1456</vehicle_no><vehicle_type>maruthi</vehicle_type></xmlcontent></abc> 

;
;
;
encoding="UTF-8"
standalone="yes"?><abc><xmlcontent><address>Chennai</address><name>Ramya</name><mobileno>987878</mobileno><phoneno>43423</phoneno><vehicle_colour>red</vehicle_colour><vehicle_no>TN1456</vehicle_no><vehicle_type>maruthi</vehicle_type></xmlcontent></abc>
(CONT...)

---------------------------------------------------------------------------------------------------------------------------------------

The problem is:
now it is not created 100 files instead it put the same xml content again
and again in the single output.txt file (around 30,000 lines). how to avoid
this issue. i want to retrieve it once.





 
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/Camel-Route-How-to-avoid-Multiple-files-in-target-folder-tp3244637p3246205.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Camel Route - How to avoid Multiple files in target folder

Posted by Geert Schuring <ge...@schuring.eu>.
Maybe you can provide us with some more detailed information on what you
are trying to achieve, because it looks like you're calling a RESTfull
webservice with a static id value, and are then surprised when subsequent
responses are all the same, which is exactly what the service should do.

If you want to periodically poll a webservice, then use a quartz endpoint
to generate events that trigger the http consumer, and file producer.

Geert.

>
> HI,
> I tried to fetch the output using following code what u gave,
>
> from("http://localhost/testservice/resources/1")
> .setHeader(FileComponent.HEADER_FILE_NAME, constant("output.txt"))
> .to("file:/target/")
>
>
>
> But in Output.txt file have put the same record again and again ( its
> around
> 30,000 line )
>
>
> <?xml version="1.0" encoding="UTF-8"
> standalone="yes"?><abc><xmlcontent><address>Chennai</address><name>Ramya</name><mobileno>987878</mobileno><phoneno>43423</phoneno><vehicle_colour>red</vehicle_colour><vehicle_no>TN1456</vehicle_no><vehicle_type>maruthi</vehicle_type></xmlcontent></abc><?xml
> version="1.0" encoding="UTF-8"
> standalone="yes"?><abc><xmlcontent><address>Chennai</address><name>Ramya</name><mobileno>987878</mobileno><phoneno>43423</phoneno><vehicle_colour>red</vehicle_colour><vehicle_no>TN1456</vehicle_no><vehicle_type>maruthi</vehicle_type></xmlcontent></abc><?xml
> version="1.0" encoding="UTF-8"
> standalone="yes"?><abc><xmlcontent><address>Chennai</address><name>Ramya</name><mobileno>987878</mobileno><phoneno>43423</phoneno><vehicle_colour>red</vehicle_colour><vehicle_no>TN1456</vehicle_no><vehicle_type>maruthi</vehicle_type></xmlcontent></abc><?xml
> version="1.0" encoding="UTF-8"
> standalone="yes"?><abc><xmlcontent><address>Chennai</address><name>Ramya</name><mobileno>987878</mobileno><phoneno>43423</phoneno><vehicle_colour>red</vehicle_colour><vehicle_no>TN1456</vehicle_no><vehicle_type>maruthi</vehicle_type></xmlcontent></abc>
>
>
>
> Pls give the sample code  and give  ur valuable feedback for this..
>
>
>
> --
> View this message in context:
> http://servicemix.396122.n5.nabble.com/Camel-Route-How-to-avoid-Multiple-files-in-target-folder-tp3244637p3245001.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>
>



Re: Camel Route - How to avoid Multiple files in target folder

Posted by servicemix-user <mo...@gmail.com>.
HI,
I tried to fetch the output using following code what u gave,

from("http://localhost/testservice/resources/1")
.setHeader(FileComponent.HEADER_FILE_NAME, constant("output.txt"))
.to("file:/target/") 



But in Output.txt file have put the same record again and again ( its around
30,000 line )


<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><abc><xmlcontent><address>Chennai</address><name>Ramya</name><mobileno>987878</mobileno><phoneno>43423</phoneno><vehicle_colour>red</vehicle_colour><vehicle_no>TN1456</vehicle_no><vehicle_type>maruthi</vehicle_type></xmlcontent></abc><?xml
version="1.0" encoding="UTF-8"
standalone="yes"?><abc><xmlcontent><address>Chennai</address><name>Ramya</name><mobileno>987878</mobileno><phoneno>43423</phoneno><vehicle_colour>red</vehicle_colour><vehicle_no>TN1456</vehicle_no><vehicle_type>maruthi</vehicle_type></xmlcontent></abc><?xml
version="1.0" encoding="UTF-8"
standalone="yes"?><abc><xmlcontent><address>Chennai</address><name>Ramya</name><mobileno>987878</mobileno><phoneno>43423</phoneno><vehicle_colour>red</vehicle_colour><vehicle_no>TN1456</vehicle_no><vehicle_type>maruthi</vehicle_type></xmlcontent></abc><?xml
version="1.0" encoding="UTF-8"
standalone="yes"?><abc><xmlcontent><address>Chennai</address><name>Ramya</name><mobileno>987878</mobileno><phoneno>43423</phoneno><vehicle_colour>red</vehicle_colour><vehicle_no>TN1456</vehicle_no><vehicle_type>maruthi</vehicle_type></xmlcontent></abc> 



Pls give the sample code  and give  ur valuable feedback for this..



-- 
View this message in context: http://servicemix.396122.n5.nabble.com/Camel-Route-How-to-avoid-Multiple-files-in-target-folder-tp3244637p3245001.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Camel Route - How to avoid Multiple files in target folder

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Nov 1, 2010 at 9:38 AM, Geert Schuring <ge...@schuring.eu> wrote:
> Hey,
>
> If you configure the file producer endpoint to use a fixed filename and
> append any messages to it instead of replacing it, you'll get 1 file that
> lists all received messages.
>
> There are 2 ways to set the filename;
>
> 1:
> from("http://localhost/testservice/resources/1")
> .setHeader(FileComponent.HEADER_FILE_NAME, constant("output.txt"))
> .to("file:/target/")
>
> 2:
> from("http://localhost/testservice/resources/1")
> .to("file:/target/output.txt?autoCreate=false")
>
> Autocreate must be set to false here because otherwise the file component
> will create a directory called 'output.txt', and write those 100 files
> there.
>
>
> To make sure the messages are not overwriting each-other you set append to
> true:
>
> from("http://localhost/testservice/resources/1")
> .to("file:/target/output.txt?autoCreate=false&append=true")
>
> Even though the default value of append is 'true', its always a good idea
> to explicitly set parameters that are essential for you.
>
> For a complete description of the File component see:
> http://camel.apache.org/file.html
>

Actually if you are using Camel 2.x then its this page
http://camel.apache.org/file2.html


>
> Greets,
> Geert.
>
>
>>
>> hi
>>
>> i deployed a camel routing service in servicemix.  here is my code
>>                        try {
>>                               context.addRoutes(new RouteBuilder() {
>>                                public void configure() {
>>
>> from("http://localhost/testservice/resources/1").to("file:/target/");
>>                                } });
>>                          } catch (Exception e) {
>>                               e.printStackTrace();
>>                         }
>>                        try{
>>                             context.start();
>>                              Thread.sleep(5000);
>>                               context.stop();
>>                       }catch(Exception e){}
>>
>> while the program(servicemix) is running it is invoked the web service
>> (http://localhost/testservice/resources/1) specified in the from() method,
>> and the output of the xml values are stored inside the target folder.
>>  my xml output will be like this, <?xml version=1.1><root> <test>my sample
>> service </test></root>
>>  Problem:
>>    It creates multiple text file along with the xml value inside the
>> targer
>> folder. when ever i execute the program it will put around 100 text files
>> in
>> the target folder . i want to store it in a single text file. how do i
>> overcome this issue.
>>
>> --
>> View this message in context:
>> http://servicemix.396122.n5.nabble.com/Camel-Route-How-to-avoid-Multiple-files-in-target-folder-tp3244637p3244637.html
>> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>>
>>
>>
>
>
>



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

Re: Camel Route - How to avoid Multiple files in target folder

Posted by Geert Schuring <ge...@schuring.eu>.
Hey,

If you configure the file producer endpoint to use a fixed filename and
append any messages to it instead of replacing it, you'll get 1 file that
lists all received messages.

There are 2 ways to set the filename;

1:
from("http://localhost/testservice/resources/1")
.setHeader(FileComponent.HEADER_FILE_NAME, constant("output.txt"))
.to("file:/target/")

2:
from("http://localhost/testservice/resources/1")
.to("file:/target/output.txt?autoCreate=false")

Autocreate must be set to false here because otherwise the file component
will create a directory called 'output.txt', and write those 100 files
there.


To make sure the messages are not overwriting each-other you set append to
true:

from("http://localhost/testservice/resources/1")
.to("file:/target/output.txt?autoCreate=false&append=true")

Even though the default value of append is 'true', its always a good idea
to explicitly set parameters that are essential for you.

For a complete description of the File component see:
http://camel.apache.org/file.html


Greets,
Geert.


>
> hi
>
> i deployed a camel routing service in servicemix.  here is my code
>                        try {
> 			        context.addRoutes(new RouteBuilder() {
> 			         public void configure() {
>
> from("http://localhost/testservice/resources/1").to("file:/target/");
> 			         } });
> 		           } catch (Exception e) {
> 				e.printStackTrace();
>                   	  }
> 	                 try{
>                 	      context.start();
>                              Thread.sleep(5000);
>                               context.stop();
>                  	}catch(Exception e){}
>
> while the program(servicemix) is running it is invoked the web service
> (http://localhost/testservice/resources/1) specified in the from() method,
> and the output of the xml values are stored inside the target folder.
>  my xml output will be like this, <?xml version=1.1><root> <test>my sample
> service </test></root>
>  Problem:
>    It creates multiple text file along with the xml value inside the
> targer
> folder. when ever i execute the program it will put around 100 text files
> in
> the target folder . i want to store it in a single text file. how do i
> overcome this issue.
>
> --
> View this message in context:
> http://servicemix.396122.n5.nabble.com/Camel-Route-How-to-avoid-Multiple-files-in-target-folder-tp3244637p3244637.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>
>