Hi

Just to inform Camel have the camel-jetty component that allows you to
expose a HTTP service and let Camel handle the request and return a
reply.
http://camel.apache.org/jetty

But you got the right source about the Camel Servlet as it was Willem
who wrote it.


On Wed, Aug 12, 2009 at 6:28 PM, janylj<jan...@gmail.com> 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>
>>>
>>>
>>>
>>
>>
>>
>
> --
> View this message in context: 
> http://www.nabble.com/How-to-create-a-Servlet-component--tp24909157p24940161.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Reply via email to