camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From janylj <jan...@gmail.com>
Subject How to create a Servlet component?
Date Mon, 10 Aug 2009 23:11:19 GMT

Hello,

Camel is pretty new to me. This might be a simple question but I cannot find
the answer in the web. 

I am following Servlet Component page
(http://camel.apache.org/servlet.html). However, when I start Tomcat, there
are repeating warning message said,

Aug 10, 2009 3:44:03 PM
org.apache.camel.impl.DefaultPollingConsumerPollStrategy rollback
WARNING: Consumer Consumer[servlet:/hello] could not poll endpoint:
servlet:/hello caused by: unsupported protocol: 'servlet'
java.lang.IllegalStateException: unsupported protocol: 'servlet'
	at
org.apache.commons.httpclient.protocol.Protocol.lazyRegisterProtocol(Protocol.java:149)
	at
org.apache.commons.httpclient.protocol.Protocol.getProtocol(Protocol.java:117)
	at org.apache.commons.httpclient.HttpHost.<init>(HttpHost.java:107)
	at
org.apache.commons.httpclient.HttpMethodBase.setURI(HttpMethodBase.java:280)
	at
org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:220)
	at
org.apache.commons.httpclient.methods.GetMethod.<init>(GetMethod.java:89)
	at
org.apache.camel.component.http.HttpPollingConsumer.createMethod(HttpPollingConsumer.java:110)
	at
org.apache.camel.component.http.HttpPollingConsumer.receiveNoWait(HttpPollingConsumer.java:60)
	at
org.apache.camel.impl.DefaultScheduledPollConsumer.poll(DefaultScheduledPollConsumer.java:45)
	at
org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:98)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:417)
	at
java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:280)
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:135)
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:65)
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:142)
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:166)
	at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
	at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
	at java.lang.Thread.run(Thread.java:595)

My web.xml has:

	<!-- location of spring xml files -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:camel-config.xml</param-value>
	</context-param>

	<!-- the listener that kick-starts Spring -->
	<listener>
	
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	
	<servlet>
		<servlet-name>CamelServlet</servlet-name>
		<servlet-class>
			org.apache.camel.component.servlet.CamelHttpTransportServlet 
		</servlet-class>
		<init-param>
			<param-name>matchOnUriPrefix</param-name>
			<param-value>true</param-value>
		</init-param>
	</servlet>
	
	<servlet-mapping>
		<servlet-name>CamelServlet</servlet-name>
		<url-pattern>/services/*</url-pattern>
	</servlet-mapping>

The camel-context.xml has:

    <!-- create a camel context as to start Camel -->
	<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
		<package>package.has.routebuilderl</package>
	</camelContext>
	<bean id="servlet" class="org.apache.camel.component.http.HttpComponent">
		<property name="camelContext" ref="camel" />
	</bean>

The RouteBuilder is exactly what lists in the web page.

from("servlet:///hello").process(new Processor() { 
    public void process(Exchange exchange) throws Exception { 
        String contentType =
exchange.getIn().getHeader(Exchange.CONTENT_TYPE, String.class); 
        String path = exchange.getIn().getHeader(Exchange.HTTP_PATH,
String.class); 
        assertEquals("Get a wrong content type", CONTENT_TYPE, contentType); 
        String charsetEncoding =
exchange.getIn().getHeader(Exchange.HTTP_CHARACTER_ENCODING, String.class); 
        assertEquals("Get a wrong charset name", "UTF-8", charsetEncoding); 
        exchange.getOut().setHeader(Exchange.CONTENT_TYPE, contentType + ";
charset=UTF-8");                         
        exchange.getOut().setHeader("PATH", path); 
        exchange.getOut().setBody("Hello World"); 
    } 
}); 




-- 
View this message in context: http://www.nabble.com/How-to-create-a-Servlet-component--tp24909157p24909157.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Mime
View raw message