camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen (Confluence)" <conflue...@apache.org>
Subject [CONF] Apache Camel > Jetty
Date Thu, 15 Aug 2013 13:21:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/en/2176/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/Jetty">Jetty</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >| {{httpClientThreadPool}} | {{null}} | *Deprecated:* *Producer only*: To use a custom thread pool for the client. This option is removed from Camel 2.11 onwards. | <br>| {{sslContextParameters}} | {{null}} | *Camel 2.8:* To configure a custom SSL/TLS configuration options at the component level.&amp;nbsp; See&amp;nbsp; [Using the JSSE Configuration Utility|#Using the JSSE Configuration Utility] for more details. | <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">| {{requestBufferSize}} | {{null}} | *Camel 2.11.2:* Allows to configure a custom value of the request buffer size on the Jetty connectors. | <br>| {{requestHeaderSize}} | {{null}} | *Camel 2.11.2:* Allows to configure a custom value of the request header size on the Jetty connectors. | <br>| {{responseBufferSize}} | {{null}} | *Camel 2.11.2:* Allows to configure a custom value of the response buffer size on the Jetty connectors. | <br>| {{responseHeaderSize}} | {{null}} | *Camel 2.11.2:* Allows to configure a custom value of the response header size on the Jetty connectors. | <br></td></tr>
            <tr><td class="diff-unchanged" >{div} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="Jetty-JettyComponent"></a>Jetty Component</h2>

<p>The <b>jetty</b> component provides HTTP-based <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">endpoints</a> for consuming and producing HTTP requests. That is, the Jetty component behaves as a simple Web server.<br/>
Jetty can also be used as a http client which mean you can also use it with Camel as a producer.</p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Stream</b><br />Jetty is stream based, which means the input it receives is submitted to Camel as a stream. That means you will only be able to read the content of the stream <b>once</b>.<br/>
If you find a situation where the message body appears to be empty or you need to access the data multiple times (eg: doing multicasting, or redelivery error handling)<br/>
you should use <a href="/confluence/display/CAMEL/Stream+caching" title="Stream caching">Stream caching</a> or convert the message body to a <tt>String</tt> which is safe to be re-read multiple times.</td></tr></table></div>

<p>Maven users will need to add the following dependency to their <tt>pom.xml</tt> for this component:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-jetty&lt;/artifactId&gt;
    &lt;version&gt;x.x.x&lt;/version&gt;
    &lt;!-- use the same version as your Camel core version --&gt;
&lt;/dependency&gt;
</pre>
</div></div>

<h3><a name="Jetty-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
jetty:http://hostname[:port][/resourceUri][?options]
</pre>
</div></div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="Jetty-Options"></a>Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>sessionSupport</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Specifies whether to enable the session manager on the server side of Jetty. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpClient.XXX</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Configuration of Jetty's <a href="http://wiki.eclipse.org/Jetty/Tutorial/HttpClient" class="external-link" rel="nofollow">HttpClient</a>. For example, setting <tt>httpClient.idleTimeout=30000</tt> sets the idle timeout to 30 seconds. And <tt>httpClient.timeout=30000</tt> sets the request timeout to 30 seconds, in case you want to timeout sooner if you have long running request/response calls. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpClient</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> To use a shared <tt>org.eclipse.jetty.client.HttpClient</tt> for all producers created by this endpoint. This option should only be used in special circumstances. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpClientMinThreads</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> <b>Producer only</b>: To set a value for minimum number of threads in <tt>HttpClient</tt> thread pool. This setting override any setting configured on component level. Notice that both a min and max size must be configured. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpClientMaxThreads</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> <b>Producer only</b>: To set a value for maximum number of threads in <tt>HttpClient</tt> thread pool. This setting override any setting configured on component level. Notice that both a min and max size must be configured. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpBindingRef</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Reference to an <tt>org.apache.camel.component.http.HttpBinding</tt> in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. <tt>HttpBinding</tt> can be used to customize how a response should be written for the consumer. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>jettyHttpBindingRef</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.6.0+:</b> Reference to an <tt>org.apache.camel.component.jetty.JettyHttpBinding</tt> in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. <tt>JettyHttpBinding</tt> can be used to customize how a response should be written for the producer. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>matchOnUriPrefix</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Whether or not the <tt>CamelServlet</tt> should try to find a target consumer by matching the URI prefix if no exact match is found. See here <a href="/confluence/display/CAMEL/How+do+I+let+Jetty+match+wildcards" title="How do I let Jetty match wildcards">How do I let Jetty match wildcards</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>handlers</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Specifies a comma-delimited set of <tt>org.mortbay.jetty.Handler</tt> instances in your <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> (such as your Spring <tt>ApplicationContext</tt>). These handlers are added to the Jetty servlet context (for example, to add security). <b>Important:</b> You can not use different handlers with different Jetty endpoints using the same port number. The handlers is associated to the port number. If you need different handlers, then use different port numbers. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>chunked</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.2:</b> If this option is false Jetty servlet will disable the HTTP streaming and set the content-length header on the response </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>enableJmx</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> If this option is true, Jetty JMX support will be enabled for this endpoint. See <a href="#Jetty-JettyJMXsupport">Jetty JMX support</a> for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>disableStreamCache</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> Determines whether or not the raw input stream from Jetty is cached or not (Camel will read the stream into a in memory/overflow to file, <a href="/confluence/display/CAMEL/Stream+caching" title="Stream caching">Stream caching</a>) cache. By default Camel will cache the Jetty input stream to support reading it multiple times to ensure it Camel can retrieve all data from the stream. However you can set this option to <tt>true</tt> when you for example need to access the raw stream, such as streaming it directly to a file or other persistent store. DefaultHttpBinding will copy the request input stream into a stream cache and put it into message body if this option is <tt>false</tt> to support reading the stream multiple times. If you use <a href="/confluence/display/CAMEL/Jetty" title="Jetty">Jetty</a> to bridge/proxy an endpoint then consider enabling this option to improve performance, in case you do not need to read the message payload multiple times. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>throwExceptionOnFailure</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Option to disable throwing the <tt>HttpOperationFailedException</tt> in case of failed responses from the remote server. This allows you to get all responses regardles of the HTTP status code. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transferException</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.6:</b>  If enabled and an <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> failed processing on the consumer side, and if the caused Exception was send back serialized in the response as a <tt>application/x-java-serialized-object</tt> content type. On the producer side the exception will be deserialized and thrown as is, instead of the <tt>HttpOperationFailedException</tt>. The caused exception is required to be serialized. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>bridgeEndpoint</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> If the option is true , HttpProducer will ignore the Exchange.HTTP_URI header, and use the endpoint's URI for request. You may also set the <b>throwExceptionOnFailure</b> to be false to let the HttpProducer send all the fault response back. <br class="atl-forced-newline" />
<b>Camel 2.3:</b> If the option is true, HttpProducer and CamelServlet will skip the gzip processing if the content-encoding is "gzip". Also consider setting <b>disableStreamCache</b> to true to optimize when bridging. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>enableMultipartFilter</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.5:</b> Whether Jetty <tt>org.eclipse.jetty.servlets.MultiPartFilter</tt> is enabled or not. You should set this value to <tt>false</tt> when bridging endpoints, to ensure multipart requests is proxied/bridged as well. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>multipartFilterRef</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.6:</b> Allows using a custom multipart filter. Note: setting <tt>multipartFilterRef</tt> forces the value of <tt>enableMultipartFilter</tt> to <tt>true</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>filtersRef</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9:</b> Allows using a custom filters which is putted into a list and can be find in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a></td>
</tr>
<tr>
<td class='confluenceTd'> <tt>continuationTimeout</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.6:</b> Allows to set a timeout in millis when using <a href="/confluence/display/CAMEL/Jetty" title="Jetty">Jetty</a> as consumer (server). By default Jetty uses 30000. You can use a value of <tt>&lt;= 0</tt> to never expire. If a timeout occurs then the request will be expired and Jetty will return back a http error 503 to the client. This option is only in use when using <a href="/confluence/display/CAMEL/Jetty" title="Jetty">Jetty</a> with the <a href="/confluence/display/CAMEL/Asynchronous+Routing+Engine" title="Asynchronous Routing Engine">Asynchronous Routing Engine</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>useContinuation</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.6:</b> Whether or not to use <a href="http://wiki.eclipse.org/Jetty/Feature/Continuations" class="external-link" rel="nofollow">Jetty continuations</a> for the Jetty Server. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sslContextParametersRef</tt><br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> <tt>null</tt><br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> Reference to a <tt>org.apache.camel.util.jsse.SSLContextParameters</tt> in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>.&nbsp; This reference overrides any configured SSLContextParameters at the component level.&nbsp; See <a href="#Jetty-UsingtheJSSEConfigurationUtility">Using the JSSE Configuration Utility</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>traceEnabled</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Specifies whether to enable HTTP TRACE for this Jetty consumer. By default TRACE is turned off. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>headerFilterStrategy</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> Reference to a instance of <tt>org.apache.camel.spi.HeaderFilterStrategy</tt> in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. It will be used to apply the custom headerFilterStrategy on the new create HttpJettyEndpoint. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>urlRewrite</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> <b>Producer only</b> Refers to a custom <tt>org.apache.camel.component.http.UrlRewrite</tt> which allows you to rewrite urls when you bridge/proxy endpoints. See more details at <a href="/confluence/display/CAMEL/UrlRewrite" title="UrlRewrite">UrlRewrite</a> and <a href="/confluence/display/CAMEL/How+to+use+Camel+as+a+HTTP+proxy+between+a+client+and+server" title="How to use Camel as a HTTP proxy between a client and server">How to use Camel as a HTTP proxy between a client and server</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>responseBufferSize</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.12:</b> To use a custom buffer size on the <tt>javax.servlet.ServletResponse</tt>. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Jetty-MessageHeaders"></a>Message Headers</h3>

<p>Camel uses the same message headers as the <a href="/confluence/display/CAMEL/HTTP" title="HTTP">HTTP</a> component.<br/>
>From Camel 2.2, it also uses (Exchange.HTTP_CHUNKED,CamelHttpChunked) header to turn on or turn off the chuched encoding on the camel-jetty consumer.</p>

<p>Camel also populates <b>all</b> request.parameter and request.headers. For example, given a client request with the URL, <tt><a href="http://myserver/myserver?orderid=123" class="external-link" rel="nofollow">http://myserver/myserver?orderid=123</a></tt>, the exchange will contain a header named <tt>orderid</tt> with the value 123. </p>

<p>Starting with Camel 2.2.0, you can get the request.parameter from the message header not only from Get Method, but also other HTTP method.</p>

<h3><a name="Jetty-Usage"></a>Usage</h3>

<p>The Jetty component supports both consumer and producer endpoints. Another option for producing to other HTTP endpoints, is to use the <a href="/confluence/display/CAMEL/HTTP" title="HTTP">HTTP Component</a></p>

<h3><a name="Jetty-ComponentOptions"></a>Component Options</h3>

<p>The <tt>JettyHttpComponent</tt> provides the following options:</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>enableJmx</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> If this option is true, Jetty JMX support will be enabled for this endpoint. See <a href="#Jetty-JettyJMXsupport">Jetty JMX support</a> for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sslKeyPassword</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Consumer only</b>: The password for the keystore when using SSL. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sslPassword</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Consumer only</b>: The password when using SSL. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sslKeystore</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Consumer only</b>: The path to the keystore. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>minThreads</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.5</b> <b>Consumer only</b>: To set a value for minimum number of threads in server thread pool. Notice that both a min and max size must be configured. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxThreads</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.5</b> <b>Consumer only</b>: To set a value for maximum number of threads in server thread pool. Notice that both a min and max size must be configured. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>threadPool</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.5</b> <b>Consumer only</b>: To use a custom thread pool for the server. This option should only be used in special circumstances. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sslSocketConnectors</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.3</b> <b>Consumer only:</b> A map which contains per port number specific SSL connectors. See section <em>SSL support</em> for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>socketConnectors</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.5</b> <b>Consumer only:</b> A map which contains per port number specific HTTP connectors. Uses the same principle as <tt>sslSocketConnectors</tt> and therefore see section <em>SSL support</em> for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sslSocketConnectorProperties</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.5</b> <b>Consumer only</b>. A map which contains general SSL connector properties. See section <em>SSL support</em> for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>socketConnectorProperties</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.5</b> <b>Consumer only</b>. A map which contains general HTTP connector properties. Uses the same principle as <tt>sslSocketConnectorProperties</tt> and therefore see section <em>SSL support</em> for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpClient</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Deprecated:</b> <b>Producer only</b>: To use a custom <tt>HttpClient</tt> with the jetty producer. This option is removed from Camel 2.11 onwards, instead you can set the option on the endpoint instead. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpClientMinThreads</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Producer only</b>: To set a value for minimum number of threads in <tt>HttpClient</tt> thread pool. Notice that both a min and max size must be configured. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpClientMaxThreads</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Producer only</b>: To set a value for maximum number of threads in <tt>HttpClient</tt> thread pool. Notice that both a min and max size must be configured. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpClientThreadPool</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Deprecated:</b> <b>Producer only</b>: To use a custom thread pool for the client. This option is removed from Camel 2.11 onwards. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sslContextParameters</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> To configure a custom SSL/TLS configuration options at the component level.&nbsp; See&nbsp; <a href="#Jetty-UsingtheJSSEConfigurationUtility">Using the JSSE Configuration Utility</a> for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>requestBufferSize</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11.2:</b> Allows to configure a custom value of the request buffer size on the Jetty connectors. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>requestHeaderSize</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11.2:</b> Allows to configure a custom value of the request header size on the Jetty connectors. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>responseBufferSize</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11.2:</b> Allows to configure a custom value of the response buffer size on the Jetty connectors. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>responseHeaderSize</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11.2:</b> Allows to configure a custom value of the response header size on the Jetty connectors. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Jetty-ProducerExample"></a>Producer Example</h3>

<p>The following is a basic example of how to send an HTTP request to an existing HTTP endpoint.</p>

<p>in Java DSL</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
from("direct:start").to("jetty://http://www.google.com");
</pre>
</div></div>

<p>or in Spring XML</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;route&gt;
    &lt;from uri="direct:start"/&gt;
    &lt;to uri="jetty://http://www.google.com"/&gt;
&lt;route&gt;
</pre>
</div></div>

<h3><a name="Jetty-ConsumerExample"></a>Consumer Example</h3>

<p>In this sample we define a route that exposes a HTTP service at <tt><a href="http://localhost:8080/myapp/myservice" class="external-link" rel="nofollow">http://localhost:8080/myapp/myservice</a></tt>:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="theme: Default; brush: java; gutter: false"><![CDATA[
from("jetty:http://localhost:{{port}}/myapp/myservice").process(new MyBookService());
]]></script>
</div></div>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Usage of localhost</b><br />When you specify <tt>localhost</tt> in a URL, Camel exposes the endpoint only on the local TCP/IP network interface, so it cannot be accessed from outside the machine it operates on.

<p>If you need to expose a Jetty endpoint on a specific network interface, the numerical IP address of this interface should be used as the host. If you need to expose a Jetty endpoint on all network interfaces, the <tt>0.0.0.0</tt> address should be used.</p></td></tr></table></div>

<p>Our business logic is implemented in the <tt>MyBookService</tt> class, which accesses the HTTP request contents and then returns a response.<br/>
<b>Note:</b> The <tt>assert</tt> call appears in this example, because the code is part of an unit test.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="theme: Default; brush: java; gutter: false"><![CDATA[
public class MyBookService implements Processor {
    public void process(Exchange exchange) throws Exception {
        // just get the body as a string
        String body = exchange.getIn().getBody(String.class);

        // we have access to the HttpServletRequest here and we can grab it if we need it
        HttpServletRequest req = exchange.getIn().getBody(HttpServletRequest.class);
        assertNotNull(req);

        // for unit testing
        assertEquals("bookid=123", body);

        // send a html response
        exchange.getOut().setBody("&lt;html&gt;&lt;body&gt;Book 123 is Camel in Action&lt;/body&gt;&lt;/html&gt;");
    }
}
]]></script>
</div></div>

<p>The following sample shows a content-based route that routes all requests containing the URI parameter, <tt>one</tt>, to the endpoint, <tt>mock:one</tt>, and all others to <tt>mock:other</tt>.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="theme: Default; brush: java; gutter: false"><![CDATA[
from("jetty:" + serverUri)
    .choice()
    .when().simple("${header.one}").to("mock:one")
    .otherwise()
    .to("mock:other");
]]></script>
</div></div>
<p>So if a client sends the HTTP request, <tt><a href="http://serverUri?one=hello" class="external-link" rel="nofollow">http://serverUri?one=hello</a></tt>, the Jetty component will copy the HTTP request parameter, <tt>one</tt> to the exchange's <tt>in.header</tt>. We can then use the <tt>simple</tt> language to route exchanges that contain this header to a specific endpoint and all others to another. If we used a language more powerful than <a href="/confluence/display/CAMEL/Simple" title="Simple">Simple</a>&#45;&#45;<del>such as</del> <del><a href="/confluence/display/CAMEL/EL" title="EL">EL</a></del> <del>or</del> <del><a href="/confluence/display/CAMEL/OGNL" title="OGNL">OGNL</a></del>&#45;-we could also test for the parameter value and do routing based on the header value as well.</p>

<h3><a name="Jetty-SessionSupport"></a>Session Support</h3>

<p>The session support option, <tt>sessionSupport</tt>, can be used to enable a <tt>HttpSession</tt> object and access the session object while processing the exchange. For example, the following route enables sessions:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;route&gt;
    &lt;from uri="jetty:http://0.0.0.0/myapp/myservice/?sessionSupport=true"/&gt;
    &lt;processRef ref="myCode"/&gt;
&lt;route&gt;
</pre>
</div></div>

<p>The <tt>myCode</tt> <a href="/confluence/display/CAMEL/Processor" title="Processor">Processor</a> can be instantiated by a Spring <tt>bean</tt> element:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;bean id="myCode"class="com.mycompany.MyCodeProcessor"/&gt;
</pre>
</div></div>

<p>Where the processor implementation can access the <tt>HttpSession</tt> as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
public void process(Exchange exchange) throws Exception {
    HttpSession session = exchange.getIn(HttpMessage.class).getRequest().getSession();
    ...
}
</pre>
</div></div>

<h3><a name="Jetty-SSLSupport%28HTTPS%29"></a>SSL Support (HTTPS)</h3>


<h5><a name="Jetty-UsingtheJSSEConfigurationUtility"></a>Using the JSSE Configuration Utility</h5>

<p>As of Camel 2.8, the Jetty component supports SSL/TLS configuration through the <a href="/confluence/display/CAMEL/Camel+Configuration+Utilities" title="Camel Configuration Utilities">Camel JSSE Configuration Utility</a>.&nbsp;  This utility greatly decreases the amount of component specific code  you need to write and is configurable at the endpoint and component  levels.&nbsp; The following examples demonstrate how to use the utility with  the Jetty component.</p>

<h6><a name="Jetty-Programmaticconfigurationofthecomponent"></a>Programmatic configuration of the component</h6>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
KeyStoreParameters ksp = new KeyStoreParameters();
ksp.setResource("/users/home/server/keystore.jks");
ksp.setPassword("keystorePassword");

KeyManagersParameters kmp = new KeyManagersParameters();
kmp.setKeyStore(ksp);
kmp.setKeyPassword("keyPassword");

SSLContextParameters scp = new SSLContextParameters();
scp.setKeyManagers(kmp);

JettyComponent jettyComponent = getContext().getComponent("jetty", JettyComponent.class);
jettyComponent.setSslContextParameters(scp);
</pre>
</div></div>

<h6><a name="Jetty-SpringDSLbasedconfigurationofendpoint"></a>Spring DSL based configuration of endpoint</h6>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
...
  &lt;camel:sslContextParameters
      id="sslContextParameters"&gt;
    &lt;camel:keyManagers
        keyPassword="keyPassword"&gt;
      &lt;camel:keyStore
          resource="/users/home/server/keystore.jks"
          password="keystorePassword"/&gt;
    &lt;/camel:keyManagers&gt;
  &lt;/camel:sslContextParameters&gt;...
...
  &lt;to uri="jetty:https://127.0.0.1/mail/?sslContextParametersRef=sslContextParameters"/&gt;
...
</pre>
</div></div>

<h5><a name="Jetty-ConfiguringJettyDirectly"></a>Configuring Jetty Directly</h5>

<p>Jetty provides SSL support out of the box. To enable Jetty to run in SSL mode, simply format the URI with the <tt>https://</tt> prefix---for example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;from uri="jetty:https://0.0.0.0/myapp/myservice/"/&gt;
</pre>
</div></div>

<p>Jetty also needs to know where to load your keystore from and what passwords to use in order to load the correct SSL certificate. Set the following JVM System Properties:</p>

<p><b>until Camel 2.2</b></p>
<ul>
	<li><tt>jetty.ssl.keystore</tt> specifies the location of the Java keystore file, which contains the Jetty server's own X.509 certificate in a <em>key entry</em>. A key entry stores the X.509 certificate (effectively, the <em>public key</em>) and also its associated private key.</li>
	<li><tt>jetty.ssl.password</tt> the store password, which is required to access the keystore file (this is the same password that is supplied to the <tt>keystore</tt> command's <tt>&#45;storepass</tt> option).</li>
	<li><tt>jetty.ssl.keypassword</tt> the key password, which is used to access the certificate's key entry in the keystore (this is the same password that is supplied to the <tt>keystore</tt> command's <tt>&#45;keypass</tt> option).</li>
</ul>


<p><b>from Camel 2.3 onwards</b></p>
<ul>
	<li><tt>org.eclipse.jetty.ssl.keystore</tt> specifies the location of the Java keystore file, which contains the Jetty server's own X.509 certificate in a <em>key entry</em>. A key entry stores the X.509 certificate (effectively, the <em>public key</em>) and also its associated private key.</li>
	<li><tt>org.eclipse.jetty.ssl.password</tt> the store password, which is required to access the keystore file (this is the same password that is supplied to the <tt>keystore</tt> command's <tt>&#45;storepass</tt> option).</li>
	<li><tt>org.eclipse.jetty.ssl.keypassword</tt> the key password, which is used to access the certificate's key entry in the keystore (this is the same password that is supplied to the <tt>keystore</tt> command's <tt>&#45;keypass</tt> option).</li>
</ul>


<p>For details of how to configure SSL on a Jetty endpoint, read the following documentation at the Jetty Site: <a href="http://docs.codehaus.org/display/JETTY/How+to+configure+SSL" class="external-link" rel="nofollow">http://docs.codehaus.org/display/JETTY/How+to+configure+SSL</a></p>




<p>Some SSL properties aren't exposed directly by Camel, however Camel does expose the underlying SslSocketConnector, which will allow you to set properties like needClientAuth for mutual authentication requiring a client certificate or wantClientAuth for mutual authentication where a client doesn't need a certificate but can have one. There's a slight difference between the various Camel versions:</p>

<p><b>Up to Camel 2.2</b></p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;bean id="jetty" class="org.apache.camel.component.jetty.JettyHttpComponent"&gt;
    &lt;property name="sslSocketConnectors"&gt;
        &lt;map&gt;
            &lt;entry key="8043"&gt;
                &lt;bean class="org.mortbay.jetty.security.SslSocketConnector"&gt;
                    &lt;property name="password"value="..."/&gt;
                    &lt;property name="keyPassword"value="..."/&gt;
                    &lt;property name="keystore"value="..."/&gt;
                    &lt;property name="needClientAuth"value="..."/&gt;
                    &lt;property name="truststore"value="..."/&gt;
                &lt;/bean&gt;
            &lt;/entry&gt;
        &lt;/map&gt;
    &lt;/property&gt;
&lt;/bean&gt;
</pre>
</div></div>


<p><b>Camel 2.3, 2.4</b></p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;bean id="jetty" class="org.apache.camel.component.jetty.JettyHttpComponent"&gt;
    &lt;property name="sslSocketConnectors"&gt;
        &lt;map&gt;
            &lt;entry key="8043"&gt;
                &lt;bean class="org.eclipse.jetty.server.ssl.SslSocketConnector"&gt;
                    &lt;property name="password"value="..."/&gt;
                    &lt;property name="keyPassword"value="..."/&gt;
                    &lt;property name="keystore"value="..."/&gt;
                    &lt;property name="needClientAuth"value="..."/&gt;
                    &lt;property name="truststore"value="..."/&gt;
                &lt;/bean&gt;
            &lt;/entry&gt;
        &lt;/map&gt;
    &lt;/property&gt;
&lt;/bean&gt;
</pre>
</div></div>

<p>&#42;From Camel 2.5 we switch to use SslSelectChannelConnector *</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;bean id="jetty" class="org.apache.camel.component.jetty.JettyHttpComponent"&gt;
    &lt;property name="sslSocketConnectors"&gt;
        &lt;map&gt;
            &lt;entry key="8043"&gt;
                &lt;bean class="org.eclipse.jetty.server.ssl.SslSelectChannelConnector"&gt;
                    &lt;property name="password"value="..."/&gt;
                    &lt;property name="keyPassword"value="..."/&gt;
                    &lt;property name="keystore"value="..."/&gt;
                    &lt;property name="needClientAuth"value="..."/&gt;
                    &lt;property name="truststore"value="..."/&gt;
                &lt;/bean&gt;
            &lt;/entry&gt;
        &lt;/map&gt;
    &lt;/property&gt;
&lt;/bean&gt;
</pre>
</div></div>


<p>The value you use as keys in the above map is the port you configure Jetty to listen on.</p>

<h4><a name="Jetty-ConfiguringgeneralSSLproperties"></a>Configuring general SSL properties</h4>

<p><b>Available as of Camel 2.5</b></p>

<p>Instead of a per port number specific SSL socket connector (as shown above) you can now configure general properties which applies for all SSL socket connectors (which is not explicit configured as above with the port number as entry).</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;bean id="jetty" class="org.apache.camel.component.jetty.JettyHttpComponent"&gt;
    &lt;property name="sslSocketConnectorProperties"&gt;
        &lt;map&gt;
            &lt;entry key="password"value="..."/&gt;
            &lt;entry key="keyPassword"value="..."/&gt;
            &lt;entry key="keystore"value="..."/&gt;
            &lt;entry key="needClientAuth"value="..."/&gt;
            &lt;entry key="truststore"value="..."/&gt;
        &lt;/map&gt;
    &lt;/property&gt;
&lt;/bean&gt;
</pre>
</div></div>


<h4><a name="Jetty-HowtoobtainreferencetotheX509Certificate"></a>How to obtain reference to the X509Certificate</h4>

<p>Jetty stores a reference to the certificate in the HttpServletRequest which you can access from code as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
HttpServletRequest req = exchange.getIn().getBody(HttpServletRequest.class);
X509Certificate cert = (X509Certificate) req.getAttribute("javax.servlet.request.X509Certificate")
</pre>
</div></div>

<h4><a name="Jetty-ConfiguringgeneralHTTPproperties"></a>Configuring general HTTP properties</h4>

<p><b>Available as of Camel 2.5</b></p>

<p>Instead of a per port number specific HTTP socket connector (as shown above) you can now configure general properties which applies for all HTTP socket connectors (which is not explicit configured as above with the port number as entry).</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;bean id="jetty" class="org.apache.camel.component.jetty.JettyHttpComponent"&gt;
    &lt;property name="socketConnectorProperties"&gt;
        &lt;map&gt;
            &lt;entry key="acceptors" value="4"/&gt;
            &lt;entry key="maxIdleTime" value="300000"/&gt;
        &lt;/map&gt;
    &lt;/property&gt;
&lt;/bean&gt;
</pre>
</div></div>


<h3><a name="Jetty-DefaultbehaviorforreturningHTTPstatuscodes"></a>Default behavior for returning HTTP status codes</h3>

<p>The default behavior of HTTP status codes is defined by the <tt>org.apache.camel.component.http.DefaultHttpBinding</tt> class, which handles how a response is written and also sets the HTTP status code.</p>

<p>If the exchange was processed successfully, the 200 HTTP status code is returned.<br/>
If the exchange failed with an exception, the 500 HTTP status code is returned, and the stacktrace is returned in the body. If you want to specify which HTTP status code to return, set the code in the <tt>HttpProducer.HTTP_RESPONSE_CODE</tt> header of the OUT message.</p>

<h3><a name="Jetty-CustomizingHttpBinding"></a>Customizing HttpBinding</h3>

<p>By default, Camel uses the <tt>org.apache.camel.component.http.DefaultHttpBinding</tt> to handle how a response is written. If you like, you can customize this behavior either by implementing your own <tt>HttpBinding</tt> class or by extending <tt>DefaultHttpBinding</tt> and overriding the appropriate methods.</p>

<p>The following example shows how to customize the <tt>DefaultHttpBinding</tt> in order to change how exceptions are returned:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="theme: Default; brush: java; gutter: false"><![CDATA[
public class MyHttpBinding extends DefaultHttpBinding {
    public MyHttpBinding(HttpEndpoint ep) {
        super(ep);
    }
    @Override
    public void doWriteExceptionResponse(Throwable exception, HttpServletResponse response) throws IOException {
        // we override the doWriteExceptionResponse as we only want to alter the binding how exceptions is
        // written back to the client. 

        // we just return HTTP 200 so the client thinks its okay
        response.setStatus(200);
        // and we return this fixed text
        response.getWriter().write("Something went wrong but we dont care");
    }
}
]]></script>
</div></div>

<p>We can then create an instance of our binding and register it in the Spring registry as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;bean id="mybinding"class="com.mycompany.MyHttpBinding"/&gt;
</pre>
</div></div>

<p>And then we can reference this binding when we define the route:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;route&gt;&lt;from uri="jetty:http://0.0.0.0:8080/myapp/myservice?httpBindingRef=mybinding"/&gt;&lt;to uri="bean:doSomething"/&gt;&lt;/route&gt;
</pre>
</div></div>

<h3><a name="Jetty-Jettyhandlersandsecurityconfiguration"></a>Jetty handlers and security configuration</h3>

<p>You can configure a list of Jetty handlers on the endpoint, which can be useful for enabling advanced Jetty security features. These handlers are configured in Spring XML as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;-- Jetty Security handling --&gt;
&lt;bean id="userRealm" class="org.mortbay.jetty.plus.jaas.JAASUserRealm"&gt;
    &lt;property name="name" value="tracker-users"/&gt;
    &lt;property name="loginModuleName" value="ldaploginmodule"/&gt;
&lt;/bean&gt;

&lt;bean id="constraint" class="org.mortbay.jetty.security.Constraint"&gt;
    &lt;property name="name" value="BASIC"/&gt;
    &lt;property name="roles" value="tracker-users"/&gt;
    &lt;property name="authenticate" value="true"/&gt;
&lt;/bean&gt;

&lt;bean id="constraintMapping" class="org.mortbay.jetty.security.ConstraintMapping"&gt;
    &lt;property name="constraint" ref="constraint"/&gt;
    &lt;property name="pathSpec" value="/*"/&gt;
&lt;/bean&gt;

&lt;bean id="securityHandler" class="org.mortbay.jetty.security.SecurityHandler"&gt;
    &lt;property name="userRealm" ref="userRealm"/&gt;
    &lt;property name="constraintMappings" ref="constraintMapping"/&gt;
&lt;/bean&gt;
</pre>
</div></div>

<p><b>And from Camel 2.3 onwards</b> you can configure a list of Jetty handlers as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;-- Jetty Security handling --&gt;
&lt;bean id="constraint" class="org.eclipse.jetty.http.security.Constraint"&gt;
    &lt;property name="name" value="BASIC"/&gt;
    &lt;property name="roles" value="tracker-users"/&gt;
    &lt;property name="authenticate" value="true"/&gt;
&lt;/bean&gt;

&lt;bean id="constraintMapping" class="org.eclipse.jetty.security.ConstraintMapping"&gt;
    &lt;property name="constraint" ref="constraint"/&gt;
    &lt;property name="pathSpec" value="/*"/&gt;
&lt;/bean&gt;

&lt;bean id="securityHandler" class="org.eclipse.jetty.security.ConstraintSecurityHandler"&gt;
    &lt;property name="authenticator"&gt;
        &lt;bean class="org.eclipse.jetty.security.authentication.BasicAuthenticator"/&gt;
    &lt;/property&gt;
    &lt;property name="constraintMappings"&gt;
        &lt;list&gt;
            &lt;ref bean="constraintMapping"/&gt;
        &lt;/list&gt;
    &lt;/property&gt;
&lt;/bean&gt;
</pre>
</div></div>

<p>You can then define the endpoint as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
from("jetty:http://0.0.0.0:9080/myservice?handlers=securityHandler")
</pre>
</div></div>

<p>If you need more handlers, set the <tt>handlers</tt> option equal to a comma-separated list of bean IDs.</p>

<h3><a name="Jetty-HowtoreturnacustomHTTP500replymessage"></a>How to return a custom HTTP 500 reply message</h3>

<p>You may want to return a custom reply message when something goes wrong, instead of the default reply message Camel <a href="/confluence/display/CAMEL/Jetty" title="Jetty">Jetty</a> replies with.<br/>
You could use a custom <tt>HttpBinding</tt> to be in control of the message mapping, but often it may be easier to use Camel's <a href="/confluence/display/CAMEL/Exception+Clause" title="Exception Clause">Exception Clause</a> to construct the custom reply message. For example as show here, where we return <tt>Dude something went wrong</tt> with HTTP error code 500:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="theme: Default; brush: java; gutter: false"><![CDATA[
from("jetty://http://localhost:{{port}}/myserver")
    // use onException to catch all exceptions and return a custom reply message
    .onException(Exception.class)
        .handled(true)
        // create a custom failure response
        .transform(constant("Dude something went wrong"))
        // we must remember to set error code 500 as handled(true)
        // otherwise would let Camel thing its a OK response (200)
        .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500))
    .end()
    // now just force an exception immediately
    .throwException(new IllegalArgumentException("I cannot do this"));
]]></script>
</div></div>

<h3><a name="Jetty-MultipartFormsupport"></a>Multi-part Form support</h3>

<p>From Camel 2.3.0, camel-jetty support to multipart form post out of box. The submitted form-data are mapped into the message header. Camel-jetty creates an attachment for each uploaded file. The file name is mapped to the name of the attachment. The content type is set as the content type of the attachment file name. You can find the example here.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Note: getName() functions as shown below in versions 2.5 and higher. In earlier versions you receive the temporary file name for the attachment instead</b></div><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="theme: Default; brush: java; gutter: false"><![CDATA[
// Set the jetty temp directory which store the file for multi part form
// camel-jetty will clean up the file after it handled the request.
// The option works rightly from Camel 2.4.0
getContext().getProperties().put("CamelJettyTempDir", "target");

from("jetty://http://localhost:{{port}}/test").process(new Processor() {

    public void process(Exchange exchange) throws Exception {
        Message in = exchange.getIn();
        assertEquals("Get a wrong attachement size", 1, in.getAttachments().size());
        // The file name is attachment id
        DataHandler data = in.getAttachment("NOTICE.txt");

        assertNotNull("Should get the DataHandle NOTICE.txt", data);
        // This assert is wrong, but the correct content-type (application/octet-stream)
        // will not be returned until Jetty makes it available - currently the content-type
        // returned is just the default for FileDataHandler (for the implentation being used)
        //assertEquals("Get a wrong content type", "text/plain", data.getContentType());
        assertEquals("Got the wrong name", "NOTICE.txt", data.getName());

        assertTrue("We should get the data from the DataHandle", data.getDataSource()
            .getInputStream().available() &gt; 0);

        // The other form date can be get from the message header
        exchange.getOut().setBody(in.getHeader("comment"));
    }

});
]]></script>
</div></div>

<h3><a name="Jetty-JettyJMXsupport"></a>Jetty JMX support</h3>

<p>From Camel 2.3.0, camel-jetty supports the enabling of Jetty's JMX capabilities at the component and endpoint level with the endpoint configuration taking priority.  Note that JMX must be enabled within the Camel context in order to enable JMX support in this component as the component provides Jetty with a reference to the MBeanServer registered with the Camel context.  Because the camel-jetty component caches and reuses Jetty resources for a given protocol/host/port pairing, this configuration option will only be evaluated during the creation of the first endpoint to use a protocol/host/port pairing.  For example, given two routes created from the following XML fragments, JMX support would remain enabled for all endpoints listening on "https://0.0.0.0".</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;from uri="jetty:https://0.0.0.0/myapp/myservice1/?enableJmx=true"/&gt;
</pre>
</div></div>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;from uri="jetty:https://0.0.0.0/myapp/myservice2/?enableJmx=false"/&gt;
</pre>
</div></div>

<p>The camel-jetty component also provides for direct configuration of the Jetty MBeanContainer.  Jetty creates MBean names dynamically.  If you are running another instance of Jetty outside of the Camel context and sharing the same MBeanServer between the instances, you can provide both instances with a reference to the same MBeanContainer in order to avoid name collisions when registering Jetty MBeans.</p>


<h3><a name="Jetty-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/HTTP" title="HTTP">HTTP</a></li>
</ul>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://cwiki.apache.org/confluence/users/removespacenotification.action?spaceKey=CAMEL">Stop watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://cwiki.apache.org/confluence/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Jetty">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=64903&revisedVersion=74&originalVersion=73">View Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Jetty?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message