hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rola...@apache.org
Subject svn commit: r569662 - in /jakarta/httpcomponents/httpcore/trunk: module-main/src/main/java/org/apache/http/impl/ module-main/src/main/java/org/apache/http/impl/io/ module-main/src/main/java/org/apache/http/message/ module-nio/src/main/java/org/apache/h...
Date Sat, 25 Aug 2007 13:20:23 GMT
Author: rolandw
Date: Sat Aug 25 06:20:22 2007
New Revision: 569662

URL: http://svn.apache.org/viewvc?rev=569662&view=rev
Log:
introduced LineFormatter interface

Added:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java
  (with props)
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineFormatter.java
  (with props)
Modified:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/AbstractMessageWriter.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpRequestWriter.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpResponseWriter.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeader.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicRequestLine.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicStatusLine.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineParser.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractMessageWriter.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/HttpRequestWriter.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/HttpResponseWriter.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java?rev=569662&r1=569661&r2=569662&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java
Sat Aug 25 06:20:22 2007
@@ -105,7 +105,8 @@
     protected HttpMessageWriter createRequestWriter(
             final SessionOutputBuffer buffer,
             final HttpParams params) {
-        return new HttpRequestWriter(buffer, params);
+        //@@@ how to configure the formatter?
+        return new HttpRequestWriter(buffer, null, params);
     }
     
     protected void init(

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java?rev=569662&r1=569661&r2=569662&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
Sat Aug 25 06:20:22 2007
@@ -105,7 +105,8 @@
     protected HttpMessageWriter createResponseWriter(
             final SessionOutputBuffer buffer,
             final HttpParams params) {
-        return new HttpResponseWriter(buffer, params);
+        //@@@ how to configure the formatter?
+        return new HttpResponseWriter(buffer, null, params);
     }
     
     protected void init(

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/AbstractMessageWriter.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/AbstractMessageWriter.java?rev=569662&r1=569661&r2=569662&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/AbstractMessageWriter.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/AbstractMessageWriter.java
Sat Aug 25 06:20:22 2007
@@ -39,45 +39,44 @@
 import org.apache.http.HttpMessage;
 import org.apache.http.io.HttpMessageWriter;
 import org.apache.http.io.SessionOutputBuffer;
-import org.apache.http.message.BasicHeader;
-import org.apache.http.message.BufferedHeader;
+import org.apache.http.message.LineFormatter;
+import org.apache.http.message.BasicLineFormatter;
 import org.apache.http.params.HttpParams;
 import org.apache.http.util.CharArrayBuffer;
 
 public abstract class AbstractMessageWriter implements HttpMessageWriter {
     
-    private final SessionOutputBuffer sessionBuffer;    
-    private final CharArrayBuffer lineBuf;
-    
-    public AbstractMessageWriter(final SessionOutputBuffer buffer, final HttpParams params)
{
+    protected final SessionOutputBuffer sessionBuffer;    
+    protected final CharArrayBuffer lineBuf;
+    protected final LineFormatter lineFormatter;
+
+    public AbstractMessageWriter(final SessionOutputBuffer buffer,
+                                 final LineFormatter formatter,
+                                 final HttpParams params) {
         super();
         if (buffer == null) {
             throw new IllegalArgumentException("Session input buffer may not be null");
         }
         this.sessionBuffer = buffer;
-        this.lineBuf = new CharArrayBuffer(128); 
+        this.lineBuf = new CharArrayBuffer(128);
+        this.lineFormatter = (formatter != null) ?
+            formatter : BasicLineFormatter.DEFAULT;
     }
     
-    protected abstract void writeHeadLine(CharArrayBuffer lineBuffer, HttpMessage message);
+    protected abstract void writeHeadLine(HttpMessage message)
+        throws IOException
+        ;
 
     public void write(
             final HttpMessage message) throws IOException, HttpException {
         if (message == null) {
             throw new IllegalArgumentException("HTTP message may not be null");
         }
-        this.lineBuf.clear();
-        writeHeadLine(this.lineBuf, message);
-        this.sessionBuffer.writeLine(this.lineBuf);
+        writeHeadLine(message);
         for (Iterator it = message.headerIterator(); it.hasNext(); ) {
             Header header = (Header) it.next();
-            if (header instanceof BufferedHeader) {
-                // If the header is backed by a buffer, re-use the buffer
-                this.sessionBuffer.writeLine(((BufferedHeader)header).getBuffer());
-            } else {
-                this.lineBuf.clear();
-                BasicHeader.format(this.lineBuf, header);
-                this.sessionBuffer.writeLine(this.lineBuf);
-            }
+            this.sessionBuffer.writeLine
+                (lineFormatter.formatHeader(header, this.lineBuf));
         }
         this.lineBuf.clear();
         this.sessionBuffer.writeLine(this.lineBuf);

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpRequestWriter.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpRequestWriter.java?rev=569662&r1=569661&r2=569662&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpRequestWriter.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpRequestWriter.java
Sat Aug 25 06:20:22 2007
@@ -31,23 +31,29 @@
 
 package org.apache.http.impl.io;
 
+import java.io.IOException;
+
 import org.apache.http.HttpMessage;
 import org.apache.http.HttpRequest;
 import org.apache.http.io.SessionOutputBuffer;
-import org.apache.http.message.BasicRequestLine;
+import org.apache.http.message.LineFormatter;
 import org.apache.http.params.HttpParams;
 import org.apache.http.util.CharArrayBuffer;
 
 public class HttpRequestWriter extends AbstractMessageWriter {
 
-    public HttpRequestWriter(final SessionOutputBuffer buffer, final HttpParams params) {
-        super(buffer, params);
+    public HttpRequestWriter(final SessionOutputBuffer buffer,
+                             final LineFormatter formatter,
+                             final HttpParams params) {
+        super(buffer, formatter, params);
     }
     
-    protected void writeHeadLine(
-            final CharArrayBuffer lineBuffer, 
-            final HttpMessage message) {
-        BasicRequestLine.format(lineBuffer, ((HttpRequest) message).getRequestLine());
+    protected void writeHeadLine(final HttpMessage message)
+        throws IOException {
+
+        final CharArrayBuffer buffer = lineFormatter.formatRequestLine
+            (((HttpRequest) message).getRequestLine(), this.lineBuf);
+        this.sessionBuffer.writeLine(buffer);
     }
 
 }

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpResponseWriter.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpResponseWriter.java?rev=569662&r1=569661&r2=569662&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpResponseWriter.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpResponseWriter.java
Sat Aug 25 06:20:22 2007
@@ -31,23 +31,29 @@
 
 package org.apache.http.impl.io;
 
+import java.io.IOException;
+
 import org.apache.http.HttpMessage;
 import org.apache.http.HttpResponse;
 import org.apache.http.io.SessionOutputBuffer;
-import org.apache.http.message.BasicStatusLine;
+import org.apache.http.message.LineFormatter;
 import org.apache.http.params.HttpParams;
 import org.apache.http.util.CharArrayBuffer;
 
 public class HttpResponseWriter extends AbstractMessageWriter {
 
-    public HttpResponseWriter(final SessionOutputBuffer buffer, final HttpParams params)
{
-        super(buffer, params);
+    public HttpResponseWriter(final SessionOutputBuffer buffer,
+                              final LineFormatter formatter,
+                              final HttpParams params) {
+        super(buffer, formatter, params);
     }
     
-    protected void writeHeadLine(
-            final CharArrayBuffer lineBuffer, 
-            final HttpMessage message) {
-        BasicStatusLine.format(lineBuffer, ((HttpResponse) message).getStatusLine());
+    protected void writeHeadLine(final HttpMessage message)
+        throws IOException {
+
+        final CharArrayBuffer buffer = lineFormatter.formatStatusLine
+            (((HttpResponse) message).getStatusLine(), this.lineBuf);
+        this.sessionBuffer.writeLine(buffer);
     }
 
 }

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeader.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeader.java?rev=569662&r1=569661&r2=569662&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeader.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeader.java
Sat Aug 25 06:20:22 2007
@@ -150,7 +150,7 @@
      * @param buffer the buffer to append to
      * @param header the header to format
      */
-    public static void format(final CharArrayBuffer buffer, final Header header) {
+    /*public@@@*/ static void format(final CharArrayBuffer buffer, final Header header) {
         if (buffer == null) {
             throw new IllegalArgumentException("String buffer may not be null");
         }
@@ -167,7 +167,7 @@
     /**
      * @see #format(CharArrayBuffer, Header)
      */
-    public static String format(final Header header) {
+    /*public@@@*/ static String format(final Header header) {
         CharArrayBuffer buffer = new CharArrayBuffer(32);
         format(buffer, header);
         return buffer.toString();

Added: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java?rev=569662&view=auto
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java
(added)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java
Sat Aug 25 06:20:22 2007
@@ -0,0 +1,135 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.message;
+
+
+import org.apache.http.HttpVersion;
+import org.apache.http.RequestLine;
+import org.apache.http.StatusLine;
+import org.apache.http.Header;
+import org.apache.http.util.CharArrayBuffer;
+
+
+/**
+ * Interface for formatting elements of the HEAD section of an HTTP message.
+ * This is the complement to {@link LineParser}.
+ * There are individual methods for formatting a request line, a
+ * status line, or a header line. The formatting does <i>not</i> include the
+ * trailing line break sequence CR-LF.
+ * The formatted lines are returned in memory, the formatter does not depend
+ * on any specific IO mechanism.
+ * Instances of this interface are expected to be stateless and thread-safe.
+ *
+ * @author <a href="mailto:rolandw AT apache.org">Roland Weber</a>
+ *
+ *
+ * <!-- empty lines above to avoid 'svn diff' context problems -->
+ * @version $Revision$ $Date$
+ *
+ * @since 4.0
+ */
+public class BasicLineFormatter implements LineFormatter {
+
+    /**
+     * A default instance of this class, for use as default or fallback.
+     * Note that {@link BasicLineFormatter} is not a singleton, there can
+     * be many instances of the class itself and of derived classes.
+     * The instance here provides non-customized, default behavior.
+     */
+    public final static BasicLineFormatter DEFAULT = new BasicLineFormatter();
+
+
+
+    // public default constructor
+
+
+    /**
+     * Obtains a buffer for formatting.
+     *
+     * @param buffer    a buffer already available, or <code>null</code>
+     *
+     * @return  the cleared argument buffer if there is one, or
+     *          a new empty buffer that can be used for formatting
+     */
+    protected CharArrayBuffer initBuffer(CharArrayBuffer buffer) {
+        if (buffer != null) {
+            buffer.clear();
+        } else {
+            buffer = new CharArrayBuffer(64);
+        }
+        return buffer;
+    }
+
+
+    // non-javadoc, see interface LineFormatter
+    public CharArrayBuffer formatRequestLine(RequestLine reqline,
+                                             CharArrayBuffer buffer) {
+
+        CharArrayBuffer result = initBuffer(buffer);
+        BasicRequestLine.format(result, reqline); //@@@ move code here
+        return result;
+    }
+
+
+
+    // non-javadoc, see interface LineFormatter
+    public CharArrayBuffer formatStatusLine(StatusLine statline,
+                                            CharArrayBuffer buffer) {
+        CharArrayBuffer result = initBuffer(buffer);
+        BasicStatusLine.format(result, statline); //@@@ move code here
+        return result;
+    }
+
+
+
+    // non-javadoc, see interface LineFormatter
+    public CharArrayBuffer formatHeader(Header header,
+                                        CharArrayBuffer buffer) {
+        if (header == null) {
+            throw new IllegalArgumentException
+                ("Header must not be null.");
+        }
+        CharArrayBuffer result = null;
+
+        if (header instanceof BufferedHeader) {
+            // If the header is backed by a buffer, re-use the buffer
+            result = ((BufferedHeader)header).getBuffer();
+        } else {
+            result = initBuffer(buffer);
+            BasicHeader.format(result, header); //@@@ move code here
+        }
+        return result;
+
+    } // formatHeader
+
+
+} // class BasicLineFormatter

Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicRequestLine.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicRequestLine.java?rev=569662&r1=569661&r2=569662&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicRequestLine.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicRequestLine.java
Sat Aug 25 06:20:22 2007
@@ -94,7 +94,7 @@
         return buffer.toString();
     }
     
-    public static void format(final CharArrayBuffer buffer, final RequestLine requestline)
{
+    /*public@@@*/ static void format(final CharArrayBuffer buffer, final RequestLine requestline)
{
         if (buffer == null) {
             throw new IllegalArgumentException("String buffer may not be null");
         }
@@ -108,7 +108,7 @@
         BasicHttpVersionFormat.format(buffer, requestline.getHttpVersion());
     }
  
-    public static String format(final RequestLine requestline) {
+    /*public@@@*/ static String format(final RequestLine requestline) {
         CharArrayBuffer buffer = new CharArrayBuffer(64);
         format(buffer, requestline);
         return buffer.toString();

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicStatusLine.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicStatusLine.java?rev=569662&r1=569661&r2=569662&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicStatusLine.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicStatusLine.java
Sat Aug 25 06:20:22 2007
@@ -126,7 +126,7 @@
         return buffer.toString();
     }
     
-    public static void format(final CharArrayBuffer buffer, final StatusLine statusline)
{
+    /*public@@@*/ static void format(final CharArrayBuffer buffer, final StatusLine statusline)
{
         if (buffer == null) {
             throw new IllegalArgumentException("String buffer may not be null");
         }
@@ -142,7 +142,7 @@
         }
     }
  
-    public static String format(final StatusLine statusline) {
+    /*public@@@*/ static String format(final StatusLine statusline) {
         CharArrayBuffer buffer = new CharArrayBuffer(32);
         format(buffer, statusline);
         return buffer.toString();

Added: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineFormatter.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineFormatter.java?rev=569662&view=auto
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineFormatter.java
(added)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineFormatter.java
Sat Aug 25 06:20:22 2007
@@ -0,0 +1,129 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.message;
+
+
+import org.apache.http.HttpVersion;
+import org.apache.http.RequestLine;
+import org.apache.http.StatusLine;
+import org.apache.http.Header;
+import org.apache.http.util.CharArrayBuffer;
+
+
+/**
+ * Interface for formatting elements of the HEAD section of an HTTP message.
+ * This is the complement to {@link LineParser}.
+ * There are individual methods for formatting a request line, a
+ * status line, or a header line. The formatting does <i>not</i> include the
+ * trailing line break sequence CR-LF.
+ * Instances of this interface are expected to be stateless and thread-safe.
+ *
+ * <p>
+ * The formatted lines are returned in memory, the formatter does not depend
+ * on any specific IO mechanism.
+ * In order to avoid unnecessary creation of temporary objects,
+ * a buffer can be passed as argument to all formatting methods.
+ * The implementation may or may not actually use that buffer for formatting.
+ * If it is used, the buffer will first be cleared.
+ * The argument buffer can always be re-used after the call. The buffer
+ * returned as the result, if it is different from the argument buffer,
+ * MUST NOT be modified.
+ * </p>
+ *
+ *
+ * @author <a href="mailto:rolandw AT apache.org">Roland Weber</a>
+ *
+ *
+ * <!-- empty lines above to avoid 'svn diff' context problems -->
+ * @version $Revision$ $Date$
+ *
+ * @since 4.0
+ */
+public interface LineFormatter {
+
+
+    /**
+     * Formats a request line.
+     *
+     * @param reqline   the request line to format
+     * @param buffer    a buffer available for formatting, or
+     *                  <code>null</code>.
+     *                  The buffer will be cleared before use.
+     *
+     * @return  the formatted request line
+     */
+    CharArrayBuffer formatRequestLine(RequestLine reqline,
+                                      CharArrayBuffer buffer) 
+        ;
+
+
+    /**
+     * Formats a status line.
+     *
+     * @param statline  the status line to format
+     * @param buffer    a buffer available for formatting, or
+     *                  <code>null</code>.
+     *                  The buffer will be cleared before use.
+     * @param buffer    a buffer holding the line to parse
+     *
+     * @return  the formatted status line
+     *
+     * @throws ParseException        in case of a parse error
+     */
+    CharArrayBuffer formatStatusLine(StatusLine statline,
+                                     CharArrayBuffer buffer) 
+        ;
+
+
+    /**
+     * Formats a header.
+     * Due to header continuation, the result may be multiple lines.
+     * In order to generate well-formed HTTP, the lines in the result
+     * must be separated by the HTTP line break sequence CR-LF.
+     * There is <i>no</i> trailing CR-LF in the result.
+     * <br/>
+     * See the class comment for details about the buffer argument.
+     *
+     * @param header    the header to format
+     * @param buffer    a buffer available for formatting, or
+     *                  <code>null</code>.
+     *                  The buffer will be cleared before use.
+     *
+     * @return  a buffer holding the formatted header, never <code>null</code>.
+     *          The returned buffer may be different from the argument buffer.
+     *
+     * @throws ParseException        in case of a parse error
+     */
+    CharArrayBuffer formatHeader(Header header, CharArrayBuffer buffer)
+        ;
+
+}

Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineFormatter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineFormatter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineFormatter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineParser.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineParser.java?rev=569662&r1=569661&r2=569662&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineParser.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineParser.java
Sat Aug 25 06:20:22 2007
@@ -48,6 +48,8 @@
  * on any specific IO mechanism.
  * Instances of this interface are expected to be stateless and thread-safe.
  *
+ * @author <a href="mailto:rolandw AT apache.org">Roland Weber</a>
+ *
  *
  * <!-- empty lines above to avoid 'svn diff' context problems -->
  * @version $Revision$ $Date$

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java?rev=569662&r1=569661&r2=569662&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
Sat Aug 25 06:20:22 2007
@@ -85,7 +85,8 @@
     protected NHttpMessageWriter createRequestWriter(
             final SessionOutputBuffer buffer,
             final HttpParams params) {
-        return new HttpRequestWriter(buffer, params);
+        //@@@ how to configure the formatter?
+        return new HttpRequestWriter(buffer, null, params);
     }
     
     public void resetInput() {

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java?rev=569662&r1=569661&r2=569662&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
Sat Aug 25 06:20:22 2007
@@ -82,7 +82,8 @@
     protected NHttpMessageWriter createResponseWriter(
             final SessionOutputBuffer buffer,
             final HttpParams params) {
-        return new HttpResponseWriter(buffer, params);
+        //@@@ how to configure the formatter?
+        return new HttpResponseWriter(buffer, null, params);
     }
     
     public void resetInput() {

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractMessageWriter.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractMessageWriter.java?rev=569662&r1=569661&r2=569662&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractMessageWriter.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractMessageWriter.java
Sat Aug 25 06:20:22 2007
@@ -37,8 +37,8 @@
 import org.apache.http.Header;
 import org.apache.http.HttpException;
 import org.apache.http.HttpMessage;
-import org.apache.http.message.BasicHeader;
-import org.apache.http.message.BufferedHeader;
+import org.apache.http.message.LineFormatter;
+import org.apache.http.message.BasicLineFormatter;
 import org.apache.http.nio.NHttpMessageWriter;
 import org.apache.http.nio.reactor.SessionOutputBuffer;
 import org.apache.http.params.HttpParams;
@@ -46,41 +46,39 @@
 
 public abstract class AbstractMessageWriter implements NHttpMessageWriter {
     
-    private final SessionOutputBuffer sessionBuffer;    
-    private final CharArrayBuffer lineBuf;
-    
-    public AbstractMessageWriter(final SessionOutputBuffer buffer, final HttpParams params)
{
+    protected final SessionOutputBuffer sessionBuffer;    
+    protected final CharArrayBuffer lineBuf;
+    protected final LineFormatter lineFormatter;
+
+    public AbstractMessageWriter(final SessionOutputBuffer buffer,
+                                 final LineFormatter formatter,
+                                 final HttpParams params) {
         super();
         if (buffer == null) {
             throw new IllegalArgumentException("Session input buffer may not be null");
         }
         this.sessionBuffer = buffer;
-        this.lineBuf = new CharArrayBuffer(64); 
+        this.lineBuf = new CharArrayBuffer(64);
+        this.lineFormatter = (formatter != null) ?
+            formatter : BasicLineFormatter.DEFAULT;
     }
     
     public void reset() {
     }
     
-    protected abstract void writeHeadLine(CharArrayBuffer lineBuffer, HttpMessage message);
+    protected abstract void writeHeadLine(HttpMessage message)
+        throws IOException;
 
     public void write(
             final HttpMessage message) throws IOException, HttpException {
         if (message == null) {
             throw new IllegalArgumentException("HTTP message may not be null");
         }
-        this.lineBuf.clear();
-        writeHeadLine(this.lineBuf, message);
-        this.sessionBuffer.writeLine(this.lineBuf);
+        writeHeadLine(message);
         for (Iterator it = message.headerIterator(); it.hasNext(); ) {
             Header header = (Header) it.next();
-            if (header instanceof BufferedHeader) {
-                // If the header is backed by a buffer, re-use the buffer
-                this.sessionBuffer.writeLine(((BufferedHeader)header).getBuffer());
-            } else {
-                this.lineBuf.clear();
-                BasicHeader.format(this.lineBuf, header);
-                this.sessionBuffer.writeLine(this.lineBuf);
-            }
+            this.sessionBuffer.writeLine
+                (lineFormatter.formatHeader(header, this.lineBuf));
         }
         this.lineBuf.clear();
         this.sessionBuffer.writeLine(this.lineBuf);

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/HttpRequestWriter.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/HttpRequestWriter.java?rev=569662&r1=569661&r2=569662&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/HttpRequestWriter.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/HttpRequestWriter.java
Sat Aug 25 06:20:22 2007
@@ -31,23 +31,29 @@
 
 package org.apache.http.impl.nio.codecs;
 
+import java.io.IOException;
+
 import org.apache.http.HttpMessage;
 import org.apache.http.HttpRequest;
-import org.apache.http.message.BasicRequestLine;
+import org.apache.http.message.LineFormatter;
 import org.apache.http.nio.reactor.SessionOutputBuffer;
 import org.apache.http.params.HttpParams;
 import org.apache.http.util.CharArrayBuffer;
 
 public class HttpRequestWriter extends AbstractMessageWriter {
 
-    public HttpRequestWriter(final SessionOutputBuffer buffer, final HttpParams params) {
-        super(buffer, params);
+    public HttpRequestWriter(final SessionOutputBuffer buffer,
+                             final LineFormatter formatter,
+                             final HttpParams params) {
+        super(buffer, formatter, params);
     }
     
-    protected void writeHeadLine(
-            final CharArrayBuffer lineBuffer, 
-            final HttpMessage message) {
-        BasicRequestLine.format(lineBuffer, ((HttpRequest) message).getRequestLine());
+    protected void writeHeadLine(final HttpMessage message)
+        throws IOException {
+
+        final CharArrayBuffer buffer = lineFormatter.formatRequestLine
+            (((HttpRequest) message).getRequestLine(), this.lineBuf);
+        this.sessionBuffer.writeLine(buffer);
     }
 
 }

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/HttpResponseWriter.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/HttpResponseWriter.java?rev=569662&r1=569661&r2=569662&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/HttpResponseWriter.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/HttpResponseWriter.java
Sat Aug 25 06:20:22 2007
@@ -31,23 +31,29 @@
 
 package org.apache.http.impl.nio.codecs;
 
+import java.io.IOException;
+
 import org.apache.http.HttpMessage;
 import org.apache.http.HttpResponse;
-import org.apache.http.message.BasicStatusLine;
+import org.apache.http.message.LineFormatter;
 import org.apache.http.nio.reactor.SessionOutputBuffer;
 import org.apache.http.params.HttpParams;
 import org.apache.http.util.CharArrayBuffer;
 
 public class HttpResponseWriter extends AbstractMessageWriter {
 
-    public HttpResponseWriter(final SessionOutputBuffer buffer, final HttpParams params)
{
-        super(buffer, params);
+    public HttpResponseWriter(final SessionOutputBuffer buffer,
+                              final LineFormatter formatter,
+                              final HttpParams params) {
+        super(buffer, formatter, params);
     }
     
-    protected void writeHeadLine(
-            final CharArrayBuffer lineBuffer, 
-            final HttpMessage message) {
-        BasicStatusLine.format(lineBuffer, ((HttpResponse) message).getStatusLine());
+    protected void writeHeadLine(final HttpMessage message)
+        throws IOException {
+
+        final CharArrayBuffer buffer = lineFormatter.formatStatusLine
+            (((HttpResponse) message).getStatusLine(), this.lineBuf);
+        this.sessionBuffer.writeLine(buffer);
     }
 
 }



Mime
View raw message