Hi,

I just wrote a simple unit test which is based on your test case, I got the same error. That is because the camel context is created before the servlet instance is initialized. So I added an init parameter in the CamelHttpTransportServlet to consumer the spring application context configure file, and make sure the camel context is created after servlet initialization.

You can find the example here.
http://svn.apache.org/viewvc?rev=803805&view=rev

Willem

janylj wrote:
Sure.

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>package.contains.route.builder</package>
        </camelContext>
</beans>

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>
        
        <servlet-mapping>
                <servlet-name>CamelServlet</servlet-name>
                <url-pattern>/services/*</url-pattern>
        </servlet-mapping>
        
        <!-- 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>               
</web-app>

RouteBuilder java class:
public class ServletToJmsRouteBuilder extends RouteBuilder {

        public void configure() throws Exception {
                from("servlet:///hello?servletName=CamelServlet").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"); }
        });             
        }
}

Please let me know if you need anything else. Thanks a lot.


willem.jiang wrote:
Hi,

Can you show me the camel-config.xml?
A simple demo help me debug the issue.

Willem

janylj wrote:
willem.jiang wrote:
If you create the servlet component, you need to specify the servlet which the component will attach to.
<bean id="servlet"
class="org.apache.camel.component.servlet.ServletComponent">
        <property name="camelContext" ref="camel" />
         <property name="servletName" value="CamelServlet" />
</bean>


doesn't work, because Tomcat starts error said,

Caused by: org.springframework.beans.InvalidPropertyException: Invalid
property 'servletName' of bean class
[org.apache.camel.component.servlet.ServletComponent]: No property
'servletName' found


willem.jiang wrote:
You don't need to specify the servlet component in spring, if there is only one camel servlet created in the web context.


doesn't work, because Tomcat starts error said,

Caused by: java.lang.IllegalArgumentException: Can't find the deployied
servlet, please set the ServletComponent with it or delopy a
CamelHttpTransportServlet int the web container

What I am missing? Please note that I am using Spring
ContextLoaderListener.
Thanks a lot.

my web.xml,

        <!-- 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>
                <load-on-startup>1</load-on-startup>
        </servlet>
        
        <servlet-mapping>
                <servlet-name>CamelServlet</servlet-name>
                <url-pattern>/services/*</url-pattern>
        </servlet-mapping>







Reply via email to