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 > Netty HTTP
Date Wed, 11 Dec 2013 15:57: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/Netty+HTTP">Netty
HTTP</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" >| {{traceEnabled}} | {{false}} | Specifies
whether to enable HTTP TRACE for this Netty HTTP consumer. By default TRACE is turned off.
| <br>| {{transferException}} | {{false}} | If enabled and an [Exchange] failed processing
on the consumer side, and if the caused Exception was send back serialized in the response
as a {{application/x-java-serialized-object}} content type. On the producer side the exception
will be deserialized and thrown as is, instead of the {{HttpOperationFailedException}}. The
caused exception is required to be serialized. | <br></td></tr>
            <tr><td class="diff-changed-lines" >| {{urlDecodeHeaders}} | <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">{{true}}</span>
<span class="diff-added-words"style="background-color: #dfd;"> </span> | If this
option is enabled, then during binding from Netty to Camel [Message] then the header values
will be URL decoded (eg %20 will be a space character. Notice this option is used by the default
{{org.apache.camel.component.netty.http.NettyHttpBinding}} and therefore if you implement
a custom {{org.apache.camel.component.netty.http.NettyHttpBinding}} then you would need to
decode the headers accordingly to this option. <span class="diff-added-words"style="background-color:
#dfd;">*Notice:* This option is default {{true}} for Camel 2.12.x, and default {{false}}
from Camel 2.13 onwards.</span> | <br></td></tr>
            <tr><td class="diff-unchanged" >| {{nettySharedHttpServer}} | {{null}}
| To use a shared [Netty HTTP] server. See [Netty HTTP Server Example] for more details. |
<br>| {{disableStreamCache}} | {{false}} | Determines whether or not the raw input stream
from Netty {{HttpRequest#getContent()}} is cached or not (Camel will read the stream into
a in light-weight memory based Stream caching) cache. By default Camel will cache the Netty
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 {{true}} when you for example need to
access the raw stream, such as streaming it directly to a file or other persistent store.
Mind that if you enable this option, then you cannot read the Netty stream multiple times
out of the box, and you would need manually to reset the reader index on the Netty raw stream.
| <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="NettyHTTP-NettyHTTPComponent"></a>Netty HTTP Component</h2>
<p><b>Available as of Camel 2.12</b></p>

<p>The <b>netty-http</b> component is an extension to <a href="/confluence/display/CAMEL/Netty"
title="Netty">Netty</a> component to facilitiate HTTP transport with <a href="/confluence/display/CAMEL/Netty"
title="Netty">Netty</a>.</p>

<p>This camel component supports both producer and consumer endpoints.</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>Upgrade to
Netty 4.0 planned</b><br />This component is intended to be upgraded to use Netty
4.0 when <tt>camel-netty4</tt> component has finished being upgraded. At the time
being this component is still based on Netty 3.x. The upgrade is intended to be as backwards
compatible as possible.</td></tr></table></div>

<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
/>Netty 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-netty-http&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="NettyHTTP-URIformat"></a>URI format</h3>

<p>The URI scheme for a netty component is 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;">
netty-http:http://localhost:8080[?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="NettyHTTP-HTTPOptions"></a>HTTP Options</h3>

<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>A lot more
options</b><br /><b>Important:</b> This component inherits all the
options from <a href="/confluence/display/CAMEL/Netty" title="Netty">Netty</a>.
So make sure to look at the <a href="/confluence/display/CAMEL/Netty" title="Netty">Netty</a>
documentation as well.<br/>
Notice that some options from <a href="/confluence/display/CAMEL/Netty" title="Netty">Netty</a>
is not applicable when using this <a href="/confluence/display/CAMEL/Netty+HTTP" title="Netty
HTTP">Netty HTTP</a> component, such as options related to UDP transport.</td></tr></table></div>

<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>chunkedMaxContentLength</tt> </td>
<td class='confluenceTd'> <tt>1mb</tt> </td>
<td class='confluenceTd'> Value in bytes the max content length per chunked frame received
on the Netty HTTP server. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>compression</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Allow using gzip/deflate for compression on the Netty HTTP
server if the client supports it from the HTTP headers. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>headerFilterStrategy</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> To use a custom  <tt>org.apache.camel.spi.HeaderFilterStrategy</tt>
to filter headers. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>httpMethodRestrict</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> To disable HTTP methods on the Netty HTTP consumer. You can
specify multiple separated by comma. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>mapHeaders</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> If this option is enabled, then during binding from Netty
to Camel <a href="/confluence/display/CAMEL/Message" title="Message">Message</a>
then the headers will be mapped as well (eg added as header to the Camel <a href="/confluence/display/CAMEL/Message"
title="Message">Message</a> as well). You can turn off this option to disable this.
The headers can still be accessed from the <tt>org.apache.camel.component.netty.http.NettyHttpMessage</tt>
message with the method <tt>getHttpRequest()</tt> that returns the Netty HTTP
request <tt>org.jboss.netty.handler.codec.http.HttpRequest</tt> instance. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>matchOnUriPrefix</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Whether or not Camel should try to find a target consumer
by matching the URI prefix if no exact match is found. See further below for more details.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>nettyHttpBinding</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> To use a custom <tt>org.apache.camel.component.netty.http.NettyHttpBinding</tt>
for binding to/from Netty and Camel Message API. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>bridgeEndpoint</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If the option is <tt>true</tt>, the producer will
ignore the <tt>Exchange.HTTP_URI</tt> header, and use the endpoint's URI for request.
You may also set the <tt>throwExceptionOnFailure</tt> to be <tt>false</tt>
to let the producer send all the fault response back. </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>traceEnabled</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Specifies whether to enable HTTP TRACE for this Netty HTTP
consumer. By default TRACE is turned off. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transferException</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> 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>urlDecodeHeaders</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> If this option is enabled, then during binding from Netty
to Camel <a href="/confluence/display/CAMEL/Message" title="Message">Message</a>
then the header values will be URL decoded (eg %20 will be a space character. Notice this
option is used by the default <tt>org.apache.camel.component.netty.http.NettyHttpBinding</tt>
and therefore if you implement a custom <tt>org.apache.camel.component.netty.http.NettyHttpBinding</tt>
then you would need to decode the headers accordingly to this option. <b>Notice:</b>
This option is default <tt>true</tt> for Camel 2.12.x, and default <tt>false</tt>
from Camel 2.13 onwards. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>nettySharedHttpServer</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> To use a shared <a href="/confluence/display/CAMEL/Netty+HTTP"
title="Netty HTTP">Netty HTTP</a> server. See <a href="/confluence/display/CAMEL/Netty+HTTP+Server+Example"
title="Netty HTTP Server Example">Netty HTTP Server Example</a> for more details.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>disableStreamCache</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Determines whether or not the raw input stream from Netty
<tt>HttpRequest#getContent()</tt> is cached or not (Camel will read the stream
into a in light-weight memory based Stream caching) cache. By default Camel will cache the
Netty 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. Mind that if you enable this option, then you cannot read the Netty stream
multiple times out of the box, and you would need manually to reset the reader index on the
Netty raw stream. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>securityConfiguration</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Consumer only</b>. Refers to a <tt>org.apache.camel.component.netty.http.NettyHttpSecurityConfiguration</tt>
for configuring secure web resources. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>send503whenSuspended</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Consumer only</b>. Whether to send back HTTP
status code 503 when the consumer has been suspended. If the option is <tt>false</tt>
then the Netty Acceptor is unbound when the consumer is suspended, so clients cannot connect
anymore. </td>
</tr>
</tbody></table>
</div>
</div>

<p>The <tt>NettyHttpSecurityConfiguration</tt> has 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>authenticate</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Whether authentication is enabled. Can be used to quickly
turn this off. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>constraint</tt> </td>
<td class='confluenceTd'> <tt>Basic</tt> </td>
<td class='confluenceTd'> The constraint supported. Currently only <tt>Basic</tt>
is implemented and supported. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>realm</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The name of the JAAS security realm. This option is mandatory.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>securityConstraint</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Allows to plugin a security constraint mapper where you can
define ACL to web resources. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>securityAuthenticator</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Allows to plugin a authenticator that performs the authentication.
If none has been configured then the <tt>org.apache.camel.component.netty.http.JAASSecurityAuthenticator</tt>
is used by default. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>loginDeniedLoggingLevel</tt> </td>
<td class='confluenceTd'> <tt>DEBUG</tt> </td>
<td class='confluenceTd'> Logging level used when a login attempt failed, which allows
to see more details why the login failed. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>roleClassName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> To specify FQN class names of <tt>Principal</tt>
implementations that contains user roles. If none has been specified, then the <a href="/confluence/display/CAMEL/Netty+HTTP"
title="Netty HTTP">Netty HTTP</a> component will by default assume a <tt>Principal</tt>
is role based if its FQN classname has the lower-case word <tt>role</tt> in its
classname. You can specify multiple class names separated by comma. </td>
</tr>
</tbody></table>
</div>
</div>

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

<p>The following headers can be used on the producer to control the HTTP request.</p>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHttpMethod</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Allow to control what HTTP method to use such as GET, POST,
TRACE etc. The type can also be a <tt>org.jboss.netty.handler.codec.http.HttpMethod</tt>
instance. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHttpQuery</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Allows to provide URI query parameters as a <tt>String</tt>
value that overrides the endpoint configuration. Separate multiple parameters using the &amp;
sign. For example: <tt>foo=bar&amp;beer=yes</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Content-Type</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> To set the content-type of the HTTP body. For example: <tt>text/plain;
charset="UTF-8"</tt>. </td>
</tr>
</tbody></table>
</div>
</div>

<p>The following headers is provided as meta-data when a route starts from an <a
href="/confluence/display/CAMEL/Netty+HTTP" title="Netty HTTP">Netty HTTP</a> endpoint:</p>

<p>The description in the table takes offset in a route having: <tt>from("netty-http:http:0.0.0.0:8080/myapp")...</tt>
</p>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHttpMethod</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The HTTP method used, such as GET, POST, TRACE etc. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHttpUrl</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The URL including protocol, host and port, etc: <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;">http://0.0.0.0:8080/myapp</pre>
</div></div> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHttpUri</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The URI without protocol, host and port, etc: <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;">/myapp</pre>
</div></div> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHttpQuery</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Any query parameters, such as <tt>foo=bar&amp;beer=yes</tt>
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHttpPath</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Additional context-path. This value is empty if the client
called the context-path <tt>/myapp</tt>. If the client calls <tt>/myapp/mystuff</tt>,
then this header value is <tt>/mystuff</tt>. In other words its the value after
the context-path configured on the route endpoint. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHttpCharacterEncoding</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The charset from the content-type header. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHttpAuthentication</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> If the user was authenticated using HTTP Basic then this header
is added with the value <tt>Basic</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Content-Type</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The content type if provided. For example: <tt>text/plain;
charset="UTF-8"</tt>. </td>
</tr>
</tbody></table>
</div>
</div>


<h3><a name="NettyHTTP-AccesstoNettytypes"></a>Access to Netty types</h3>

<p>This component uses the <tt>org.apache.camel.component.netty.http.NettyHttpMessage</tt>
as the message implementation on the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a>.
This allows end users to get access to the original Netty request/response instances if needed,
as shown below:</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;">
org.jboss.netty.handler.codec.http.HttpRequest request = exchange.getIn(NettyHttpMessage.class).getHttpRequest();
</pre>
</div></div>

<h3><a name="NettyHTTP-Examples"></a>Examples</h3>

<p>In the route below we use <a href="/confluence/display/CAMEL/Netty+HTTP" title="Netty
HTTP">Netty HTTP</a> as a HTTP server, which returns back a hardcoded "Bye World"
message. </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("netty-http:http://0.0.0.0:8080/foo")
      .transform().constant("Bye World");
</pre>
</div></div>

<p>And we can call this HTTP server using Camel also, with the <a href="/confluence/display/CAMEL/ProducerTemplate"
title="ProducerTemplate">ProducerTemplate</a> as shown below:</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;">
    String out = template.requestBody("netty-http:http://localhost:8080/foo", "Hello World",
String.class);
    System.out.println(out);
</pre>
</div></div>

<p>And we get back "Bye World" as the output.</p>

<h3><a name="NettyHTTP-HowdoIletNettymatchwildcards"></a>How do I let Netty
match wildcards</h3>

<p>By default <a href="/confluence/display/CAMEL/Netty+HTTP" title="Netty HTTP">Netty
HTTP</a> will only match on exact uri's. But you can instruct Netty to match prefixes.
For example</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("netty-http:http://0.0.0.0:8123/foo").to("mock:foo");
</pre>
</div></div>

<p>In the route above <a href="/confluence/display/CAMEL/Netty+HTTP" title="Netty
HTTP">Netty HTTP</a> will only match if the uri is an exact match, so it will match
if you enter<br/>
<tt><a href="http://0.0.0.0:8123/foo" class="external-link" rel="nofollow">http://0.0.0.0:8123/foo</a></tt>
but not match if you do <tt><a href="http://0.0.0.0:8123/foo/bar" class="external-link"
rel="nofollow">http://0.0.0.0:8123/foo/bar</a></tt>.</p>

<p>So if you want to enable wildcard matching you do 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;">
from("netty-http:http://0.0.0.0:8123/foo?matchOnUriPrefix=true").to("mock:foo");
</pre>
</div></div>
<p>So now Netty matches any endpoints with starts with <tt>foo</tt>.</p>

<p>To match <b>any</b> endpoint you can do:</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("netty-http:http://0.0.0.0:8123?matchOnUriPrefix=true").to("mock:foo");
</pre>
</div></div>

<h3><a name="NettyHTTP-Usingmultiplerouteswithsameport"></a>Using multiple
routes with same port</h3>

<p>In the same <a href="/confluence/display/CAMEL/CamelContext" title="CamelContext">CamelContext</a>
you can have multiple routes from <a href="/confluence/display/CAMEL/Netty+HTTP" title="Netty
HTTP">Netty HTTP</a> that shares the same port (eg a <tt>org.jboss.netty.bootstrap.ServerBootstrap</tt>
instance). Doing this requires a number of bootstrap options to be identical in the routes,
as the routes will share the same <tt>org.jboss.netty.bootstrap.ServerBootstrap</tt>
instance. The instance will be configured with the options from the first route created.</p>

<p>The options the routes must be identical configured is all the options defined in
the <tt>org.apache.camel.component.netty.NettyServerBootstrapConfiguration</tt>
configuration class. If you have configured another route with different options, Camel will
throw an exception on startup, indicating the options is not identical. To mitigate this ensure
all options is identical.</p>

<p>Here is an example with two routes that share the same port.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>Two routes sharing the same port</b></div><div
class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
from("netty-http:http://0.0.0.0:{{port}}/foo")
  .to("mock:foo")
  .transform().constant("Bye World");

from("netty-http:http://0.0.0.0:{{port}}/bar")
  .to("mock:bar")
  .transform().constant("Bye Camel");
</pre>
</div></div>

<p>And here is an example of a mis configured 2nd route that do not have identical <tt>org.apache.camel.component.netty.NettyServerBootstrapConfiguration</tt>
option as the 1st route. This will cause Camel to fail on startup.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>Two routes sharing the same port, but the 2nd
route is misconfigured and will fail on starting</b></div><div class="codeContent
panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
from("netty-http:http://0.0.0.0:{{port}}/foo")
  .to("mock:foo")
  .transform().constant("Bye World");

// we cannot have a 2nd route on same port with SSL enabled, when the 1st route is NOT
from("netty-http:http://0.0.0.0:{{port}}/bar?ssl=true")
  .to("mock:bar")
  .transform().constant("Bye Camel");
</pre>
</div></div>

<h4><a name="NettyHTTP-Reusingsameserverbootstrapconfigurationwithmultipleroutes"></a>Reusing
same server bootstrap configuration with multiple routes</h4>

<p>By configuring the common server bootstrap option in an single instance of a <tt>org.apache.camel.component.netty.NettyServerBootstrapConfiguration</tt>
type, we can use the <tt>bootstrapConfiguration</tt> option on the <a href="/confluence/display/CAMEL/Netty+HTTP"
title="Netty HTTP">Netty HTTP</a> consumers to refer and reuse the same options across
all consumers.</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="nettyHttpBootstrapOptions" class="org.apache.camel.component.netty.NettyServerBootstrapConfiguration"&gt;
  &lt;property name="backlog" value="200"/&gt;
  &lt;property name="connectionTimeout" value="20000"/&gt;
  &lt;property name="workerCount" value="16"/&gt;
&lt;/bean&gt;
</pre>
</div></div>

<p>And in the routes you refer to this option as shown below</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="netty-http:http://0.0.0.0:{{port}}/foo?bootstrapConfiguration=#nettyHttpBootstrapOptions"/&gt;
  ...
&lt;/route&gt;

&lt;route&gt;
  &lt;from uri="netty-http:http://0.0.0.0:{{port}}/bar?bootstrapConfiguration=#nettyHttpBootstrapOptions"/&gt;
  ...
&lt;/route&gt;

&lt;route&gt;
  &lt;from uri="netty-http:http://0.0.0.0:{{port}}/beer?bootstrapConfiguration=#nettyHttpBootstrapOptions"/&gt;
  ...
&lt;/route&gt;
</pre>
</div></div>

<h4><a name="NettyHTTP-ReusingsameserverbootstrapconfigurationwithmultipleroutesacrossmultiplebundlesinOSGicontainer"></a>Reusing
same server bootstrap configuration with multiple routes across multiple bundles in OSGi container</h4>

<p>See the <a href="/confluence/display/CAMEL/Netty+HTTP+Server+Example" title="Netty
HTTP Server Example">Netty HTTP Server Example</a> for more details and example how
to do that.</p>


<h3><a name="NettyHTTP-UsingHTTPBasicAuthentication"></a>Using HTTP Basic
Authentication</h3>

<p>The <a href="/confluence/display/CAMEL/Netty+HTTP" title="Netty HTTP">Netty
HTTP</a> consumer supports HTTP basic authentication by specifying the security realm
name to use, as shown below</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;">
&lt;route&gt;
   &lt;from uri="netty-http:http://0.0.0.0:{{port}}/foo?securityConfiguration.realm=karaf"/&gt;
   ...
&lt;/route&gt;
</pre>
</div></div>

<p>The realm name is mandatory to enable basic authentication. By default the JAAS based
authenticator is used, which will use the realm name specified (karaf in the example above)
and use the JAAS realm and the JAAS {{LoginModule}}s of this realm for authentication.</p>

<p>End user of Apache Karaf / ServiceMix has a karaf realm out of the box, and hence
why the example above would work out of the box in these containers.</p>

<h4><a name="NettyHTTP-SpecifyingACLonwebresources"></a>Specifying ACL on
web resources</h4>

<p>The <tt>org.apache.camel.component.netty.http.SecurityConstraint</tt>
allows to define constrains on web resources. And the <tt>org.apache.camel.component.netty.http.SecurityConstraintMapping</tt>
is provided out of the box, allowing to easily define inclusions and exclusions with roles.</p>

<p>For example as shown below in the XML DSL, we define the constraint bean:</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="constraint" class="org.apache.camel.component.netty.http.SecurityConstraintMapping"&gt;
    &lt;!-- inclusions defines url -&gt; roles restrictions --&gt;
    &lt;!-- a * should be used for any role accepted (or even no roles) --&gt;
    &lt;property name="inclusions"&gt;
      &lt;map&gt;
        &lt;entry key="/*" value="*"/&gt;
        &lt;entry key="/admin/*" value="admin"/&gt;
        &lt;entry key="/guest/*" value="admin,guest"/&gt;
      &lt;/map&gt;
    &lt;/property&gt;
    &lt;!-- exclusions is used to define public urls, which requires no authentication
--&gt;
    &lt;property name="exclusions"&gt;
      &lt;set&gt;
        &lt;value&gt;/public/*&lt;/value&gt;
      &lt;/set&gt;
    &lt;/property&gt;
  &lt;/bean&gt;
</pre>
</div></div>

<p>The constraint above is define so that</p>
<ul class="alternate" type="square">
	<li>access to /* is restricted and any roles is accepted (also if user has no roles)</li>
	<li>access to /admin/* requires the admin role</li>
	<li>access to /guest/* requires the admin or guest role</li>
	<li>access to /public/* is an exclusion which means no authentication is needed, and
is therefore public for everyone without logging in</li>
</ul>


<p>To use this constraint we just need to refer to the bean id as shown below:</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="netty-http:http://0.0.0.0:{{port}}/foo?matchOnUriPrefix=true&amp;amp;securityConfiguration.realm=karaf&amp;amp;securityConfiguration.securityConstraint=#constraint"/&gt;
   ...
&lt;/route&gt;
</pre>
</div></div>


<h3><a name="NettyHTTP-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/Netty" title="Netty">Netty</a></li>
	<li><a href="/confluence/display/CAMEL/Netty+HTTP+Server+Example" title="Netty HTTP
Server Example">Netty HTTP Server Example</a></li>
	<li><a href="/confluence/display/CAMEL/Jetty" title="Jetty">Jetty</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/Netty+HTTP">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=31820132&revisedVersion=24&originalVersion=23">View
Changes</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message