camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woggle23 <mattfelst...@yahoo.co.uk>
Subject Camel Servlet Tomcat Problem
Date Tue, 01 Mar 2011 14:44:16 GMT
Afternoon All

I've been trying to write a simple application that listens on a
camel-servlet endpoint, and is deployed in an Apache Tomcat container. I've
principly been following the information on the following forum links to
create the application:

http://camel.465427.n5.nabble.com/Camel-and-Tomcat-td3386793.html#a3390331
http://camel.465427.n5.nabble.com/How-to-create-a-Servlet-component-td475676.html#a475684
http://camel.apache.org/servlet.html

My project consists of the following:

web.xml:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
id="WebApp_ID" version="2.5"> 

	<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> 
		<load-on-startup>1</load-on-startup> 
	</servlet> 

	<!--  see  http://camel.apache.org/servlet.html-->
	<servlet>
		<servlet-name>SpringApplicationContext</servlet-name>
	
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
		<load-on-startup>2</load-on-startup>
	</servlet>

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


camel-config.xml:

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation=" 
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> 

	<!-- create a camel context as to start Camel --> 
	<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> 
		<package>org.apache.camel.Tomcat</package> 
	</camelContext> 
</beans>

The route, ServletToJmsRouteBuilder.java, located in
<project_root>\src\main\java\org\apache\camel\Tomcat:

package org.apache.camel.Tomcat;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;

public class ServletToJmsRouteBuilder extends RouteBuilder { 

        public void configure() throws Exception {  
		from("servlet:///hello").process(new Processor() {

            public void process(Exchange exchange) { 
                String contentType = (String)
exchange.getIn().getHeader(Exchange.CONTENT_TYPE, String.class); 
                String path = (String)
exchange.getIn().getHeader(Exchange.HTTP_PATH, String.class); 
                String charsetEncoding = (String)
exchange.getIn().getHeader(Exchange.HTTP_CHARACTER_ENCODING, String.class); 
                exchange.getOut().setHeader(Exchange.CONTENT_TYPE,
contentType + "; charset=UTF-8");                         
                exchange.getOut().setHeader("PATH", path); 
                exchange.getOut().setBody("Hello World"); 
            } 
        }); 
        } 
}

The project is built via the maven package lifecycle. The pom.xml file
contains the following:

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
 	<groupId>org.apache.camel</groupId>
    <artifactId>CamelTomcat</artifactId>
    <name>Camel Tomcat Servlet Example</name>
    <description>A Camel Servlet example using Tomcat</description>
    <packaging>war</packaging>
	<version>0.0.1-SNAPSHOT</version>
	
    <dependencies>
        <!-- camel -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>2.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring</artifactId>
            <version>2.4.0</version>
        </dependency>
        
        <dependency>
	  		<!--  use the same version as the camel-core version -->
	  		<groupId>org.apache.camel</groupId>
	  		<artifactId>camel-servlet</artifactId>
	  		<version>2.4.0</version>
  		</dependency>
        
        <!-- logging -->
         
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.14</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.1</version>
        </dependency>

    </dependencies>

</project>


When Tomcat deploys the .war file, it displays the message:

INFO: Deploying web application archive CamelTomcat-0.0.1-SNAPSHOT.war
01-Mar-2011 14:27:59 org.apache.catalina.loader.WebappClassLoader
validateJarFile
INFO:
validateJarFile(C:\MF\Tools\apache-tomcat-7.0.8\apache-tomcat-7.0.8\webapp
s\CamelTomcat-0.0.1-SNAPSHOT\WEB-INF\lib\geronimo-servlet_2.4_spec-1.1.1.jar)
-
jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class:
javax/serv
let/Servlet.class

I'm unsure if this is stopping the application being accessible. But when I
attempt to access the servlet endpoint using the following URL I get a
message stating "The requested resource() is not available":

http://localhost:8080/CamelTomcat-0.0.1-SNAPSHOT/services/hello

Any ideas what I'm doing wrong? I'm very new to Camel/Tomcat and appreciate
any help you can provide.

Many thanks

Matt

-- 
View this message in context: http://camel.465427.n5.nabble.com/Camel-Servlet-Tomcat-Problem-tp3405032p3405032.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message