camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > ghttp
Date Tue, 17 Nov 2009 05:20:01 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/CAMEL/ghttp">ghttp</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~mrt1nz">Martin
Krasser</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <h2><a name="ghttp-%7B%7Bghttp%7D%7DComponent"></a><tt>ghttp</tt>
Component</h2>

<p>The <tt>ghttp</tt> component contributes to the <a href="/confluence/display/CAMEL/GAE"
title="GAE">Camel Components for Google App Engine</a> (GAE). It provides connectivity
to the GAE <a href="http://code.google.com/appengine/docs/java/urlfetch/" rel="nofollow">URL
fetch service</a> but can also be used to receive messages from servlets (the only way
to receive HTTP requests on GAE). This is achieved by extending the <tt><a href="/confluence/display/CAMEL/SERVLET"
title="SERVLET">Servlet component</a></tt>. As a consequence, <tt>ghttp</tt>
URI formats and options sets differ on the consumer-side (<tt>from</tt>) and producer-side
(<tt>to</tt>). </p>

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

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>Format</th>
<th class='confluenceTh'>Context</th>
<th class='confluenceTh'>Comment</th>
</tr>
<tr>
<td class='confluenceTd'><div class="code panel" style="border-width: 1px;"><div
class="codeContent panelContent">
<pre class="code-java">
ghttp:<span class="code-comment">///path[?options]</span>
</pre>
</div></div></td>
<td class='confluenceTd'>Consumer</td>
<td class='confluenceTd'>See also <a href="/confluence/display/CAMEL/SERVLET" title="SERVLET">Servlet
component</a></td>
</tr>
<tr>
<td class='confluenceTd'><div class="code panel" style="border-width: 1px;"><div
class="codeContent panelContent">
<pre class="code-java">
ghttp:<span class="code-comment">//hostname[:port][/path][?options]
</span>ghttps:<span class="code-comment">//hostname[:port][/path][?options]</span>
</pre>
</div></div></td>
<td class='confluenceTd'>Producer</td>
<td class='confluenceTd'>See also <a href="/confluence/display/CAMEL/HTTP" title="HTTP">Http
component</a></td>
</tr>
</tbody></table>

<h3><a name="ghttp-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Context </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>bridgeEndpoint</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Producer </td>
<td class='confluenceTd'>If set to <tt>true</tt> the <tt>Exchange.HTTP_URI</tt>
header will be ignored. To override the default endpoint URI with the <tt>Exchange.HTTP_URI</tt>
header set this option to <tt>false</tt>.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>throwExceptionOnFailure</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Producer </td>
<td class='confluenceTd'>Throw a <tt>org.apache.camel.component.gae.http</tt>
if the response code is &gt;= 400. To disable throwing an exception set this option to
<tt>false</tt>.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>inboundBindingRef</tt> </td>
<td class='confluenceTd'> reference to <tt>GHttpBinding</tt> </td>
<td class='confluenceTd'> Consumer </td>
<td class='confluenceTd'>Reference to an <tt>InboundBinding&lt;GHttpEndpoint,
HttpServletRequest, HttpServletResponse&gt;</tt> in the <a href="/confluence/display/CAMEL/Registry"
title="Registry">Registry</a> for customizing the binding of an <tt>Exchange</tt>
to the Servlet API. The referenced binding is used as post-processor to <tt>org.apache.camel.component.http.HttpBinding</tt>.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>outboundBindingRef</tt> </td>
<td class='confluenceTd'> reference to <tt>GHttpBinding</tt> </td>
<td class='confluenceTd'> Producer </td>
<td class='confluenceTd'>Reference to an <tt>OutboundBinding&lt;GHttpEndpoint,
HTTPRequest, HTTPResponse&gt;</tt> in the <a href="/confluence/display/CAMEL/Registry"
title="Registry">Registry</a> for customizing the binding of an <tt>Exchange</tt>
to the <tt>URLFetchService</tt>.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>urlFetchServiceRef</tt> </td>
<td class='confluenceTd'> reference to <tt>URLFetchServiceFactory.getURLFetchService()</tt>
</td>
<td class='confluenceTd'> Producer </td>
<td class='confluenceTd'>Reference to an <tt>URLFetchService</tt> in the
<a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. Only
relevant in context of testing. </td>
</tr>
</tbody></table>

<p>On the consumer-side, all options of the <a href="/confluence/display/CAMEL/SERVLET"
title="SERVLET">Servlet component</a> are supported.</p>

<h3><a name="ghttp-Messageheaders"></a>Message headers</h3>

<p>On the producer-side the following headers of the <a href="/confluence/display/CAMEL/HTTP"
title="HTTP">Http component</a> are supported.</p>

<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>Exchange.CONTENT_TYPE</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'>The HTTP content type. Is set on both the <tt>in</tt>
and <tt>out</tt> message to provide a content type, such as <tt>text/html</tt>.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Exchange.CONTENT_ENCODING</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'>The HTTP content encoding. Is set on both the <tt>in</tt>
and <tt>out</tt> message to provide a content encoding, such as <tt>gzip</tt>.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Exchange.HTTP_METHOD</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'>The HTTP method to execute. One of <tt>GET</tt>,
<tt>POST</tt>, <tt>PUT</tt> and <tt>DELETE</tt>. If not
set, <tt>POST</tt> will be used if the message body is not <tt>null</tt>,
<tt>GET</tt> otherwise.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Exchange.HTTP_QUERY</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'>Overrides the query part of the endpoint URI or the the query
part of <tt>Exchange.HTTP_URI</tt> (if defined). The query string must be in decoded
form.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Exchange.HTTP_URI</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'>Overrides the default endpoint URI if the <tt>bridgeEndpoint</tt>
option is set to <tt>false</tt>. The URI string must be in decoded form.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Exchange.RESPONSE_CODE</tt> </td>
<td class='confluenceTd'> <tt>int</tt> </td>
<td class='confluenceTd'>The HTTP response code from URL fetch service responses.</td>
</tr>
</tbody></table>

<p>On the consumer-side all headers of the <a href="/confluence/display/CAMEL/SERVLET"
title="SERVLET">Servlet component</a> component are supported.</p>

<h3><a name="ghttp-Messagebody"></a>Message body</h3>

<p>On the producer side the <tt>in</tt> message body is converted to a <tt>byte[]</tt>.
The <tt>out</tt> message body is made available as <tt>InputStream</tt>.
If the reponse size exceeds 1 megabyte a <a href="http://code.google.com/appengine/docs/java/javadoc/"
rel="nofollow">ResponseTooLargeException</a> is thrown by the URL fetch service (see
<a href="http://code.google.com/appengine/docs/java/urlfetch/overview.html#Quotas_and_Limits"
rel="nofollow">quotas and limits</a>).</p>

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

<h4><a name="ghttp-Receivingmessages"></a>Receiving messages</h4>

<p>For receiving messages via the <tt>ghttp</tt> component, a <tt>CamelHttpTransportServlet</tt>
must be <a href="/confluence/display/CAMEL/GAE#GAE-webxml">configured and mapped</a>
in the application's <tt>web.xml</tt>. For example, to handle requests targeted
at <tt>http://&lt;appname&gt;.appspot.com/camel/*</tt> or <tt><a
href="http://localhost/camel/*" rel="nofollow">http://localhost/camel/*</a></tt>
(when using a local development server) the following servlet mapping must be defined:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>web.xml</b></div><div class="codeContent
panelContent">
<pre class="code-xml">
    ...
    <span class="code-tag">&lt;servlet&gt;</span>
        <span class="code-tag">&lt;servlet-name&gt;</span>CamelServlet<span
class="code-tag">&lt;/servlet-name&gt;</span>
        <span class="code-tag">&lt;servlet-class&gt;</span>org.apache.camel.component.servlet.CamelHttpTransportServlet<span
class="code-tag">&lt;/servlet-class&gt;</span>
        ...
    <span class="code-tag">&lt;/servlet&gt;</span>
    ...
    <span class="code-tag">&lt;servlet-mapping&gt;</span>
        <span class="code-tag">&lt;servlet-name&gt;</span>CamelServlet<span
class="code-tag">&lt;/servlet-name&gt;</span>
        <span class="code-tag">&lt;url-pattern&gt;</span>/camel/*<span
class="code-tag">&lt;/url-pattern&gt;</span>
    <span class="code-tag">&lt;/servlet-mapping&gt;</span>
    ...
</pre>
</div></div>

<p>Endpoint URI path definitions are relative to this servlet mapping e.g. the route</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"ghttp:<span class="code-comment">///greeting"</span>).transform().constant(<span
class="code-quote">"Hello"</span>)</span>
</pre>
</div></div>

<p>processes requests targeted at <tt>http://&lt;appname&gt;.appspot.com/camel/greeting</tt>.
In this example, the request body is ignored and the response body is set to <tt>Hello</tt>.
Requests targeted at <tt>http://&lt;appname&gt;.appspot.com/camel/greeting/*</tt>
are not processed by default. This requires setting the option <tt>matchOnUriPrefix</tt>
to <tt>true</tt>.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"ghttp:<span class="code-comment">///greeting?matchOnUriPrefix=<span
class="code-keyword">true</span>"</span>).transform().constant(<span class="code-quote">"Hello"</span>)</span>
</pre>
</div></div>

<h4><a name="ghttp-Sendingmessages"></a>Sending messages</h4>

<p>For sending resquests to external HTTP services the <tt>ghttp</tt> component
uses the <a href="http://code.google.com/appengine/docs/java/urlfetch/" rel="nofollow">URL
fetch service</a>. For example, the Camel homepage can the retrieved with the following
endpoint definition on the producer-side.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(...)
...
.to(<span class="code-quote">"ghttp:<span class="code-comment">//camel.apache.org"</span>)
</span>...
</pre>
</div></div>


<p>The HTTP method used depends on the <tt>Exchange.HTTP_METHOD</tt> message
header or on the presence of an in-message body (<tt>GET</tt> if <tt>null</tt>,
<tt>POST</tt> otherwise). Retrieving the Camel homepage via a GAE application
is as simple as</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"ghttp:<span class="code-comment">///home"</span>)
</span>.to(<span class="code-quote">"ghttp:<span class="code-comment">//camel.apache.org"</span>)</span>
</pre>
</div></div>

<p>Sending a <tt>GET</tt> request to <tt>http://&lt;appname&gt;.appspot.com/camel/home</tt>
returns the Camel homepage. HTTPS-based communication with external services can be enabled
with the <tt>ghttps</tt> scheme.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(...)
...
.to(<span class="code-quote">"ghttps:<span class="code-comment">//svn.apache.org/repos/asf/camel/trunk/"</span>)
</span>...
</pre>
</div></div>

<h3><a name="ghttp-Dependencies"></a>Dependencies</h3>

<p>Maven users will need to add the following dependency to their <tt>pom.xml</tt>.
</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>pom.xml</b></div><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-gae<span
class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>${camel-version}<span
class="code-tag">&lt;/version&gt;</span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

<p>where <tt>${camel-version</tt>} must be replaced by the actual version
of Camel (2.1-M1 or higher).</p>

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

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/HTTP" title="HTTP">Http component</a></li>
	<li><a href="/confluence/display/CAMEL/SERVLET" title="SERVLET">Servlet Component</a></li>
</ul>

     </div>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/CAMEL/ghttp">View Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=5965070&revisedVersion=2&originalVersion=1">View
Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/CAMEL/ghttp?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message