You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Saurabh <co...@gmail.com> on 2012/09/04 13:41:31 UTC

Re: Naming your file with org.apache.camel.file.name

Hi Friends,

I am working on a small spike in which my task is to pick an xml from a
directory, put it on jms queue and save the xml to some other directory.

This is the code snapshot, this is after I converted the file contents in to
a string.

private static final String URI = "activemq://queue:test.MyQueue"  ;

protected void sendTo(String uri,String message) throws Exception {
		ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
		Exchange exchange = new DefaultExchange(camelContext,
ExchangePattern.InOut);
		exchange.getIn().setBody(message);
		Message camelMessage = exchange.getIn();
		camelMessage.setHeader(Exchange.FILE_NAME, "testmesage");
		System.out.println(exchange.getExchangeId());
		System.out.println(exchange.getIn().getMessageId());
		
		producerTemplate.send(uri, exchange);
		Thread.sleep(1000);
	}

and camel route is 
    <route>
    	<from uri="jms:test.MyQueue"/>
    	<to uri="file://target/test?noop=true/>
    </route>

The file appears in target but with name 
ID-localhost-46447-1346755756577-0-2-2-1-1

and not "testmessage" as I specified.

hope I am clear
Please help

Thanks in advance
Saurabh






--
View this message in context: http://camel.465427.n5.nabble.com/Naming-your-file-with-org-apache-camel-file-name-tp473074p5718602.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: Naming your file with org.apache.camel.file.name

Posted by Saurabh <co...@gmail.com>.
Thanks Arnaud for the reply 

I feel I was not able to describe myself fully in my last post. In the
example below I am picking a xml file src/data/message1.xml and putting it
in a queue test.MyQueue.

After listen this using camel, as shown in camel context and pass this
message in target/test folder. Here I am getting exchangeId as file name
rather than name "testmesage" that I specified.

Integration test class is :

public class AppTest 
    extends TestCase
{
	protected CamelContext camelContext;
	private static final String URI = "activemq://queue:test.MyQueue"  ;
	BrokerService broker;
	public void setUp() throws Exception{
		ApplicationContext applicationContext = new
ClassPathXmlApplicationContext("META-INF/spring/camel-context.xml");
		camelContext = (CamelContext)applicationContext.getBean("camel");
		broker = new BrokerService();
		broker.addConnector("tcp://localhost:61616");
		broker.start();
	}

	
	protected void sendTo(String uri,String message) throws Exception {
		ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
		Exchange exchange = new DefaultExchange(camelContext,
ExchangePattern.InOut);
		exchange.getIn().setBody(message);
		Message camelMessage = exchange.getIn();
		camelMessage.setHeader(Exchange.FILE_NAME, "testmesage");
		System.out.println(exchange.getExchangeId());
		System.out.println(exchange.getIn().getMessageId());
		
		producerTemplate.send(uri, exchange);
		Thread.sleep(1000);
	}
		
   public void testMeth() throws Exception {
	   	File file = new File("src/data/message1.xml");
	   	FileReader fileReader = new FileReader(file);
	   	BufferedReader bufferedReader = new BufferedReader(fileReader);
	   	String message= null;
	   	String str=null;
	   	while( ( (str=bufferedReader.readLine()) != null)) {
	   		message=message+str;
	   	}
	   	sendTo(URI, message);
   }
   
   public void tearDown() {
	   
   }
}

camel route in camel-context.xml is  :

<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">

    <route>
    	<from uri="jms:test.MyQueue"/>
    	<to uri="file://target/test?noop=true/>
    </route>

  </camelContext>

Thanks
Saurabh
thecafetechno.com



--
View this message in context: http://camel.465427.n5.nabble.com/Naming-your-file-with-org-apache-camel-file-name-tp473074p5718605.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: Naming your file with org.apache.camel.file.name

Posted by DEPREZ Arnaud AWL-IT <ar...@atos.net>.
I don't see where you call the method sendTo(...).
If you don't call it, Camel will put the Exchange ID as the name of your file.


Arnaud Deprez
Analyst-Programmer
Acquiring Back-Office
+32 2 727 72 09
arnaud.deprez@atos.net
Chaussee de Haecht 1442 Haachtsesteenweg
1130 Brussels
Belgium
atosworldline.be

 please don't print unless you really need to

-----Original Message-----
From: Saurabh [mailto:computerfresher@gmail.com]
Sent: mardi 4 septembre 2012 13:42
To: users@camel.apache.org
Subject: Re: Naming your file with org.apache.camel.file.name


Hi Friends,

I am working on a small spike in which my task is to pick an xml from a
directory, put it on jms queue and save the xml to some other directory.

This is the code snapshot, this is after I converted the file contents in to
a string.

private static final String URI = "activemq://queue:test.MyQueue"  ;

protected void sendTo(String uri,String message) throws Exception {
                ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
                Exchange exchange = new DefaultExchange(camelContext,
ExchangePattern.InOut);
                exchange.getIn().setBody(message);
                Message camelMessage = exchange.getIn();
                camelMessage.setHeader(Exchange.FILE_NAME, "testmesage");
                System.out.println(exchange.getExchangeId());
                System.out.println(exchange.getIn().getMessageId());

                producerTemplate.send(uri, exchange);
                Thread.sleep(1000);
        }

and camel route is
    <route>
        <from uri="jms:test.MyQueue"/>
        <to uri="file://target/test?noop=true/>
    </route>

The file appears in target but with name
ID-localhost-46447-1346755756577-0-2-2-1-1

and not "testmessage" as I specified.

hope I am clear
Please help

Thanks in advance
Saurabh






--
View this message in context: http://camel.465427.n5.nabble.com/Naming-your-file-with-org-apache-camel-file-name-tp473074p5718602.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Atos Worldline SA/NV - Chaussee de Haecht 1442 Haachtsesteenweg
- 1130 Brussels - Belgium
RPM-RPR Bruxelles-Brussel - TVA-BTW BE 0418.547.872
Bankrekening-Compte Bancaire-Bank Account 310-0269424-44
BIC BBRUBEBB - IBAN BE55 3100 2694 2444

"The information contained in this e-mail and any attachment thereto is confidential and may contain information which is protected by intellectual property rights.
This information is intended for the exclusive use of the recipient(s) named above.
This e-mail does not constitute any binding relationship or offer toward any of the addressees.
If you are not one of the addressees , one of their employees or a proxy holder entitled to hand over this message to the addressee(s), any use of the information contained herein (e.g. reproduction, divulgation, communication or distribution,...) is prohibited.
If you have received this message in error, please notify the sender and destroy it immediately after.
The integrity and security of this message cannot be guaranteed and it may be subject to data corruption, interception and unauthorized amendment, for which we accept no liability."