cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache CXF Documentation > Asynchronous Client HTTP Transport
Date Tue, 02 Oct 2012 16:43:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CXF20DOC&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/CXF20DOC/Asynchronous+Client+HTTP+Transport">Asynchronous
Client HTTP Transport</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~dkulp">Daniel
Kulp</a>
    </h4>
        <br/>
                         <h4>Changes (2)</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" >CXF also has an HTTP client transport
that is based on the [Apache HTTP Components HttpAsyncClient|http://hc.apache.org/httpcomponents-asyncclient-dev/index.html]
library.   The HttpAsyncClient library uses a non-blocking IO model.  This allows many more
requests to be outstanding without consume extra background threads.   It also allows greater
control over things like Keep-Alive handling which is very difficult or impossible with the
HttpURLConnection based transport.   However, the non-blocking model does not perform quite
as well as the blocking model for pure synchronous request/response transactions. <br>
<br></td></tr>
            <tr><td class="diff-unchanged" >By default, if the cxf-rt-transports-http-hc
module is found on the classpath, CXF will use the HttpAsyncClient based implementation for
any Async calls, but will continue to use the HttpURLConnection based transport for synchronous
calls.   This allows a good balance of performance for the common synchronous cases with scalability
for the asynchronous cases.  However, using a contextual property of &quot;use.async.http.conduit&quot;
and set to true/false, you can control whether the async or blocking version is used. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h3.
Setting Credentials <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">The
&quot;normal&quot; CXF/JAX-WS method of setting user credentials via the BindingProvider.USERNAME_PROPERTY/PASSWORD_PROPERTY
will work with the Async transport as well.   However, the Async transport does have some
additional capabilities around NTLM that can be leveraged.  In order to use that, you need
to: <br> <br>* Turn on the AutoRedirect and turn off the Chunking for the Conduit.
  This will allow CXF to cache the response in a manner that will allow the transport to keep
resending the request during the authentication negotiation. <br> <br>* Set the
property &quot;org.apache.http.auth.Credentials&quot; to an instance of the Credentials.
 For example: {code:java} <br>Credentials creds = new NTCredentials(&quot;username&quot;,
&quot;pswd&quot;, null, &quot;domain&quot;); <br>bp.getRequestContext().put(Credentials.class.getName(),
creds); <br>{code} <br> <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h3. Configuration  <br>The Asynchronous
HTTP Transport has several options that can set using Bus properties or via the OSGi configuration
services to control various aspects of the underlying Apache HTTP Components HttpAsyncClient
objects. <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h1><a name="AsynchronousClientHTTPTransport-AsynchronousClientHTTPTransport"></a>Asynchronous
Client HTTP Transport</h1>

<p>By default, CXF uses a transport based on the in-JDK HttpURLConnection object to
perform HTTP requests.   The HttpURLConnection object uses a blocking model for all IO operations
which requires a per-thread execution model.   From a pure performance standpoint, this model
generally performs very well, but it does have problems scaling when many requests need to
be executed simultaneously.</p>

<p>Also, the JAX-WS specification allows for generation of asynchronous methods on generated
proxies as well as using asynchronous methods on the Dispatch objects.   These methods can
take an AsyncHandler object and return a polling Future object so applications do not have
to wait for the response.   With the HttpURLConnection based transport, CXF was forced to
consume a background thread for each outstanding request.</p>

<p>CXF also has an HTTP client transport that is based on the <a href="http://hc.apache.org/httpcomponents-asyncclient-dev/index.html"
class="external-link" rel="nofollow">Apache HTTP Components HttpAsyncClient</a> library.
  The HttpAsyncClient library uses a non-blocking IO model.  This allows many more requests
to be outstanding without consume extra background threads.   It also allows greater control
over things like Keep-Alive handling which is very difficult or impossible with the HttpURLConnection
based transport.   However, the non-blocking model does not perform quite as well as the blocking
model for pure synchronous request/response transactions.</p>

<p>By default, if the cxf-rt-transports-http-hc module is found on the classpath, CXF
will use the HttpAsyncClient based implementation for any Async calls, but will continue to
use the HttpURLConnection based transport for synchronous calls.   This allows a good balance
of performance for the common synchronous cases with scalability for the asynchronous cases.
 However, using a contextual property of "use.async.http.conduit" and set to true/false, you
can control whether the async or blocking version is used.</p>

<h3><a name="AsynchronousClientHTTPTransport-SettingCredentials"></a>Setting
Credentials</h3>

<p>The "normal" CXF/JAX-WS method of setting user credentials via the BindingProvider.USERNAME_PROPERTY/PASSWORD_PROPERTY
will work with the Async transport as well.   However, the Async transport does have some
additional capabilities around NTLM that can be leveraged.  In order to use that, you need
to:</p>

<ul>
	<li>Turn on the AutoRedirect and turn off the Chunking for the Conduit.   This will
allow CXF to cache the response in a manner that will allow the transport to keep resending
the request during the authentication negotiation.</li>
</ul>


<ul>
	<li>Set the property "org.apache.http.auth.Credentials" to an instance of the Credentials.
 For example: 
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Credentials creds = <span class="code-keyword">new</span> NTCredentials(<span
class="code-quote">"username"</span>, <span class="code-quote">"pswd"</span>,
<span class="code-keyword">null</span>, <span class="code-quote">"domain"</span>);
bp.getRequestContext().put(Credentials.class.getName(), creds);
</pre>
</div></div></li>
</ul>



<h3><a name="AsynchronousClientHTTPTransport-Configuration"></a>Configuration
</h3>
<p>The Asynchronous HTTP Transport has several options that can set using Bus properties
or via the OSGi configuration services to control various aspects of the underlying Apache
HTTP Components HttpAsyncClient objects.</p>

<p>Settings related to the underlying TCP socket:</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<td class='confluenceTd'>org.apache.cxf.transport.http.async.TCP_NODELAY </td>
<td class='confluenceTd'> The TCP_NODELAY for the socket.   Defaults to true.</td>
</tr>
<tr>
<td class='confluenceTd'>org.apache.cxf.transport.http.async.SO_KEEPALIVE</td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'>org.apache.cxf.transport.http.async.SO_LINGER</td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'>org.apache.cxf.transport.http.async.SO_TIMEOUT</td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
</tbody></table>
</div>


<p>Settings related to Keep-Alive connection management:</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<td class='confluenceTd'>org.apache.cxf.transport.http.async.CONNECTION_TTL</td>
<td class='confluenceTd'> Maximum time a connection is held open in ms. Default is 60000.
</td>
</tr>
<tr>
<td class='confluenceTd'>org.apache.cxf.transport.http.async.MAX_CONNECTIONS</td>
<td class='confluenceTd'> Maximum number of connections opened per host.  Default is
1000. </td>
</tr>
<tr>
<td class='confluenceTd'>org.apache.cxf.transport.http.async.MAX_PER_HOST_CONNECTIONS</td>
<td class='confluenceTd'> Maximum number of connections opened in total.  Default is
5000. </td>
</tr>
</tbody></table>
</div>


<p>Settings related to Apache HttpAsyncClient threads and selectors:</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<td class='confluenceTd'>org.apache.cxf.transport.http.async.ioThreadCount</td>
<td class='confluenceTd'> Number of threads HttpAsyncClient uses to process IO events.
 Default is "-1" which means one thread per CPU core.</td>
</tr>
<tr>
<td class='confluenceTd'>org.apache.cxf.transport.http.async.interestOpQueued</td>
<td class='confluenceTd'> true/false for whether the interest ops are queues or process
directly.</td>
</tr>
<tr>
<td class='confluenceTd'>org.apache.cxf.transport.http.async.selectInterval</td>
<td class='confluenceTd'> Default 1000 ms.  How often the selector thread wakes up if
there are no events to process additional things like queue expirations.</td>
</tr>
</tbody></table>
</div>


<p>Setting to control which conduit is used</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<td class='confluenceTd'>org.apache.cxf.transport.http.async.usePolicy</td>
<td class='confluenceTd'> ALWAYS, ASYNC_ONLY, NEVER.   </td>
</tr>
</tbody></table>
</div>

    </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/CXF20DOC/Asynchronous+Client+HTTP+Transport">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=30737094&revisedVersion=4&originalVersion=3">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CXF20DOC/Asynchronous+Client+HTTP+Transport?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message