You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bu...@apache.org on 2015/07/21 10:22:07 UTC

svn commit: r959089 [3/3] - in /websites/production/camel/content: ./ books.data/ books.thumbs/ cache/

Modified: websites/production/camel/content/rest-dsl.html
==============================================================================
--- websites/production/camel/content/rest-dsl.html (original)
+++ websites/production/camel/content/rest-dsl.html Tue Jul 21 08:22:06 2015
@@ -86,115 +86,126 @@
         <tr>
         <td valign="top" width="100%">
 <div class="wiki-content maincontent"><h2 id="RestDSL-RestDSL">Rest DSL</h2><p><strong>Available as of Camel 2.14</strong></p><p>Apache Camel offers a REST styled DSL which can be used with Java or XML. The intention is to allow end users to define REST services using a REST style with verbs such as get, post, delete etc.</p><h4 id="RestDSL-Howitworks">How it works</h4><p>The Rest DSL is a facade that builds <a shape="rect" href="rest.html">Rest</a>&#160;endpoints as consumers for Camel routes. The actual REST transport is leveraged by using Camel REST components such as&#160;<a shape="rect" href="restlet.html">Restlet</a>,&#160;<a shape="rect" href="spark-rest.html">Spark-rest</a>, and others that has native REST integration.</p><h3 id="RestDSL-ComponentssupportingRestDSL">Components supporting Rest DSL</h3><p>The following Camel components supports the Rest DSL. See the bottom of this page for how to integrate a component with the Rest DSL.</p><ul><li><a shape="rect" href="netty-h
 ttp.html">camel-netty-http</a></li><li><a shape="rect" href="jetty.html">camel-jetty</a></li><li><a shape="rect" href="restlet.html">camel-restlet</a></li><li><a shape="rect" href="servlet.html">camel-servlet</a></li><li><a shape="rect" href="spark-rest.html">camel-spark-rest</a></li></ul><h3 id="RestDSL-RestDSLwithJava">Rest DSL with Java</h3><p>To use the Rest DSL in Java then just do as with regular Camel routes by extending the&#160;<code>RouteBuilder</code> and define the routes in the&#160;<code>configure</code> method.</p><p>A simple REST service can be define as follows, where we use rest() to define the services as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">    protected RouteBuilder createRouteBuilder() throws Exception {
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[    protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                rest("/say")
-                    .get("/hello").to("direct:hello")
-                    .get("/bye").consumes("application/json").to("direct:bye")
-                    .post("/bye").to("mock:update");
-
-                from("direct:hello")
-                    .transform().constant("Hello World");
-                from("direct:bye")
-                    .transform().constant("Bye World");
+                rest(&quot;/say&quot;)
+                    .get(&quot;/hello&quot;).to(&quot;direct:hello&quot;)
+                    .get(&quot;/bye&quot;).consumes(&quot;application/json&quot;).to(&quot;direct:bye&quot;)
+                    .post(&quot;/bye&quot;).to(&quot;mock:update&quot;);
+
+                from(&quot;direct:hello&quot;)
+                    .transform().constant(&quot;Hello World&quot;);
+                from(&quot;direct:bye&quot;)
+                    .transform().constant(&quot;Bye World&quot;);
             }
         };
-    }</pre>
+    }]]></script>
 </div></div><p>&#160;</p><p>This defines a REST service with the following url mappings:</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh">Base Path</th><th colspan="1" rowspan="1" class="confluenceTh">Uri template</th><th colspan="1" rowspan="1" class="confluenceTh">Verb</th><th colspan="1" rowspan="1" class="confluenceTh">Consumes</th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><span>/say</span></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>/hello</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>get</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><em>all</em></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>/say</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>/bye</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>get</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>application/json</p></td></tr><tr><td colspa
 n="1" rowspan="1" class="confluenceTd"><p>/say</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>/bye</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>post</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><em>all</em></p></td></tr></tbody></table></div><p>Notice that in the REST service we route directly to a Camel endpoint using the to(). This is because the Rest DSL has a short-hand for routing directly to an endpoint using to(). An alternative is to embed a Camel route directly using route() - there is such an example further below.</p><h3 id="RestDSL-RestDSLwithXML">Rest DSL with XML</h3><p>The REST DSL supports the XML DSL also using either Spring or Blueprint. The example above can be define in XML as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">  &lt;camelContext xmlns="http://camel.apache.org/schema/spring"&gt;
-    &lt;rest path="/say"&gt;
-      &lt;get uri="/hello"&gt;
-        &lt;to uri="direct:hello"/&gt;
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[  &lt;camelContext xmlns=&quot;http://camel.apache.org/schema/spring&quot;&gt;
+    &lt;rest path=&quot;/say&quot;&gt;
+      &lt;get uri=&quot;/hello&quot;&gt;
+        &lt;to uri=&quot;direct:hello&quot;/&gt;
       &lt;/get&gt;
-      &lt;get uri="/bye" consumes="application/json"&gt;
-        &lt;to uri="direct:bye"/&gt;
+      &lt;get uri=&quot;/bye&quot; consumes=&quot;application/json&quot;&gt;
+        &lt;to uri=&quot;direct:bye&quot;/&gt;
       &lt;/get&gt;
-      &lt;post uri="/bye"&gt;
-        &lt;to uri="mock:update"/&gt;
+      &lt;post uri=&quot;/bye&quot;&gt;
+        &lt;to uri=&quot;mock:update&quot;/&gt;
       &lt;/post&gt;
     &lt;/rest&gt;
     &lt;route&gt;
-      &lt;from uri="direct:hello"/&gt;
+      &lt;from uri=&quot;direct:hello&quot;/&gt;
       &lt;transform&gt;
         &lt;constant&gt;Hello World&lt;/constant&gt;
       &lt;/transform&gt;
     &lt;/route&gt;
     &lt;route&gt;
-      &lt;from uri="direct:bye"/&gt;
+      &lt;from uri=&quot;direct:bye&quot;/&gt;
       &lt;transform&gt;
         &lt;constant&gt;Bye World&lt;/constant&gt;
       &lt;/transform&gt;
     &lt;/route&gt;
-  &lt;/camelContext&gt;</pre>
+  &lt;/camelContext&gt;]]></script>
 </div></div><p>&#160;</p><h3 id="RestDSL-Usingbasepath">Using base path</h3><p>The REST DSL allows to define base path to make the DSL a bit more DRY. For example to define a customer path, we can set the base path in rest("/customer") and then provide the uri templates in the verbs, as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">  rest("/customers/")
-      .get("/{id}").to("direct:customerDetail")
-      .get("/{id}/orders").to("direct:customerOrders")
-      .post("/neworder").to("direct:customerNewOrder");
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[  rest(&quot;/customers/&quot;)
+      .get(&quot;/{id}&quot;).to(&quot;direct:customerDetail&quot;)
+      .get(&quot;/{id}/orders&quot;).to(&quot;direct:customerOrders&quot;)
+      .post(&quot;/neworder&quot;).to(&quot;direct:customerNewOrder&quot;);
 
-</pre>
+]]></script>
 </div></div><p>&#160;</p><p>And using XML DSL it becomes:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">    &lt;rest path="/customers/"&gt;
-      &lt;get uri="/{id}"&gt;
-        &lt;to uri="direct:customerDetail"/&gt;
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[    &lt;rest path=&quot;/customers/&quot;&gt;
+      &lt;get uri=&quot;/{id}&quot;&gt;
+        &lt;to uri=&quot;direct:customerDetail&quot;/&gt;
       &lt;/get&gt;
-      &lt;get uri="/{id}/orders"&gt;
-        &lt;to uri="direct:customerOrders"/&gt;
+      &lt;get uri=&quot;/{id}/orders&quot;&gt;
+        &lt;to uri=&quot;direct:customerOrders&quot;/&gt;
       &lt;/get&gt;
-      &lt;post uri="/neworder"&gt;
-        &lt;to uri="direct:customerNewOrder"/&gt;
+      &lt;post uri=&quot;/neworder&quot;&gt;
+        &lt;to uri=&quot;direct:customerNewOrder&quot;/&gt;
       &lt;/post&gt;
-    &lt;/rest&gt;</pre>
+    &lt;/rest&gt;]]></script>
 </div></div><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>The REST DSL will take care of duplicate path separators when using base path and uri templates. In the example above the rest base path ends with a slash ( / ) and the verb starts with a slash ( / ). But Apache Camel will take care of this and remove the duplicated slash.</p></div></div><p>It is not required to use both base path and uri templates. You can omit the bast path and define the base path and uri template in the verbs only. The example above can be defined as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">    &lt;rest&gt;
-      &lt;get uri="/customers/{id}"&gt;
-        &lt;to uri="direct:customerDetail"/&gt;
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[    &lt;rest&gt;
+      &lt;get uri=&quot;/customers/{id}&quot;&gt;
+        &lt;to uri=&quot;direct:customerDetail&quot;/&gt;
       &lt;/get&gt;
-      &lt;get uri="/customers/{id}/orders"&gt;
-        &lt;to uri="direct:customerOrders"/&gt;
+      &lt;get uri=&quot;/customers/{id}/orders&quot;&gt;
+        &lt;to uri=&quot;direct:customerOrders&quot;/&gt;
       &lt;/get&gt;
-      &lt;post uri="/customers/neworder"&gt;
-        &lt;to uri="direct:customerNewOrder"/&gt;
+      &lt;post uri=&quot;/customers/neworder&quot;&gt;
+        &lt;to uri=&quot;direct:customerNewOrder&quot;/&gt;
       &lt;/post&gt;
-    &lt;/rest&gt;</pre>
-</div></div><h3 id="RestDSL-EmbeddingCamelroutes">Embedding Camel routes</h3><p>Each of the rest service becomes a Camel route,&#160;so in the first example we have 2 x get and 1 x post REST service, which each become a Camel route. And we have 2 regular Camel routes, meaning we have 3 + 2 = 5 routes in total.&#160;</p><p>There are two route modes with the Rest DSL</p><ul><li><span style="line-height: 1.4285715;">mini using a singular to</span></li><li><span style="line-height: 1.4285715;">embedding a Camel route using route&#160;</span></li></ul><p><span style="line-height: 1.4285715;">The first example is using the former with a singular to. And that is why we end up with 3 + 2 = 5 total routes.</span></p><p><span style="line-height: 1.4285715;">The same example could use embedded Camel routes, which is shown below:</span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">    protected RouteBuilder createRouteBuilder() throws Exception {
+    &lt;/rest&gt;]]></script>
+</div></div><h3 id="RestDSL-UsingDynamicTo">Using Dynamic To</h3><p><strong>Available as of Camel 2.16</strong></p><p>The&#160;<a shape="rect" href="rest-dsl.html">Rest DSL</a> supports the new .toD &lt;toD&gt; as dynamic to in the rest-dsl. For example to do a request/reply over&#160;<a shape="rect" href="jms.html">JMS</a> where the queue name is dynamic defined</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ public void configure() throws Exception {
+   rest(&quot;/say&quot;)
+     .get(&quot;/hello/{language}&quot;).toD(&quot;jms:queue:hello-${header.language}&quot;);
+}]]></script>
+</div></div><h3 id="RestDSL-AndinXMLDSL">And in XML DSL</h3><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[&lt;rest uri=&quot;/say&quot;&gt;
+  &lt;get uri=&quot;/hello//{language}&quot;&gt;
+    &lt;toD uri=&quot;jms:queue:hello-${header.language}&quot;/&gt;
+  &lt;/get&gt;
+&lt;rest&gt;]]></script>
+</div></div><p>&#160;</p><p>See more details at&#160;<a shape="rect" href="message-endpoint.html">Message Endpoint</a> about the dynamic to, and what syntax it supports. By default it uses the&#160;<a shape="rect" href="simple.html">Simple</a> language, but it has more power than so.</p><h3 id="RestDSL-EmbeddingCamelroutes">Embedding Camel routes</h3><p>Each of the rest service becomes a Camel route,&#160;so in the first example we have 2 x get and 1 x post REST service, which each become a Camel route. And we have 2 regular Camel routes, meaning we have 3 + 2 = 5 routes in total.&#160;</p><p>There are two route modes with the Rest DSL</p><ul><li><span style="line-height: 1.4285715;">mini using a singular to</span></li><li><span style="line-height: 1.4285715;">embedding a Camel route using route&#160;</span></li></ul><p><span style="line-height: 1.4285715;">The first example is using the former with a singular to. And that is why we end up with 3 + 2 = 5 total routes.</span></p><p><
 span style="line-height: 1.4285715;">The same example could use embedded Camel routes, which is shown below:</span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[    protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                rest("/say/hello")
-                    .get().route().transform().constant("Hello World");
-                rest("/say/bye")
-                    .get().consumes("application/json").route().transform().constant("Bye World").endRest()
-                    .post().to("mock:update");
+                rest(&quot;/say/hello&quot;)
+                    .get().route().transform().constant(&quot;Hello World&quot;);
+                rest(&quot;/say/bye&quot;)
+                    .get().consumes(&quot;application/json&quot;).route().transform().constant(&quot;Bye World&quot;).endRest()
+                    .post().to(&quot;mock:update&quot;);
         };
-    }</pre>
+    }]]></script>
 </div></div><p><span style="line-height: 1.4285715;">In the example above, we are embedding routes directly in the rest service using .route(). Notice we need to use .endRest() to tell Camel where the route ends, so we can&#160;<em>go back</em> to the Rest DSL and continue defining REST services.</span></p><div class="confluence-information-macro confluence-information-macro-tip"><p class="title">Configuring route options</p><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>In the embedded route you can configure the route settings such as routeId, autoStartup and various other options you can set on routes today.</p><pre>.get().route().routeId("myRestRoute").autoStartup(false).transform().constant("Hello World");</pre></div></div><h3 id="RestDSL-ManagingRestservices"><span style="font-size: 16.0px;line-height: 1.5625;">Managing Rest services</span></h3><p>Each of the rest service bec
 omes a Camel route, so in the first example we have 2 x get and 1 x post REST service, which each become a Camel route. This makes it&#160;<em>the same</em> from Camel to manage and run these services - as they are just Camel routes. This means any tooling and API today that deals with Camel routes, also work with the REST services.</p><p>This means you can use JMX to stop/start routes, and also get the JMX metrics about the routes, such as number of message processed, and their performance statistics.</p><p>There is also a Rest Registry JMX MBean that contains a registry of all REST services which has been defined.&#160;</p><h3 id="RestDSL-BindingtoPOJOsusing">Binding to POJOs using</h3><p>The Rest DSL supports automatic binding json/xml contents to/from POJOs using Camels&#160;<a shape="rect" href="data-format.html">Data Format</a>. By default the binding mode is off, meaning there is no automatic binding happening for incoming and outgoing messages.</p><p>You may want to use bind
 ing if you develop POJOs that maps to your REST services request and response types. This allows you as a developer to work with the POJOs in Java code.</p><p>The binding modes are:</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh">Binding Mode</th><th colspan="1" rowspan="1" class="confluenceTh">Description</th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>off</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Binding is turned off. This is the default option.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>auto</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Binding is enabled and Camel is relaxed and support json, xml or both if the needed data formats are included in the classpath. Notice that if for example <code>camel-jaxb</code> is not on the classpath, then XML binding is not enabled.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p
 >json</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Binding to/from json is enabled, and requires a json capabile data format on the classpath. By default Camel will use <code>json-jackson</code> as the data format.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>xml</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Binding to/from xml is enabled, and requires <code>camel-jaxb</code> on the classpath.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>json_xml</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Biding to/from json and xml is enabled and requires both data formats to be on the classpath.</p></td></tr></tbody></table></div><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>From <strong>Camel 2.14.1</strong> onwards when using c
 amel-jaxb for xml bindings, then you can use the option <code>mustBeJAXBElement</code> to relax the output message body must be a class with JAXB annotations. You can use this in situations where the message body is already in XML format, and you want to use the message body as-is as the output type. If that is the case, then set the <span>dataFormatProperty option <code>mustBeJAXBElement</code><span> to <code>false</code> value.</span></span></p></div></div><p>&#160;</p><p>To use binding you must include the necessary data formats on the classpath, such as&#160;<code>camel-jaxb</code> and/or&#160;<code>camel-jackson</code>. And then enable the binding mode. You can configure the binding mode globally on the rest configuration, and then override per rest service as well.</p><p>To enable binding you configure this in Java DSL as shown below</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">restConfiguration().component("restlet").host("localhost").port(portNum).bindingMode(RestBindingMode.auto);</pre>
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[restConfiguration().component(&quot;restlet&quot;).host(&quot;localhost&quot;).port(portNum).bindingMode(RestBindingMode.auto);]]></script>
 </div></div><p>And in XML DSL</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">    &lt;restConfiguration bindingMode="auto" component="restlet" port="8080"/&gt;</pre>
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[    &lt;restConfiguration bindingMode=&quot;auto&quot; component=&quot;restlet&quot; port=&quot;8080&quot;/&gt;]]></script>
 </div></div><p>&#160;</p><p>When binding is enabled Camel will bind the incoming and outgoing messages automatic, accordingly to the content type of the message. If the message is json, then json binding happens; and so if the message is xml then xml binding happens. The binding happens for incoming and reply messages. The table below summaries what binding occurs for incoming and reply messages.&#160;</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh">Message Body</th><th colspan="1" rowspan="1" class="confluenceTh">Direction</th><th colspan="1" rowspan="1" class="confluenceTh">Binding Mode</th><th colspan="1" rowspan="1" class="confluenceTh">Message Body</th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>XML</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Incoming</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>auto<br clear="none">xml<br clear="none">json_xml&#160;</p></td><td
  colspan="1" rowspan="1" class="confluenceTd"><p>POJO</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>POJO</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Outgoing</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>auto</p><p>xml</p><p>json_xml&#160;</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>XML</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>JSON</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Incoming</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>auto</p><p>json</p><p>json_xml&#160;</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>POJO</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>POJO</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Outgoing</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>auto</p><p>json</p><p>json_xml&#160;</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>JSON</p></td></tr></tbody></table><
 /div><p>&#160;</p><p>When using binding you must also configure what POJO type to map to. This is mandatory for incoming messages, and optional for outgoing.&#160;</p><p>For example to map from xml/json to a pojo class&#160;<code>UserPojo</code> you do this in Java DSL as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">// configure to use restlet on localhost with the given port
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[// configure to use restlet on localhost with the given port
 // and enable auto binding mode
-restConfiguration().component("restlet").host("localhost").port(portNum).bindingMode(RestBindingMode.auto);
+restConfiguration().component(&quot;restlet&quot;).host(&quot;localhost&quot;).port(portNum).bindingMode(RestBindingMode.auto);
 
 // use the rest DSL to define the rest services
-rest("/users/")
+rest(&quot;/users/&quot;)
     .post().type(UserPojo.class)
-        .to("direct:newUser");</pre>
+        .to(&quot;direct:newUser&quot;);]]></script>
 </div></div><p>Notice we use&#160;<code>type</code> to define the incoming type. We can optionally define an outgoing type (which can be a good idea, to make it known from the DSL and also for tooling and JMX APIs to know both the incoming and outgoing types of the REST services.). To define the outgoing type, we use&#160;<code>outType</code> as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">// configure to use restlet on localhost with the given port
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[// configure to use restlet on localhost with the given port
 // and enable auto binding mode
-restConfiguration().component("restlet").host("localhost").port(portNum).bindingMode(RestBindingMode.auto);
+restConfiguration().component(&quot;restlet&quot;).host(&quot;localhost&quot;).port(portNum).bindingMode(RestBindingMode.auto);
 
 // use the rest DSL to define the rest services
-rest("/users/")
+rest(&quot;/users/&quot;)
     .post().type(UserPojo.class).outType(CountryPojo.class)
-        .to("direct:newUser");</pre>
+        .to(&quot;direct:newUser&quot;);]]></script>
 </div></div><p><span style="line-height: 1.4285715;"><br clear="none"></span></p><p><span style="line-height: 1.4285715;">The&#160;</span><code style="line-height: 1.4285715;">UserPojo</code><span style="line-height: 1.4285715;"> is just a plain pojo with getter/setter as shown:</span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">public class UserPojo {
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[public class UserPojo {
     private int id;
     private String name;
     public int getId() {
@@ -209,9 +220,9 @@ rest("/users/")
     public void setName(String name) {
         this.name = name;
     }
-}</pre>
+}]]></script>
 </div></div><p>The&#160;<code>UserPojo</code> only supports json, as XML requires to use JAXB annotations, so we can add those annotations if we want to support XML also</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">@XmlRootElement(name = "user")
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[@XmlRootElement(name = &quot;user&quot;)
 @XmlAccessorType(XmlAccessType.FIELD)
 public class UserPojo {
     @XmlAttribute
@@ -232,81 +243,81 @@ public class UserPojo {
     }
 }
 
-</pre>
+]]></script>
 </div></div><p>By having the JAXB annotations the POJO supports both json and xml bindings.</p><h3 id="RestDSL-ConfiguringRestDSL"><span style="line-height: 1.5625;">Configuring Rest DSL</span></h3><p>The Rest DSL allows to configure the following options using a builder style</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh">Option</th><th colspan="1" rowspan="1" class="confluenceTh">Default</th><th colspan="1" rowspan="1" class="confluenceTh">Description</th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>component</p></td><td colspan="1" rowspan="1" class="confluenceTd">&#160;</td><td colspan="1" rowspan="1" class="confluenceTd"><p>The Camel Rest component to use for the REST transport, such as restlet, spark-rest. If no component has been explicit configured, then Camel will lookup if there is a Camel component that integrates with the Rest DSL, or if a&#160;<code>org.apache.camel.spi.RestConsumerFa
 ctory</code>&#160;is registered in the registry. If either one is found, then that is being used.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>scheme</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>http</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The scheme to use for exposing the REST service. Usually http or https is supported</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>hostname</p></td><td colspan="1" rowspan="1" class="confluenceTd">&#160;</td><td colspan="1" rowspan="1" class="confluenceTd"><p>The hostname to use for exposing the REST service.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>port</p></td><td colspan="1" rowspan="1" class="confluenceTd">&#160;</td><td colspan="1" rowspan="1" class="confluenceTd"><p>The port number to use for exposing the REST service. Notice if you use servlet component then the port number configured here does not apply, as the port number in use is
  the actual port number the servlet component is using. eg if using Apache Tomcat its the tomcat http port, if using Apache Karaf its the HTTP service in Karaf that uses port 8181 by default etc. Though in those situations setting the port number here, allows tooling and JMX to know the port number, so its recommended to set the port number to the number that the servlet engine uses.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>contextPath</p></td><td colspan="1" rowspan="1" class="confluenceTd">&#160;</td><td colspan="1" rowspan="1" class="confluenceTd"><p>Sets a leading context-path the REST services will be using. This can be used when using components such as <a shape="rect" href="servlet.html">SERVLET</a> where the deployed web application is deployed using a context-path.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>restHostNameResolver</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>localHostName</p></td><td colspan=
 "1" rowspan="1" class="confluenceTd"><p>If no hostname has been explicit configured, then this resolver is used to compute the hostname the REST service will be using. The resolver supports <code>localHostName</code> or <code>localIp</code>.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>bindingMode</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>off</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Whether binding is in use. See further above for more details.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>skipBindingOnErrorCode</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>true</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.14.1</strong>: Whether to skip binding on output if there is a custom HTTP error code header. This allows to build custom error messages that do not bind to json / xml etc, as success messages otherwise will do. See further below for an example.</p></td>
 </tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>enableCORS</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>false</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.14.1:</strong> Whether to enable CORS headers in the HTTP response.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>jsonDataFormat</p></td><td colspan="1" rowspan="1" class="confluenceTd">&#160;</td><td colspan="1" rowspan="1" class="confluenceTd"><p>Name of specific json data format to use. By default <code>json-jackson</code> will be used. <strong>Important:</strong> This option is only for setting a custom name of the data format, not to refer to an existing data format instance. <strong>Notice:</strong> Currently Jackson is what we recommend and are using for testing.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>xmlDataFormat</p></td><td colspan="1" rowspan="1" class="confluenceTd">&#160;</td><td colspan="1" rowspan="1" clas
 s="confluenceTd"><p>Name of specific XML data format to use. By default <code>jaxb</code> will be used. <strong>Important:</strong><span> This option is only for setting a custom name of the data format, not to refer to an existing data format instance. </span><strong>Notice:</strong> Currently only <code>jaxb</code> is supported.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>componentProperty</p></td><td colspan="1" rowspan="1" class="confluenceTd">&#160;</td><td colspan="1" rowspan="1" class="confluenceTd"><p>Allows to configure as many additional properties. This is used to configure component specific options such as for&#160;<a shape="rect" href="restlet.html">Restlet</a>&#160;/&#160;<a shape="rect" href="spark-rest.html">Spark-Rest</a>&#160;etc.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>endpointProperty</p></td><td colspan="1" rowspan="1" class="confluenceTd">&#160;</td><td colspan="1" rowspan="1" class="confluenceTd"><p><span>
 Allows to configure as many additional properties. This is used to configure endpoint specific options for <span>&#160;</span><a shape="rect" href="restlet.html">Restlet</a><span>&#160;/&#160;</span><a shape="rect" href="spark-rest.html">Spark-Rest</a><span>&#160;etc.</span></span></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>consumerProperty</p></td><td colspan="1" rowspan="1" class="confluenceTd">&#160;</td><td colspan="1" rowspan="1" class="confluenceTd"><p><span>Allows to configure as many additional properties. This is used to configure consumer specific options for </span><span>&#160;</span><a shape="rect" href="restlet.html">Restlet</a><span>&#160;/&#160;</span><a shape="rect" href="spark-rest.html">Spark-Rest</a><span>&#160;etc.</span></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>dataFormatProperty</p></td><td colspan="1" rowspan="1" class="confluenceTd">&#160;</td><td colspan="1" rowspan="1" class="confluenceTd"><p>Allows to c
 onfigure as many additional properties. This is used to configure the data format specific options. For example set property prettyPrint to true to have json outputted in pretty mode. From <strong>Camel 2.14.1</strong> onwards the keys can be prefixed with either</p><ul style="list-style-type: square;"><li><p>json.in.</p></li><li><p>json.out.</p></li><li><p>xml.in.</p></li><li><p>xml.out.</p></li></ul><p>to denote that the option is only for either JSON or XML data format, and only for either the in or the out going. For example a key with value "xml.out.mustBeJAXBElement" is only for the XML data format for the outgoing. A key without a prefix is a common key for all situations.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>corsHeaderProperty</p></td><td colspan="1" rowspan="1" class="confluenceTd">&#160;</td><td colspan="1" rowspan="1" class="confluenceTd"><p>Allows to configure custom CORS headers.</p></td></tr></tbody></table></div><p>&#160;</p><p><span st
 yle="line-height: 1.4285715;">For example to configure to use the spark-rest component on port 9091, then we can do as follows</span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">restConfiguration().component("spark-rest").port(9091).componentProperty("foo", "123");</pre>
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[restConfiguration().component(&quot;spark-rest&quot;).port(9091).componentProperty(&quot;foo&quot;, &quot;123&quot;);]]></script>
 </div></div><p><span style="line-height: 1.4285715;"><br clear="none"></span></p><p><span style="line-height: 1.4285715;">And with XML DSL</span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">&lt;restConfiguration component="spark-rest" port="9091"&gt; &lt;componentProperty key="foo" value="123"/&gt; &lt;/restConfiguration&gt;</pre>
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[&lt;restConfiguration component=&quot;spark-rest&quot; port=&quot;9091&quot;&gt; &lt;componentProperty key=&quot;foo&quot; value=&quot;123&quot;/&gt; &lt;/restConfiguration&gt;]]></script>
 </div></div><p><span style="line-height: 1.4285715;"><br clear="none"></span></p><p>You can configure properties on these levels.&#160;</p><ul><li>component - Is used to set any options on the Component class. You can also configure these directly on the component.</li><li>endpoint - Is used set any option on the endpoint level. Many of the Camel components has many options you can set on endpoint level.</li><li>consumer - Is used to set any option on the consumer level. Some components has consumer options, which you can also configure from endpoint level by prefixing the option with "consumer."&#160;</li><li>data format - Is used to set any option on the data formats. For example to enable pretty print in the json data format.</li><li>cors headers - If cors is enabled, then custom CORS headers can be set. See below for the default values which are in used. If a custom header is set then that value takes precedence over the default value.</li></ul><p>You can set multiple options of
  the same level, so you can can for example configure 2 component options, and 3 endpoint options etc.</p><p>&#160;</p><h3 id="RestDSL-EnablingordisablingJacksonJSONfeatures">Enabling or disabling Jackson JSON features</h3><p><strong>Available as of Camel 2.15</strong></p><p>When using JSON binding you may want to turn specific Jackson features on or off. For example to disable failing on unknown properties (eg json input has a property which cannot be mapped to a POJO) then configure this using the dataFormatProperty as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">restConfiguration().component("jetty").host("localhost").port(getPort()).bindingMode(RestBindingMode.json)
-   .dataFormatProperty("json.in.disableFeatures", "FAIL_ON_UNKNOWN_PROPERTIES");</pre>
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[restConfiguration().component(&quot;jetty&quot;).host(&quot;localhost&quot;).port(getPort()).bindingMode(RestBindingMode.json)
+   .dataFormatProperty(&quot;json.in.disableFeatures&quot;, &quot;FAIL_ON_UNKNOWN_PROPERTIES&quot;);]]></script>
 </div></div><p>You can disable more features by separating the values using comma, such as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">   .dataFormatProperty("json.in.disableFeatures", "FAIL_ON_UNKNOWN_PROPERTIES,ADJUST_DATES_TO_CONTEXT_TIME_ZONE");</pre>
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[   .dataFormatProperty(&quot;json.in.disableFeatures&quot;, &quot;FAIL_ON_UNKNOWN_PROPERTIES,ADJUST_DATES_TO_CONTEXT_TIME_ZONE&quot;);]]></script>
 </div></div><p>Likewise you can enable features using the enableFeatures such as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">restConfiguration().component("jetty").host("localhost").port(getPort()).bindingMode(RestBindingMode.json)
-   .dataFormatProperty("json.in.disableFeatures", "FAIL_ON_UNKNOWN_PROPERTIES,ADJUST_DATES_TO_CONTEXT_TIME_ZONE")
-   .dataFormatProperty("json.in.enableFeatures", "FAIL_ON_NUMBERS_FOR_ENUMS,USE_BIG_DECIMAL_FOR_FLOATS");</pre>
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[restConfiguration().component(&quot;jetty&quot;).host(&quot;localhost&quot;).port(getPort()).bindingMode(RestBindingMode.json)
+   .dataFormatProperty(&quot;json.in.disableFeatures&quot;, &quot;FAIL_ON_UNKNOWN_PROPERTIES,ADJUST_DATES_TO_CONTEXT_TIME_ZONE&quot;)
+   .dataFormatProperty(&quot;json.in.enableFeatures&quot;, &quot;FAIL_ON_NUMBERS_FOR_ENUMS,USE_BIG_DECIMAL_FOR_FLOATS&quot;);]]></script>
 </div></div><p>The values that can be used for enabling and disabling features on Jackson are the names of the enums from the following three Jackson classes</p><ul><li>com.fasterxml.jackson.databind.SerializationFeature</li><li>com.fasterxml.jackson.databind.DeserializationFeature</li><li>com.fasterxml.jackson.databind.MapperFeature</li></ul><p>&#160;</p><p>The rest configuration is of course also possible using XML DSL</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">&lt;restConfiguration component="jetty" host="localhost" port="9090" bindingMode="json"&gt;
-  &lt;dataFormatProperty key="json.in.disableFeatures" value="FAIL_ON_UNKNOWN_PROPERTIES,ADJUST_DATES_TO_CONTEXT_TIME_ZONE"/&gt;
-  &lt;dataFormatProperty key="json.in.enableFeatures" value="FAIL_ON_NUMBERS_FOR_ENUMS,USE_BIG_DECIMAL_FOR_FLOATS"/&gt;
-&lt;/restConfiguration&gt;</pre>
+<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[&lt;restConfiguration component=&quot;jetty&quot; host=&quot;localhost&quot; port=&quot;9090&quot; bindingMode=&quot;json&quot;&gt;
+  &lt;dataFormatProperty key=&quot;json.in.disableFeatures&quot; value=&quot;FAIL_ON_UNKNOWN_PROPERTIES,ADJUST_DATES_TO_CONTEXT_TIME_ZONE&quot;/&gt;
+  &lt;dataFormatProperty key=&quot;json.in.enableFeatures&quot; value=&quot;FAIL_ON_NUMBERS_FOR_ENUMS,USE_BIG_DECIMAL_FOR_FLOATS&quot;/&gt;
+&lt;/restConfiguration&gt;]]></script>
 </div></div><p>&#160;</p><h3 id="RestDSL-DefaultCORSheaders">Default CORS headers</h3><p><strong>Available as of Camel 2.14.1</strong></p><p>If CORS is enabled then the follow headers is in use by default. You can configure custom CORS headers which takes precedence over the default value.</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh">Key</th><th colspan="1" rowspan="1" class="confluenceTh">Value</th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>Access-Control-Allow-Origin</p></td><td colspan="1" rowspan="1" class="confluenceTd">*</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>Access-Control-Allow-Methods</p></td><td colspan="1" rowspan="1" class="confluenceTd">GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, CONNECT, PATCH</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>Access-Control-Allow-Headers</p></td><td colspan="1" rowspan="1" class="confluenceTd">Origin, Ac
 cept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>Access-Control-Max-Age</p></td><td colspan="1" rowspan="1" class="confluenceTd">3600</td></tr></tbody></table></div><p>&#160;</p><h3 id="RestDSL-Definingacustomerrormessageas-is">Defining a custom error message as-is</h3><p>If you want to define custom error messages to be sent back to the client with a HTTP error code (eg such as 400, 404 etc.) then from&#160;<strong>Camel 2.14.1</strong> onwards you just set a header with the key&#160;<code>Exchange.HTTP_RESPONSE_CODE</code> to the error code (must be 300+) such as 404. And then the message body with any reply message, and optionally set the content-type header as well. There is a little example shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">                restConfiguration().component("restlet").host("localhost").port(portNum).bindingMode(RestBindingMode.json);
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[                restConfiguration().component(&quot;restlet&quot;).host(&quot;localhost&quot;).port(portNum).bindingMode(RestBindingMode.json);
                 // use the rest DSL to define the rest services
-                rest("/users/")
-                    .post("lives").type(UserPojo.class).outType(CountryPojo.class)
+                rest(&quot;/users/&quot;)
+                    .post(&quot;lives&quot;).type(UserPojo.class).outType(CountryPojo.class)
                         .route()
                             .choice()
-                                .when().simple("${body.id} &lt; 100")
-                                    .bean(new UserErrorService(), "idToLowError")
+                                .when().simple(&quot;${body.id} &lt; 100&quot;)
+                                    .bean(new UserErrorService(), &quot;idToLowError&quot;)
                                 .otherwise()
-                                    .bean(new UserService(), "livesWhere");</pre>
+                                    .bean(new UserService(), &quot;livesWhere&quot;);]]></script>
 </div></div><p>In this example if the input id is a number that is below 100, we want to send back a custom error message, using the UserErrorService bean, which is implemented as shown:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">public class UserErrorService {
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[public class UserErrorService {
     public void idToLowError(Exchange exchange) {
-        exchange.getIn().setBody("id value is too low");
-        exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "text/plain");
+        exchange.getIn().setBody(&quot;id value is too low&quot;);
+        exchange.getIn().setHeader(Exchange.CONTENT_TYPE, &quot;text/plain&quot;);
         exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, 400);
     }
-}</pre>
+}]]></script>
 </div></div><p>In the UserErrorService bean we build our custom error message, and set the HTTP error code to 400. This is important, as that tells rest-dsl that this is a custom error message, and the message should not use the output pojo binding (eg would otherwise bind to CountryPojo).</p><h3 id="RestDSL-CatchingJsonParserExceptionandreturningacustomerrormessage">Catching JsonParserException and returning a custom error message</h3><p>From&#160;<strong>Camel 2.14.1</strong> onwards you return a custom message as-is (see previous section). So we can leverage this with Camel error handler to catch JsonParserException, handle that exception and build our custom response message. For example to return a HTTP error code 400 with a hardcoded message, we can do as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">onException(JsonParseException.class)
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[onException(JsonParseException.class)
     .handled(true)
     .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(400))
-    .setHeader(Exchange.CONTENT_TYPE, constant("text/plain"))
-    .setBody().constant("Invalid json data");
+    .setHeader(Exchange.CONTENT_TYPE, constant(&quot;text/plain&quot;))
+    .setBody().constant(&quot;Invalid json data&quot;);
 
-</pre>
+]]></script>
 </div></div><p>&#160;</p><h3 id="RestDSL-IntegrationaCamelcomponentwithRestDSL">Integration a Camel component with Rest DSL</h3><p>Any Apache Camel component can integrate with the Rest DSL if they can be used as a REST service (eg as a REST consumer in Camel lingo). To integrate with the Rest DSL, then the component should implement the&#160;<code>org.apache.camel.spi.RestConsumerFactory</code>. The Rest DSL will then invoke the&#160;<code>createConsumer</code> method when it setup the Camel routes from the defined DSL. The component should then implement logic to create a Camel consumer that exposes the REST services based on the given parameters, such as path, verb, and other options. For example see the source code for camel-restlet, camel-spark-rest.</p><h3 id="RestDSL-SwaggerAPI">Swagger API</h3><p>The Rest DSL supports <a shape="rect" href="swagger.html">Swagger</a>&#160;by the&#160;<code>camel-swagger</code> module. See more details at &#160;<a shape="rect" href="swagger.htm
 l">Swagger</a>&#160;and the&#160;<code>camel-example-servlet-rest-tomcat</code> example from the Apache Camel distribution.</p><p>From&#160;<strong>Camel 2.16</strong> onwards you can define each parameter fine grained with details such as name, description, data type, parameter type and so on, using the &lt;param&gt;. For example to define the id path parameter you can do as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">&lt;!-- this is a rest GET to view an user by the given id --&gt;
-&lt;get uri="/{id}" outType="org.apache.camel.example.rest.User"&gt;
+<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[&lt;!-- this is a rest GET to view an user by the given id --&gt;
+&lt;get uri=&quot;/{id}&quot; outType=&quot;org.apache.camel.example.rest.User&quot;&gt;
   &lt;description&gt;Find user by id&lt;/description&gt;
-  &lt;param name="id" type="path" description="The id of the user to get" dataType="int"/&gt;
-  &lt;to uri="bean:userService?method=getUser(${header.id})"/&gt;
-&lt;/get&gt;</pre>
+  &lt;param name=&quot;id&quot; type=&quot;path&quot; description=&quot;The id of the user to get&quot; dataType=&quot;int&quot;/&gt;
+  &lt;to uri=&quot;bean:userService?method=getUser(${header.id})&quot;/&gt;
+&lt;/get&gt;]]></script>
 </div></div><p>And in Java DSL</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">.get("/{id}").description("Find user by id").outType(User.class)
-    .param().name("id").type(path).description("The id of the user to get").dataType("int").endParam()
-    .to("bean:userService?method=getUser(${header.id})")</pre>
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[.get(&quot;/{id}&quot;).description(&quot;Find user by id&quot;).outType(User.class)
+    .param().name(&quot;id&quot;).type(path).description(&quot;The id of the user to get&quot;).dataType(&quot;int&quot;).endParam()
+    .to(&quot;bean:userService?method=getUser(${header.id})&quot;)]]></script>
 </div></div><p>The body parameter type requires to use body as well for the name. For example a REST PUT operation to create/update an user could be done as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">&lt;!-- this is a rest PUT to create/update an user --&gt;
-&lt;put type="org.apache.camel.example.rest.User"&gt;
+<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[&lt;!-- this is a rest PUT to create/update an user --&gt;
+&lt;put type=&quot;org.apache.camel.example.rest.User&quot;&gt;
   &lt;description&gt;Updates or create a user&lt;/description&gt;
-  &lt;param name="body" type="body" description="The user to update or create"/&gt;
-  &lt;to uri="bean:userService?method=updateUser"/&gt;
-&lt;/put&gt;</pre>
+  &lt;param name=&quot;body&quot; type=&quot;body&quot; description=&quot;The user to update or create&quot;/&gt;
+  &lt;to uri=&quot;bean:userService?method=updateUser&quot;/&gt;
+&lt;/put&gt;]]></script>
 </div></div><p>And in Java DSL</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">.put().description("Updates or create a user").type(User.class)
-    .param().name("body").type(body).description("The user to update or create").endParam()
-    .to("bean:userService?method=updateUser")</pre>
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[.put().description(&quot;Updates or create a user&quot;).type(User.class)
+    .param().name(&quot;body&quot;).type(body).description(&quot;The user to update or create&quot;).endParam()
+    .to(&quot;bean:userService?method=updateUser&quot;)]]></script>
 </div></div><p>&#160;</p><p>For an example see the&#160;<code>examples/camel-example-servlet-rest-tomcat</code>&#160;of the Apache Camel distribution.</p><h3 id="RestDSL-SeeAlso">See Also</h3><ul><li><a shape="rect" href="dsl.html">DSL</a></li><li><a shape="rect" href="rest.html">Rest</a></li><li><a shape="rect" href="swagger.html">Swagger</a></li><li><a shape="rect" href="spark-rest.html">Spark-rest</a></li><li><a shape="rect" href="how-do-i-import-rests-from-other-xml-files.html">How do I import rests from other XML files</a></li></ul></div>
         </td>
         <td valign="top">
           <div class="navigation">
             <div class="navigation_top">
                 <!-- NavigationBar -->
-<div class="navigation_bottom" id="navigation_bottom"><h3 id="Navigation-Overviewhttps://cwiki.apache.org/confluence/pages/viewpage.action?pageId=49132"><a shape="rect" href="overview.html">Overview</a></h3><ul class="alternate"><li><a shape="rect" href="index.html">Home</a></li><li><a shape="rect" href="download.html">Download</a></li><li><a shape="rect" href="getting-started.html">Getting Started</a></li><li><a shape="rect" href="faq.html">FAQ</a></li></ul><h3 id="Navigation-Documentationhttps://cwiki.apache.org/confluence/pages/viewpage.action?pageId=49534"><a shape="rect" href="documentation.html">Documentation</a></h3><ul class="alternate"><li><a shape="rect" href="user-guide.html">User Guide</a></li><li><a shape="rect" href="manual.html">Manual</a></li><li><a shape="rect" href="books.html">Books</a></li><li><a shape="rect" href="tutorials.html">Tutorials</a></li><li><a shape="rect" href="examples.html">Examples</a></li><li><a shape="rect" href="cookbook.html">Cookbook</a></li>
 <li><a shape="rect" href="architecture.html">Architecture</a></li><li><a shape="rect" href="enterprise-integration-patterns.html">Enterprise Integration Patterns</a></li><li><a shape="rect" href="dsl.html">DSL</a></li><li><a shape="rect" href="components.html">Components</a></li><li><a shape="rect" href="data-format.html">Data Format</a></li><li><a shape="rect" href="languages.html">Languages</a></li><li><a shape="rect" href="security.html">Security</a></li><li><a shape="rect" href="security-advisories.html">Security Advisories</a></li></ul><h3 id="Navigation-Search">Search</h3><form enctype="application/x-www-form-urlencoded" method="get" id="cse-search-box" action="http://www.google.com/cse">
+<div class="navigation_bottom" id="navigation_bottom"><h3 id="Navigation-Overview"><a shape="rect" href="overview.html">Overview</a></h3><ul class="alternate"><li><a shape="rect" href="index.html">Home</a></li><li><a shape="rect" href="download.html">Download</a></li><li><a shape="rect" href="getting-started.html">Getting Started</a></li><li><a shape="rect" href="faq.html">FAQ</a></li></ul><h3 id="Navigation-Documentation"><a shape="rect" href="documentation.html">Documentation</a></h3><ul class="alternate"><li><a shape="rect" href="user-guide.html">User Guide</a></li><li><a shape="rect" href="manual.html">Manual</a></li><li><a shape="rect" href="books.html">Books</a></li><li><a shape="rect" href="tutorials.html">Tutorials</a></li><li><a shape="rect" href="examples.html">Examples</a></li><li><a shape="rect" href="cookbook.html">Cookbook</a></li><li><a shape="rect" href="architecture.html">Architecture</a></li><li><a shape="rect" href="enterprise-integration-patterns.html">Enterprise
  Integration Patterns</a></li><li><a shape="rect" href="dsl.html">DSL</a></li><li><a shape="rect" href="components.html">Components</a></li><li><a shape="rect" href="data-format.html">Data Format</a></li><li><a shape="rect" href="languages.html">Languages</a></li><li><a shape="rect" href="security.html">Security</a></li><li><a shape="rect" href="security-advisories.html">Security Advisories</a></li></ul><h3 id="Navigation-Search">Search</h3><form enctype="application/x-www-form-urlencoded" method="get" id="cse-search-box" action="http://www.google.com/cse">
   <div>
     <input type="hidden" name="cx" value="007878419884033443453:m5nhvy4hmyq">
     <input type="hidden" name="ie" value="UTF-8">
@@ -314,7 +325,7 @@ public class UserPojo {
     <input type="submit" name="sa" value="Search">
   </div>
 </form>
-<script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&amp;lang=en"></script><h3 id="Navigation-Communityhttps://cwiki.apache.org/confluence/pages/viewpage.action?pageId=49115"><a shape="rect" href="community.html">Community</a></h3><ul class="alternate"><li><a shape="rect" href="support.html">Support</a></li><li><a shape="rect" href="contributing.html">Contributing</a></li><li><a shape="rect" href="discussion-forums.html">Discussion Forums</a></li><li><a shape="rect" href="mailing-lists.html">Mailing Lists</a></li><li><a shape="rect" href="user-stories.html">User Stories</a></li><li><a shape="rect" href="news.html">News</a></li><li><a shape="rect" href="articles.html">Articles</a></li><li><a shape="rect" href="site.html">Site</a></li><li><a shape="rect" href="team.html">Team</a></li><li><a shape="rect" class="external-link" href="http://camel-extra.googlecode.com/" rel="nofollow">Camel Extra</a></li></ul><h3 id="Navigation-Developershttps://cwi
 ki.apache.org/confluence/pages/viewpage.action?pageId=49124"><a shape="rect" href="developers.html">Developers</a></h3><ul class="alternate"><li><a shape="rect" href="developers.html">Developer Guide</a></li><li><a shape="rect" href="source.html">Source</a></li><li><a shape="rect" href="building.html">Building</a></li><li><a shape="rect" href="javadoc.html">JavaDoc</a></li><li><a shape="rect" href="irc-room.html">IRC Room</a></li></ul><h3 id="Navigation-ApacheSoftwareFoundation">Apache Software Foundation</h3><ul class="alternate"><li><a shape="rect" class="external-link" href="http://www.apache.org/licenses/">License</a></li><li><a shape="rect" class="external-link" href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li><li><a shape="rect" class="external-link" href="http://www.apache.org/foundation/thanks.html">Thanks</a></li><li><a shape="rect" class="external-link" href="http://www.apache.org/security/">Security</a></li></ul></div>
+<script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&amp;lang=en"></script><h3 id="Navigation-Community"><a shape="rect" href="community.html">Community</a></h3><ul class="alternate"><li><a shape="rect" href="support.html">Support</a></li><li><a shape="rect" href="contributing.html">Contributing</a></li><li><a shape="rect" href="discussion-forums.html">Discussion Forums</a></li><li><a shape="rect" href="mailing-lists.html">Mailing Lists</a></li><li><a shape="rect" href="user-stories.html">User Stories</a></li><li><a shape="rect" href="news.html">News</a></li><li><a shape="rect" href="articles.html">Articles</a></li><li><a shape="rect" href="site.html">Site</a></li><li><a shape="rect" href="team.html">Team</a></li><li><a shape="rect" class="external-link" href="http://camel-extra.googlecode.com/" rel="nofollow">Camel Extra</a></li></ul><h3 id="Navigation-Developers"><a shape="rect" href="developers.html">Developers</a></h3><ul class="alternate"
 ><li><a shape="rect" href="developers.html">Developer Guide</a></li><li><a shape="rect" href="source.html">Source</a></li><li><a shape="rect" href="building.html">Building</a></li><li><a shape="rect" href="javadoc.html">JavaDoc</a></li><li><a shape="rect" href="irc-room.html">IRC Room</a></li></ul><h3 id="Navigation-ApacheSoftwareFoundation">Apache Software Foundation</h3><ul class="alternate"><li><a shape="rect" class="external-link" href="http://www.apache.org/licenses/">License</a></li><li><a shape="rect" class="external-link" href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li><li><a shape="rect" class="external-link" href="http://www.apache.org/foundation/thanks.html">Thanks</a></li><li><a shape="rect" class="external-link" href="http://www.apache.org/security/">Security</a></li></ul></div>
                 <!-- NavigationBar -->
             </div>
           </div>