hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1499478 - in /httpcomponents/httpcore/trunk: httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ httpcore/src/main/java/org/apache/http/impl/io/ src/docbkx/
Date Wed, 03 Jul 2013 17:12:36 GMT
Author: olegk
Date: Wed Jul  3 17:12:36 2013
New Revision: 1499478

URL: http://svn.apache.org/r1499478
Log:
Removed references to deprecated APIs from HttpCore tutorial

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestWriter.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseWriter.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java
    httpcomponents/httpcore/trunk/src/docbkx/advanced.xml
    httpcomponents/httpcore/trunk/src/docbkx/fundamentals.xml
    httpcomponents/httpcore/trunk/src/docbkx/nio-ext.xml
    httpcomponents/httpcore/trunk/src/docbkx/preface.xml

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestWriter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestWriter.java?rev=1499478&r1=1499477&r2=1499478&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestWriter.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestWriter.java Wed Jul  3 17:12:36 2013
@@ -57,7 +57,6 @@ public class DefaultHttpRequestWriter ex
         super(buffer, formatter, params);
     }
 
-
     /**
      * Creates an instance of DefaultHttpRequestWriter.
      *
@@ -73,6 +72,13 @@ public class DefaultHttpRequestWriter ex
         super(buffer, formatter);
     }
 
+    /**
+     * @since 4.3
+     */
+    public DefaultHttpRequestWriter(final SessionOutputBuffer buffer) {
+        super(buffer, null);
+    }
+
     @Override
     protected void writeHeadLine(final HttpRequest message) throws IOException {
         final CharArrayBuffer buffer = lineFormatter.formatRequestLine(

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseWriter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseWriter.java?rev=1499478&r1=1499477&r2=1499478&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseWriter.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseWriter.java Wed Jul  3 17:12:36 2013
@@ -72,6 +72,13 @@ public class DefaultHttpResponseWriter e
         super(buffer, formatter);
     }
 
+    /**
+     * @since 4.3
+     */
+    public DefaultHttpResponseWriter(final SessionOutputBuffer buffer) {
+        super(buffer, null);
+    }
+
     @Override
     protected void writeHeadLine(final HttpResponse message) throws IOException {
         final CharArrayBuffer buffer = lineFormatter.formatStatusLine(

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java?rev=1499478&r1=1499477&r2=1499478&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java Wed Jul  3 17:12:36 2013
@@ -105,6 +105,12 @@ public class SessionInputBufferImpl impl
         this.decoder = chardecoder;
     }
 
+    public SessionInputBufferImpl(
+            final HttpTransportMetricsImpl metrics,
+            final int buffersize) {
+        this(metrics, buffersize, buffersize, null, null);
+    }
+
     public void bind(final InputStream instream) {
         this.instream = instream;
     }

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java?rev=1499478&r1=1499477&r2=1499478&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java Wed Jul  3 17:12:36 2013
@@ -92,6 +92,12 @@ public class SessionOutputBufferImpl imp
         this.encoder = charencoder;
     }
 
+    public SessionOutputBufferImpl(
+            final HttpTransportMetricsImpl metrics,
+            final int buffersize) {
+        this(metrics, buffersize, buffersize, null);
+    }
+
     public void bind(final OutputStream outstream) {
         this.outstream = outstream;
     }

Modified: httpcomponents/httpcore/trunk/src/docbkx/advanced.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/src/docbkx/advanced.xml?rev=1499478&r1=1499477&r2=1499478&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/src/docbkx/advanced.xml (original)
+++ httpcomponents/httpcore/trunk/src/docbkx/advanced.xml Wed Jul  3 17:12:36 2013
@@ -89,12 +89,12 @@ CharArrayBuffer buf = new CharArrayBuffe
 buf.append("HTTP/1.1 200");
 ParserCursor cursor = new ParserCursor(0, buf.length());
 
-LineParser parser = new BasicLineParser();
+LineParser parser = BasicLineParser.INSTANCE;
 ProtocolVersion ver = parser.parseProtocolVersion(buf, cursor);
 System.out.println(ver);
 System.out.println(buf.substringTrimmed(
-    cursor.getPos(),
-    cursor.getUpperBound()));
+        cursor.getPos(),
+        cursor.getUpperBound()));
 ]]></programlisting>
             <para>stdout &gt;</para>
             <programlisting><![CDATA[
@@ -202,14 +202,13 @@ name1="value1"; param1="p1", name2="valu
             reading and writing <literal>CR-LF</literal> delimited lines.
             </para>
             <programlisting><![CDATA[
-Socket socket1;
-Socket socket2;
-HttpParams params = new BasicHttpParams();
-SessionInputBuffer inbuffer = new SocketInputBuffer(
-    socket1, 4096, params);
-SessionOutputBuffer outbuffer = new SocketOutputBuffer(
-    socket2, 4096, params);
-
+Socket socket1 = <...>
+Socket socket2 = <...>
+HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
+SessionInputBufferImpl inbuffer = new SessionInputBufferImpl(metrics, 8 * 1024);
+inbuffer.bind(socket1.getInputStream());
+SessionOutputBufferImpl outbuffer = new SessionOutputBufferImpl(metrics, 8 * 1024);
+outbuffer.bind(socket2.getOutputStream());
 CharArrayBuffer linebuf = new CharArrayBuffer(1024);
 inbuffer.readLine(linebuf);
 outbuffer.writeLine(linebuf);
@@ -220,14 +219,11 @@ outbuffer.writeLine(linebuf);
             with <literal>CR-LF</literal> delimited lines in a non-blocking I/O mode.
             </para>
             <programlisting><![CDATA[
-ReadableByteChannel channel1;
-WritableByteChannel channel2;
+ReadableByteChannel channel1 = <...>
+WritableByteChannel channel2 = <...>
 
-HttpParams params = new BasicHttpParams();
-SessionInputBuffer inbuffer = new SessionInputBufferImpl(
-    4096, 1024, params);
-SessionOutputBuffer outbuffer = new SessionOutputBufferImpl(
-    4096, 1024, params);
+SessionInputBuffer inbuffer = new SessionInputBufferImpl(8 * 1024);
+SessionOutputBuffer outbuffer = new SessionOutputBufferImpl(8 * 1024);
 
 CharArrayBuffer linebuf = new CharArrayBuffer(1024);
 boolean endOfStream = false;
@@ -256,96 +252,56 @@ if (outbuffer.hasData()) {
             Example of HTTP request parsing / writing for blocking HTTP connections:
             </para>
             <programlisting><![CDATA[
-SessionInputBuffer inbuffer;
-SessionOutputBuffer outbuffer;
-
-HttpParams params = new BasicHttpParams();
-
-HttpMessageParser requestParser = new HttpRequestParser(
-        inbuffer,
-        new BasicLineParser(),
-        new DefaultHttpRequestFactory(),
-        params);
-
-HttpRequest request = (HttpRequest) requestParser.parse();
-
-HttpMessageWriter requestWriter = new HttpRequestWriter(
-        outbuffer,
-        new BasicLineFormatter(),
-        params);
+SessionInputBuffer inbuffer = <...>
+SessionOutputBuffer outbuffer = <...>
 
+HttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(
+    inbuffer);
+HttpRequest request = requestParser.parse();
+HttpMessageWriter<HttpRequest> requestWriter = new DefaultHttpRequestWriter(
+    outbuffer);
 requestWriter.write(request);
 ]]></programlisting>
             <para>
             Example of HTTP response parsing / writing for blocking HTTP connections:
             </para>
             <programlisting><![CDATA[
-SessionInputBuffer inbuffer;
-SessionOutputBuffer outbuffer;
-
-HttpParams params = new BasicHttpParams();
-
-HttpMessageParser responseParser = new HttpResponseParser(
-        inbuffer,
-        new BasicLineParser(),
-        new DefaultHttpResponseFactory(),
-        params);
-
-HttpResponse response = (HttpResponse) responseParser.parse();
-
-HttpMessageWriter responseWriter = new HttpResponseWriter(
-        outbuffer,
-        new BasicLineFormatter(),
-        params);
+SessionInputBuffer inbuffer = <...>
+SessionOutputBuffer outbuffer = <...>
 
+HttpMessageParser<HttpResponse> responseParser = new DefaultHttpResponseParser(
+        inbuffer);
+HttpResponse response = responseParser.parse();
+HttpMessageWriter<HttpResponse> responseWriter = new DefaultHttpResponseWriter(
+        outbuffer);
 responseWriter.write(response);
 ]]></programlisting>
             <para>
             Example of HTTP request parsing / writing for non-blocking HTTP connections:
             </para>
             <programlisting><![CDATA[
-SessionInputBuffer inbuffer;
-SessionOutputBuffer outbuffer;
-
-HttpParams params = new BasicHttpParams();
-
-NHttpMessageParser requestParser = new DefaultHttpRequestParser(
-        inbuffer,
-        new BasicLineParser(),
-        new DefaultHttpRequestFactory(),
-        params);
-
-HttpRequest request = (HttpRequest) requestParser.parse();
-
-NHttpMessageWriter requestWriter = new DefaultHttpRequestWriter(
-        outbuffer,
-        new BasicLineFormatter(),
-        params);
+SessionInputBuffer inbuffer = <...>
+SessionOutputBuffer outbuffer  = <...>
 
+NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(
+        inbuffer);
+HttpRequest request = requestParser.parse();
+NHttpMessageWriter<HttpRequest> requestWriter = new DefaultHttpRequestWriter(
+        outbuffer);
 requestWriter.write(request);
 ]]></programlisting>
             <para>
             Example of HTTP response parsing / writing for non-blocking HTTP connections:
             </para>
             <programlisting><![CDATA[
-SessionInputBuffer inbuffer;
-SessionOutputBuffer outbuffer;
-
-HttpParams params = new BasicHttpParams();
-
-NHttpMessageParser responseParser = new DefaultHttpResponseParser(
-        inbuffer,
-        new BasicLineParser(),
-        new DefaultHttpResponseFactory(),
-        params);
-
-HttpResponse response = (HttpResponse) responseParser.parse();
+SessionInputBuffer inbuffer = <...>
+SessionOutputBuffer outbuffer  = <...>
 
+NHttpMessageParser<HttpResponse> responseParser = new DefaultHttpResponseParser(
+        inbuffer);
+HttpResponse response = responseParser.parse();
 NHttpMessageWriter responseWriter = new DefaultHttpResponseWriter(
-        outbuffer,
-        new BasicLineFormatter(),
-        params);
-
+        outbuffer);
 responseWriter.write(response);
 ]]></programlisting>
         </section>
@@ -360,6 +316,7 @@ responseWriter.write(response);
             optional <interfacename>FormattedHeader</interfacename> interface.
             </para>
             <programlisting><![CDATA[
+HttpResponse response = <...>
 Header h1 = response.getFirstHeader("Content-Type");
 if (h1 instanceof FormattedHeader) {
     CharArrayBuffer buf = ((FormattedHeader) h1).getBuffer();
@@ -368,91 +325,4 @@ if (h1 instanceof FormattedHeader) {
 ]]></programlisting>
         </section>
     </section>
-    <section>
-        <title>Customizing HTTP connections</title>
-        <para>
-        One can customize the way HTTP connections parse and format HTTP messages by extending the
-        default implementations and overriding factory methods and replacing the default parser or
-        formatter implementations with a custom one.
-        </para>
-        <para>
-        For blocking HTTP connections one also can provide custom implementation of session
-        input/output buffers.
-        </para>
-        <programlisting><![CDATA[
-class MyDefaultHttpClientConnection
-                        extends DefaultHttpClientConnection {
-
-    @Override
-    protected SessionInputBuffer createSessionInputBuffer(
-            Socket socket,
-            int buffersize,
-            HttpParams params) throws IOException {
-        return new MySocketInputBuffer(socket, buffersize, params);
-    }
-
-    @Override
-    protected SessionOutputBuffer createSessionOutputBuffer(
-            Socket socket,
-            int buffersize,
-            HttpParams params) throws IOException {
-        return new MySocketOutputBuffer(socket, buffersize, params);
-    }
-
-    @Override
-    protected HttpMessageWriter createRequestWriter(
-            SessionOutputBuffer buffer,
-            HttpParams params) {
-        return new MyHttpRequestWriter(
-            buffer, new BasicLineFormatter(), params);
-    }
-
-    @Override
-    protected HttpMessageParser createResponseParser(
-            SessionInputBuffer buffer,
-            HttpResponseFactory responseFactory,
-            HttpParams params) {
-        return new MyHttpResponseParser(
-        buffer, new BasicLineParser(), responseFactory, params);
-    }
-
-};
-]]></programlisting>
-        <para>
-        For non-blocking HTTP connection implementation one can replace the default HTTP message
-        parser and formatter implementations. The session input/output buffer implementations can
-        be overridden at the I/O reactor level.
-        </para>
-        <programlisting><![CDATA[
-class MyDefaultNHttpClientConnection
-                        extends DefaultNHttpClientConnection {
-
-    public MyDefaultNHttpClientConnection(
-            IOSession session,
-            HttpResponseFactory responseFactory,
-            ByteBufferAllocator allocator,
-            HttpParams params) {
-        super(session, responseFactory, allocator, params);
-    }
-
-    @Override
-    protected NHttpMessageWriter createRequestWriter(
-            SessionOutputBuffer buffer,
-            HttpParams params) {
-        return new HttpRequestWriter(
-            buffer, new BasicLineFormatter(), params);
-    }
-
-    @Override
-    protected NHttpMessageParser createResponseParser(
-            SessionInputBuffer buffer,
-            HttpResponseFactory responseFactory,
-            HttpParams params) {
-        return new HttpResponseParser(
-            buffer, new BasicLineParser(), responseFactory, params);
-    }
-
-};
-]]></programlisting>
-    </section>
 </chapter>

Modified: httpcomponents/httpcore/trunk/src/docbkx/fundamentals.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/src/docbkx/fundamentals.xml?rev=1499478&r1=1499477&r2=1499478&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/src/docbkx/fundamentals.xml (original)
+++ httpcomponents/httpcore/trunk/src/docbkx/fundamentals.xml Wed Jul  3 17:12:36 2013
@@ -286,11 +286,10 @@ c3 = c
                 </para>
                 <programlisting><![CDATA[
 StringEntity myEntity = new StringEntity("important message",
-    "UTF-8");
+    Consts.UTF_8);
 
 System.out.println(myEntity.getContentType());
 System.out.println(myEntity.getContentLength());
-System.out.println(EntityUtils.getContentCharSet(myEntity));
 System.out.println(EntityUtils.toString(myEntity));
 System.out.println(EntityUtils.toByteArray(myEntity).length);
 ]]></programlisting>
@@ -298,7 +297,6 @@ System.out.println(EntityUtils.toByteArr
                 <programlisting><![CDATA[
 Content-Type: text/plain; charset=UTF-8
 17
-UTF-8
 important message
 17
 ]]></programlisting>
@@ -431,8 +429,8 @@ myEntity.setContentLength(340); // sets 
                 to the constructor.
                 </para>
                 <programlisting><![CDATA[
-String myData = "Hello world on the other side!!";
-ByteArrayEntity myEntity = new ByteArrayEntity(myData.getBytes());
+ByteArrayEntity myEntity = new ByteArrayEntity(new byte[] {1,2,3},
+        ContentType.APPLICATION_OCTET_STREAM);
 ]]></programlisting>
             </section>
             <section id="string-entity">
@@ -447,19 +445,21 @@ ByteArrayEntity myEntity = new ByteArray
                 <programlisting><![CDATA[
 StringBuilder sb = new StringBuilder();
 Map<String, String> env = System.getenv();
-for (Entry<String, String> envEntry : env.entrySet()) {
-    sb.append(envEntry.getKey()).append(": ")
-    .append(envEntry.getValue()).append("\n");
+for (Map.Entry<String, String> envEntry : env.entrySet()) {
+    sb.append(envEntry.getKey())
+            .append(": ").append(envEntry.getValue())
+            .append("\r\n");
 }
 
 // construct without a character encoding (defaults to ISO-8859-1)
 HttpEntity myEntity1 = new StringEntity(sb.toString());
 
 // alternatively construct with an encoding (mime type defaults to "text/plain")
-HttpEntity myEntity2 = new StringEntity(sb.toString(), "UTF-8");
+HttpEntity myEntity2 = new StringEntity(sb.toString(), Consts.UTF_8);
 
 // alternatively construct with an encoding and a mime type
-HttpEntity myEntity3 = new StringEntity(sb.toString(), "text/html", "UTF-8");
+HttpEntity myEntity3 = new StringEntity(sb.toString(),
+        ContentType.create("text/plain", Consts.UTF_8));
 ]]></programlisting>
             </section>
             <section id="input-stream-entity">
@@ -490,7 +490,7 @@ InputStreamEntity myEntity = new InputSt
                 </para>
                 <programlisting><![CDATA[
 HttpEntity entity = new FileEntity(staticFile,
-    "application/java-archive");
+        ContentType.create("application/java-archive"));
 ]]></programlisting>
             </section>
             <section id="entity-wrapper">
@@ -548,17 +548,16 @@ BufferedHttpEntity myBufferedEntity = ne
             HTTP connections can be bound to any arbitrary network socket.
             </para>
             <programlisting><![CDATA[
-Socket socket = new Socket();
-// Initialize socket
-BasicHttpParams params = new BasicHttpParams();
-DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
-conn.bind(socket, params);
-conn.isOpen();
+Socket socket = <...>
+
+DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(8 * 1024);
+conn.bind(socket);
+System.out.println(conn.isOpen());
 HttpConnectionMetrics metrics = conn.getMetrics();
-metrics.getRequestCount();
-metrics.getResponseCount();
-metrics.getReceivedBytesCount();
-metrics.getSentBytesCount();
+System.out.println(metrics.getRequestCount());
+System.out.println(metrics.getResponseCount());
+System.out.println(metrics.getReceivedBytesCount());
+System.out.println(metrics.getSentBytesCount());
 ]]></programlisting>
             <para>
             HTTP connection interfaces, both client and server, send and receive messages in two
@@ -573,11 +572,10 @@ metrics.getSentBytesCount();
             Over-simplified process of client side request execution may look like this:
             </para>
             <programlisting><![CDATA[
-Socket socket = new Socket();
-// Initialize socket
-HttpParams params = new BasicHttpParams();
-DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
-conn.bind(socket, params);
+Socket socket = <...>
+
+DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(8 * 1024);
+conn.bind(socket);
 HttpRequest request = new BasicHttpRequest("GET", "/");
 conn.sendRequestHeader(request);
 HttpResponse response = conn.receiveResponseHeader();
@@ -594,16 +592,15 @@ if (entity != null) {
             Over-simplified process of server side request handling may look like this:
             </para>
             <programlisting><![CDATA[
-Socket socket = new Socket();
-// Initialize socket
-HttpParams params = new BasicHttpParams();
-DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
-conn.bind(socket, params);
+Socket socket = <...>
+
+DefaultBHttpServerConnection conn = new DefaultBHttpServerConnection(8 * 1024);
+conn.bind(socket);
 HttpRequest request = conn.receiveRequestHeader();
 if (request instanceof HttpEntityEnclosingRequest) {
     conn.receiveRequestEntity((HttpEntityEnclosingRequest) request);
     HttpEntity entity = ((HttpEntityEnclosingRequest) request)
-        .getEntity();
+            .getEntity();
     if (entity != null) {
         // Do something useful with the entity and, when done, ensure all
         // content has been consumed, so that the underlying connection
@@ -612,8 +609,8 @@ if (request instanceof HttpEntityEnclosi
     }
 }
 HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
-    200, "OK");
-response.setEntity(new StringEntity("Got it"));
+        200, "OK") ;
+response.setEntity(new StringEntity("Got it") );
 conn.sendResponseHeader(response);
 conn.sendResponseEntity(response);
 ]]></programlisting>
@@ -840,25 +837,26 @@ conn.sendResponseEntity(response);
             executing application specific processing logic and to post-process outgoing messages.
             </para>
             <programlisting><![CDATA[
-BasicHttpProcessor httpproc = new BasicHttpProcessor();
-// Required protocol interceptors
-httpproc.addInterceptor(new RequestContent());
-httpproc.addInterceptor(new RequestTargetHost());
-// Recommended protocol interceptors
-httpproc.addInterceptor(new RequestConnControl());
-httpproc.addInterceptor(new RequestUserAgent());
-httpproc.addInterceptor(new RequestExpectContinue());
-
-HttpContext context = new BasicHttpContext();
+HttpProcessor httpproc = HttpProcessorBuilder.create()
+        // Required protocol interceptors
+        .add(new RequestContent())
+        .add(new RequestTargetHost())
+        // Recommended protocol interceptors
+        .add(new RequestConnControl())
+        .add(new RequestUserAgent("MyAgent-HTTP/1.1"))
+        // Optional protocol interceptors
+        .add(new RequestExpectContinue(true))
+        .build();
 
+HttpCoreContext context = HttpCoreContext.create();
 HttpRequest request = new BasicHttpRequest("GET", "/");
 httpproc.process(request, context);
-HttpResponse response = null;
 ]]></programlisting>
             <para>
             Send the request to the target host and get a response.
             </para>
             <programlisting><![CDATA[
+HttpResponse = <...>
 httpproc.process(response, context);
 ]]></programlisting>
             <para>
@@ -880,160 +878,23 @@ httpproc.process(response, context);
             messages.
             </para>
             <programlisting><![CDATA[
-BasicHttpProcessor httpproc = new BasicHttpProcessor();
-httpproc.addInterceptor(new HttpRequestInterceptor() {
-
-    public void process(
-            HttpRequest request,
-            HttpContext context) throws HttpException, IOException {
-        String id = (String) context.getAttribute("session-id");
-        if (id != null) {
-            request.addHeader("Session-ID", id);
-        }
-    }
-
+HttpProcessor httpproc = HttpProcessorBuilder.create()
+        .add(new HttpRequestInterceptor() {
+            public void process(
+                    HttpRequest request,
+                    HttpContext context) throws HttpException, IOException {
+                String id = (String) context.getAttribute("session-id");
+                if (id != null) {
+                    request.addHeader("Session-ID", id);
+                }
+            }
+        })
+        .build();
 
-});
+HttpCoreContext context = HttpCoreContext.create();
 HttpRequest request = new BasicHttpRequest("GET", "/");
 httpproc.process(request, context);
 ]]></programlisting>
-            <para>
-            <interfacename>HttpContext</interfacename> instances can be linked together to form a
-            hierarchy. In the simplest form one context can use content of another context to
-            obtain default values of attributes not present in the local context.
-            </para>
-            <programlisting><![CDATA[
-HttpContext parentContext = new BasicHttpContext();
-parentContext.setAttribute("param1", Integer.valueOf(1));
-parentContext.setAttribute("param2", Integer.valueOf(2));
-
-HttpContext localContext = new BasicHttpContext();
-localContext.setAttribute("param2", Integer.valueOf(0));
-localContext.setAttribute("param3", Integer.valueOf(3));
-HttpContext stack = new DefaultedHttpContext(localContext,
-    parentContext);
-
-System.out.println(stack.getAttribute("param1"));
-System.out.println(stack.getAttribute("param2"));
-System.out.println(stack.getAttribute("param3"));
-System.out.println(stack.getAttribute("param4"));
-]]></programlisting>
-                <para>stdout &gt;</para>
-                <programlisting><![CDATA[
-1
-0
-3
-null
-]]></programlisting>
-        </section>
-    </section>
-    <section>
-        <title>HTTP parameters</title>
-        <para>
-        <interfacename>HttpParams</interfacename> interface represents a collection of immutable
-        values that define a runtime behavior of a component. In many ways <interfacename>HttpParams
-        </interfacename> is similar to <interfacename>HttpContext</interfacename>. The main
-        distinction between the two lies in their use at runtime. Both interfaces represent a
-        collection of objects that are organized as a map of textual names to object values, but
-        serve distinct purposes:
-        </para>
-        <itemizedlist>
-            <listitem>
-                <para>
-                <interfacename>HttpParams</interfacename> is intended to contain simple objects:
-                integers, doubles, strings, collections and objects that remain immutable at
-                runtime. <interfacename>HttpParams</interfacename> is expected to be used in the
-                'write once - read many' mode. <interfacename>HttpContext</interfacename> is
-                intended to contain complex objects that are very likely to mutate in the course of
-                HTTP message processing.
-                </para>
-            </listitem>
-            <listitem>
-                <para>
-                The purpose of <interfacename>HttpParams</interfacename> is to define a behavior of
-                other components. Usually each complex component has its own <interfacename>
-                HttpParams</interfacename> object. The purpose of <interfacename>HttpContext
-                </interfacename> is to represent an execution state of an HTTP process. Usually
-                the same execution context is shared among many collaborating objects.
-                </para>
-            </listitem>
-        </itemizedlist>
-        <para>
-        <interfacename>HttpParams</interfacename>, like <interfacename>HttpContext</interfacename>
-        can be linked together to form a hierarchy. In the simplest form one set of parameters can
-        use content of another one to obtain default values of parameters not present in the local
-        set.
-        </para>
-        <programlisting><![CDATA[
-HttpParams parentParams = new BasicHttpParams();
-parentParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION,
-    HttpVersion.HTTP_1_0);
-parentParams.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET,
-    "UTF-8");
-
-HttpParams localParams = new BasicHttpParams();
-localParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION,
-    HttpVersion.HTTP_1_1);
-localParams.setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE,
-    Boolean.FALSE);
-HttpParams stack = new DefaultedHttpParams(localParams,
-    parentParams);
-
-System.out.println(stack.getParameter(
-    CoreProtocolPNames.PROTOCOL_VERSION));
-System.out.println(stack.getParameter(
-    CoreProtocolPNames.HTTP_CONTENT_CHARSET));
-System.out.println(stack.getParameter(
-    CoreProtocolPNames.USE_EXPECT_CONTINUE));
-System.out.println(stack.getParameter(
-    CoreProtocolPNames.USER_AGENT));
-]]></programlisting>
-        <para>stdout &gt;</para>
-        <programlisting><![CDATA[
-HTTP/1.1
-UTF-8
-false
-null
-]]></programlisting>
-        <para>
-        Please note the <classname>BasicHttpParams</classname> class does not synchronize access to
-        its internal structures and therefore may not be thread-safe.
-        </para>
-        <section>
-            <title>HTTP parameter beans</title>
-            <para>
-            <interfacename>HttpParams</interfacename> interface allows for a great deal of
-            flexibility in handling configuration of components. Most importantly, new parameters
-            can be introduced without affecting binary compatibility with older versions. However,
-            <interfacename>HttpParams</interfacename> also has a certain disadvantage compared to
-            regular Java beans: <interfacename>HttpParams</interfacename> cannot be assembled using
-            a DI framework. To mitigate the limitation, HttpCore includes a number of bean classes
-            that can be used in order to initialize <interfacename>HttpParams</interfacename> objects
-            using standard Java bean conventions.
-            </para>
-            <programlisting><![CDATA[
-HttpParams params = new BasicHttpParams();
-HttpProtocolParamBean paramsBean = new HttpProtocolParamBean(params);
-paramsBean.setVersion(HttpVersion.HTTP_1_1);
-paramsBean.setContentCharset("UTF-8");
-paramsBean.setUseExpectContinue(true);
-
-System.out.println(params.getParameter(
-    CoreProtocolPNames.PROTOCOL_VERSION));
-System.out.println(params.getParameter(
-    CoreProtocolPNames.HTTP_CONTENT_CHARSET));
-System.out.println(params.getParameter(
-    CoreProtocolPNames.USE_EXPECT_CONTINUE));
-System.out.println(params.getParameter(
-    CoreProtocolPNames.USER_AGENT));
-]]></programlisting>
-        <para>stdout &gt;</para>
-        <programlisting><![CDATA[
-HTTP/1.1
-UTF-8
-false
-null
-]]></programlisting>
         </section>
     </section>
     <section>
@@ -1053,16 +914,13 @@ null
             application specific content generation and processing.
             </para>
             <programlisting><![CDATA[
-HttpParams params;
-// Initialize HTTP parameters
-HttpProcessor httpproc;
-// Initialize HTTP processor
-
-HttpService httpService = new HttpService(
-        httpproc,
-        new DefaultConnectionReuseStrategy(),
-        new DefaultHttpResponseFactory());
-httpService.setParams(params);
+HttpProcessor httpproc = HttpProcessorBuilder.create()
+        .add(new ResponseDate())
+        .add(new ResponseServer("MyServer-HTTP/1.1"))
+        .add(new ResponseContent())
+        .add(new ResponseConnControl())
+        .build();
+HttpService httpService = new HttpService(httpproc, null);
 ]]></programlisting>
             <section>
                 <title>HTTP request handlers</title>
@@ -1083,9 +941,9 @@ HttpRequestHandler myRequestHandler = ne
             HttpResponse response,
             HttpContext context) throws HttpException, IOException {
         response.setStatusCode(HttpStatus.SC_OK);
-        response.addHeader("Content-Type", "text/plain");
         response.setEntity(
-            new StringEntity("some important message"));
+                new StringEntity("some important message",
+                        ContentType.TEXT_PLAIN));
     }
 
 };
@@ -1103,17 +961,17 @@ HttpRequestHandler myRequestHandler = ne
                 <literal>*&lt;uri&gt;</literal>.
                 </para>
                 <programlisting><![CDATA[
-HttpService httpService;
-// Initialize HTTP service
+HttpProcessor httpproc = <...>
 
-HttpRequestHandlerRegistry handlerResolver =
-    new HttpRequestHandlerRegistry();
-handlerReqistry.register("/service/*", myRequestHandler1);
-handlerReqistry.register("*.do", myRequestHandler2);
-handlerReqistry.register("*", myRequestHandler3);
-
-// Inject handler resolver
-httpService.setHandlerResolver(handlerResolver);
+HttpRequestHandler myRequestHandler1 = <...>
+HttpRequestHandler myRequestHandler2 = <...>
+HttpRequestHandler myRequestHandler3 = <...>
+
+UriHttpRequestHandlerMapper handlerMapper = new UriHttpRequestHandlerMapper();
+handlerMapper.register("/service/*", myRequestHandler1);
+handlerMapper.register("*.do", myRequestHandler2);
+handlerMapper.register("*", myRequestHandler3);
+HttpService httpService = new HttpService(httpproc, handlerMapper);
 ]]></programlisting>
                 <para>
                 Users are encouraged to provide more sophisticated implementations of
@@ -1135,12 +993,9 @@ httpService.setHandlerResolver(handlerRe
                 by the <classname>HttpService</classname> are thread-safe.
                 </para>
                 <programlisting><![CDATA[
-HttpService httpService;
-// Initialize HTTP service
-HttpServerConnection conn;
-// Initialize connection
-HttpContext context;
-// Initialize HTTP context
+HttpService httpService = <...>
+HttpServerConnection conn = <...>
+HttpContext context = <...>
 
 boolean active = true;
 try {
@@ -1167,23 +1022,21 @@ try {
             response has been received.
             </para>
             <programlisting><![CDATA[
-HttpClientConnection conn;
-// Create connection
-HttpParams params;
-// Initialize HTTP parameters
-HttpProcessor httpproc;
-// Initialize HTTP processor
-HttpContext context;
-// Initialize HTTP context
+HttpClientConnection conn = <...>
 
+HttpProcessor httpproc = HttpProcessorBuilder.create()
+        .add(new RequestContent())
+        .add(new RequestTargetHost())
+        .add(new RequestConnControl())
+        .add(new RequestUserAgent("MyClient/1.1"))
+        .add(new RequestExpectContinue(true))
+        .build();
 HttpRequestExecutor httpexecutor = new HttpRequestExecutor();
 
-BasicHttpRequest request = new BasicHttpRequest("GET", "/");
-request.setParams(params);
+HttpRequest request = new BasicHttpRequest("GET", "/");
+HttpCoreContext context = HttpCoreContext.create();
 httpexecutor.preProcess(request, httpproc, context);
-HttpResponse response = httpexecutor.execute(
-    request, conn, context);
-response.setParams(params);
+HttpResponse response = httpexecutor.execute(request, conn, context);
 httpexecutor.postProcess(response, httpproc, context);
 
 HttpEntity entity = response.getEntity();

Modified: httpcomponents/httpcore/trunk/src/docbkx/nio-ext.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/src/docbkx/nio-ext.xml?rev=1499478&r1=1499477&r2=1499478&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/src/docbkx/nio-ext.xml (original)
+++ httpcomponents/httpcore/trunk/src/docbkx/nio-ext.xml Wed Jul  3 17:12:36 2013
@@ -25,31 +25,6 @@
 <chapter id="nio">
     <title>NIO extensions</title>
     <section>
-        <title>Benefits and shortcomings of the non-blocking I/O model</title>
-        <para>
-        Contrary to the popular belief, the performance of NIO in terms of raw data throughput is
-        significantly lower than that of blocking I/O. NIO does not necessarily fit all use cases
-        and should be used only where appropriate:
-        </para>
-        <itemizedlist>
-            <listitem>
-                <para>
-                handling of thousands of connections, a significant number of which can be idle.
-                </para>
-            </listitem>
-            <listitem>
-                <para>
-                handling high latency connections.
-                </para>
-            </listitem>
-            <listitem>
-                <para>
-                request / response handling needs to be decoupled.
-                </para>
-            </listitem>
-        </itemizedlist>
-    </section>
-    <section>
         <title>Differences from other NIO frameworks</title>
         <para>
         Solves similar problems as other frameworks, but has certain distinct features:
@@ -91,10 +66,8 @@
         thread per CPU core.
         </para>
         <programlisting><![CDATA[
-HttpParams params = new BasicHttpParams();
-int workerCount = 2;
-IOReactor ioreactor = new DefaultConnectingIOReactor(workerCount,
-    params);
+IOReactorConfig config = IOReactorConfig.DEFAULT;
+IOReactor ioreactor = new DefaultConnectingIOReactor(config);
 ]]></programlisting>
         <section>
             <title>I/O dispatchers</title>
@@ -108,10 +81,10 @@ IOReactor ioreactor = new DefaultConnect
             events.
             </para>
             <programlisting><![CDATA[
-HttpParams params = new BasicHttpParams();
-IOReactor ioreactor = new DefaultConnectingIOReactor(2, params);
+IOReactorConfig config = IOReactorConfig.DEFAULT;
+IOReactor ioreactor = new DefaultConnectingIOReactor(config);
 
-IOEventDispatch eventDispatch = new MyIOEventDispatch();
+IOEventDispatch eventDispatch = <...>
 ioreactor.execute(eventDispatch);
 ]]></programlisting>
             <para>
@@ -171,6 +144,7 @@ ioreactor.execute(eventDispatch);
             remaining sessions.
             </para>
             <programlisting><![CDATA[
+IOReactor ioreactor = <...>
 long gracePeriod = 3000L; // milliseconds
 ioreactor.shutdown(gracePeriod);
 ]]></programlisting>
@@ -191,7 +165,7 @@ ioreactor.shutdown(gracePeriod);
             to the session.
             </para>
             <programlisting><![CDATA[
-IOSession iosession;
+IOSession iosession = <...>
 ReadableByteChannel ch = (ReadableByteChannel) iosession.channel();
 ByteBuffer dst = ByteBuffer.allocate(2048);
 ch.read(dst);
@@ -205,9 +179,11 @@ ch.read(dst);
             be stored within the session itself.
             </para>
             <programlisting><![CDATA[
-IOSession iosession;
-Object someState;
+IOSession iosession = <...>
+Object someState = <...>
 iosession.setAttribute("state", someState);
+...
+IOSession iosession = <...>
 Object currentState = iosession.getAttribute("state");
 ]]></programlisting>
             <para>
@@ -222,7 +198,7 @@ Object currentState = iosession.getAttri
             session by setting its event mask.
             </para>
             <programlisting><![CDATA[
-IOSession iosession;
+IOSession iosession = <...>
 iosession.setEventMask(SelectionKey.OP_READ | SelectionKey.OP_WRITE);
 ]]></programlisting>
             <para>
@@ -230,6 +206,7 @@ iosession.setEventMask(SelectionKey.OP_R
             individually.
             </para>
             <programlisting><![CDATA[
+IOSession iosession = <...>
 iosession.setEvent(SelectionKey.OP_READ);
 iosession.clearEvent(SelectionKey.OP_READ);
 ]]></programlisting>
@@ -253,8 +230,8 @@ iosession.clearEvent(SelectionKey.OP_REA
             SessionBufferStatus</interfacename> interface.
             </para>
             <programlisting><![CDATA[
-IOSession iosession;
-SessionBufferStatus myBufferStatus = new MySessionBufferStatus();
+IOSession iosession = <...>
+SessionBufferStatus myBufferStatus = <...>
 iosession.setBufferStatus(myBufferStatus);
 iosession.hasBufferedInput();
 iosession.hasBufferedOutput();
@@ -278,12 +255,10 @@ iosession.hasBufferedOutput();
             listening for incoming connections on one or several ports.
             </para>
             <programlisting><![CDATA[
-ListeningIOReactor ioreactor;
-
-ListenerEndpoint ep1 = ioreactor.listen(new InetSocketAddress(8081));
+ListeningIOReactor ioreactor = <...>
+ListenerEndpoint ep1 = ioreactor.listen(new InetSocketAddress(8081) );
 ListenerEndpoint ep2 = ioreactor.listen(new InetSocketAddress(8082));
 ListenerEndpoint ep3 = ioreactor.listen(new InetSocketAddress(8083));
-
 // Wait until all endpoints are up
 ep1.waitFor();
 ep2.waitFor();
@@ -299,7 +274,7 @@ ep3.waitFor();
             endpoint at runtime, and close it if desired.
             </para>
             <programlisting><![CDATA[
-ListeningIOReactor ioreactor;
+ListeningIOReactor ioreactor = <...>
 
 Set<ListenerEndpoint> eps = ioreactor.getEndpoints();
 for (ListenerEndpoint ep: eps) {
@@ -323,7 +298,7 @@ for (ListenerEndpoint ep: eps) {
             establishing connections with remote hosts.
             </para>
             <programlisting><![CDATA[
-ConnectingIOReactor ioreactor;
+ConnectingIOReactor ioreactor = <...>
 
 SessionRequest sessionRequest = ioreactor.connect(
         new InetSocketAddress("www.google.com", 80),
@@ -367,7 +342,7 @@ if (!sessionRequest.isCompleted()) {
             local address.
             </para>
             <programlisting><![CDATA[
-ConnectingIOReactor ioreactor;
+ConnectingIOReactor ioreactor = <...>
 
 SessionRequest sessionRequest = ioreactor.connect(
         new InetSocketAddress("www.google.com", 80),
@@ -396,7 +371,7 @@ HttpHost virtualHost = (HttpHost) iosess
             as request completion, cancellation, failure or timeout.
             </para>
             <programlisting><![CDATA[
-ConnectingIOReactor ioreactor;
+ConnectingIOReactor ioreactor = <...>
 
 SessionRequest sessionRequest = ioreactor.connect(
         new InetSocketAddress("www.google.com", 80), null, null,
@@ -435,9 +410,10 @@ SessionRequest sessionRequest = ioreacto
             thread only when the I/O selector is not engaged in a select operation.
             </para>
             <programlisting><![CDATA[
-HttpParams params = new BasicHttpParams();
-NIOReactorParams.setInterestOpsQueueing(params, true);
-ListeningIOReactor ioreactor = new DefaultListeningIOReactor(2, params);
+IOReactorConfig config = IOReactorConfig.custom()
+        .setInterestOpQueued(true)
+        .build();
+ListeningIOReactor ioreactor = new DefaultListeningIOReactor(config);
 ]]></programlisting>
         </section>
     </section>
@@ -459,7 +435,7 @@ ListeningIOReactor ioreactor = new Defau
         IOReactorExceptionHandler</interfacename> interface.
         </para>
         <programlisting><![CDATA[
-DefaultConnectingIOReactor ioreactor;
+DefaultConnectingIOReactor ioreactor = <...>
 
 ioreactor.setExceptionHandler(new IOReactorExceptionHandler() {
 
@@ -502,7 +478,7 @@ ioreactor.setExceptionHandler(new IOReac
             I/O reactor.
             </para>
             <programlisting><![CDATA[
-DefaultConnectingIOReactor ioreactor;
+DefaultConnectingIOReactor ioreactor = <...>
 
 // Give it 5 sec grace period
 ioreactor.shutdown(5000);
@@ -532,10 +508,8 @@ for (ExceptionEvent event: events) {
             </interfacename> instance is thread-safe and can be manipulated from multiple threads.
             </para>
             <programlisting><![CDATA[
-// Get non-blocking HTTP connection
-DefaultNHttpClientConnection conn;
-// State
-Object myStateObject;
+DefaultNHttpClientConnection conn = <...>
+Object myStateObject = <...>
 
 HttpContext context = conn.getContext();
 context.setAttribute("state", myStateObject);
@@ -549,17 +523,17 @@ context.setAttribute("state", myStateObj
             be null if there is no incoming or outgoing message currently being transferred.
             </para>
             <programlisting><![CDATA[
-NHttpConnection conn;
+NHttpConnection conn = <...>
 
 HttpRequest request = conn.getHttpRequest();
 if (request != null) {
     System.out.println("Transferring request: " +
-        request.getRequestLine());
+            request.getRequestLine());
 }
 HttpResponse response = conn.getHttpResponse();
 if (response != null) {
     System.out.println("Transferring response: " +
-        response.getStatusLine());
+            response.getStatusLine());
 }
 ]]></programlisting>
             <para>
@@ -574,15 +548,11 @@ if (response != null) {
             Over-simplified process of submitting a request on the client side may look like this:
             </para>
             <programlisting><![CDATA[
-// Obtain HTTP connection
-NHttpClientConnection conn;
-
+NHttpClientConnection conn = <...>
 // Obtain execution context
 HttpContext context = conn.getContext();
-
 // Obtain processing state
 Object state = context.getAttribute("state");
-
 // Generate a request based on the state information
 HttpRequest request = new BasicHttpRequest("GET", "/");
 
@@ -593,12 +563,9 @@ System.out.println(conn.isRequestSubmitt
             Over-simplified process of submitting a response on the server side may look like this:
             </para>
             <programlisting><![CDATA[
-// Obtain HTTP connection
-NHttpServerConnection conn;
-
+NHttpServerConnection conn = <...>
 // Obtain execution context
 HttpContext context = conn.getContext();
-
 // Obtain processing state
 Object state = context.getAttribute("state");
 
@@ -687,8 +654,7 @@ System.out.println(conn.isResponseSubmit
             transferred.
             </para>
             <programlisting><![CDATA[
-//Obtain content decoder
-ContentDecoder decoder;
+ContentDecoder decoder = <...>
 //Read data in
 ByteBuffer dst = ByteBuffer.allocate(2048);
 decoder.read(dst);
@@ -703,8 +669,7 @@ if (decoder.isCompleted()) {
             marked as fully transferred.
             </para>
             <programlisting><![CDATA[
-// Obtain content encoder
-ContentEncoder encoder;
+ContentEncoder encoder = <...>
 // Prepare output data
 ByteBuffer src = ByteBuffer.allocate(2048);
 // Write data out
@@ -721,8 +686,7 @@ encoder.complete();
             HttpEntity#writeTo()</methodname> methods of the enclosed entities.
             </para>
             <programlisting><![CDATA[
-// Obtain HTTP connection
-NHttpServerConnection conn;
+NHttpServerConnection conn  = <...>
 
 HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
     HttpStatus.SC_OK, "OK");
@@ -743,8 +707,7 @@ conn.submitResponse(response);
             of the incoming entity such as content length.
             </para>
             <programlisting><![CDATA[
-// Obtain HTTP connection
-NHttpClientConnection conn;
+NHttpClientConnection conn = <...>
 
 HttpResponse response = conn.getHttpResponse();
 HttpEntity entity = response.getEntity();
@@ -812,8 +775,7 @@ if (entity != null) {
             file bypassing an intermediate <classname>java.nio.ByteBuffer</classname>.
             </para>
             <programlisting><![CDATA[
-//Obtain content decoder
-ContentDecoder decoder;
+ContentDecoder decoder = <...>
 //Prepare file channel
 FileChannel dst;
 //Make use of direct file I/O if possible
@@ -833,8 +795,7 @@ if (decoder instanceof FileContentDecode
             from a file bypassing an intermediate <classname>java.nio.ByteBuffer</classname>.
             </para>
             <programlisting><![CDATA[
-// Obtain content encoder
-ContentEncoder encoder;
+ContentEncoder encoder = <...>
 // Prepare file channel
 FileChannel src;
 // Make use of direct file I/O if possible
@@ -1146,9 +1107,8 @@ if (encoder instanceof FileContentEncode
                 a given byte array. This byte array is supplied to the constructor.
                 </para>
                 <programlisting><![CDATA[
-String myData = "Hello world on the other side!!";
-NByteArrayEntity entity = new NByteArrayEntity(myData.getBytes());
-    ]]></programlisting>
+NByteArrayEntity entity = new NByteArrayEntity(new byte[] {1, 2, 3});
+]]></programlisting>
             </section>
             <section id="string-n-entity">
                 <title><classname>NStringEntity</classname></title>
@@ -1159,11 +1119,8 @@ NByteArrayEntity entity = new NByteArray
                 the data in the <classname>java.lang.String</classname>.
                 </para>
                 <programlisting><![CDATA[
-String myData = "Hello world on the other side!!";
-// construct without a character encoding
-NStringEntity myEntity1 = new NStringEntity(myData);
-// alternatively construct with an encoding
-NStringEntity myEntity2 = new NStringEntity(myData, "UTF-8");
+NStringEntity myEntity = new NStringEntity("important message",
+        Consts.UTF_8);
     ]]></programlisting>
             </section>
             <section id="file-n-entity">
@@ -1176,7 +1133,7 @@ NStringEntity myEntity2 = new NStringEnt
                 </para>
                 <programlisting><![CDATA[
 File staticFile = new File("/path/to/myapp.jar");
-NHttpEntity entity = new NFileEntity(staticFile,
+NFileEntity entity = new NFileEntity(staticFile,
     ContentType.create("application/java-archive", null));
     ]]></programlisting>
                 <para>
@@ -1216,23 +1173,18 @@ NHttpEntity entity = new NFileEntity(sta
             application specific content generation and processing.
             </para>
             <programlisting><![CDATA[
-HttpParams params;
-// Initialize HTTP parameters
-HttpProcessor httpproc;
-// Initialize HTTP processor
-HttpAsyncRequestHandlerResolver handlerResolver;
-// Initialize HTTP request resolver
-HttpAsyncService protocolHandler = new HttpAsyncService(
-        httpproc,
-        new DefaultConnectionReuseStrategy(),
-        new DefaultHttpResponseFactory(),
-        handlerResolver,
-        null,
-        params);
-NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory;
-// Initialize HTTP connection factory
+HttpProcessor httpproc = HttpProcessorBuilder.create()
+        .add(new ResponseDate())
+        .add(new ResponseServer("MyServer-HTTP/1.1"))
+        .add(new ResponseContent())
+        .add(new ResponseConnControl())
+        .build();
+HttpAsyncService protocolHandler = new HttpAsyncService(httpproc, null);
 IOEventDispatch ioEventDispatch = new DefaultHttpServerIODispatch(
-    protocolHandler, connFactory);
+        protocolHandler,
+        new DefaultNHttpServerConnectionFactory(ConnectionConfig.DEFAULT));
+ListeningIOReactor ioreactor = new DefaultListeningIOReactor();
+ioreactor.execute(ioEventDispatch);
 ]]></programlisting>
             <section>
                 <title>Non-blocking HTTP request handlers</title>
@@ -1262,7 +1214,7 @@ HttpAsyncRequestHandler<HttpRequest> rh 
         HttpResponse response = httpexchange.getResponse();
         response.setStatusCode(HttpStatus.SC_OK);
         NFileEntity body = new NFileEntity(new File("static.html"),
-                ContentType.create("text/html", null));
+                ContentType.create("text/html", Consts.UTF_8));
         response.setEntity(body);
         httpexchange.submitResponse(new BasicAsyncResponseProducer(response));
     }
@@ -1377,7 +1329,7 @@ HttpAsyncRequestHandler<HttpRequest> rh 
                 HttpResponse response = httpexchange.getResponse();
                 response.setStatusCode(HttpStatus.SC_OK);
                 NFileEntity body = new NFileEntity(new File("static.html"),
-                        ContentType.create("text/html", null));
+                        ContentType.create("text/html", Consts.UTF_8));
                 response.setEntity(body);
                 httpexchange.submitResponse(new BasicAsyncResponseProducer(response));
             }
@@ -1610,8 +1562,11 @@ HttpAsyncRequestHandler<HttpRequest> rh 
                 <literal>*&lt;uri&gt;</literal>.
                 </para>
                 <programlisting><![CDATA[
-HttpAsyncRequestHandlerRegistry handlerReqistry =
-    new HttpAsyncRequestHandlerRegistry();
+HttpAsyncRequestHandler<?> myRequestHandler1 = <...>
+HttpAsyncRequestHandler<?> myRequestHandler2 = <...>
+HttpAsyncRequestHandler<?> myRequestHandler3 = <...>
+UriHttpAsyncRequestHandlerMapper handlerReqistry =
+        new UriHttpAsyncRequestHandlerMapper();
 handlerReqistry.register("/service/*", myRequestHandler1);
 handlerReqistry.register("*.do", myRequestHandler2);
 handlerReqistry.register("*", myRequestHandler3);
@@ -1649,9 +1604,10 @@ handlerReqistry.register("*", myRequestH
             </para>
             <programlisting><![CDATA[
 HttpAsyncRequestExecutor ph = new HttpAsyncRequestExecutor();
-NHttpConnectionFactory<DefaultNHttpClientConnection> connFactory;
-// Initialize HTTP connection factory
-IOEventDispatch ioEventDispatch = new DefaultHttpClientIODispatch(ph, connFactory);
+IOEventDispatch ioEventDispatch = new DefaultHttpClientIODispatch(ph,
+        new DefaultNHttpClientConnectionFactory(ConnectionConfig.DEFAULT));
+ConnectingIOReactor ioreactor = new DefaultConnectingIOReactor();
+ioreactor.execute(ioEventDispatch);
 ]]></programlisting>
             <para>
             The <classname>HttpAsyncRequester</classname> utility class can be used to abstract
@@ -1661,17 +1617,15 @@ IOEventDispatch ioEventDispatch = new De
             authentication and does not handle redirects automatically.
             </para>
             <programlisting><![CDATA[
-HttpParams params;
-// Initialize HTTP parameters
-HttpProcessor httpprocessor;
-// Initialize HTTP processor
-HttpAsyncRequester requester = new HttpAsyncRequester(
-        httpprocessor,
-        new DefaultConnectionReuseStrategy(),
-        params);
-
-//Obtain HTTP connection
-NHttpClientConnection conn;
+HttpProcessor httpproc = HttpProcessorBuilder.create()
+        .add(new RequestContent())
+        .add(new RequestTargetHost())
+        .add(new RequestConnControl())
+        .add(new RequestUserAgent("MyAgent-HTTP/1.1"))
+        .add(new RequestExpectContinue(true))
+        .build();
+HttpAsyncRequester requester = new HttpAsyncRequester(httpproc);
+NHttpClientConnection conn = <...>
 Future<HttpResponse> future = requester.execute(
         new BasicAsyncRequestProducer(
                 new HttpHost("localhost"),
@@ -1924,20 +1878,15 @@ HttpResponse response = future.get();
             special preconditions or modifications.
             </para>
             <programlisting><![CDATA[
-// Initialize HTTP parameters
-HttpParams params;
-// Initialize default SSL context
-SSLContext sslcontext = SSLContext.getInstance("SSL");
+SSLContext sslcontext = SSLContext.getInstance("Default");
 sslcontext.init(null, null, null);
 // Plain I/O session
-IOSession iosession;
+IOSession iosession = <...>
 SSLIOSession sslsession = new SSLIOSession(
         iosession, SSLMode.CLIENT, sslcontext, null);
 iosession.setAttribute(SSLIOSession.SESSION_KEY, sslsession);
 NHttpClientConnection conn = new DefaultNHttpClientConnection(
-        sslsession,
-        new DefaultHttpResponseFactory(),
-        new HeapByteBufferAllocator(), params);
+        sslsession, 8 * 1024);
 ]]></programlisting>
             <para>
             One can also use <classname>SSLNHttpClientConnectionFactory</classname> or <classname>
@@ -1945,12 +1894,12 @@ NHttpClientConnection conn = new Default
             encrypterd HTTP connections.
             </para>
             <programlisting><![CDATA[
-// Initialize HTTP parameters
-HttpParams params;
+SSLContext sslcontext = SSLContext.getInstance("Default");
+sslcontext.init(null, null, null);
 // Plain I/O session
-IOSession iosession;
+IOSession iosession = <...>
 SSLNHttpClientConnectionFactory connfactory = new SSLNHttpClientConnectionFactory(
-        params);
+        sslcontext, null, ConnectionConfig.DEFAULT);
 NHttpClientConnection conn = connfactory.createConnection(iosession);
 ]]></programlisting>
             <section>
@@ -1989,14 +1938,13 @@ NHttpClientConnection conn = connfactory
                     </listitem>
                 </itemizedlist>
                 <programlisting><![CDATA[
-// Plain I/O session
-IOSession iosession;
-// Initialize default SSL context
-SSLContext sslcontext = SSLContext.getInstance("SSL");
+SSLContext sslcontext = SSLContext.getInstance("Default");
 sslcontext.init(null, null, null);
+// Plain I/O session
+IOSession iosession = <...>
 
 SSLIOSession sslsession = new SSLIOSession(
-    iosession, SSLMode.CLIENT, sslcontext, new SSLSetupHandler() {
+        iosession, SSLMode.CLIENT, sslcontext, new SSLSetupHandler() {
 
     public void initalize(final SSLEngine sslengine) throws SSLException {
         // Enforce strong ciphers
@@ -2024,11 +1972,11 @@ SSLIOSession sslsession = new SSLIOSessi
             SSLNHttpServerConnectionFactory</classname> classes.
             </para>
             <programlisting><![CDATA[
-// Initialize HTTP parameters
-HttpParams params;
-// Initialize default SSL context
-SSLContext sslcontext = SSLContext.getInstance("SSL");
+SSLContext sslcontext = SSLContext.getInstance("Default");
 sslcontext.init(null, null, null);
+// Plain I/O session
+IOSession iosession = <...>
+
 SSLSetupHandler mysslhandler = new SSLSetupHandler() {
 
     public void initalize(final SSLEngine sslengine) throws SSLException {
@@ -2045,11 +1993,8 @@ SSLSetupHandler mysslhandler = new SSLSe
 
 
 };
-// Plain I/O session
-IOSession iosession;
 SSLNHttpClientConnectionFactory connfactory = new SSLNHttpClientConnectionFactory(
-        sslcontext, mysslhandler, params);
-// Create SSL connection
+        sslcontext, mysslhandler, ConnectionConfig.DEFAULT);
 NHttpClientConnection conn = connfactory.createConnection(iosession);
 ]]></programlisting>
             </section>

Modified: httpcomponents/httpcore/trunk/src/docbkx/preface.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/src/docbkx/preface.xml?rev=1499478&r1=1499477&r2=1499478&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/src/docbkx/preface.xml (original)
+++ httpcomponents/httpcore/trunk/src/docbkx/preface.xml Wed Jul  3 17:12:36 2013
@@ -88,7 +88,7 @@
             </listitem>
             <listitem>
                 <para>
-                A replacement for a Servlet container or a competitor to the Servlet API
+                A replacement for Servlet APIs
                 </para>
             </listitem>
         </itemizedlist>



Mime
View raw message