Author: buildbot Date: Fri Nov 13 09:22:52 2015 New Revision: 972283 Log: Production update by buildbot for camel
Modified: websites/production/camel/content/book-component-appendix.html websites/production/camel/content/book-in-one-page.html websites/production/camel/content/cache/main.pageCache websites/production/camel/content/jetty.html Modified: websites/production/camel/content/book-component-appendix.html ============================================================================== --- websites/production/camel/content/book-component-appendix.html (original) +++ websites/production/camel/content/book-component-appendix.html Fri Nov 13 09:22:52 2015 @@ -1075,11 +1075,11 @@ template.send("direct:alias-verify& ]]></script> </div></div><p></p><h3 id="BookComponentAppendix-SeeAlso.8">See Also</h3> <ul><li><a shape="rect" href="configuring-camel.html">Configuring Camel</a></li><li><a shape="rect" href="component.html">Component</a></li><li><a shape="rect" href="endpoint.html">Endpoint</a></li><li><a shape="rect" href="getting-started.html">Getting Started</a></li></ul><ul><li><a shape="rect" href="crypto.html">Crypto</a> Crypto is also available as a <a shape="rect" href="data-format.html">Data Format</a></li></ul> <h2 id="BookComponentAppendix-CXFComponent">CXF Component</h2><div class="confluence-information-macro confluence-information-macro-note"><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>When using CXF as a consumer, the <a shape="rect" href="cxf-bean-component.html">CXF Bean Component</a> allows you to factor out how message payloads are received from their processing as a RESTful or SOAP web service. This has the potential of using a multitude of transports to cons ume web services. The bean component's configuration is also simpler and provides the fastest method to implement web services using Camel and CXF.</p></div></div><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>When using CXF in streaming modes (see DataFormat option), then also read about <a shape="rect" href="stream-caching.html">Stream caching</a>.</p></div></div><p>The <strong>cxf:</strong> component provides integration with <a shape="rect" href="http://cxf.apache.org">Apache CXF</a> for connecting to JAX-WS services hosted in CXF.</p><p><style type="text/css">/*<![CDATA[*/ -div.rbtoc1447337865437 {padding: 0px;} -div.rbtoc1447337865437 ul {list-style: disc;margin-left: 0px;} -div.rbtoc1447337865437 li {margin-left: 0px;padding-left: 0px;} +div.rbtoc1447406343557 {padding: 0px;} +div.rbtoc1447406343557 ul {list-style: disc;margin-left: 0px;} +div.rbtoc1447406343557 li {margin-left: 0px;padding-left: 0px;} -/*]]>*/</style></p><div class="toc-macro rbtoc1447337865437"> +/*]]>*/</style></p><div class="toc-macro rbtoc1447406343557"> <ul class="toc-indentation"><li><a shape="rect" href="#BookComponentAppendix-CXFComponent">CXF Component</a> <ul class="toc-indentation"><li><a shape="rect" href="#BookComponentAppendix-URIformat">URI format</a></li><li><a shape="rect" href="#BookComponentAppendix-Options">Options</a> <ul class="toc-indentation"><li><a shape="rect" href="#BookComponentAppendix-Thedescriptionsofthedataformats">The descriptions of the dataformats</a> @@ -5178,7 +5178,7 @@ from("direct:hello") .to("jdbc:testdb"); ]]></script> </div></div><p> </p><p></p><h3 id="BookComponentAppendix-SeeAlso.29">See Also</h3> -<ul><li><a shape="rect" href="configuring-camel.html">Configuring Camel</a></li><li><a shape="rect" href="component.html">Component</a></li><li><a shape="rect" href="endpoint.html">Endpoint</a></li><li><a shape="rect" href="getting-started.html">Getting Started</a></li></ul><ul class="alternate"><li><a shape="rect" href="sql.html">SQL</a></li></ul> <h2 id="BookComponentAppendix-JettyComponent">Jetty Component</h2><p>The <strong>jetty</strong> component provides HTTP-based <a shape="rect" href="endpoint.html">endpoints</a> for consuming and producing HTTP requests. That is, the Jetty component behaves as a simple Web server.<br clear="none"> Jetty can also be used as a http client which mean you can also use it with Camel as a producer.</p><div class="confluence-information-macro confluence-information-macro-information"><p class="title">Stream</p><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro- body"><p>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 <strong>once</strong>.<br clear="none">If you find a situation where the message body appears to be empty or you need to access the Exchange.HTTP_RESPONSE_CODE data multiple times (e.g.: doing multicasting, or redelivery error handling), you should use <a shape="rect" href="stream-caching.html">Stream caching</a> or convert the message body to a <code>String</code> which is safe to be re-read multiple times.</p></div></div><p>Maven users will need to add the following dependency to their <code>pom.xml</code> for this component:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<ul><li><a shape="rect" href="configuring-camel.html">Configuring Camel</a></li><li><a shape="rect" href="component.html">Component</a></li><li><a shape="rect" href="endpoint.html">Endpoint</a></li><li><a shape="rect" href="getting-started.html">Getting Started</a></li></ul><ul class="alternate"><li><a shape="rect" href="sql.html">SQL</a></li></ul> <h2 id="BookComponentAppendix-JettyComponent">Jetty Component</h2><p>The <strong>jetty</strong> component provides HTTP-based <a shape="rect" href="endpoint.html">endpoints</a> for consuming and producing HTTP requests. That is, the Jetty component behaves as a simple Web server.<br clear="none"> Jetty can also be used as a http client which mean you can also use it with Camel as a producer.</p><div class="confluence-information-macro confluence-information-macro-information"><p class="title">Stream</p><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro- body"><p><span style="color: rgb(0,0,0);">The </span><code>assert</code><span style="color: rgb(0,0,0);"> call appears in this example, because the code is part of an unit test.</span>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 <strong>once</strong>.<br clear="none">If you find a situation where the message body appears to be empty or you need to access the Exchange.HTTP_RESPONSE_CODE data multiple times (e.g.: doing multicasting, or redelivery error handling), you should use <a shape="rect" href="stream-caching.html">Stream caching</a> or convert the message body to a <code>String</code> which is safe to be re-read multiple times.</p></div></div><p>Maven users will need to add the following dependency to their <code>pom.xml</code> for this component:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-jetty</artifactId> @@ -5198,7 +5198,38 @@ from("direct:hello") <to uri="jetty://http://www.google.com"/> <route> ]]></script> -</div></div><h3 id="BookComponentAppendix-ConsumerExample">Consumer Example</h3><p>In this sample we define a route that exposes a HTTP service at <code><a shape="rect" class="external-link" href="http://localhost:8080/myapp/myservice" rel="nofollow">http://localhost:8080/myapp/myservice</a></code>:</p><div class="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div><div class="confluence-information-macro confluence-information-macro-note"><p class="title">Usage of localhost</p><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>When you specify <code>localhost</code> 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><p>If you need to expose a Jetty endpoint on a specific network interface, the numerical IP addr ess of this interface should be used as the host. If you need to expose a Jetty endpoint on all network interfaces, the <code>0.0.0.0</code> address should be used.</p></div></div><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>To listen across an entire URI prefix, see <a shape="rect" href="how-do-i-let-jetty-match-wildcards.html">How do I let Jetty match wildcards</a>.</p></div></div><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>If you actually want to expose routes by HTTP and already have a Servlet, you should instead refer to the <a shape="rect" href="https://cwiki.apache.org/confluence/display/CXF20DOC/Servlet+Transport">Servle t Transport</a>.</p></div></div><p> </p><p>Our business logic is implemented in the <code>MyBookService</code> class, which accesses the HTTP request contents and then returns a response.<br clear="none"> <strong>Note:</strong> The <code>assert</code> call appears in this example, because the code is part of an unit test.</p><div class="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>The following sample shows a content-based route that routes all requests containing the URI parameter, <code>one</code>, to the endpoint, <code>mock:one</code>, and all others to <code>mock:other</code>.<div class="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>So if a client sends the HTTP request, <code><a shape="rect" class="external-link" href="http://serverUri?one=hello" rel="nofollow">http://serverUri?one=hello</a></code>, the Je tty component will copy the HTTP request parameter, <code>one</code> to the exchange's <code>in.header</code>. We can then use the <code>simple</code> 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 shape="rect" href="simple.html">Simple</a> (such as <a shape="rect" href="el.html">EL</a> or <a shape="rect" href="ognl.html">OGNL</a>) we could also test for the parameter value and do routing based on the header value as well.<h3 id="BookComponentAppendix-SessionSupport">Session Support</h3><p>The session support option, <code>sessionSupport</code>, can be used to enable a <code>HttpSession</code> object and access the session object while processing the exchange. For example, the following route enables sessions:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><h3 id="BookComponentAppendix-ConsumerExample">Consumer Example</h3><p>In this sample we define a route that exposes a HTTP service at <code><a shape="rect" class="external-link" href="http://localhost:8080/myapp/myservice" rel="nofollow">http://localhost:8080/myapp/myservice</a></code>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +from("jetty:http://localhost:{{port}}/myapp/myservice").process(new MyBookService()); +]]></script> +</div></div><div class="confluence-information-macro confluence-information-macro-note"><p class="title">Usage of localhost</p><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>When you specify <code>localhost</code> 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><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 <code>0.0.0.0</code> address should be used.</p></div></div><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>To listen across an entire UR I prefix, see <a shape="rect" href="how-do-i-let-jetty-match-wildcards.html">How do I let Jetty match wildcards</a>.</p></div></div><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>If you actually want to expose routes by HTTP and already have a Servlet, you should instead refer to the <a shape="rect" href="https://cwiki.apache.org/confluence/display/CXF20DOC/Servlet+Transport">Servlet Transport</a>.</p></div></div><p> </p><p>Our business logic is implemented in the <code>MyBookService</code> class, which accesses the HTTP request contents and then returns a response.<br clear="none"> <strong>Note:</strong> The <code>assert</code> call appears in this example, because the code is part of an unit test.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +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("<html><body>Book 123 is Camel in Action</body></html>"); + } +} +]]></script> +</div></div>The following sample shows a content-based route that routes all requests containing the URI parameter, <code>one</code>, to the endpoint, <code>mock:one</code>, and all others to <code>mock:other</code>.<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +from("jetty:" + serverUri) + .choice() + .when().simple("${header.one}").to("mock:one") + .otherwise() + .to("mock:other"); +]]></script> +</div></div>So if a client sends the HTTP request, <code><a shape="rect" class="external-link" href="http://serverUri?one=hello" rel="nofollow">http://serverUri?one=hello</a></code>, the Jetty component will copy the HTTP request parameter, <code>one</code> to the exchange's <code>in.header</code>. We can then use the <code>simple</code> 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 shape="rect" href="simple.html">Simple</a> (such as <a shape="rect" href="el.html">EL</a> or <a shape="rect" href="ognl.html">OGNL</a>) we could also test for the parameter value and do routing based on the header value as well.<h3 id="BookComponentAppendix-SessionSupport">Session Support</h3><p>The session support option, <code>sessionSupport</code>, can be used to enable a <code>HttpSession</code> object and access the session object while processing the exchange. For example, the following ro ute enables sessions:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> <from uri="jetty:http://0.0.0.0/myapp/myservice/?sessionSupport=true"/> <processRef ref="myCode"/> @@ -5336,7 +5367,23 @@ X509Certificate cert = (X509Certificate) </map> </property> </bean>]]></script> -</div></div><p>This is particularly useful when an existing Apache server handles TLS connections for a domain and proxies them to application servers internally.</p><h3 id="BookComponentAppendix-DefaultbehaviorforreturningHTTPstatuscodes">Default behavior for returning HTTP status codes</h3><p>The default behavior of HTTP status codes is defined by the <code>org.apache.camel.component.http.DefaultHttpBinding</code> 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 clear="none"> 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 <code>Exchange.HTTP_RESPONSE_CODE</code> header of the OUT message.</p><h3 id="BookComponentAppendix-CustomizingHttpBinding">Customizing HttpBinding</h3><p>By default, Camel uses the <code >org.apache.camel.component.http.DefaultHttpBinding</code> to handle how a >response is written. If you like, you can customize this behavior either by >implementing your own <code>HttpBinding</code> class or by extending ><code>DefaultHttpBinding</code> and overriding the appropriate >methods.</p><p>The following example shows how to customize the ><code>DefaultHttpBinding</code> in order to change how exceptions are >returned:</p><div class="error"><span class="error">Error formatting macro: >snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> ></div>We can then create an instance of our binding and register it in the >Spring registry as follows:<div class="code panel pdl" style="border-width: >1px;"><div class="codeContent panelContent pdl"> +</div></div><p>This is particularly useful when an existing Apache server handles TLS connections for a domain and proxies them to application servers internally.</p><h3 id="BookComponentAppendix-DefaultbehaviorforreturningHTTPstatuscodes">Default behavior for returning HTTP status codes</h3><p>The default behavior of HTTP status codes is defined by the <code>org.apache.camel.component.http.DefaultHttpBinding</code> 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 clear="none"> 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 <code>Exchange.HTTP_RESPONSE_CODE</code> header of the OUT message.</p><h3 id="BookComponentAppendix-CustomizingHttpBinding">Customizing HttpBinding</h3><p>By default, Camel uses the <code >org.apache.camel.component.http.DefaultHttpBinding</code> to handle how a >response is written. If you like, you can customize this behavior either by >implementing your own <code>HttpBinding</code> class or by extending ><code>DefaultHttpBinding</code> and overriding the appropriate >methods.</p><p>The following example shows how to customize the ><code>DefaultHttpBinding</code> in order to change how exceptions are >returned:</p><div class="code panel pdl" style="border-width: 1px;"><div >class="codeContent panelContent pdl"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +public class MyHttpBinding extends DefaultHttpBinding { + + @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>We can then create an instance of our binding and register it in the Spring registry as follows:<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<bean id="mybinding"class="com.mycompany.MyHttpBinding"/> ]]></script> </div></div><p>And then we can reference this binding when we define the route:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> @@ -5392,7 +5439,60 @@ X509Certificate cert = (X509Certificate) </div></div><p>You can then define the endpoint as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from("jetty:http://0.0.0.0:9080/myservice?handlers=securityHandler") ]]></script> -</div></div><p>If you need more handlers, set the <code>handlers</code> option equal to a comma-separated list of bean IDs.</p><h3 id="BookComponentAppendix-HowtoreturnacustomHTTP500replymessage">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 shape="rect" href="jetty.html">Jetty</a> replies with.<br clear="none"> You could use a custom <code>HttpBinding</code> to be in control of the message mapping, but often it may be easier to use Camel's <a shape="rect" href="exception-clause.html">Exception Clause</a> to construct the custom reply message. For example as show here, where we return <code>Dude something went wrong</code> with HTTP error code 500:</p><div class="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div><h3 id="BookComponentAppendix-Multi-partFormsupport">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="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div><h3 id="BookComponentAppendix-JettyJMXsupport">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 an d 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 pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><p>If you need more handlers, set the <code>handlers</code> option equal to a comma-separated list of bean IDs.</p><h3 id="BookComponentAppendix-HowtoreturnacustomHTTP500replymessage">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 shape="rect" href="jetty.html">Jetty</a> replies with.<br clear="none"> You could use a custom <code>HttpBinding</code> to be in control of the message mapping, but often it may be easier to use Camel's <a shape="rect" href="exception-clause.html">Exception Clause</a> to construct the custom reply message. For example as show here, where we return <code>Dude something went wrong</code> with HTTP error code 500:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +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 id="BookComponentAppendix-Multi-partFormsupport">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 pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" 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 pdl"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![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() > 0); + + // The other form date can be get from the message + // header + exchange.getOut().setBody(in.getHeader("comment")); + } + +}); +]]></script> +</div></div><h3 id="BookComponentAppendix-JettyJMXsupport">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 pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<from uri="jetty:https://0.0.0.0/myapp/myservice1/?enableJmx=true"/> ]]></script> </div></div><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> Modified: websites/production/camel/content/book-in-one-page.html ============================================================================== --- websites/production/camel/content/book-in-one-page.html (original) +++ websites/production/camel/content/book-in-one-page.html Fri Nov 13 09:22:52 2015 @@ -3703,11 +3703,11 @@ The tutorial has been designed in two pa While not actual tutorials you might find working through the source of the various <a shape="rect" href="examples.html">Examples</a> useful.</li></ul> <h2 id="BookInOnePage-TutorialonSpringRemotingwithJMS">Tutorial on Spring Remoting with JMS</h2><p> </p><div class="confluence-information-macro confluence-information-macro-information"><p class="title">Thanks</p><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>This tutorial was kindly donated to Apache Camel by Martin Gilday.</p></div></div><h2 id="BookInOnePage-Preface">Preface</h2><p>This tutorial aims to guide the reader through the stages of creating a project which uses Camel to facilitate the routing of messages from a JMS queue to a <a shape="rect" class="external-link" href="http://www.springramework.org" rel="nofollow">Spring</a> service. The route works in a synchronous fashion returning a response to the client.</p><p><style type="text/css">/*<![CDATA[*/ -div.rbtoc1447337887773 {padding: 0px;} -div.rbtoc1447337887773 ul {list-style: disc;margin-left: 0px;} -div.rbtoc1447337887773 li {margin-left: 0px;padding-left: 0px;} +div.rbtoc1447406403392 {padding: 0px;} +div.rbtoc1447406403392 ul {list-style: disc;margin-left: 0px;} +div.rbtoc1447406403392 li {margin-left: 0px;padding-left: 0px;} -/*]]>*/</style></p><div class="toc-macro rbtoc1447337887773"> +/*]]>*/</style></p><div class="toc-macro rbtoc1447406403392"> <ul class="toc-indentation"><li><a shape="rect" href="#BookInOnePage-TutorialonSpringRemotingwithJMS">Tutorial on Spring Remoting with JMS</a></li><li><a shape="rect" href="#BookInOnePage-Preface">Preface</a></li><li><a shape="rect" href="#BookInOnePage-Prerequisites">Prerequisites</a></li><li><a shape="rect" href="#BookInOnePage-Distribution">Distribution</a></li><li><a shape="rect" href="#BookInOnePage-About">About</a></li><li><a shape="rect" href="#BookInOnePage-CreatetheCamelProject">Create the Camel Project</a> <ul class="toc-indentation"><li><a shape="rect" href="#BookInOnePage-UpdatethePOMwithDependencies">Update the POM with Dependencies</a></li></ul> </li><li><a shape="rect" href="#BookInOnePage-WritingtheServer">Writing the Server</a> @@ -5812,11 +5812,11 @@ So we completed the last piece in the pi <p>This example has been removed from <strong>Camel 2.9</strong> onwards. Apache Axis 1.4 is a very old and unsupported framework. We encourage users to use <a shape="rect" href="cxf.html">CXF</a> instead of Axis.</p></div></div> <style type="text/css">/*<![CDATA[*/ -div.rbtoc1447337888947 {padding: 0px;} -div.rbtoc1447337888947 ul {list-style: disc;margin-left: 0px;} -div.rbtoc1447337888947 li {margin-left: 0px;padding-left: 0px;} +div.rbtoc1447406403859 {padding: 0px;} +div.rbtoc1447406403859 ul {list-style: disc;margin-left: 0px;} +div.rbtoc1447406403859 li {margin-left: 0px;padding-left: 0px;} -/*]]>*/</style><div class="toc-macro rbtoc1447337888947"> +/*]]>*/</style><div class="toc-macro rbtoc1447406403859"> <ul class="toc-indentation"><li><a shape="rect" href="#BookInOnePage-TutorialusingAxis1.4withApacheCamel">Tutorial using Axis 1.4 with Apache Camel</a> <ul class="toc-indentation"><li><a shape="rect" href="#BookInOnePage-Prerequisites">Prerequisites</a></li><li><a shape="rect" href="#BookInOnePage-Distribution">Distribution</a></li><li><a shape="rect" href="#BookInOnePage-Introduction">Introduction</a></li><li><a shape="rect" href="#BookInOnePage-SettinguptheprojecttorunAxis">Setting up the project to run Axis</a> <ul class="toc-indentation"><li><a shape="rect" href="#BookInOnePage-Maven2">Maven 2</a></li><li><a shape="rect" href="#BookInOnePage-wsdl">wsdl</a></li><li><a shape="rect" href="#BookInOnePage-ConfiguringAxis">Configuring Axis</a></li><li><a shape="rect" href="#BookInOnePage-RunningtheExample">Running the Example</a></li></ul> @@ -17311,11 +17311,11 @@ template.send("direct:alias-verify& ]]></script> </div></div><p></p><h3 id="BookInOnePage-SeeAlso.28">See Also</h3> <ul><li><a shape="rect" href="configuring-camel.html">Configuring Camel</a></li><li><a shape="rect" href="component.html">Component</a></li><li><a shape="rect" href="endpoint.html">Endpoint</a></li><li><a shape="rect" href="getting-started.html">Getting Started</a></li></ul><ul><li><a shape="rect" href="crypto.html">Crypto</a> Crypto is also available as a <a shape="rect" href="data-format.html">Data Format</a></li></ul> <h2 id="BookInOnePage-CXFComponent">CXF Component</h2><div class="confluence-information-macro confluence-information-macro-note"><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>When using CXF as a consumer, the <a shape="rect" href="cxf-bean-component.html">CXF Bean Component</a> allows you to factor out how message payloads are received from their processing as a RESTful or SOAP web service. This has the potential of using a multitude of transports to consume web services. The bean component's configuration is also simpler and provides the fastest method to implement web services using Camel and CXF.</p></div></div><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>When using CXF in streaming modes (see DataFormat option), then also read about <a shape="rect" href="stream-caching.html">Stream caching</a>.</p></div></div><p>The <strong>cxf:</strong> component provides integration with <a shape="rect" href="http://cxf.apache.org">Apache CXF</a> for connecting to JAX-WS services hosted in CXF.</p><p><style type="text/css">/*<![CDATA[*/ -div.rbtoc1447337934546 {padding: 0px;} -div.rbtoc1447337934546 ul {list-style: disc;margin-left: 0px;} -div.rbtoc1447337934546 li {margin-left: 0px;padding-left: 0px;} +div.rbtoc1447406463832 {padding: 0px;} +div.rbtoc1447406463832 ul {list-style: disc;margin-left: 0px;} +div.rbtoc1447406463832 li {margin-left: 0px;padding-left: 0px;} -/*]]>*/</style></p><div class="toc-macro rbtoc1447337934546"> +/*]]>*/</style></p><div class="toc-macro rbtoc1447406463832"> <ul class="toc-indentation"><li><a shape="rect" href="#BookInOnePage-CXFComponent">CXF Component</a> <ul class="toc-indentation"><li><a shape="rect" href="#BookInOnePage-URIformat">URI format</a></li><li><a shape="rect" href="#BookInOnePage-Options">Options</a> <ul class="toc-indentation"><li><a shape="rect" href="#BookInOnePage-Thedescriptionsofthedataformats">The descriptions of the dataformats</a> @@ -21414,7 +21414,7 @@ from("direct:hello") .to("jdbc:testdb"); ]]></script> </div></div><p> </p><p></p><h3 id="BookInOnePage-SeeAlso.49">See Also</h3> -<ul><li><a shape="rect" href="configuring-camel.html">Configuring Camel</a></li><li><a shape="rect" href="component.html">Component</a></li><li><a shape="rect" href="endpoint.html">Endpoint</a></li><li><a shape="rect" href="getting-started.html">Getting Started</a></li></ul><ul class="alternate"><li><a shape="rect" href="sql.html">SQL</a></li></ul> <h2 id="BookInOnePage-JettyComponent">Jetty Component</h2><p>The <strong>jetty</strong> component provides HTTP-based <a shape="rect" href="endpoint.html">endpoints</a> for consuming and producing HTTP requests. That is, the Jetty component behaves as a simple Web server.<br clear="none"> Jetty can also be used as a http client which mean you can also use it with Camel as a producer.</p><div class="confluence-information-macro confluence-information-macro-information"><p class="title">Stream</p><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p >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 <strong>once</strong>.<br clear="none">If you find a situation >where the message body appears to be empty or you need to access the >Exchange.HTTP_RESPONSE_CODE data multiple times (e.g.: doing multicasting, or >redelivery error handling), you should use <a shape="rect" >href="stream-caching.html">Stream caching</a> or convert the message body to >a <code>String</code> which is safe to be re-read multiple >times.</p></div></div><p>Maven users will need to add the following >dependency to their <code>pom.xml</code> for this component:</p><div >class="code panel pdl" style="border-width: 1px;"><div class="codeContent >panelContent pdl"> +<ul><li><a shape="rect" href="configuring-camel.html">Configuring Camel</a></li><li><a shape="rect" href="component.html">Component</a></li><li><a shape="rect" href="endpoint.html">Endpoint</a></li><li><a shape="rect" href="getting-started.html">Getting Started</a></li></ul><ul class="alternate"><li><a shape="rect" href="sql.html">SQL</a></li></ul> <h2 id="BookInOnePage-JettyComponent">Jetty Component</h2><p>The <strong>jetty</strong> component provides HTTP-based <a shape="rect" href="endpoint.html">endpoints</a> for consuming and producing HTTP requests. That is, the Jetty component behaves as a simple Web server.<br clear="none"> Jetty can also be used as a http client which mean you can also use it with Camel as a producer.</p><div class="confluence-information-macro confluence-information-macro-information"><p class="title">Stream</p><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p ><span style="color: rgb(0,0,0);">The </span><code>assert</code><span >style="color: rgb(0,0,0);"> call appears in this example, because the >code is part of an unit test.</span>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 <strong>once</strong>.<br >clear="none">If you find a situation where the message body appears to be >empty or you need to access the Exchange.HTTP_RESPONSE_CODE data multiple >times (e.g.: doing multicasting, or redelivery error handling), you should >use <a shape="rect" href="stream-caching.html">Stream caching</a> or convert >the message body to a <code>String</code> which is safe to be re-read >multiple times.</p></div></div><p>Maven users will need to add the following >dependency to their <code>pom.xml</code> for this component:</p><div >class="code panel pdl" style="border-width: 1px;"><div class="codeContent >panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-jetty</artifactId> @@ -21434,7 +21434,38 @@ from("direct:hello") <to uri="jetty://http://www.google.com"/> <route> ]]></script> -</div></div><h3 id="BookInOnePage-ConsumerExample">Consumer Example</h3><p>In this sample we define a route that exposes a HTTP service at <code><a shape="rect" class="external-link" href="http://localhost:8080/myapp/myservice" rel="nofollow">http://localhost:8080/myapp/myservice</a></code>:</p><div class="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div><div class="confluence-information-macro confluence-information-macro-note"><p class="title">Usage of localhost</p><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>When you specify <code>localhost</code> 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><p>If you need to expose a Jetty endpoint on a specific network interface, the numerical IP address of t his interface should be used as the host. If you need to expose a Jetty endpoint on all network interfaces, the <code>0.0.0.0</code> address should be used.</p></div></div><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>To listen across an entire URI prefix, see <a shape="rect" href="how-do-i-let-jetty-match-wildcards.html">How do I let Jetty match wildcards</a>.</p></div></div><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>If you actually want to expose routes by HTTP and already have a Servlet, you should instead refer to the <a shape="rect" href="https://cwiki.apache.org/confluence/display/CXF20DOC/Servlet+Transport">Servlet Transp ort</a>.</p></div></div><p> </p><p>Our business logic is implemented in the <code>MyBookService</code> class, which accesses the HTTP request contents and then returns a response.<br clear="none"> <strong>Note:</strong> The <code>assert</code> call appears in this example, because the code is part of an unit test.</p><div class="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>The following sample shows a content-based route that routes all requests containing the URI parameter, <code>one</code>, to the endpoint, <code>mock:one</code>, and all others to <code>mock:other</code>.<div class="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>So if a client sends the HTTP request, <code><a shape="rect" class="external-link" href="http://serverUri?one=hello" rel="nofollow">http://serverUri?one=hello</a></code>, the Jetty comp onent will copy the HTTP request parameter, <code>one</code> to the exchange's <code>in.header</code>. We can then use the <code>simple</code> 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 shape="rect" href="simple.html">Simple</a> (such as <a shape="rect" href="el.html">EL</a> or <a shape="rect" href="ognl.html">OGNL</a>) we could also test for the parameter value and do routing based on the header value as well.<h3 id="BookInOnePage-SessionSupport">Session Support</h3><p>The session support option, <code>sessionSupport</code>, can be used to enable a <code>HttpSession</code> object and access the session object while processing the exchange. For example, the following route enables sessions:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><h3 id="BookInOnePage-ConsumerExample">Consumer Example</h3><p>In this sample we define a route that exposes a HTTP service at <code><a shape="rect" class="external-link" href="http://localhost:8080/myapp/myservice" rel="nofollow">http://localhost:8080/myapp/myservice</a></code>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +from("jetty:http://localhost:{{port}}/myapp/myservice").process(new MyBookService()); +]]></script> +</div></div><div class="confluence-information-macro confluence-information-macro-note"><p class="title">Usage of localhost</p><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>When you specify <code>localhost</code> 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><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 <code>0.0.0.0</code> address should be used.</p></div></div><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>To listen across an entire UR I prefix, see <a shape="rect" href="how-do-i-let-jetty-match-wildcards.html">How do I let Jetty match wildcards</a>.</p></div></div><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>If you actually want to expose routes by HTTP and already have a Servlet, you should instead refer to the <a shape="rect" href="https://cwiki.apache.org/confluence/display/CXF20DOC/Servlet+Transport">Servlet Transport</a>.</p></div></div><p> </p><p>Our business logic is implemented in the <code>MyBookService</code> class, which accesses the HTTP request contents and then returns a response.<br clear="none"> <strong>Note:</strong> The <code>assert</code> call appears in this example, because the code is part of an unit test.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +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("<html><body>Book 123 is Camel in Action</body></html>"); + } +} +]]></script> +</div></div>The following sample shows a content-based route that routes all requests containing the URI parameter, <code>one</code>, to the endpoint, <code>mock:one</code>, and all others to <code>mock:other</code>.<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +from("jetty:" + serverUri) + .choice() + .when().simple("${header.one}").to("mock:one") + .otherwise() + .to("mock:other"); +]]></script> +</div></div>So if a client sends the HTTP request, <code><a shape="rect" class="external-link" href="http://serverUri?one=hello" rel="nofollow">http://serverUri?one=hello</a></code>, the Jetty component will copy the HTTP request parameter, <code>one</code> to the exchange's <code>in.header</code>. We can then use the <code>simple</code> 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 shape="rect" href="simple.html">Simple</a> (such as <a shape="rect" href="el.html">EL</a> or <a shape="rect" href="ognl.html">OGNL</a>) we could also test for the parameter value and do routing based on the header value as well.<h3 id="BookInOnePage-SessionSupport">Session Support</h3><p>The session support option, <code>sessionSupport</code>, can be used to enable a <code>HttpSession</code> object and access the session object while processing the exchange. For example, the following route enab les sessions:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> <from uri="jetty:http://0.0.0.0/myapp/myservice/?sessionSupport=true"/> <processRef ref="myCode"/> @@ -21572,7 +21603,23 @@ X509Certificate cert = (X509Certificate) </map> </property> </bean>]]></script> -</div></div><p>This is particularly useful when an existing Apache server handles TLS connections for a domain and proxies them to application servers internally.</p><h3 id="BookInOnePage-DefaultbehaviorforreturningHTTPstatuscodes">Default behavior for returning HTTP status codes</h3><p>The default behavior of HTTP status codes is defined by the <code>org.apache.camel.component.http.DefaultHttpBinding</code> 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 clear="none"> 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 <code>Exchange.HTTP_RESPONSE_CODE</code> header of the OUT message.</p><h3 id="BookInOnePage-CustomizingHttpBinding">Customizing HttpBinding</h3><p>By default, Camel uses the <code>org.apache.came l.component.http.DefaultHttpBinding</code> to handle how a response is written. If you like, you can customize this behavior either by implementing your own <code>HttpBinding</code> class or by extending <code>DefaultHttpBinding</code> and overriding the appropriate methods.</p><p>The following example shows how to customize the <code>DefaultHttpBinding</code> in order to change how exceptions are returned:</p><div class="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>We can then create an instance of our binding and register it in the Spring registry as follows:<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><p>This is particularly useful when an existing Apache server handles TLS connections for a domain and proxies them to application servers internally.</p><h3 id="BookInOnePage-DefaultbehaviorforreturningHTTPstatuscodes">Default behavior for returning HTTP status codes</h3><p>The default behavior of HTTP status codes is defined by the <code>org.apache.camel.component.http.DefaultHttpBinding</code> 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 clear="none"> 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 <code>Exchange.HTTP_RESPONSE_CODE</code> header of the OUT message.</p><h3 id="BookInOnePage-CustomizingHttpBinding">Customizing HttpBinding</h3><p>By default, Camel uses the <code>org.apache.came l.component.http.DefaultHttpBinding</code> to handle how a response is written. If you like, you can customize this behavior either by implementing your own <code>HttpBinding</code> class or by extending <code>DefaultHttpBinding</code> and overriding the appropriate methods.</p><p>The following example shows how to customize the <code>DefaultHttpBinding</code> in order to change how exceptions are returned:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +public class MyHttpBinding extends DefaultHttpBinding { + + @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>We can then create an instance of our binding and register it in the Spring registry as follows:<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<bean id="mybinding"class="com.mycompany.MyHttpBinding"/> ]]></script> </div></div><p>And then we can reference this binding when we define the route:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> @@ -21628,7 +21675,60 @@ X509Certificate cert = (X509Certificate) </div></div><p>You can then define the endpoint as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from("jetty:http://0.0.0.0:9080/myservice?handlers=securityHandler") ]]></script> -</div></div><p>If you need more handlers, set the <code>handlers</code> option equal to a comma-separated list of bean IDs.</p><h3 id="BookInOnePage-HowtoreturnacustomHTTP500replymessage">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 shape="rect" href="jetty.html">Jetty</a> replies with.<br clear="none"> You could use a custom <code>HttpBinding</code> to be in control of the message mapping, but often it may be easier to use Camel's <a shape="rect" href="exception-clause.html">Exception Clause</a> to construct the custom reply message. For example as show here, where we return <code>Dude something went wrong</code> with HTTP error code 500:</p><div class="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div><h3 id="BookInOnePage-Multi-partFormsupport">Multi-part Form support</h3><p>F rom 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="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div><h3 id="BookInOnePage-JettyJMXsupport">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 pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><p>If you need more handlers, set the <code>handlers</code> option equal to a comma-separated list of bean IDs.</p><h3 id="BookInOnePage-HowtoreturnacustomHTTP500replymessage">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 shape="rect" href="jetty.html">Jetty</a> replies with.<br clear="none"> You could use a custom <code>HttpBinding</code> to be in control of the message mapping, but often it may be easier to use Camel's <a shape="rect" href="exception-clause.html">Exception Clause</a> to construct the custom reply message. For example as show here, where we return <code>Dude something went wrong</code> with HTTP error code 500:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +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 id="BookInOnePage-Multi-partFormsupport">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 pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" 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 pdl"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![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() > 0); + + // The other form date can be get from the message + // header + exchange.getOut().setBody(in.getHeader("comment")); + } + +}); +]]></script> +</div></div><h3 id="BookInOnePage-JettyJMXsupport">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 pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<from uri="jetty:https://0.0.0.0/myapp/myservice1/?enableJmx=true"/> ]]></script> </div></div><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> Modified: websites/production/camel/content/cache/main.pageCache ============================================================================== Binary files - no diff available. Modified: websites/production/camel/content/jetty.html ============================================================================== --- websites/production/camel/content/jetty.html (original) +++ websites/production/camel/content/jetty.html Fri Nov 13 09:22:52 2015 @@ -86,7 +86,7 @@ <tbody> <tr> <td valign="top" width="100%"> -<div class="wiki-content maincontent"><h2 id="Jetty-JettyComponent">Jetty Component</h2><p>The <strong>jetty</strong> component provides HTTP-based <a shape="rect" href="endpoint.html">endpoints</a> for consuming and producing HTTP requests. That is, the Jetty component behaves as a simple Web server.<br clear="none"> Jetty can also be used as a http client which mean you can also use it with Camel as a producer.</p><div class="confluence-information-macro confluence-information-macro-information"><p class="title">Stream</p><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>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 <strong>once</strong>.<br clear="none">If you find a situation where the message body appears to be empty or you need to access the Exchange.HTTP_RESPONSE_CODE d ata multiple times (e.g.: doing multicasting, or redelivery error handling), you should use <a shape="rect" href="stream-caching.html">Stream caching</a> or convert the message body to a <code>String</code> which is safe to be re-read multiple times.</p></div></div><p>Maven users will need to add the following dependency to their <code>pom.xml</code> for this component:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<div class="wiki-content maincontent"><h2 id="Jetty-JettyComponent">Jetty Component</h2><p>The <strong>jetty</strong> component provides HTTP-based <a shape="rect" href="endpoint.html">endpoints</a> for consuming and producing HTTP requests. That is, the Jetty component behaves as a simple Web server.<br clear="none"> Jetty can also be used as a http client which mean you can also use it with Camel as a producer.</p><div class="confluence-information-macro confluence-information-macro-information"><p class="title">Stream</p><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p><span style="color: rgb(0,0,0);">The </span><code>assert</code><span style="color: rgb(0,0,0);"> call appears in this example, because the code is part of an unit test.</span>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 th e content of the stream <strong>once</strong>.<br clear="none">If you find a situation where the message body appears to be empty or you need to access the Exchange.HTTP_RESPONSE_CODE data multiple times (e.g.: doing multicasting, or redelivery error handling), you should use <a shape="rect" href="stream-caching.html">Stream caching</a> or convert the message body to a <code>String</code> which is safe to be re-read multiple times.</p></div></div><p>Maven users will need to add the following dependency to their <code>pom.xml</code> for this component:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-jetty</artifactId> @@ -106,7 +106,38 @@ <to uri="jetty://http://www.google.com"/> <route> ]]></script> -</div></div><h3 id="Jetty-ConsumerExample">Consumer Example</h3><p>In this sample we define a route that exposes a HTTP service at <code><a shape="rect" class="external-link" href="http://localhost:8080/myapp/myservice" rel="nofollow">http://localhost:8080/myapp/myservice</a></code>:</p><div class="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div><div class="confluence-information-macro confluence-information-macro-note"><p class="title">Usage of localhost</p><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>When you specify <code>localhost</code> 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><p>If you need to expose a Jetty endpoint on a specific network interface, the numerical IP address of this inte rface should be used as the host. If you need to expose a Jetty endpoint on all network interfaces, the <code>0.0.0.0</code> address should be used.</p></div></div><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>To listen across an entire URI prefix, see <a shape="rect" href="how-do-i-let-jetty-match-wildcards.html">How do I let Jetty match wildcards</a>.</p></div></div><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>If you actually want to expose routes by HTTP and already have a Servlet, you should instead refer to the <a shape="rect" href="https://cwiki.apache.org/confluence/display/CXF20DOC/Servlet+Transport">Servlet Transport</a>. </p></div></div><p> </p><p>Our business logic is implemented in the <code>MyBookService</code> class, which accesses the HTTP request contents and then returns a response.<br clear="none"> <strong>Note:</strong> The <code>assert</code> call appears in this example, because the code is part of an unit test.</p><div class="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>The following sample shows a content-based route that routes all requests containing the URI parameter, <code>one</code>, to the endpoint, <code>mock:one</code>, and all others to <code>mock:other</code>.<div class="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>So if a client sends the HTTP request, <code><a shape="rect" class="external-link" href="http://serverUri?one=hello" rel="nofollow">http://serverUri?one=hello</a></code>, the Jetty component wi ll copy the HTTP request parameter, <code>one</code> to the exchange's <code>in.header</code>. We can then use the <code>simple</code> 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 shape="rect" href="simple.html">Simple</a> (such as <a shape="rect" href="el.html">EL</a> or <a shape="rect" href="ognl.html">OGNL</a>) we could also test for the parameter value and do routing based on the header value as well.<h3 id="Jetty-SessionSupport">Session Support</h3><p>The session support option, <code>sessionSupport</code>, can be used to enable a <code>HttpSession</code> object and access the session object while processing the exchange. For example, the following route enables sessions:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><h3 id="Jetty-ConsumerExample">Consumer Example</h3><p>In this sample we define a route that exposes a HTTP service at <code><a shape="rect" class="external-link" href="http://localhost:8080/myapp/myservice" rel="nofollow">http://localhost:8080/myapp/myservice</a></code>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +from("jetty:http://localhost:{{port}}/myapp/myservice").process(new MyBookService()); +]]></script> +</div></div><div class="confluence-information-macro confluence-information-macro-note"><p class="title">Usage of localhost</p><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>When you specify <code>localhost</code> 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><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 <code>0.0.0.0</code> address should be used.</p></div></div><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>To listen across an entire UR I prefix, see <a shape="rect" href="how-do-i-let-jetty-match-wildcards.html">How do I let Jetty match wildcards</a>.</p></div></div><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>If you actually want to expose routes by HTTP and already have a Servlet, you should instead refer to the <a shape="rect" href="https://cwiki.apache.org/confluence/display/CXF20DOC/Servlet+Transport">Servlet Transport</a>.</p></div></div><p> </p><p>Our business logic is implemented in the <code>MyBookService</code> class, which accesses the HTTP request contents and then returns a response.<br clear="none"> <strong>Note:</strong> The <code>assert</code> call appears in this example, because the code is part of an unit test.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +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("<html><body>Book 123 is Camel in Action</body></html>"); + } +} +]]></script> +</div></div>The following sample shows a content-based route that routes all requests containing the URI parameter, <code>one</code>, to the endpoint, <code>mock:one</code>, and all others to <code>mock:other</code>.<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +from("jetty:" + serverUri) + .choice() + .when().simple("${header.one}").to("mock:one") + .otherwise() + .to("mock:other"); +]]></script> +</div></div>So if a client sends the HTTP request, <code><a shape="rect" class="external-link" href="http://serverUri?one=hello" rel="nofollow">http://serverUri?one=hello</a></code>, the Jetty component will copy the HTTP request parameter, <code>one</code> to the exchange's <code>in.header</code>. We can then use the <code>simple</code> 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 shape="rect" href="simple.html">Simple</a> (such as <a shape="rect" href="el.html">EL</a> or <a shape="rect" href="ognl.html">OGNL</a>) we could also test for the parameter value and do routing based on the header value as well.<h3 id="Jetty-SessionSupport">Session Support</h3><p>The session support option, <code>sessionSupport</code>, can be used to enable a <code>HttpSession</code> object and access the session object while processing the exchange. For example, the following route enables sess ions:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> <from uri="jetty:http://0.0.0.0/myapp/myservice/?sessionSupport=true"/> <processRef ref="myCode"/> @@ -244,7 +275,23 @@ X509Certificate cert = (X509Certificate) </map> </property> </bean>]]></script> -</div></div><p>This is particularly useful when an existing Apache server handles TLS connections for a domain and proxies them to application servers internally.</p><h3 id="Jetty-DefaultbehaviorforreturningHTTPstatuscodes">Default behavior for returning HTTP status codes</h3><p>The default behavior of HTTP status codes is defined by the <code>org.apache.camel.component.http.DefaultHttpBinding</code> 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 clear="none"> 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 <code>Exchange.HTTP_RESPONSE_CODE</code> header of the OUT message.</p><h3 id="Jetty-CustomizingHttpBinding">Customizing HttpBinding</h3><p>By default, Camel uses the <code>org.apache.camel.component.http .DefaultHttpBinding</code> to handle how a response is written. If you like, you can customize this behavior either by implementing your own <code>HttpBinding</code> class or by extending <code>DefaultHttpBinding</code> and overriding the appropriate methods.</p><p>The following example shows how to customize the <code>DefaultHttpBinding</code> in order to change how exceptions are returned:</p><div class="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>We can then create an instance of our binding and register it in the Spring registry as follows:<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><p>This is particularly useful when an existing Apache server handles TLS connections for a domain and proxies them to application servers internally.</p><h3 id="Jetty-DefaultbehaviorforreturningHTTPstatuscodes">Default behavior for returning HTTP status codes</h3><p>The default behavior of HTTP status codes is defined by the <code>org.apache.camel.component.http.DefaultHttpBinding</code> 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 clear="none"> 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 <code>Exchange.HTTP_RESPONSE_CODE</code> header of the OUT message.</p><h3 id="Jetty-CustomizingHttpBinding">Customizing HttpBinding</h3><p>By default, Camel uses the <code>org.apache.camel.component.http .DefaultHttpBinding</code> to handle how a response is written. If you like, you can customize this behavior either by implementing your own <code>HttpBinding</code> class or by extending <code>DefaultHttpBinding</code> and overriding the appropriate methods.</p><p>The following example shows how to customize the <code>DefaultHttpBinding</code> in order to change how exceptions are returned:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +public class MyHttpBinding extends DefaultHttpBinding { + + @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>We can then create an instance of our binding and register it in the Spring registry as follows:<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<bean id="mybinding"class="com.mycompany.MyHttpBinding"/> ]]></script> </div></div><p>And then we can reference this binding when we define the route:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> @@ -300,7 +347,60 @@ X509Certificate cert = (X509Certificate) </div></div><p>You can then define the endpoint as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from("jetty:http://0.0.0.0:9080/myservice?handlers=securityHandler") ]]></script> -</div></div><p>If you need more handlers, set the <code>handlers</code> option equal to a comma-separated list of bean IDs.</p><h3 id="Jetty-HowtoreturnacustomHTTP500replymessage">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 shape="rect" href="jetty.html">Jetty</a> replies with.<br clear="none"> You could use a custom <code>HttpBinding</code> to be in control of the message mapping, but often it may be easier to use Camel's <a shape="rect" href="exception-clause.html">Exception Clause</a> to construct the custom reply message. For example as show here, where we return <code>Dude something went wrong</code> with HTTP error code 500:</p><div class="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div><h3 id="Jetty-Multi-partFormsupport">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="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div><h3 id="Jetty-JettyJMXsupport">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/ho st/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 pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><p>If you need more handlers, set the <code>handlers</code> option equal to a comma-separated list of bean IDs.</p><h3 id="Jetty-HowtoreturnacustomHTTP500replymessage">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 shape="rect" href="jetty.html">Jetty</a> replies with.<br clear="none"> You could use a custom <code>HttpBinding</code> to be in control of the message mapping, but often it may be easier to use Camel's <a shape="rect" href="exception-clause.html">Exception Clause</a> to construct the custom reply message. For example as show here, where we return <code>Dude something went wrong</code> with HTTP error code 500:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +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 id="Jetty-Multi-partFormsupport">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 pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" 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 pdl"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![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() > 0); + + // The other form date can be get from the message + // header + exchange.getOut().setBody(in.getHeader("comment")); + } + +}); +]]></script> +</div></div><h3 id="Jetty-JettyJMXsupport">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 pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<from uri="jetty:https://0.0.0.0/myapp/myservice1/?enableJmx=true"/> ]]></script> </div></div><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">