title: Does Camel REST DSL work with a Restlet Servlet?
body: <p>I recently upgraded to Camel 2.14.1 and have been playing around the new REST DSL.  Before the upgrade I used restlet within a servlet container, i.e. with this in my web.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;!-- Restlet Servlet --&gt;
  &lt;servlet&gt;
    &lt;servlet-name&gt;RestletServlet&lt;/servlet-name&gt;
    &lt;servlet-class&gt;org.restlet.ext.spring.SpringServerServlet&lt;/servlet-class&gt;
    &lt;init-param&gt;
      &lt;param-name&gt;org.restlet.component&lt;/param-name&gt;
      &lt;param-value&gt;RestletComponent&lt;/param-value&gt;
    &lt;/init-param&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;RestletServlet&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/rs/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>And this in my camel context:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;bean id="RestletComponent" class="org.restlet.Component" /&gt;
  
  &lt;bean id="RestletComponentService" class="org.apache.camel.component.restlet.RestletComponent"&gt;
    &lt;constructor-arg index="0"&gt;
      &lt;ref bean="RestletComponent" /&gt;
    &lt;/constructor-arg&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>This does not work with the REST DSL.</p>
  
  <p>I'm testing it out with this simple route:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;rest&gt;
      &lt;get uri="/hello"&gt;
          &lt;to uri="direct:hello"/&gt;
      &lt;/get&gt;
  &lt;/rest&gt;
  &lt;route id="hello"&gt;
      &lt;from uri="direct:hello"/&gt;
      &lt;setBody&gt;&lt;constant&gt;Dolly&lt;/constant&gt;&lt;/setBody&gt;
  &lt;/route&gt;
  </code></pre>
  
  <p>The REST DSL successfully finds the RestletComponent Bean defined in my web.xml, but the bean does not have a camelContext associated with it, so I get a null pointer exception when the code tries to access the context.</p>
  
  <p>Basically, I'm beginning to suspect that the REST DSL is incompatible with Restlet within a servlet container.  I want the hosting servlet container to handle the incoming requests, I don't want to have to spawn a separate restlet server process (on a new port) for my camel contexts.</p>
  
  <p>Am I out of luck? </p>
  
  <hr>
  
  <p>OK, to make things easier, I started from one of the existing examples: camel-example-restlet-jdbc which uses restlet and altered it so it uses the new rest dsl.</p>
  
  <p>Here's the xml-dsl.xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:jdbc="http://www.springframework.org/schema/jdbc"
  
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
         http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd"&gt;
  
  &lt;import resource="common.xml" /&gt;
  
  &lt;camelContext xmlns="http://camel.apache.org/schema/spring"&gt;
      &lt;rest&gt;
          &lt;post uri="/persons"&gt;
              &lt;route&gt;
                  &lt;setBody&gt;
                      &lt;simple&gt;insert into person(firstName, lastName) values('${header.firstName}','${header.lastName}')
                      &lt;/simple&gt;
                  &lt;/setBody&gt;
                  &lt;to uri="jdbc:dataSource"/&gt;
  
                  &lt;setBody&gt;
                      &lt;!--&lt;simple&gt;select * from person ORDER BY id desc OFFSET 1 ROWS&lt;/simple&gt;--&gt;
                      &lt;simple&gt;select * from person where id in (select max(id) from person)&lt;/simple&gt;
                  &lt;/setBody&gt;
                  &lt;to uri="jdbc:dataSource"/&gt;
              &lt;/route&gt;
          &lt;/post&gt;
          &lt;get uri="/persons/{personId}"&gt;
              &lt;route&gt;
                  &lt;setBody&gt;
                      &lt;simple&gt;select * from person where id = ${header.personId}&lt;/simple&gt;
                  &lt;/setBody&gt;
                  &lt;to uri="jdbc:dataSource"/&gt;
              &lt;/route&gt;
          &lt;/get&gt;
          &lt;get uri="/persons"&gt;
              &lt;route&gt;
                  &lt;setBody&gt;
                      &lt;constant&gt;select * from person&lt;/constant&gt;
                  &lt;/setBody&gt;
                  &lt;to uri="jdbc:dataSource"/&gt;
              &lt;/route&gt;
          &lt;/get&gt;
      &lt;/rest&gt;
  
  &lt;/camelContext&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>This doesn't work. It throws java.net.SocketException: Permission denied</p>