You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2012/10/19 11:53:29 UTC
svn commit: r1400016 [2/2] - in /httpcomponents/httpcore/trunk:
httpcore-nio/src/examples/org/apache/http/examples/nio/
httpcore-nio/src/main/java/org/apache/http/impl/nio/
httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/
httpcore-nio/src/ma...
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java?rev=1400016&r1=1400015&r2=1400016&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java Fri Oct 19 09:53:27 2012
@@ -36,7 +36,7 @@ import java.nio.charset.CoderResult;
import org.apache.http.MessageConstraintException;
import org.apache.http.annotation.NotThreadSafe;
-import org.apache.http.impl.MessageConstraints;
+import org.apache.http.config.MessageConstraints;
import org.apache.http.io.BufferInfo;
import org.apache.http.io.HttpTransportMetrics;
import org.apache.http.io.SessionInputBuffer;
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=1400016&r1=1400015&r2=1400016&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 Fri Oct 19 09:53:27 2012
@@ -29,6 +29,10 @@ 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 java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLSocketFactory;
@@ -36,9 +40,12 @@ import javax.net.ssl.SSLSocketFactory;
import org.apache.http.HttpClientConnection;
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.DefaultBHttpClientConnection;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.params.Config;
+import org.apache.http.params.HttpParamConfig;
import org.apache.http.params.HttpParams;
import org.apache.http.pool.ConnFactory;
import org.apache.http.util.Args;
@@ -55,9 +62,8 @@ import org.apache.http.util.Args;
public class BasicConnFactory implements ConnFactory<HttpHost, HttpClientConnection> {
private final SSLSocketFactory sslfactory;
- private final int connectTimeout;
- private final TimeUnit tunit;
- private final HttpParams params;
+ private final SocketConfig sconfig;
+ private final ConnectionConfig cconfig;
/**
* @deprecated (4.3) use
@@ -66,10 +72,10 @@ public class BasicConnFactory implements
@Deprecated
public BasicConnFactory(final SSLSocketFactory sslfactory, final HttpParams params) {
super();
+ Args.notNull(params, "HTTP params");
this.sslfactory = sslfactory;
- this.params = Args.notNull(params, "HTTP params");
- this.connectTimeout = Config.getInt(params, CoreConnectionPNames.CONNECTION_TIMEOUT, 0);
- this.tunit = TimeUnit.MILLISECONDS;
+ this.sconfig = HttpParamConfig.getSocketConfig(params);
+ this.cconfig = HttpParamConfig.getConnectionConfig(params);
}
/**
@@ -84,27 +90,25 @@ public class BasicConnFactory implements
* @since 4.3
*/
public BasicConnFactory(
- final SSLSocketFactory sslfactory,
- int connectTimeout, final TimeUnit tunit) {
+ final SSLSocketFactory sslfactory, final SocketConfig sconfig, final ConnectionConfig cconfig) {
super();
this.sslfactory = sslfactory;
- this.connectTimeout = connectTimeout;
- this.tunit = tunit != null ? tunit : TimeUnit.MILLISECONDS;
- this.params = null;
+ this.sconfig = sconfig != null ? sconfig : SocketConfig.DEFAULT;
+ this.cconfig = cconfig != null ? cconfig : ConnectionConfig.DEFAULT;
}
/**
* @since 4.3
*/
- public BasicConnFactory(int connectTimeout, final TimeUnit tunit) {
- this(null, connectTimeout, tunit);
+ public BasicConnFactory(final SocketConfig sconfig, final ConnectionConfig cconfig) {
+ this(null, sconfig, cconfig);
}
/**
* @since 4.3
*/
public BasicConnFactory() {
- this(null, 0, TimeUnit.MILLISECONDS);
+ this(null, SocketConfig.DEFAULT, ConnectionConfig.DEFAULT);
}
/**
@@ -131,16 +135,33 @@ public class BasicConnFactory implements
if (socket == null) {
throw new IOException(scheme + " scheme is not supported");
}
- int timeout = (int) tunit.toMillis(Math.min(connectTimeout, Integer.MAX_VALUE));
- socket.setSoTimeout(timeout);
- socket.connect(new InetSocketAddress(host.getHostName(), host.getPort()), timeout);
- if (params != null) {
- return create(socket, this.params);
- } else {
- DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(8 * 1024);
- conn.bind(socket);
- return conn;
+ socket.setSoTimeout(this.sconfig.getSoTimeout());
+ socket.connect(new InetSocketAddress(host.getHostName(), host.getPort()), this.cconfig.getConnectTimeout());
+ socket.setTcpNoDelay(this.sconfig.isTcpNoDelay());
+ int linger = this.sconfig.getSoLinger();
+ if (linger >= 0) {
+ socket.setSoLinger(linger > 0, linger);
}
+ CharsetDecoder chardecoder = null;
+ CharsetEncoder charencoder = null;
+ Charset charset = this.cconfig.getCharset();
+ CodingErrorAction malformedInputAction = this.cconfig.getMalformedInputAction() != null ?
+ this.cconfig.getMalformedInputAction() : CodingErrorAction.REPORT;
+ 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);
+ }
+ DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(8 * 1024,
+ chardecoder, charencoder,
+ this.cconfig.getMessageConstraints());
+ conn.bind(socket);
+ return conn;
}
}
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnPool.java?rev=1400016&r1=1400015&r2=1400016&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnPool.java Fri Oct 19 09:53:27 2012
@@ -32,6 +32,8 @@ import java.util.concurrent.atomic.Atomi
import org.apache.http.HttpClientConnection;
import org.apache.http.HttpHost;
import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.config.ConnectionConfig;
+import org.apache.http.config.SocketConfig;
import org.apache.http.params.HttpParams;
import org.apache.http.pool.AbstractConnPool;
import org.apache.http.pool.ConnFactory;
@@ -66,8 +68,8 @@ public class BasicConnPool extends Abstr
/**
* @since 4.3
*/
- public BasicConnPool(int connectTimeout, final TimeUnit tunit) {
- super(new BasicConnFactory(connectTimeout, tunit), 2, 20);
+ public BasicConnPool(final SocketConfig sconfig, final ConnectionConfig cconfig) {
+ super(new BasicConnFactory(sconfig, cconfig), 2, 20);
}
@Override
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/HttpMessageParserFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/HttpMessageParserFactory.java?rev=1400016&r1=1400015&r2=1400016&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/HttpMessageParserFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/HttpMessageParserFactory.java Fri Oct 19 09:53:27 2012
@@ -28,7 +28,7 @@
package org.apache.http.io;
import org.apache.http.HttpMessage;
-import org.apache.http.impl.MessageConstraints;
+import org.apache.http.config.MessageConstraints;
/**
* Factory for {@link HttpMessageParser} instances.
Added: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpParamConfig.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpParamConfig.java?rev=1400016&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpParamConfig.java (added)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpParamConfig.java Fri Oct 19 09:53:27 2012
@@ -0,0 +1,78 @@
+/*
+ * ====================================================================
+ * 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.params;
+
+import java.nio.charset.Charset;
+import java.nio.charset.CodingErrorAction;
+
+import org.apache.http.config.ConnectionConfig;
+import org.apache.http.config.MessageConstraints;
+import org.apache.http.config.SocketConfig;
+
+/**
+ * @deprecated (4.3) provided for compatibility with {@link HttpParams}. Do not use.
+ *
+ * @since 4.3
+ */
+public final class HttpParamConfig {
+
+ private HttpParamConfig() {
+ }
+
+ public static SocketConfig getSocketConfig(final HttpParams params) {
+ return SocketConfig.custom()
+ .setSoTimeout(HttpConnectionParams.getSoTimeout(params))
+ .setSoReuseAddress(HttpConnectionParams.getSoReuseaddr(params))
+ .setSoKeepAlive(HttpConnectionParams.getSoKeepalive(params))
+ .setSoLinger(HttpConnectionParams.getLinger(params))
+ .setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params))
+ .build();
+ }
+
+ public static MessageConstraints getMessageConstraints(final HttpParams params) {
+ return MessageConstraints.custom()
+ .setMaxHeaderCount(params.getIntParameter(CoreConnectionPNames.MAX_HEADER_COUNT, -1))
+ .setMaxLineLength(params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1))
+ .build();
+ }
+
+ public static ConnectionConfig getConnectionConfig(final HttpParams params) {
+ MessageConstraints messageConstraints = getMessageConstraints(params);
+ String csname = HttpProtocolParams.getHttpElementCharset(params);
+ return ConnectionConfig.custom()
+ .setConnectTimeout(HttpConnectionParams.getConnectionTimeout(params))
+ .setCharset(csname != null ? Charset.forName(csname) : null)
+ .setMalformedInputAction((CodingErrorAction)
+ params.getParameter(CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION))
+ .setMalformedInputAction((CodingErrorAction)
+ params.getParameter(CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION))
+ .setMessageConstraints(messageConstraints)
+ .build();
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpParamConfig.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpParamConfig.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpParamConfig.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/SessionInputBufferMock.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/SessionInputBufferMock.java?rev=1400016&r1=1400015&r2=1400016&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/SessionInputBufferMock.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/SessionInputBufferMock.java Fri Oct 19 09:53:27 2012
@@ -34,6 +34,7 @@ import java.io.UnsupportedEncodingExcept
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
+import org.apache.http.config.MessageConstraints;
import org.apache.http.impl.io.HttpTransportMetricsImpl;
import org.apache.http.impl.io.SessionInputBufferImpl;
Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestSessionInOutBuffers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestSessionInOutBuffers.java?rev=1400016&r1=1400015&r2=1400016&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestSessionInOutBuffers.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestSessionInOutBuffers.java Fri Oct 19 09:53:27 2012
@@ -34,7 +34,7 @@ import java.nio.charset.CharsetEncoder;
import java.nio.charset.CodingErrorAction;
import org.apache.http.Consts;
-import org.apache.http.impl.MessageConstraints;
+import org.apache.http.config.MessageConstraints;
import org.apache.http.impl.SessionInputBufferMock;
import org.apache.http.impl.SessionOutputBufferMock;
import org.apache.http.io.HttpTransportMetrics;
@@ -333,7 +333,7 @@ public class TestSessionInOutBuffers {
byte[] tmp = s.getBytes("US-ASCII");
// no limit
SessionInputBufferMock inbuffer1 = new SessionInputBufferMock(tmp, 5,
- MessageConstraints.UNLIMITED);
+ MessageConstraints.DEFAULT);
Assert.assertNotNull(inbuffer1.readLine());
long bytesRead = inbuffer1.getMetrics().getBytesTransferred();
Assert.assertEquals(60, bytesRead);
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=1400016&r1=1400015&r2=1400016&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 Fri Oct 19 09:53:27 2012
@@ -29,7 +29,6 @@ package org.apache.http.impl.pool;
import static org.junit.Assert.assertEquals;
import java.net.ServerSocket;
-import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLServerSocketFactory;
@@ -37,6 +36,8 @@ import javax.net.ssl.SSLSocketFactory;
import org.apache.http.HttpClientConnection;
import org.apache.http.HttpHost;
+import org.apache.http.config.ConnectionConfig;
+import org.apache.http.config.SocketConfig;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -64,7 +65,8 @@ public class TestBasicConnPool {
sslServer = (SSLServerSocket) SSLServerSocketFactory.getDefault().createServerSocket(0);
sslServerPort = sslServer.getLocalPort();
- connFactory = new BasicConnFactory(100, TimeUnit.MILLISECONDS);
+ SocketConfig sconfig = SocketConfig.custom().setSoTimeout(100).build();
+ connFactory = new BasicConnFactory(sconfig, ConnectionConfig.DEFAULT);
pool = new BasicConnPool(connFactory);
}
@@ -93,8 +95,9 @@ public class TestBasicConnPool {
@Test
public void testHttpsCreateConnection() throws Exception {
+ SocketConfig sconfig = SocketConfig.custom().setSoTimeout(100).build();
connFactory = new BasicConnFactory((SSLSocketFactory)SSLSocketFactory.getDefault(),
- 100, TimeUnit.MILLISECONDS);
+ sconfig, ConnectionConfig.DEFAULT);
host = new HttpHost("localhost", sslServerPort, "https");
conn = connFactory.create(host);
Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/LoggingBHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/LoggingBHttpClientConnection.java?rev=1400016&r1=1400015&r2=1400016&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/LoggingBHttpClientConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/LoggingBHttpClientConnection.java Fri Oct 19 09:53:27 2012
@@ -40,9 +40,9 @@ import org.apache.commons.logging.LogFac
import org.apache.http.Header;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
+import org.apache.http.config.MessageConstraints;
import org.apache.http.entity.ContentLengthStrategy;
import org.apache.http.impl.DefaultBHttpClientConnection;
-import org.apache.http.impl.MessageConstraints;
import org.apache.http.io.HttpMessageParserFactory;
import org.apache.http.io.HttpMessageWriterFactory;
Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/LoggingBHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/LoggingBHttpServerConnection.java?rev=1400016&r1=1400015&r2=1400016&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/LoggingBHttpServerConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/LoggingBHttpServerConnection.java Fri Oct 19 09:53:27 2012
@@ -40,9 +40,9 @@ import org.apache.commons.logging.LogFac
import org.apache.http.Header;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
+import org.apache.http.config.MessageConstraints;
import org.apache.http.entity.ContentLengthStrategy;
import org.apache.http.impl.DefaultBHttpServerConnection;
-import org.apache.http.impl.MessageConstraints;
import org.apache.http.io.HttpMessageParserFactory;
import org.apache.http.io.HttpMessageWriterFactory;