camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Netty HTTP
Date Tue, 04 Jun 2013 12:24:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/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 (4)</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" >{div} <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h3.
Access to Netty types <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">This
component uses the {{org.apache.camel.component.netty.http.NettyHttpMessage}} as the message
implementation on the [Exchange]. This allows end users to get access to the original Netty
request/response instances if needed, as shown below: <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{code}
<br>org.jboss.netty.handler.codec.http.HttpRequest request = exchange.getIn(NettyHttpMessage.class).getHttpRequest();
<br>{code} <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h3.
Examples <br> <br>In the route below we use [Netty HTTP] as a HTTP server, which
returns back a hardcoded &quot;Bye World&quot; message.  <br>{code} <br>
   from(&quot;netty-http:http://0.0.0.0:8080/foo&quot;) <br>      .transform().constant(&quot;Bye
World&quot;); <br>{code} <br> <br>And we can call this HTTP server using
Camel also, with the [ProducerTemplate] as shown below: <br>{code} <br>    String
out = template.requestBody(&quot;netty-http:http://localhost:8080/foo&quot;, &quot;Hello
World&quot;, String.class); <br>    System.out.println(out); <br>{code} <br>
<br>And we get back &quot;Bye World&quot; as the output. <br> <br>
<br></td></tr>
            <tr><td class="diff-unchanged" >{include:Endpoint See Also} <br>-
[Netty] <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>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="code-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span
class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-netty-http<span
class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same
version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</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="code-java">
netty-http:http:<span class="code-comment">//localhost:8080[?options]</span>
</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>

<p><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.</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>chunked</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Allow using chunked transfer if the client supports it from
the HTTP headers. </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 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>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>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'> <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 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. </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>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>

<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="code-java">
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="code-java">
    from(<span class="code-quote">"netty-http:http:<span class="code-comment">//0.0.0.0:8080/foo"</span>)
</span>      .transform().constant(<span class="code-quote">"Bye World"</span>);
</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="code-java">
    <span class="code-object">String</span> out = template.requestBody(<span
class="code-quote">"netty-http:http:<span class="code-comment">//localhost:8080/foo"</span>,
<span class="code-quote">"Hello World"</span>, <span class="code-object">String</span>.class);
</span>    <span class="code-object">System</span>.out.println(out);
</pre>
</div></div>

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


<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>
</ul>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change 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=7&originalVersion=6">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Netty+HTTP?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message