You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Elezabeth <El...@ibsplc.com> on 2012/09/25 14:55:01 UTC

Camel and tomcat

Hi ,I am trying to make use of  camel in tomcat server. My requirement is to
read a cvs file in a folder whenever a *http request* is hit. I was able to
do this successfully using camel when I was using the "Run as a Java
application" in y IDE.Now I have to do the same thing in "Run on server" and
I using tomcat server 7.0 .  But now nothing is working..  I am not able to
understand wat exactly is happening. I checked the camel servlet tomcat
example.But that couldn't help me..I am pasting my code
below./*OagProcessor.java*/public class OagProcessor extends RouteBuilder {   
DataFormat bindy = new BindyCsvDataFormat(           
"jp.co.airlink.gavss.adapter.eai.oag.job");    Exchange exchnge = null;   
String fileName = null;    @Override    public void configure() throws
Exception {        System.out.println("in configure");       
from("http://localhost:8080/test").inOnly("seda:myfile");       
from("seda:myfile").inOnly("bean:fileConsumer?method=consumeFile")               
.unmarshal(bindy)               
.to("bean:validateFileInput?method=receiveOagData");   
}}*/FileConsumer.java/*public class FileConsumer {		@Inject	private
ConsumerTemplate consumer;		@Inject	private ProducerTemplate producer;	
public void setConsumer(ConsumerTemplate consumer) {		this.consumer =
consumer;	}		public void setProducer(ProducerTemplate producer) {	
this.producer = producer;	}	public void consumeFile(Exchange exchange)
throws Exception {		System.out.println("File Name in Consumer ->
"+exchange.getIn().getHeaders());		String fileName =
(String)exchange.getIn().getHeader("filename");		Exchange recievedEx =
consumer.receive("file:d:/a/?fileName="+fileName);	
System.out.println("Recieved ->
"+recievedEx.getIn().getBody().getClass().getName());				InputStream
inputStream =
GenericFileConverter.genericFileToInputStream((GenericFile<?>)recievedEx.getIn().getBody(),
recievedEx);		System.out.println("InputStream >>> "+inputStream);			
exchange.getIn().setBody(inputStream);		//producer.sendBody("seda:myfile",
inputStream);	}}*/camel-context.xml/*															  								
*/web.xml/*s<?xml version="1.0" encoding="UTF-8"?>		
org.springframework.web.context.ContextLoaderListener			 	
contextConfigLocation		/WEB-INF/conf/bootstrap.xml
/WEB-INF/spring/camel-context.xml	 				appServlet	
org.springframework.web.servlet.DispatcherServlet					contextConfigLocation					
/WEB-INF/conf/bootstrap.xml							1				mySerlvet	
org.apache.camel.component.servlet.CamelHttpTransportServlet				
contextConfigLocation						/WEB-INF/spring/camel-context.xml								2			
myServlet		/				appServlet		/	 		DB Connection		jdbc/gavss	
javax.sql.DataSource		Container	 web.xml is the portion where I am not very
quite sure of. I started my server.. the only thing I get in the console log
is  File Name in Consumer -> null....Can anyone tell me what is wrong here?



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-and-tomcat-tp5719942.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel and tomcat

Posted by Elezabeth <El...@ibsplc.com>.
Yes Willem . Exactly . You are right. 

I missed out this point in my last post. I had already changed the route
definition as below:

 /from("servlet:///camel?matchOnUriPrefix=true").inOnly("seda:myfile");
        from("seda:myfile").inOnly("bean:fileConsumer?method=consumeFile")
                .unmarshal(bindy)
                .to("bean:validateFileInput?method=receiveOagData");/


Earlier,I tried giving a different camel servlet name in web.xml  and gave
the servlet name in my route as given in your post . But some how it din't
work . So I changed the name to the default name *CamelServlet* . 

I think the main issue was with my route definition . I should have given
*servlet:///* instead of *http://* . Now it is working fine..:)



-----
Thanks & Regards
Elz
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-and-tomcat-tp5719942p5720100.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel and tomcat

Posted by Willem jiang <wi...@gmail.com>.
camel-servlet is using the CamelServlet as the servlet name by default.
You can use the servletName option to specify the servlet name as you want.
Like this

 from("servlet:/hello?servletName=CamelServlet1").transform(simple("Hello ${header.name}"));


-- 
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.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, September 27, 2012 at 4:26 PM, Elezabeth wrote:

> Hi ,
> 
> Thank you for the suggestion. Actually my issue got resolved . The issue was
> with the name of the servlet that I have defined in the web.xml (http://web.xml) file. 
> 
> When i gave the name of the servlet as *"CamelServlet"* , it worked. 
> 
> */web.xml/* (http://web.xml/*)
> 
> 
> <listener>
> 
> <listener-class>org.springframework.web.context.ContextLoaderListener (http://web.context.ContextLoaderListener)</listener-class>
> </listener>
> 
> <context-param>
> <param-name>contextConfigLocation</param-name>
> <param-value>/WEB-INF/spring/camel-context.xml</param-value>
> </context-param>
> 
> <servlet>
> <servlet-name>*CamelServlet*</servlet-name>
> 
> <servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
> <load-on-startup>1</load-on-startup>
> </servlet>
> 
> <servlet-mapping>
> <servlet-name>*CamelServlet*</servlet-name>
> <url-pattern>/services/*</url-pattern>
> </servlet-mapping>
> 
> 
> 
> 
> -----
> Thanks & Regards
> Elz
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-and-tomcat-tp5719942p5720096.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Re: Camel and tomcat

Posted by Elezabeth <El...@ibsplc.com>.
Hi ,

Thank you for the suggestion. Actually my issue got resolved . The issue was
with the name of the servlet that I have defined in the web.xml file. 

When i gave the name of the servlet as *"CamelServlet"* , it worked. 

*/web.xml/*


	<listener>
	
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>/WEB-INF/spring/camel-context.xml</param-value>
	</context-param>

	<servlet>
		<servlet-name>*CamelServlet*</servlet-name>
	
<servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>*CamelServlet*</servlet-name>
		<url-pattern>/services/*</url-pattern>
	</servlet-mapping>




-----
Thanks & Regards
Elz
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-and-tomcat-tp5719942p5720096.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel and tomcat

Posted by Willem jiang <wi...@gmail.com>.
Hi,

You need to take a good look at the camel-servlet[1] component, as you want to get the file name from the client http request.

[1]http://camel.apache.org/servlet.html

-- 
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.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 Tuesday, September 25, 2012 at 8:55 PM, Elezabeth wrote:

> Hi ,I am trying to make use of camel in tomcat server. My requirement is to
> read a cvs file in a folder whenever a *http request* is hit. I was able to
> do this successfully using camel when I was using the "Run as a Java
> application" in y IDE.Now I have to do the same thing in "Run on server" and
> I using tomcat server 7.0 . But now nothing is working.. I am not able to
> understand wat exactly is happening. I checked the camel servlet tomcat
> example.But that couldn't help me..I am pasting my code
> below./*OagProcessor.java*/public class OagProcessor extends RouteBuilder { 
> DataFormat bindy = new BindyCsvDataFormat( 
> "jp.co.airlink.gavss.adapter.eai.oag.job"); Exchange exchnge = null; 
> String fileName = null; @Override public void configure() throws
> Exception { System.out.println("in configure"); 
> from("http://localhost:8080/test").inOnly("seda:myfile"); 
> from("seda:myfile").inOnly("bean:fileConsumer?method=consumeFile") 
> .unmarshal(bindy) 
> .to("bean:validateFileInput?method=receiveOagData"); 
> }}*/FileConsumer.java/*public class FileConsumer { @Inject private
> ConsumerTemplate consumer; @Inject private ProducerTemplate producer; 
> public void setConsumer(ConsumerTemplate consumer) { this.consumer =
> consumer; } public void setProducer(ProducerTemplate producer) { 
> this.producer = producer; } public void consumeFile(Exchange exchange)
> throws Exception { System.out.println("File Name in Consumer ->
> "+exchange.getIn().getHeaders()); String fileName =
> (String)exchange.getIn().getHeader("filename"); Exchange recievedEx =
> consumer.receive("file:d:/a/?fileName="+fileName); 
> System.out.println("Recieved ->
> "+recievedEx.getIn().getBody().getClass().getName()); InputStream
> inputStream =
> GenericFileConverter.genericFileToInputStream((GenericFile<?>)recievedEx.getIn().getBody(),
> recievedEx); System.out.println("InputStream >>> "+inputStream); 
> exchange.getIn().setBody(inputStream); //producer.sendBody("seda:myfile",
> inputStream); }}*/camel-context.xml/* 
> */web.xml/*s (http://web.xml/*s)<?xml version="1.0" encoding="UTF-8"?> 
> org.springframework.web.context.ContextLoaderListener (http://web.context.ContextLoaderListener) 
> contextConfigLocation /WEB-INF/conf/bootstrap.xml
> /WEB-INF/spring/camel-context.xml appServlet 
> org.springframework.web.servlet.DispatcherServlet (http://web.servlet.DispatcherServlet) contextConfigLocation 
> /WEB-INF/conf/bootstrap.xml 1 mySerlvet 
> org.apache.camel.component.servlet.CamelHttpTransportServlet 
> contextConfigLocation /WEB-INF/spring/camel-context.xml 2 
> myServlet / appServlet / DB Connection jdbc/gavss 
> javax.sql.DataSource Container web.xml (http://web.xml) is the portion where I am not very
> quite sure of. I started my server.. the only thing I get in the console log
> is File Name in Consumer -> null....Can anyone tell me what is wrong here?
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-and-tomcat-tp5719942.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).