hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1414679 - in /httpcomponents/httpclient/trunk/httpclient/src: main/java/org/apache/http/impl/conn/ test/java/org/apache/http/impl/conn/ test/java/org/apache/http/mockup/
Date Wed, 28 Nov 2012 13:42:09 GMT
Author: olegk
Date: Wed Nov 28 13:42:08 2012
New Revision: 1414679

URL: http://svn.apache.org/viewvc?rev=1414679&view=rev
Log:
DefaultClientConnectionFactory to use lenient HttpResponseParser implementation

Added:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpResponseParserFactory.java
  (with props)
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/SessionInputBufferMock.java
  (contents, props changed)
      - copied, changed from r1414678, httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SessionInputBufferMockup.java
Removed:
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SessionInputBufferMockup.java
Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionFactory.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpResponseParser.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultHttpResponseParser.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionFactory.java?rev=1414679&r1=1414678&r2=1414679&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionFactory.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionFactory.java
Wed Nov 28 13:42:08 2012
@@ -65,7 +65,8 @@ public class DefaultClientConnectionFact
         return new SocketClientConnectionImpl(8 * 1024,
                 chardecoder, charencoder,
                 cconfig.getMessageConstraints(),
-                null, null, null, null);
+                null, null, null, 
+                DefaultHttpResponseParserFactory.INSTANCE);
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpResponseParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpResponseParser.java?rev=1414679&r1=1414678&r2=1414679&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpResponseParser.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpResponseParser.java
Wed Nov 28 13:42:08 2012
@@ -30,6 +30,7 @@ package org.apache.http.impl.conn;
 import java.io.IOException;
 
 import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.config.MessageConstraints;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -39,25 +40,22 @@ import org.apache.http.HttpResponseFacto
 import org.apache.http.NoHttpResponseException;
 import org.apache.http.ProtocolException;
 import org.apache.http.StatusLine;
+import org.apache.http.impl.DefaultHttpResponseFactory;
 import org.apache.http.impl.io.AbstractMessageParser;
 import org.apache.http.io.SessionInputBuffer;
+import org.apache.http.message.BasicLineParser;
 import org.apache.http.message.LineParser;
 import org.apache.http.message.ParserCursor;
 import org.apache.http.params.HttpParams;
 import org.apache.http.util.CharArrayBuffer;
 
 /**
- * Default HTTP response parser implementation.
- * <p>
- * The following parameters can be used to customize the behavior of this
- * class:
- * <ul>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_HEADER_COUNT}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}</li>
- * </ul>
+ * Lenient HTTP response parser implementation that can skip malformed data until 
+ * a valid HTTP response message head is encountered.
  *
  * @since 4.2
  */
+@SuppressWarnings("deprecation")
 @ThreadSafe // no public methods
 public class DefaultHttpResponseParser extends AbstractMessageParser<HttpResponse>
{
 
@@ -66,6 +64,11 @@ public class DefaultHttpResponseParser e
     private final HttpResponseFactory responseFactory;
     private final CharArrayBuffer lineBuf;
 
+    /**
+     * @deprecated (4.3) use {@link DefaultHttpResponseParser#DefaultHttpResponseParser(
+     *   SessionInputBuffer, LineParser, HttpResponseFactory, MessageConstraints)}
+     */
+    @Deprecated
     public DefaultHttpResponseParser(
             final SessionInputBuffer buffer,
             final LineParser parser,
@@ -79,6 +82,41 @@ public class DefaultHttpResponseParser e
         this.responseFactory = responseFactory;
         this.lineBuf = new CharArrayBuffer(128);
     }
+    
+    /**
+     * Creates new instance of DefaultHttpResponseParser.
+     *
+     * @param buffer the session input buffer.
+     * @param lineParser the line parser. If <code>null</code> {@link BasicLineParser#INSTANCE}
+     *   will be used.
+     * @param responseFactory HTTP response factory. If <code>null</code> 
+     *   {@link DefaultHttpResponseFactory#INSTANCE} will be used.
+     * @param constraints the message constraints. If <code>null</code>
+     *   {@link MessageConstraints#DEFAULT} will be used.
+     * 
+     * @since 4.3
+     */
+    public DefaultHttpResponseParser(
+            final SessionInputBuffer buffer,
+            final LineParser lineParser,
+            final HttpResponseFactory responseFactory,
+            final MessageConstraints constraints) {
+        super(buffer, lineParser, constraints);
+        this.responseFactory = responseFactory != null ? responseFactory :
+                DefaultHttpResponseFactory.INSTANCE;
+        this.lineBuf = new CharArrayBuffer(128);
+    }
+
+    /**
+     * Creates new instance of DefaultHttpResponseParser.
+     *
+     * @param buffer the session input buffer.
+     * 
+     * @since 4.3
+     */
+    public DefaultHttpResponseParser(final SessionInputBuffer buffer) {
+        this(buffer, null, null, MessageConstraints.DEFAULT);
+    }
 
     @Override
     protected HttpResponse parseHead(

Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpResponseParserFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpResponseParserFactory.java?rev=1414679&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpResponseParserFactory.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpResponseParserFactory.java
Wed Nov 28 13:42:08 2012
@@ -0,0 +1,71 @@
+/*
+ * ====================================================================
+ * 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.impl.conn;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpResponseFactory;
+import org.apache.http.annotation.Immutable;
+import org.apache.http.config.MessageConstraints;
+import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.io.HttpMessageParser;
+import org.apache.http.io.HttpMessageParserFactory;
+import org.apache.http.io.SessionInputBuffer;
+import org.apache.http.message.BasicLineParser;
+import org.apache.http.message.LineParser;
+
+/**
+ * Default factory for response message parsers.
+ *
+ * @since 4.3
+ */
+@Immutable
+public class DefaultHttpResponseParserFactory implements HttpMessageParserFactory<HttpResponse>
{
+
+    public static final DefaultHttpResponseParserFactory INSTANCE = new DefaultHttpResponseParserFactory();
+
+    private final LineParser lineParser;
+    private final HttpResponseFactory responseFactory;
+
+    public DefaultHttpResponseParserFactory(final LineParser lineParser,
+            final HttpResponseFactory responseFactory) {
+        super();
+        this.lineParser = lineParser != null ? lineParser : BasicLineParser.INSTANCE;
+        this.responseFactory = responseFactory != null ? responseFactory
+                : DefaultHttpResponseFactory.INSTANCE;
+    }
+
+    public DefaultHttpResponseParserFactory() {
+        this(null, null);
+    }
+
+    public HttpMessageParser<HttpResponse> create(final SessionInputBuffer buffer,
+            final MessageConstraints constraints) {
+        return new DefaultHttpResponseParser(buffer, lineParser, responseFactory, constraints);
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpResponseParserFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpResponseParserFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpResponseParserFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/SessionInputBufferMock.java
(from r1414678, httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SessionInputBufferMockup.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/SessionInputBufferMock.java?p2=httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/SessionInputBufferMock.java&p1=httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SessionInputBufferMockup.java&r1=1414678&r2=1414679&rev=1414679&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SessionInputBufferMockup.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/SessionInputBufferMock.java
Wed Nov 28 13:42:08 2012
@@ -25,95 +25,85 @@
  *
  */
 
-package org.apache.http.mockup;
+package org.apache.http.impl.conn;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
 
-import org.apache.http.impl.io.AbstractSessionInputBuffer;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpParams;
+import org.apache.http.config.MessageConstraints;
+import org.apache.http.impl.io.HttpTransportMetricsImpl;
+import org.apache.http.impl.io.SessionInputBufferImpl;
 
 /**
  * {@link org.apache.http.io.SessionInputBuffer} mockup implementation.
  */
-public class SessionInputBufferMockup extends AbstractSessionInputBuffer {
+public class SessionInputBufferMock extends SessionInputBufferImpl {
 
     public static final int BUFFER_SIZE = 16;
 
-    public SessionInputBufferMockup(
-            final InputStream instream,
-            int buffersize,
-            final HttpParams params) {
-        super();
-        init(instream, buffersize, params);
+    public SessionInputBufferMock(
+            final InputStream instream, 
+            int buffersize, 
+            final MessageConstraints constrains,
+            final CharsetDecoder decoder) {
+        super(new HttpTransportMetricsImpl(), buffersize, -1, constrains, decoder);
+        bind(instream);
     }
 
-    public SessionInputBufferMockup(
+    public SessionInputBufferMock(
             final InputStream instream,
             int buffersize) {
-        this(instream, buffersize, new BasicHttpParams());
+        this(instream, buffersize, null, null);
     }
 
-    public SessionInputBufferMockup(
+    public SessionInputBufferMock(
             final byte[] bytes,
-            final HttpParams params) {
-        this(bytes, BUFFER_SIZE, params);
-    }
-
-    public SessionInputBufferMockup(
-            final byte[] bytes) {
-        this(bytes, BUFFER_SIZE, new BasicHttpParams());
+            int buffersize,
+            final MessageConstraints constrains,
+            final CharsetDecoder decoder) {
+        this(new ByteArrayInputStream(bytes), buffersize, constrains, decoder);
     }
 
-    public SessionInputBufferMockup(
+    public SessionInputBufferMock(
             final byte[] bytes,
             int buffersize,
-            final HttpParams params) {
-        this(new ByteArrayInputStream(bytes), buffersize, params);
+            final MessageConstraints constrains) {
+        this(new ByteArrayInputStream(bytes), buffersize, constrains, null);
     }
 
-    public SessionInputBufferMockup(
+    public SessionInputBufferMock(
             final byte[] bytes,
             int buffersize) {
-        this(new ByteArrayInputStream(bytes), buffersize, new BasicHttpParams());
+        this(new ByteArrayInputStream(bytes), buffersize);
     }
 
-    public SessionInputBufferMockup(
-            final String s,
-            final String charset,
-            int buffersize,
-            final HttpParams params)
-        throws UnsupportedEncodingException {
-        this(s.getBytes(charset), buffersize, params);
+    public SessionInputBufferMock(
+            final byte[] bytes) {
+        this(bytes, BUFFER_SIZE);
     }
 
-    public SessionInputBufferMockup(
-            final String s,
-            final String charset,
-            int buffersize)
-        throws UnsupportedEncodingException {
-        this(s.getBytes(charset), buffersize, new BasicHttpParams());
+    public SessionInputBufferMock(
+            final byte[] bytes, final Charset charset) {
+        this(bytes, BUFFER_SIZE, null, charset != null ? charset.newDecoder() : null);
     }
 
-    public SessionInputBufferMockup(
-            final String s,
-            final String charset,
-            final HttpParams params)
-        throws UnsupportedEncodingException {
-        this(s.getBytes(charset), params);
+    public SessionInputBufferMock(
+            final byte[] bytes, 
+            final CharsetDecoder decoder) {
+        this(bytes, BUFFER_SIZE, null, decoder);
     }
 
-    public SessionInputBufferMockup(
+    public SessionInputBufferMock(
             final String s,
-            final String charset)
-        throws UnsupportedEncodingException {
-        this(s.getBytes(charset), new BasicHttpParams());
-
+            final Charset charset) throws UnsupportedEncodingException {
+        this(s.getBytes(charset.name()), charset);
     }
 
+    @Override
     public boolean isDataAvailable(int timeout) throws IOException {
         return true;
     }

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/SessionInputBufferMock.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/SessionInputBufferMock.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/SessionInputBufferMock.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultHttpResponseParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultHttpResponseParser.java?rev=1414679&r1=1414678&r2=1414679&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultHttpResponseParser.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultHttpResponseParser.java
Wed Nov 28 13:42:08 2012
@@ -27,24 +27,20 @@
 
 package org.apache.http.impl.conn;
 
+import org.apache.http.Consts;
 import org.apache.http.Header;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
 import org.apache.http.NoHttpResponseException;
 import org.apache.http.ProtocolException;
-import org.apache.http.impl.DefaultHttpResponseFactory;
 import org.apache.http.io.HttpMessageParser;
 import org.apache.http.io.SessionInputBuffer;
-import org.apache.http.message.BasicLineParser;
-import org.apache.http.mockup.SessionInputBufferMockup;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpParams;
 import org.apache.http.util.CharArrayBuffer;
 import org.junit.Assert;
 import org.junit.Test;
 
 /**
- * Tests for <code>DefaultResponseParser</code>.
+ * Tests for {@link DefaultResponseParser}.
  */
 public class TestDefaultHttpResponseParser {
 
@@ -59,13 +55,8 @@ public class TestDefaultHttpResponsePars
             "header2: value2\r\n" +
             "\r\n";
 
-        HttpParams params = new BasicHttpParams();
-        SessionInputBuffer inbuffer = new SessionInputBufferMockup(s, "US-ASCII", params);
-        HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(
-                inbuffer,
-                BasicLineParser.DEFAULT,
-                new DefaultHttpResponseFactory(),
-                params);
+        SessionInputBuffer inbuffer = new SessionInputBufferMock(s, Consts.ASCII);
+        HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(inbuffer);
 
         HttpResponse response = parser.parse();
         Assert.assertNotNull(response);
@@ -90,18 +81,13 @@ public class TestDefaultHttpResponsePars
             "header2: value2\r\n" +
             "\r\n";
 
-        HttpParams params = new BasicHttpParams();
-        SessionInputBuffer inbuffer = new SessionInputBufferMockup(s, "US-ASCII", params);
-        HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(
-                inbuffer,
-                BasicLineParser.DEFAULT,
-                new DefaultHttpResponseFactory(),
-                params) {
-
-                    @Override
-                    protected boolean reject(final CharArrayBuffer line, int count) {
-                        return count >= 2;
-                    }
+        SessionInputBuffer inbuffer = new SessionInputBufferMock(s, Consts.ASCII);
+        HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(inbuffer)
{
+
+            @Override
+            protected boolean reject(final CharArrayBuffer line, int count) {
+                return count >= 2;
+            }
 
         };
         parser.parse();
@@ -109,13 +95,8 @@ public class TestDefaultHttpResponsePars
 
     @Test(expected=NoHttpResponseException.class)
     public void testResponseParsingNoResponse() throws Exception {
-        HttpParams params = new BasicHttpParams();
-        SessionInputBuffer inbuffer = new SessionInputBufferMockup("", "US-ASCII", params);
-        HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(
-                inbuffer,
-                BasicLineParser.DEFAULT,
-                new DefaultHttpResponseFactory(),
-                params);
+        SessionInputBuffer inbuffer = new SessionInputBufferMock("", Consts.ASCII);
+        HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(inbuffer);
         parser.parse();
     }
 
@@ -126,13 +107,8 @@ public class TestDefaultHttpResponsePars
             "garbage\r\n" +
             "more garbage\r\n" +
             "a lot more garbage\r\n";
-        HttpParams params = new BasicHttpParams();
-        SessionInputBuffer inbuffer = new SessionInputBufferMockup(s, "US-ASCII", params);
-        HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(
-                inbuffer,
-                BasicLineParser.DEFAULT,
-                new DefaultHttpResponseFactory(),
-                params);
+        SessionInputBuffer inbuffer = new SessionInputBufferMock(s, Consts.ASCII);
+        HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(inbuffer);
         parser.parse();
     }
 



Mime
View raw message