hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1495811 - in /httpcomponents/httpcore/trunk: httpcore-nio/src/main/java/org/apache/http/impl/nio/ httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ httpcore/src/main/java/org/apache/http/impl/ httpcore/src/main/java/org/apache/h...
Date Sun, 23 Jun 2013 12:24:01 GMT
Author: olegk
Date: Sun Jun 23 12:24:01 2013
New Revision: 1495811

URL: http://svn.apache.org/r1495811
Log:
Cleaned up blocking and non-blocking connection initialization

Added:
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/ConnSupport.java
  (with props)
Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnectionFactory.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnectionFactory.java?rev=1495811&r1=1495810&r2=1495811&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnectionFactory.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnectionFactory.java
Sun Jun 23 12:24:01 2013
@@ -26,15 +26,11 @@
  */
 package org.apache.http.impl.nio;
 
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpResponseFactory;
 import org.apache.http.annotation.Immutable;
 import org.apache.http.config.ConnectionConfig;
+import org.apache.http.impl.ConnSupport;
 import org.apache.http.impl.DefaultHttpResponseFactory;
 import org.apache.http.impl.nio.codecs.DefaultHttpResponseParserFactory;
 import org.apache.http.nio.NHttpConnectionFactory;
@@ -59,7 +55,7 @@ public class DefaultNHttpClientConnectio
 
     private final NHttpMessageParserFactory<HttpResponse> responseParserFactory;
     private final ByteBufferAllocator allocator;
-    private final ConnectionConfig config;
+    private final ConnectionConfig cconfig;
 
     /**
      * @deprecated (4.3) use {@link
@@ -77,12 +73,13 @@ public class DefaultNHttpClientConnectio
         Args.notNull(params, "HTTP parameters");
         this.allocator = allocator;
         this.responseParserFactory = new DefaultHttpResponseParserFactory(null, responseFactory);
-        this.config = HttpParamConfig.getConnectionConfig(params);
+        this.cconfig = HttpParamConfig.getConnectionConfig(params);
     }
 
     /**
      * @deprecated (4.3) use {@link
-     *   DefaultNHttpClientConnectionFactory#DefaultNHttpClientConnectionFactory(ConnectionConfig)}
+     *   DefaultNHttpClientConnectionFactory#DefaultNHttpClientConnectionFactory(
+     *     ConnectionConfig)}
      */
     @Deprecated
     public DefaultNHttpClientConnectionFactory(final HttpParams params) {
@@ -95,19 +92,19 @@ public class DefaultNHttpClientConnectio
     public DefaultNHttpClientConnectionFactory(
             final NHttpMessageParserFactory<HttpResponse> responseParserFactory,
             final ByteBufferAllocator allocator,
-            final ConnectionConfig config) {
+            final ConnectionConfig cconfig) {
         super();
         this.allocator = allocator != null ? allocator : HeapByteBufferAllocator.INSTANCE;
         this.responseParserFactory = responseParserFactory != null ? responseParserFactory
:
             DefaultHttpResponseParserFactory.INSTANCE;
-        this.config = config != null ? config : ConnectionConfig.DEFAULT;
+        this.cconfig = cconfig != null ? cconfig : ConnectionConfig.DEFAULT;
     }
 
     /**
      * @since 4.3
      */
-    public DefaultNHttpClientConnectionFactory(final ConnectionConfig config) {
-        this(null, null, config);
+    public DefaultNHttpClientConnectionFactory(final ConnectionConfig cconfig) {
+        this(null, null, cconfig);
     }
 
     /**
@@ -123,27 +120,14 @@ public class DefaultNHttpClientConnectio
     }
 
     public DefaultNHttpClientConnection createConnection(final IOSession session) {
-        CharsetDecoder chardecoder = null;
-        CharsetEncoder charencoder = null;
-        final Charset charset = this.config.getCharset();
-        final CodingErrorAction malformedInputAction = this.config.getMalformedInputAction()
!= null ?
-                this.config.getMalformedInputAction() : CodingErrorAction.REPORT;
-        final CodingErrorAction unmappableInputAction = this.config.getUnmappableInputAction()
!= null ?
-                this.config.getUnmappableInputAction() : CodingErrorAction.REPORT;
-        if (charset != null) {
-            chardecoder = charset.newDecoder();
-            chardecoder.onMalformedInput(malformedInputAction);
-            chardecoder.onUnmappableCharacter(unmappableInputAction);
-            charencoder = charset.newEncoder();
-            charencoder.onMalformedInput(malformedInputAction);
-            charencoder.onUnmappableCharacter(unmappableInputAction);
-        }
         return new DefaultNHttpClientConnection(
                 session,
-                this.config.getBufferSize(),
-                this.config.getFragmentSizeHint(),
+                this.cconfig.getBufferSize(),
+                this.cconfig.getFragmentSizeHint(),
                 this.allocator,
-                chardecoder, charencoder, this.config.getMessageConstraints(),
+                ConnSupport.createDecoder(this.cconfig),
+                ConnSupport.createEncoder(this.cconfig),
+                this.cconfig.getMessageConstraints(),
                 null, null, null,
                 this.responseParserFactory);
     }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java?rev=1495811&r1=1495810&r2=1495811&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java
Sun Jun 23 12:24:01 2013
@@ -26,15 +26,11 @@
  */
 package org.apache.http.impl.nio;
 
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestFactory;
 import org.apache.http.annotation.Immutable;
 import org.apache.http.config.ConnectionConfig;
+import org.apache.http.impl.ConnSupport;
 import org.apache.http.impl.DefaultHttpRequestFactory;
 import org.apache.http.impl.nio.codecs.DefaultHttpRequestParserFactory;
 import org.apache.http.nio.NHttpConnectionFactory;
@@ -59,7 +55,7 @@ public class DefaultNHttpServerConnectio
 
     private final NHttpMessageParserFactory<HttpRequest> requestParserFactory;
     private final ByteBufferAllocator allocator;
-    private final ConnectionConfig config;
+    private final ConnectionConfig cconfig;
 
     /**
      * @deprecated (4.3) use {@link
@@ -77,7 +73,7 @@ public class DefaultNHttpServerConnectio
         Args.notNull(params, "HTTP parameters");
         this.requestParserFactory = new DefaultHttpRequestParserFactory(null, requestFactory);
         this.allocator = allocator;
-        this.config = HttpParamConfig.getConnectionConfig(params);
+        this.cconfig = HttpParamConfig.getConnectionConfig(params);
     }
 
     /**
@@ -107,12 +103,12 @@ public class DefaultNHttpServerConnectio
     public DefaultNHttpServerConnectionFactory(
             final ByteBufferAllocator allocator,
             final NHttpMessageParserFactory<HttpRequest> requestParserFactory,
-            final ConnectionConfig config) {
+            final ConnectionConfig cconfig) {
         super();
         this.allocator = allocator != null ? allocator : HeapByteBufferAllocator.INSTANCE;
         this.requestParserFactory = requestParserFactory != null ? requestParserFactory :
             DefaultHttpRequestParserFactory.INSTANCE;
-        this.config = config != null ? config : ConnectionConfig.DEFAULT;
+        this.cconfig = cconfig != null ? cconfig : ConnectionConfig.DEFAULT;
     }
 
     /**
@@ -123,26 +119,13 @@ public class DefaultNHttpServerConnectio
     }
 
     public DefaultNHttpServerConnection createConnection(final IOSession session) {
-        CharsetDecoder chardecoder = null;
-        CharsetEncoder charencoder = null;
-        final Charset charset = this.config.getCharset();
-        final CodingErrorAction malformedInputAction = this.config.getMalformedInputAction()
!= null ?
-                this.config.getMalformedInputAction() : CodingErrorAction.REPORT;
-        final CodingErrorAction unmappableInputAction = this.config.getUnmappableInputAction()
!= null ?
-                this.config.getUnmappableInputAction() : CodingErrorAction.REPORT;
-        if (charset != null) {
-            chardecoder = charset.newDecoder();
-            chardecoder.onMalformedInput(malformedInputAction);
-            chardecoder.onUnmappableCharacter(unmappableInputAction);
-            charencoder = charset.newEncoder();
-            charencoder.onMalformedInput(malformedInputAction);
-            charencoder.onUnmappableCharacter(unmappableInputAction);
-        }
         return new DefaultNHttpServerConnection(session,
-                this.config.getBufferSize(),
-                this.config.getFragmentSizeHint(),
+                this.cconfig.getBufferSize(),
+                this.cconfig.getFragmentSizeHint(),
                 this.allocator,
-                chardecoder, charencoder, this.config.getMessageConstraints(),
+                ConnSupport.createDecoder(this.cconfig),
+                ConnSupport.createEncoder(this.cconfig),
+                this.cconfig.getMessageConstraints(),
                 null, null,
                 this.requestParserFactory,
                 null);

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java?rev=1495811&r1=1495810&r2=1495811&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java
Sun Jun 23 12:24:01 2013
@@ -26,17 +26,13 @@
  */
 package org.apache.http.impl.nio;
 
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
 import javax.net.ssl.SSLContext;
 
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpResponseFactory;
 import org.apache.http.annotation.Immutable;
 import org.apache.http.config.ConnectionConfig;
+import org.apache.http.impl.ConnSupport;
 import org.apache.http.impl.DefaultHttpResponseFactory;
 import org.apache.http.impl.nio.codecs.DefaultHttpResponseParserFactory;
 import org.apache.http.nio.NHttpConnectionFactory;
@@ -66,7 +62,7 @@ public class SSLNHttpClientConnectionFac
     private final ByteBufferAllocator allocator;
     private final SSLContext sslcontext;
     private final SSLSetupHandler sslHandler;
-    private final ConnectionConfig config;
+    private final ConnectionConfig cconfig;
 
     /**
      * @deprecated (4.3) use {@link
@@ -88,7 +84,7 @@ public class SSLNHttpClientConnectionFac
         this.sslHandler = sslHandler;
         this.allocator = allocator;
         this.responseParserFactory = new DefaultHttpResponseParserFactory(null, responseFactory);
-        this.config = HttpParamConfig.getConnectionConfig(params);
+        this.cconfig = HttpParamConfig.getConnectionConfig(params);
     }
 
     /**
@@ -122,14 +118,14 @@ public class SSLNHttpClientConnectionFac
             final SSLSetupHandler sslHandler,
             final NHttpMessageParserFactory<HttpResponse> responseParserFactory,
             final ByteBufferAllocator allocator,
-            final ConnectionConfig config) {
+            final ConnectionConfig cconfig) {
         super();
         this.sslcontext = sslcontext;
         this.sslHandler = sslHandler;
         this.allocator = allocator != null ? allocator : HeapByteBufferAllocator.INSTANCE;
         this.responseParserFactory = responseParserFactory != null ? responseParserFactory
:
             DefaultHttpResponseParserFactory.INSTANCE;
-        this.config = config != null ? config : ConnectionConfig.DEFAULT;
+        this.cconfig = cconfig != null ? cconfig : ConnectionConfig.DEFAULT;
     }
 
     /**
@@ -188,27 +184,14 @@ public class SSLNHttpClientConnectionFac
 
     public DefaultNHttpClientConnection createConnection(final IOSession iosession) {
         final SSLIOSession ssliosession = createSSLIOSession(iosession, this.sslcontext,
this.sslHandler);
-        CharsetDecoder chardecoder = null;
-        CharsetEncoder charencoder = null;
-        final Charset charset = this.config.getCharset();
-        final CodingErrorAction malformedInputAction = this.config.getMalformedInputAction()
!= null ?
-                this.config.getMalformedInputAction() : CodingErrorAction.REPORT;
-        final CodingErrorAction unmappableInputAction = this.config.getUnmappableInputAction()
!= null ?
-                this.config.getUnmappableInputAction() : CodingErrorAction.REPORT;
-        if (charset != null) {
-            chardecoder = charset.newDecoder();
-            chardecoder.onMalformedInput(malformedInputAction);
-            chardecoder.onUnmappableCharacter(unmappableInputAction);
-            charencoder = charset.newEncoder();
-            charencoder.onMalformedInput(malformedInputAction);
-            charencoder.onUnmappableCharacter(unmappableInputAction);
-        }
         return new DefaultNHttpClientConnection(
                 ssliosession,
-                this.config.getBufferSize(),
-                this.config.getFragmentSizeHint(),
+                this.cconfig.getBufferSize(),
+                this.cconfig.getFragmentSizeHint(),
                 this.allocator,
-                chardecoder, charencoder, this.config.getMessageConstraints(),
+                ConnSupport.createDecoder(this.cconfig),
+                ConnSupport.createEncoder(this.cconfig),
+                this.cconfig.getMessageConstraints(),
                 null, null, null,
                 this.responseParserFactory);
     }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java?rev=1495811&r1=1495810&r2=1495811&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java
Sun Jun 23 12:24:01 2013
@@ -26,17 +26,13 @@
  */
 package org.apache.http.impl.nio;
 
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
 import javax.net.ssl.SSLContext;
 
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestFactory;
 import org.apache.http.annotation.Immutable;
 import org.apache.http.config.ConnectionConfig;
+import org.apache.http.impl.ConnSupport;
 import org.apache.http.impl.DefaultHttpRequestFactory;
 import org.apache.http.impl.nio.codecs.DefaultHttpRequestParserFactory;
 import org.apache.http.nio.NHttpConnectionFactory;
@@ -66,7 +62,7 @@ public class SSLNHttpServerConnectionFac
     private final ByteBufferAllocator allocator;
     private final SSLContext sslcontext;
     private final SSLSetupHandler sslHandler;
-    private final ConnectionConfig config;
+    private final ConnectionConfig cconfig;
 
     /**
      * @deprecated (4.3) use {@link
@@ -88,7 +84,7 @@ public class SSLNHttpServerConnectionFac
         this.sslHandler = sslHandler;
         this.allocator = allocator;
         this.requestParserFactory = new DefaultHttpRequestParserFactory(null, requestFactory);
-        this.config = HttpParamConfig.getConnectionConfig(params);
+        this.cconfig = HttpParamConfig.getConnectionConfig(params);
     }
 
     /**
@@ -122,14 +118,14 @@ public class SSLNHttpServerConnectionFac
             final SSLSetupHandler sslHandler,
             final NHttpMessageParserFactory<HttpRequest> requestParserFactory,
             final ByteBufferAllocator allocator,
-            final ConnectionConfig config) {
+            final ConnectionConfig cconfig) {
         super();
         this.sslcontext = sslcontext;
         this.sslHandler = sslHandler;
         this.allocator = allocator != null ? allocator : HeapByteBufferAllocator.INSTANCE;
         this.requestParserFactory = requestParserFactory != null ? requestParserFactory :
             DefaultHttpRequestParserFactory.INSTANCE;
-        this.config = config != null ? config : ConnectionConfig.DEFAULT;
+        this.cconfig = cconfig != null ? cconfig : ConnectionConfig.DEFAULT;
     }
 
     /**
@@ -188,26 +184,13 @@ public class SSLNHttpServerConnectionFac
 
     public DefaultNHttpServerConnection createConnection(final IOSession iosession) {
         final SSLIOSession ssliosession = createSSLIOSession(iosession, this.sslcontext,
this.sslHandler);
-        CharsetDecoder chardecoder = null;
-        CharsetEncoder charencoder = null;
-        final Charset charset = this.config.getCharset();
-        final CodingErrorAction malformedInputAction = this.config.getMalformedInputAction()
!= null ?
-                this.config.getMalformedInputAction() : CodingErrorAction.REPORT;
-        final CodingErrorAction unmappableInputAction = this.config.getUnmappableInputAction()
!= null ?
-                this.config.getUnmappableInputAction() : CodingErrorAction.REPORT;
-        if (charset != null) {
-            chardecoder = charset.newDecoder();
-            chardecoder.onMalformedInput(malformedInputAction);
-            chardecoder.onUnmappableCharacter(unmappableInputAction);
-            charencoder = charset.newEncoder();
-            charencoder.onMalformedInput(malformedInputAction);
-            charencoder.onUnmappableCharacter(unmappableInputAction);
-        }
         return new DefaultNHttpServerConnection(ssliosession,
-                this.config.getBufferSize(),
-                this.config.getFragmentSizeHint(),
+                this.cconfig.getBufferSize(),
+                this.cconfig.getFragmentSizeHint(),
                 this.allocator,
-                chardecoder, charencoder, this.config.getMessageConstraints(),
+                ConnSupport.createDecoder(this.cconfig),
+                ConnSupport.createEncoder(this.cconfig),
+                this.cconfig.getMessageConstraints(),
                 null, null,
                 this.requestParserFactory,
                 null);

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java?rev=1495811&r1=1495810&r2=1495811&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
Sun Jun 23 12:24:01 2013
@@ -494,7 +494,6 @@ public abstract class AbstractMultiworke
     protected void prepareSocket(final Socket socket) throws IOException {
         socket.setTcpNoDelay(this.config.isTcpNoDelay());
         socket.setKeepAlive(this.config.isSoKeepalive());
-        socket.setReuseAddress(this.config.isSoReuseAddress());
         if (this.config.getSoTimeout() > 0) {
             socket.setSoTimeout(this.config.getSoTimeout());
         }

Added: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/ConnSupport.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/ConnSupport.java?rev=1495811&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/ConnSupport.java
(added)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/ConnSupport.java
Sun Jun 23 12:24:01 2013
@@ -0,0 +1,75 @@
+/*
+ * ====================================================================
+ * 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;
+
+import org.apache.http.config.ConnectionConfig;
+
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CodingErrorAction;
+
+/**
+ * Connection support methods.
+ *
+ * @since 4.3
+ */
+public final class ConnSupport {
+
+    public static CharsetDecoder createDecoder(final ConnectionConfig cconfig) {
+        if (cconfig == null) {
+            return null;
+        }
+        final Charset charset = cconfig.getCharset();
+        final CodingErrorAction malformed = cconfig.getMalformedInputAction();
+        final CodingErrorAction unmappable = cconfig.getUnmappableInputAction();
+        if (charset != null) {
+            return charset.newDecoder()
+                    .onMalformedInput(malformed != null ? malformed : CodingErrorAction.REPORT)
+                    .onUnmappableCharacter(unmappable != null ? unmappable: CodingErrorAction.REPORT);
+        } else {
+            return null;
+        }
+    }
+
+    public static CharsetEncoder createEncoder(final ConnectionConfig cconfig) {
+        if (cconfig == null) {
+            return null;
+        }
+        final Charset charset = cconfig.getCharset();
+        if (charset != null) {
+            final CodingErrorAction malformed = cconfig.getMalformedInputAction();
+            final CodingErrorAction unmappable = cconfig.getUnmappableInputAction();
+            return charset.newEncoder()
+                .onMalformedInput(malformed != null ? malformed : CodingErrorAction.REPORT)
+                .onUnmappableCharacter(unmappable != null ? unmappable: CodingErrorAction.REPORT);
+        } else {
+            return null;
+        }
+    }
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/ConnSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/ConnSupport.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

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

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java?rev=1495811&r1=1495810&r2=1495811&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java
Sun Jun 23 12:24:01 2013
@@ -29,11 +29,8 @@ package org.apache.http.impl.pool;
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.Socket;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
 
+import javax.net.SocketFactory;
 import javax.net.ssl.SSLSocketFactory;
 
 import org.apache.http.HttpClientConnection;
@@ -41,6 +38,7 @@ import org.apache.http.HttpHost;
 import org.apache.http.annotation.Immutable;
 import org.apache.http.config.ConnectionConfig;
 import org.apache.http.config.SocketConfig;
+import org.apache.http.impl.ConnSupport;
 import org.apache.http.impl.DefaultBHttpClientConnection;
 import org.apache.http.params.CoreConnectionPNames;
 import org.apache.http.params.HttpConnectionParams;
@@ -60,6 +58,7 @@ import org.apache.http.util.Args;
 @Immutable
 public class BasicConnFactory implements ConnFactory<HttpHost, HttpClientConnection>
{
 
+    private final SocketFactory plainfactory;
     private final SSLSocketFactory sslfactory;
     private final int connectTimeout;
     private final SocketConfig sconfig;
@@ -67,12 +66,14 @@ public class BasicConnFactory implements
 
     /**
      * @deprecated (4.3) use
-     *   {@link BasicConnFactory#BasicConnFactory(SSLSocketFactory, int, SocketConfig, ConnectionConfig)}.
+     *   {@link BasicConnFactory#BasicConnFactory(SocketFactory, SSLSocketFactory, int,
+     *     SocketConfig, ConnectionConfig)}.
      */
     @Deprecated
     public BasicConnFactory(final SSLSocketFactory sslfactory, final HttpParams params) {
         super();
         Args.notNull(params, "HTTP params");
+        this.plainfactory = null;
         this.sslfactory = sslfactory;
         this.connectTimeout = HttpConnectionParams.getConnectionTimeout(params);
         this.sconfig = HttpParamConfig.getSocketConfig(params);
@@ -92,11 +93,13 @@ public class BasicConnFactory implements
      * @since 4.3
      */
     public BasicConnFactory(
+            final SocketFactory plainfactory,
             final SSLSocketFactory sslfactory,
             final int connectTimeout,
             final SocketConfig sconfig,
             final ConnectionConfig cconfig) {
         super();
+        this.plainfactory = plainfactory;
         this.sslfactory = sslfactory;
         this.connectTimeout = connectTimeout;
         this.sconfig = sconfig != null ? sconfig : SocketConfig.DEFAULT;
@@ -108,21 +111,21 @@ public class BasicConnFactory implements
      */
     public BasicConnFactory(
             final int connectTimeout, final SocketConfig sconfig, final ConnectionConfig
cconfig) {
-        this(null, connectTimeout, sconfig, cconfig);
+        this(null, null, connectTimeout, sconfig, cconfig);
     }
 
     /**
      * @since 4.3
      */
     public BasicConnFactory(final SocketConfig sconfig, final ConnectionConfig cconfig) {
-        this(null, 0, sconfig, cconfig);
+        this(null, null, 0, sconfig, cconfig);
     }
 
     /**
      * @since 4.3
      */
     public BasicConnFactory() {
-        this(null, 0, SocketConfig.DEFAULT, ConnectionConfig.DEFAULT);
+        this(null, null, 0, SocketConfig.DEFAULT, ConnectionConfig.DEFAULT);
     }
 
     /**
@@ -140,7 +143,8 @@ public class BasicConnFactory implements
         final String scheme = host.getSchemeName();
         Socket socket = null;
         if ("http".equalsIgnoreCase(scheme)) {
-            socket = new Socket();
+            socket = this.plainfactory != null ? this.plainfactory.createSocket() :
+                    new Socket();
         } if ("https".equalsIgnoreCase(scheme)) {
             if (this.sslfactory != null) {
                 socket = this.sslfactory.createSocket();
@@ -158,7 +162,6 @@ public class BasicConnFactory implements
                 port = 443;
             }
         }
-
         socket.setSoTimeout(this.sconfig.getSoTimeout());
         socket.connect(new InetSocketAddress(hostname, port), this.connectTimeout);
         socket.setTcpNoDelay(this.sconfig.isTcpNoDelay());
@@ -166,25 +169,11 @@ public class BasicConnFactory implements
         if (linger >= 0) {
             socket.setSoLinger(linger > 0, linger);
         }
-        CharsetDecoder chardecoder = null;
-        CharsetEncoder charencoder = null;
-        final Charset charset = this.cconfig.getCharset();
-        final CodingErrorAction malformedInputAction = this.cconfig.getMalformedInputAction()
!= null ?
-                this.cconfig.getMalformedInputAction() : CodingErrorAction.REPORT;
-        final CodingErrorAction unmappableInputAction = this.cconfig.getUnmappableInputAction()
!= null ?
-                this.cconfig.getUnmappableInputAction() : CodingErrorAction.REPORT;
-        if (charset != null) {
-            chardecoder = charset.newDecoder();
-            chardecoder.onMalformedInput(malformedInputAction);
-            chardecoder.onUnmappableCharacter(unmappableInputAction);
-            charencoder = charset.newEncoder();
-            charencoder.onMalformedInput(malformedInputAction);
-            charencoder.onUnmappableCharacter(unmappableInputAction);
-        }
         final DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(
                 this.cconfig.getBufferSize(),
                 this.cconfig.getFragmentSizeHint(),
-                chardecoder, charencoder,
+                ConnSupport.createDecoder(this.cconfig),
+                ConnSupport.createEncoder(this.cconfig),
                 this.cconfig.getMessageConstraints(),
                 null, null, null, null);
         conn.bind(socket);

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java?rev=1495811&r1=1495810&r2=1495811&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java
Sun Jun 23 12:24:01 2013
@@ -96,6 +96,7 @@ public class TestBasicConnPool {
     public void testHttpsCreateConnection() throws Exception {
         final SocketConfig sconfig = SocketConfig.custom().setSoTimeout(100).build();
         connFactory = new BasicConnFactory(
+                null,
                 (SSLSocketFactory)SSLSocketFactory.getDefault(),
                 0, sconfig, ConnectionConfig.DEFAULT);
         host = new HttpHost("localhost", sslServerPort, "https");



Mime
View raw message