Author: buildbot Date: Fri Jan 30 03:20:10 2015 New Revision: 938318 Log: Production update by buildbot for camel
Modified: websites/production/camel/content/cache/main.pageCache websites/production/camel/content/rest-dsl.html Modified: websites/production/camel/content/cache/main.pageCache ============================================================================== Binary files - no diff available. Modified: websites/production/camel/content/rest-dsl.html ============================================================================== --- websites/production/camel/content/rest-dsl.html (original) +++ websites/production/camel/content/rest-dsl.html Fri Jan 30 03:20:10 2015 @@ -101,7 +101,7 @@ } }; }]]></script> -</div></div><p> </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"><span>/say</span></td><td colspan="1" rowspan="1" class="confluenceTd">/hello</td><td colspan="1" rowspan="1" class="confluenceTd">get</td><td colspan="1" rowspan="1" class="confluenceTd"><em>all</em></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">/say</td><td colspan="1" rowspan="1" class="confluenceTd">/bye</td><td colspan="1" rowspan="1" class="confluenceTd">get</td><td colspan="1" rowspan="1" class="confluenceTd">application/json</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">/say</td><td cols pan="1" rowspan="1" class="confluenceTd">/bye</td><td colspan="1" rowspan="1" class="confluenceTd">post</td><td colspan="1" rowspan="1" class="confluenceTd"><em>all</em></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"> +</div></div><p> </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"> <script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ <camelContext xmlns="http://camel.apache.org/schema/spring"> <rest path="/say"> <get uri="/hello"> @@ -183,7 +183,7 @@ <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 becomes 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 <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. </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 <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 binding 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">off</td><td colspan="1" rowspan="1" class="confluenceTd">Binding is turned off. This is the default option.</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">auto</td><td colspan="1" rowspan="1" class="confluenceTd">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.</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">json</td><td colspan="1" rowspan="1" class="confluenceTd">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.</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">xml</td><td colspan="1" rowspan="1" class="confluenceTd">Binding to/from xml is enabled, and requires <code>camel-jaxb</code> on the classpath.</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">json_xml</td><td colspan="1" rowspan="1" class="confluenceTd">Biding to/from json and xml is enabled and requires both data formats to be on the classpath.</td></tr></tbody></table></div> <div class="aui-message success shadowed information-macro"> +<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 becomes 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 <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. </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 <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 binding 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 ex ample <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="aui-message success shadowed information-macro"> <span class="aui-icon icon-success">Icon</span> <div class="message-content"> <p>From <strong>Camel 2.14.1</strong> onwards when using camel-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> @@ -193,7 +193,7 @@ <script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[restConfiguration().component("restlet").host("localhost").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"> <script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ <restConfiguration bindingMode="auto" component="restlet" port="8080"/>]]></script> -</div></div><p> </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. </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">XML</td><td colspan="1" rowspan="1" class="confluenceTd">Incoming</td><td colspan="1" rowspan="1" class="confluenceTd"><p>auto<br clear="none">xml<br clear="none">json_xml </p></td><td colspan="1" r owspan="1" class="confluenceTd">POJO</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">POJO</td><td colspan="1" rowspan="1" class="confluenceTd">Outgoing</td><td colspan="1" rowspan="1" class="confluenceTd">auto<br clear="none">xml<br clear="none">json_xml </td><td colspan="1" rowspan="1" class="confluenceTd">XML</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">JSON</td><td colspan="1" rowspan="1" class="confluenceTd">Incoming</td><td colspan="1" rowspan="1" class="confluenceTd">auto<br clear="none">json<br clear="none">json_xml </td><td colspan="1" rowspan="1" class="confluenceTd">POJO</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">POJO</td><td colspan="1" rowspan="1" class="confluenceTd">Outgoing</td><td colspan="1" rowspan="1" class="confluenceTd">auto<br clear="none">json<br clear="none">json_xml </td><td colspan="1" rowspan="1" class="confluenceTd">JSON</td></tr></tbody></table></div><p> </p><p>When using binding you m ust also configure what POJO type to map to. This is mandatory for incoming messages, and optional for outgoing. </p><p>For example to map from xml/json to a pojo class <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"> +</div></div><p> </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. </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 </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 </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 </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 </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>JSON</p></td></tr></tbody></table>< /div><p> </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. </p><p>For example to map from xml/json to a pojo class <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"> <script class="theme: Default; brush: java; gutter: false" 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); @@ -251,11 +251,11 @@ public class UserPojo { } ]]></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">component</td><td colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1" class="confluenceTd">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 <code>org.apache.camel.spi.RestConsumerFactory</cod e> is registered in the registry. If either one is found, then that is being used.</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">scheme</td><td colspan="1" rowspan="1" class="confluenceTd">http</td><td colspan="1" rowspan="1" class="confluenceTd">The scheme to use for exposing the REST service. Usually http or https is supported</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">hostname</td><td colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1" class="confluenceTd">The hostname to use for exposing the REST service.</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">port</td><td colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1" class="confluenceTd">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.</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">contextPath</td><td colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1" class="confluenceTd">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.</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">restHostNameResolver</td><td colspan="1" rowspan="1" class="confluenceTd">localHostName</td><td colspan="1" rowspan="1" class="confluenceTd">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>.</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">bindingMode</td><td colspan="1" rowspan="1" class="confluenceTd">off</td><td colspan="1" rowspan="1" class="confluenceTd">Whether binding is in use. See further above for more details.</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">skipBindingOnErrorCode</td><td colspan="1" rowspan="1" class="confluenceTd">true</td><td colspan="1" rowspan="1" class="confluenceTd"><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.</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">enableCORS</td><td colspan="1" rowspan="1" class="confluenceTd">false</td><td cols pan="1" rowspan="1" class="confluenceTd"><strong>Camel 2.14.1:</strong> Whether to enable CORS headers in the HTTP response.</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">jsonDataFormat</td><td colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1" class="confluenceTd">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.</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">xmlDataFormat</td><td colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1" class="confluenceTd">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 o f the data format, not to refer to an existing data format instance. </span><strong>Notice:</strong> Currently only <code>jaxb</code> is supported.</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">componentProperty</td><td colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1" class="confluenceTd">Allows to configure as many additional properties. This is used to configure component specific options such as for <a shape="rect" href="restlet.html">Restlet</a> / <a shape="rect" href="spark-rest.html">Spark-Rest</a> etc.</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">endpointProperty</td><td colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1" class="confluenceTd"><span>Allows to configure as many additional properties. This is used to configure endpoint specific options for <span> </span><a shape="rect" href="restlet.html">Restlet</a><span> / </span><a shape="rect " href="spark-rest.html">Spark-Rest</a><span> etc.</span></span></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">consumerProperty</td><td colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1" class="confluenceTd"><span>Allows to configure as many additional properties. This is used to configure consumer specific options for </span><span> </span><a shape="rect" href="restlet.html">Restlet</a><span> / </span><a shape="rect" href="spark-rest.html">Spark-Rest</a><span> etc.</span></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">dataFormatProperty</td><td colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1" class="confluenceTd"><p>Allows to configure 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 ca n be prefixed with either</p><ul style="list-style-type: square;"><li>json.in.</li><li>json.out.</li><li>xml.in.</li><li>xml.out.</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">corsHeaderProperty</td><td colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1" class="confluenceTd">Allows to configure custom CORS headers.</td></tr></tbody></table></div><p> </p><p><span style="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"> +</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"> </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 <code>org.apache.camel.spi.RestConsumerFa ctory</code> 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"> </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"> </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"> </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"> </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"> </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"> </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 <a shape="rect" href="restlet.html">Restlet</a> / <a shape="rect" href="spark-rest.html">Spark-Rest</a> etc.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>endpointProperty</p></td><td colspan="1" rowspan="1" class="confluenceTd"> </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> </span><a shape="rect" href="restlet.html">Restlet</a><span> / </span><a shape="rect" href="spark-rest.html">Spark-Rest</a><span> 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"> </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> </span><a shape="rect" href="restlet.html">Restlet</a><span> / </span><a shape="rect" href="spark-rest.html">Spark-Rest</a><span> etc.</span></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>dataFormatProperty</p></td><td colspan="1" rowspan="1" class="confluenceTd"> </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"> </td><td colspan="1" rowspan="1" class="confluenceTd"><p>Allows to configure custom CORS headers.</p></td></tr></tbody></table></div><p> </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"> <script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[restConfiguration().component("spark-rest").port(9091).componentProperty("foo", "123");]]></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"> <script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[<restConfiguration component="spark-rest" port="9091"> <componentProperty key="foo" value="123"/> </restConfiguration>]]></script> -</div></div><p><span style="line-height: 1.4285715;"><br clear="none"></span></p><p>You can configure properties on these levels. </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." </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><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">Access-Control-Allow-Origin</td><td colspan="1" rowspan="1" class="confluenceTd">*</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">Access-Control-Allow-Methods</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">Access-Control-Allow-Headers</td ><td colspan="1" rowspan="1" class="confluenceTd">Origin, Accept, >X-Requested-With, Content-Type, Access-Control-Request-Method, >Access-Control-Request-Headers</td></tr><tr><td colspan="1" rowspan="1" >class="confluenceTd">Access-Control-Max-Age</td><td colspan="1" rowspan="1" >class="confluenceTd">3600</td></tr></tbody></table></div><p> </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 <strong>Camel 2.14.1</strong> onwards you just set a header with >the key <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"> +</div></div><p><span style="line-height: 1.4285715;"><br clear="none"></span></p><p>You can configure properties on these levels. </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." </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><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, Accept, 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> </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 <strong>Camel 2.14.1</strong> onwards you just set a header with the key <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"> <script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ restConfiguration().component("restlet").host("localhost").port(portNum).bindingMode(RestBindingMode.json); // use the rest DSL to define the rest services rest("/users/")