Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-4175

Enable Restlet servlet to be configured within a webapp

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.7.2
    • 2.8.0
    • camel-restlet
    • None
    • Patch Available

    Description

      There are three possible ways to configure a Restlet application within a servlet container (http://www.restlet.org/documentation/2.0/jee/ext/org/restlet/ext/servlet/ServerServlet.html) and using the subclassed SpringServerServlet enables configuration within Camel by injecting the Restlet Component - however this is currently only available internally within the Camel component.

      Use of the Restlet servlet within a servlet container enables routes to be configured with relative paths in URIs (removing the restrictions of hard-coded absolute URIs) and for the hosting servlet container to handle incoming requests (rather than have to spawn a separate server process on a new port).

      To configure, add the following to your camel-context.xml;

      <camelContext>
      <route id="RS_RestletDemo">
      <from uri="restlet:/demo/

      {id}

      " />
      <transform>
      <simple>Request type : ${header.CamelHttpMethod} and ID : ${header.id}</simple>
      </transform>
      </route>
      </camelContext>

      <bean id="RestletComponent" class="org.restlet.Component" />
      <bean id="RestletComponentService" class="org.apache.camel.component.restlet.RestletComponent">
      <constructor-arg index="0">
      <ref bean="RestletComponent" />
      </constructor-arg>
      </bean>

      And add this to your web.xml;

      <!-- Restlet Servlet -->
      <servlet>
      <servlet-name>RestletServlet</servlet-name>
      <servlet-class>org.restlet.ext.spring.SpringServerServlet</servlet-class>
      <init-param>
      <param-name>org.restlet.component</param-name>
      <param-value>RestletComponent</param-value>
      </init-param>
      </servlet>
      <servlet-mapping>
      <servlet-name>RestletServlet</servlet-name>
      <url-pattern>/rs/*</url-pattern>
      </servlet-mapping>

      You will then be able to access the deployed route at http://localhost:8080/mywebapp/rs/demo/1234 where;

      • localhost:8080 is the server and port of your servlet container
      • mywebapp is the name of your deployed webapp

      Your browser will then show the following content;

      "Request type : GET and ID : 1234"

      Attachments

        1. camel-4175.txt
          1 kB
          Stu Churchill

        Activity

          People

            njiang Willem Jiang
            stu.c Stu Churchill
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: