Updated new connection managers to use SocketClientConnectionImpl instead of deprecated DefaultClientConnection
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1414675 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4dc5821acb
commit
2c1d3f797a
|
@ -188,7 +188,7 @@ public class URLEncodedUtils {
|
|||
if (s == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
BasicHeaderValueParser parser = BasicHeaderValueParser.DEFAULT;
|
||||
BasicHeaderValueParser parser = BasicHeaderValueParser.INSTANCE;
|
||||
CharArrayBuffer buffer = new CharArrayBuffer(s.length());
|
||||
buffer.append(s);
|
||||
ParserCursor cursor = new ParserCursor(0, buffer.length());
|
||||
|
|
|
@ -49,7 +49,7 @@ import org.apache.http.conn.routing.HttpRoute;
|
|||
*/
|
||||
@Deprecated
|
||||
public interface ManagedClientConnection extends
|
||||
HttpClientConnection, HttpRoutedConnection, HttpSSLConnection, ConnectionReleaseTrigger {
|
||||
HttpClientConnection, HttpRoutedConnection, SocketClientConnection, ConnectionReleaseTrigger {
|
||||
|
||||
/**
|
||||
* Indicates whether this connection is secure.
|
||||
|
|
|
@ -27,16 +27,24 @@
|
|||
|
||||
package org.apache.http.conn;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
|
||||
import javax.net.ssl.SSLSession;
|
||||
|
||||
import org.apache.http.HttpClientConnection;
|
||||
import org.apache.http.HttpInetConnection;
|
||||
|
||||
/**
|
||||
* Extended interface that exposes SSL session details.
|
||||
* Extended interface that exposes {@link Socket} bind method and SSL session details.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
public interface HttpSSLConnection extends HttpInetConnection {
|
||||
public interface SocketClientConnection extends HttpClientConnection, HttpInetConnection {
|
||||
|
||||
void bind(Socket socket) throws IOException;
|
||||
|
||||
Socket getSocket();
|
||||
|
||||
/**
|
||||
* Obtains the SSL session of the underlying connection, if any.
|
|
@ -37,7 +37,7 @@ import org.apache.http.auth.AuthState;
|
|||
import org.apache.http.auth.Credentials;
|
||||
import org.apache.http.client.UserTokenHandler;
|
||||
import org.apache.http.client.protocol.ClientContext;
|
||||
import org.apache.http.conn.HttpSSLConnection;
|
||||
import org.apache.http.conn.SocketClientConnection;
|
||||
import org.apache.http.protocol.ExecutionContext;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
||||
|
@ -76,8 +76,8 @@ public class DefaultUserTokenHandler implements UserTokenHandler {
|
|||
if (userPrincipal == null) {
|
||||
HttpConnection conn = (HttpConnection) context.getAttribute(
|
||||
ExecutionContext.HTTP_CONNECTION);
|
||||
if (conn instanceof HttpSSLConnection) {
|
||||
SSLSession sslsession = ((HttpSSLConnection) conn).getSSLSession();
|
||||
if (conn instanceof SocketClientConnection) {
|
||||
SSLSession sslsession = ((SocketClientConnection) conn).getSSLSession();
|
||||
if (sslsession != null) {
|
||||
userPrincipal = sslsession.getLocalPrincipal();
|
||||
}
|
||||
|
|
|
@ -266,6 +266,18 @@ public abstract class AbstractClientConnAdapter implements ManagedClientConnecti
|
|||
return conn.isSecure();
|
||||
}
|
||||
|
||||
public void bind(Socket socket) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Socket getSocket() {
|
||||
OperatedClientConnection conn = getWrappedConnection();
|
||||
assertValid(conn);
|
||||
if (!isOpen())
|
||||
return null;
|
||||
return conn.getSocket();
|
||||
}
|
||||
|
||||
public SSLSession getSSLSession() {
|
||||
OperatedClientConnection conn = getWrappedConnection();
|
||||
assertValid(conn);
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.apache.http.conn.ConnectionRequest;
|
|||
import org.apache.http.conn.DnsResolver;
|
||||
import org.apache.http.conn.HttpClientConnectionManager;
|
||||
import org.apache.http.conn.HttpConnectionFactory;
|
||||
import org.apache.http.conn.SocketClientConnection;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.params.HttpParams;
|
||||
|
@ -70,10 +71,10 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
|||
private final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
private final HttpClientConnectionOperator connectionOperator;
|
||||
private final HttpConnectionFactory<DefaultClientConnection> connFactory;
|
||||
private final HttpConnectionFactory<SocketClientConnection> connFactory;
|
||||
|
||||
@GuardedBy("this")
|
||||
private DefaultClientConnection conn;
|
||||
private SocketClientConnection conn;
|
||||
|
||||
@GuardedBy("this")
|
||||
private HttpRoute route;
|
||||
|
@ -96,7 +97,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
|||
public BasicHttpClientConnectionManager(
|
||||
final SchemeRegistry schemeRegistry,
|
||||
final DnsResolver dnsResolver,
|
||||
final HttpConnectionFactory<DefaultClientConnection> connFactory) {
|
||||
final HttpConnectionFactory<SocketClientConnection> connFactory) {
|
||||
if (schemeRegistry == null) {
|
||||
throw new IllegalArgumentException("Scheme registry may not be null");
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.annotation.ThreadSafe;
|
||||
import org.apache.http.conn.HttpClientConnectionManager;
|
||||
import org.apache.http.conn.SocketClientConnection;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.pool.AbstractConnPool;
|
||||
import org.apache.http.pool.ConnFactory;
|
||||
|
@ -42,7 +43,7 @@ import org.apache.http.pool.ConnFactory;
|
|||
* @since 4.3
|
||||
*/
|
||||
@ThreadSafe
|
||||
class CPool extends AbstractConnPool<HttpRoute, DefaultClientConnection, CPoolEntry> {
|
||||
class CPool extends AbstractConnPool<HttpRoute, SocketClientConnection, CPoolEntry> {
|
||||
|
||||
private static AtomicLong COUNTER = new AtomicLong();
|
||||
|
||||
|
@ -59,15 +60,15 @@ class CPool extends AbstractConnPool<HttpRoute, DefaultClientConnection, CPoolEn
|
|||
}
|
||||
|
||||
@Override
|
||||
protected CPoolEntry createEntry(final HttpRoute route, final DefaultClientConnection conn) {
|
||||
protected CPoolEntry createEntry(final HttpRoute route, final SocketClientConnection conn) {
|
||||
String id = Long.toString(COUNTER.getAndIncrement());
|
||||
return new CPoolEntry(this.log, id, route, conn, this.timeToLive, this.tunit);
|
||||
}
|
||||
|
||||
static class InternalConnFactory implements ConnFactory<HttpRoute, DefaultClientConnection> {
|
||||
static class InternalConnFactory implements ConnFactory<HttpRoute, SocketClientConnection> {
|
||||
|
||||
public DefaultClientConnection create(final HttpRoute route) throws IOException {
|
||||
return new DefaultClientConnection();
|
||||
public SocketClientConnection create(final HttpRoute route) throws IOException {
|
||||
return new SocketClientConnectionImpl(8 * 1024);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.http.HttpClientConnection;
|
||||
import org.apache.http.annotation.ThreadSafe;
|
||||
import org.apache.http.conn.SocketClientConnection;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.pool.PoolEntry;
|
||||
|
||||
|
@ -40,7 +41,7 @@ import org.apache.http.pool.PoolEntry;
|
|||
* @since 4.3
|
||||
*/
|
||||
@ThreadSafe
|
||||
class CPoolEntry extends PoolEntry<HttpRoute, DefaultClientConnection> {
|
||||
class CPoolEntry extends PoolEntry<HttpRoute, SocketClientConnection> {
|
||||
|
||||
private final Log log;
|
||||
|
||||
|
@ -48,7 +49,7 @@ class CPoolEntry extends PoolEntry<HttpRoute, DefaultClientConnection> {
|
|||
final Log log,
|
||||
final String id,
|
||||
final HttpRoute route,
|
||||
final DefaultClientConnection conn,
|
||||
final SocketClientConnection conn,
|
||||
final long timeToLive, final TimeUnit tunit) {
|
||||
super(id, route, conn, timeToLive, tunit);
|
||||
this.log = log;
|
||||
|
|
|
@ -34,7 +34,7 @@ import java.lang.reflect.Proxy;
|
|||
|
||||
import org.apache.http.HttpClientConnection;
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.http.conn.HttpSSLConnection;
|
||||
import org.apache.http.conn.SocketClientConnection;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
||||
/**
|
||||
|
@ -137,7 +137,7 @@ class CPoolProxy implements InvocationHandler {
|
|||
final CPoolEntry poolEntry) {
|
||||
return (HttpClientConnection) Proxy.newProxyInstance(
|
||||
CPoolProxy.class.getClassLoader(),
|
||||
new Class<?>[] { HttpClientConnection.class, HttpSSLConnection.class, HttpContext.class },
|
||||
new Class<?>[] { HttpClientConnection.class, SocketClientConnection.class, HttpContext.class },
|
||||
new CPoolProxy(poolEntry));
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ import org.apache.http.HttpHost;
|
|||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpResponseFactory;
|
||||
import org.apache.http.params.BasicHttpParams;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.params.HttpProtocolParams;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
@ -54,7 +55,7 @@ import org.apache.http.io.HttpMessageParser;
|
|||
import org.apache.http.io.SessionInputBuffer;
|
||||
import org.apache.http.io.SessionOutputBuffer;
|
||||
|
||||
import org.apache.http.conn.HttpSSLConnection;
|
||||
import org.apache.http.conn.SocketClientConnection;
|
||||
import org.apache.http.conn.OperatedClientConnection;
|
||||
|
||||
/**
|
||||
|
@ -62,13 +63,12 @@ import org.apache.http.conn.OperatedClientConnection;
|
|||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated (4.3) deprecated in favor of {@link ClientConnectionImpl}.
|
||||
* @deprecated (4.3) deprecated in favor of {@link SocketClientConnectionImpl}.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@NotThreadSafe // connSecure, targetHost
|
||||
@Deprecated
|
||||
public class DefaultClientConnection extends SocketHttpClientConnection
|
||||
implements OperatedClientConnection, HttpSSLConnection, HttpContext {
|
||||
implements OperatedClientConnection, SocketClientConnection, HttpContext {
|
||||
|
||||
private final Log log = LogFactory.getLog(getClass());
|
||||
private final Log headerLog = LogFactory.getLog("org.apache.http.headers");
|
||||
|
@ -231,6 +231,10 @@ public class DefaultClientConnection extends SocketHttpClientConnection
|
|||
(buffer, null, responseFactory, params);
|
||||
}
|
||||
|
||||
public void bind(Socket socket) throws IOException {
|
||||
bind(socket, new BasicHttpParams());
|
||||
}
|
||||
|
||||
public void update(Socket sock, HttpHost target,
|
||||
boolean secure, HttpParams params)
|
||||
throws IOException {
|
||||
|
|
|
@ -28,18 +28,19 @@
|
|||
package org.apache.http.impl.conn;
|
||||
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.http.conn.SocketClientConnection;
|
||||
import org.apache.http.conn.HttpConnectionFactory;
|
||||
|
||||
/**
|
||||
* @since 4.3
|
||||
*/
|
||||
@Immutable
|
||||
public class DefaultClientConnectionFactory implements HttpConnectionFactory<DefaultClientConnection> {
|
||||
public class DefaultClientConnectionFactory implements HttpConnectionFactory<SocketClientConnection> {
|
||||
|
||||
public static final DefaultClientConnectionFactory INSTANCE = new DefaultClientConnectionFactory();
|
||||
|
||||
public DefaultClientConnection create() {
|
||||
return new DefaultClientConnection();
|
||||
public SocketClientConnection create() {
|
||||
return new SocketClientConnectionImpl(8 * 1024);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.apache.http.conn.ConnectionPoolTimeoutException;
|
|||
import org.apache.http.conn.ConnectionRequest;
|
||||
import org.apache.http.conn.DnsResolver;
|
||||
import org.apache.http.conn.HttpClientConnectionManager;
|
||||
import org.apache.http.conn.SocketClientConnection;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.params.HttpParams;
|
||||
|
@ -165,7 +166,7 @@ abstract class HttpClientConnectionManagerBase implements HttpClientConnectionMa
|
|||
if (entry == null) {
|
||||
return;
|
||||
}
|
||||
DefaultClientConnection conn = entry.getConnection();
|
||||
SocketClientConnection conn = entry.getConnection();
|
||||
try {
|
||||
if (conn.isOpen()) {
|
||||
entry.setState(state);
|
||||
|
@ -188,7 +189,7 @@ abstract class HttpClientConnectionManagerBase implements HttpClientConnectionMa
|
|||
if (managedConn == null) {
|
||||
throw new IllegalArgumentException("Connection may not be null");
|
||||
}
|
||||
DefaultClientConnection conn;
|
||||
SocketClientConnection conn;
|
||||
synchronized (managedConn) {
|
||||
CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn);
|
||||
conn = entry.getConnection();
|
||||
|
@ -204,7 +205,7 @@ abstract class HttpClientConnectionManagerBase implements HttpClientConnectionMa
|
|||
if (managedConn == null) {
|
||||
throw new IllegalArgumentException("Connection may not be null");
|
||||
}
|
||||
DefaultClientConnection conn;
|
||||
SocketClientConnection conn;
|
||||
synchronized (managedConn) {
|
||||
CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn);
|
||||
conn = entry.getConnection();
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.apache.http.conn.DnsResolver;
|
|||
import org.apache.http.conn.HttpClientConnectionManager;
|
||||
import org.apache.http.conn.HttpHostConnectException;
|
||||
import org.apache.http.conn.HttpInetSocketAddress;
|
||||
import org.apache.http.conn.SocketClientConnection;
|
||||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.scheme.SchemeLayeredSocketFactory;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
|
@ -86,7 +87,7 @@ class HttpClientConnectionOperator {
|
|||
}
|
||||
|
||||
public void connect(
|
||||
final DefaultClientConnection conn,
|
||||
final SocketClientConnection conn,
|
||||
final HttpHost host,
|
||||
final InetAddress local,
|
||||
final HttpContext context,
|
||||
|
@ -102,7 +103,7 @@ class HttpClientConnectionOperator {
|
|||
boolean last = i == addresses.length - 1;
|
||||
|
||||
Socket sock = sf.createSocket(params);
|
||||
conn.opening(sock, host);
|
||||
conn.bind(sock);
|
||||
|
||||
InetSocketAddress remoteAddress = new HttpInetSocketAddress(host, address, port);
|
||||
InetSocketAddress localAddress = null;
|
||||
|
@ -114,11 +115,7 @@ class HttpClientConnectionOperator {
|
|||
}
|
||||
try {
|
||||
Socket connsock = sf.connectSocket(sock, remoteAddress, localAddress, params);
|
||||
if (sock != connsock) {
|
||||
sock = connsock;
|
||||
conn.opening(sock, host);
|
||||
}
|
||||
conn.openCompleted(sf.isSecure(sock), params);
|
||||
conn.bind(connsock);
|
||||
return;
|
||||
} catch (ConnectException ex) {
|
||||
if (last) {
|
||||
|
@ -137,7 +134,7 @@ class HttpClientConnectionOperator {
|
|||
}
|
||||
|
||||
public void upgrade(
|
||||
final DefaultClientConnection conn,
|
||||
final SocketClientConnection conn,
|
||||
final HttpHost host,
|
||||
final HttpContext context,
|
||||
final HttpParams params) throws IOException {
|
||||
|
@ -157,7 +154,7 @@ class HttpClientConnectionOperator {
|
|||
} catch (ConnectException ex) {
|
||||
throw new HttpHostConnectException(host, ex);
|
||||
}
|
||||
conn.update(sock, host, lsf.isSecure(sock), params);
|
||||
conn.bind(sock);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -234,6 +234,15 @@ class ManagedClientConnectionImpl implements ManagedClientConnection {
|
|||
return conn.isSecure();
|
||||
}
|
||||
|
||||
public void bind(Socket socket) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Socket getSocket() {
|
||||
OperatedClientConnection conn = ensureConnection();
|
||||
return conn.getSocket();
|
||||
}
|
||||
|
||||
public SSLSession getSSLSession() {
|
||||
OperatedClientConnection conn = ensureConnection();
|
||||
SSLSession result = null;
|
||||
|
|
|
@ -29,24 +29,33 @@ package org.apache.http.impl.conn;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
import java.nio.charset.CharsetDecoder;
|
||||
import java.nio.charset.CharsetEncoder;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
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.conn.SocketClientConnection;
|
||||
import org.apache.http.entity.ContentLengthStrategy;
|
||||
import org.apache.http.impl.DefaultBHttpClientConnection;
|
||||
import org.apache.http.io.HttpMessageParserFactory;
|
||||
import org.apache.http.io.HttpMessageWriterFactory;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
||||
class ClientConnectionImpl extends DefaultBHttpClientConnection {
|
||||
class SocketClientConnectionImpl extends DefaultBHttpClientConnection
|
||||
implements SocketClientConnection, HttpContext {
|
||||
|
||||
private static final AtomicLong COUNT = new AtomicLong();
|
||||
|
||||
|
@ -54,8 +63,11 @@ class ClientConnectionImpl extends DefaultBHttpClientConnection {
|
|||
private final Log log;
|
||||
private final Log headerlog;
|
||||
private final Wire wire;
|
||||
private final Map<String, Object> attributes;
|
||||
|
||||
public ClientConnectionImpl(
|
||||
private volatile boolean shutdown;
|
||||
|
||||
public SocketClientConnectionImpl(
|
||||
int buffersize,
|
||||
final CharsetDecoder chardecoder,
|
||||
final CharsetEncoder charencoder,
|
||||
|
@ -71,9 +83,10 @@ class ClientConnectionImpl extends DefaultBHttpClientConnection {
|
|||
this.log = LogFactory.getLog(getClass());
|
||||
this.headerlog = LogFactory.getLog("org.apache.http.headers");
|
||||
this.wire = new Wire(LogFactory.getLog("org.apache.http.wire"), this.id);
|
||||
this.attributes = new ConcurrentHashMap<String, Object>();
|
||||
}
|
||||
|
||||
public ClientConnectionImpl(int buffersize) {
|
||||
public SocketClientConnectionImpl(int buffersize) {
|
||||
this(buffersize, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
|
@ -90,6 +103,7 @@ class ClientConnectionImpl extends DefaultBHttpClientConnection {
|
|||
if (this.log.isDebugEnabled()) {
|
||||
this.log.debug(this.id + ": Shutdown connection");
|
||||
}
|
||||
this.shutdown = true;
|
||||
super.shutdown();
|
||||
}
|
||||
|
||||
|
@ -133,4 +147,40 @@ class ClientConnectionImpl extends DefaultBHttpClientConnection {
|
|||
}
|
||||
}
|
||||
|
||||
public Object getAttribute(final String id) {
|
||||
return this.attributes.get(id);
|
||||
}
|
||||
|
||||
public Object removeAttribute(final String id) {
|
||||
return this.attributes.remove(id);
|
||||
}
|
||||
|
||||
public void setAttribute(final String id, final Object obj) {
|
||||
this.attributes.put(id, obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(final Socket socket) throws IOException {
|
||||
if (this.shutdown) {
|
||||
socket.close(); // allow this to throw...
|
||||
// ...but if it doesn't, explicitly throw one ourselves.
|
||||
throw new InterruptedIOException("Connection already shutdown");
|
||||
}
|
||||
super.bind(socket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Socket getSocket() {
|
||||
return super.getSocket();
|
||||
}
|
||||
|
||||
public SSLSession getSSLSession() {
|
||||
Socket socket = super.getSocket();
|
||||
if (socket instanceof SSLSocket) {
|
||||
return ((SSLSocket) socket).getSession();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -522,9 +522,8 @@ public class TestConnectionManagement extends LocalServerTestBase {
|
|||
|
||||
try {
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context, params);
|
||||
Assert.fail("expected exception");
|
||||
Assert.fail("IOException expected");
|
||||
} catch(IOException expected) {
|
||||
Assert.assertEquals("Connection already shutdown", expected.getMessage());
|
||||
}
|
||||
|
||||
abortingThread.join(5000);
|
||||
|
@ -578,8 +577,9 @@ public class TestConnectionManagement extends LocalServerTestBase {
|
|||
|
||||
try {
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context, params);
|
||||
Assert.fail("expected SocketException");
|
||||
} catch(SocketException expected) {}
|
||||
Assert.fail("IOException expected");
|
||||
} catch(IOException expected) {
|
||||
}
|
||||
|
||||
abortingThread.join(5000);
|
||||
if(throwRef.get() != null)
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.apache.http.HttpHost;
|
|||
import org.apache.http.conn.ConnectionRequest;
|
||||
import org.apache.http.conn.DnsResolver;
|
||||
import org.apache.http.conn.HttpConnectionFactory;
|
||||
import org.apache.http.conn.SocketClientConnection;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
|
@ -47,8 +48,8 @@ import org.mockito.Mockito;
|
|||
|
||||
public class TestBasicHttpClientConnectionManager {
|
||||
|
||||
private DefaultClientConnection conn;
|
||||
private HttpConnectionFactory<DefaultClientConnection> connFactory;
|
||||
private SocketClientConnection conn;
|
||||
private HttpConnectionFactory<SocketClientConnection> connFactory;
|
||||
private Socket socket;
|
||||
private SchemeSocketFactory plainSocketFactory;
|
||||
private SchemeRegistry schemeRegistry;
|
||||
|
@ -58,7 +59,7 @@ public class TestBasicHttpClientConnectionManager {
|
|||
@SuppressWarnings("unchecked")
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
conn = Mockito.mock(DefaultClientConnection.class);
|
||||
conn = Mockito.mock(SocketClientConnection.class);
|
||||
connFactory = Mockito.mock(HttpConnectionFactory.class);
|
||||
Mockito.when(connFactory.create()).thenReturn(conn);
|
||||
socket = Mockito.mock(Socket.class);
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.apache.http.HttpHost;
|
|||
import org.apache.http.conn.ConnectionPoolTimeoutException;
|
||||
import org.apache.http.conn.ConnectionRequest;
|
||||
import org.apache.http.conn.DnsResolver;
|
||||
import org.apache.http.conn.SocketClientConnection;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
|
@ -51,7 +52,7 @@ import org.mockito.Mockito;
|
|||
|
||||
public class TestHttpClientConnectionManagerBase {
|
||||
|
||||
private DefaultClientConnection conn;
|
||||
private SocketClientConnection conn;
|
||||
private Socket socket;
|
||||
private SchemeSocketFactory plainSocketFactory;
|
||||
private SchemeRegistry schemeRegistry;
|
||||
|
@ -63,7 +64,7 @@ public class TestHttpClientConnectionManagerBase {
|
|||
@SuppressWarnings("unchecked")
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
conn = Mockito.mock(DefaultClientConnection.class);
|
||||
conn = Mockito.mock(SocketClientConnection.class);
|
||||
socket = Mockito.mock(Socket.class);
|
||||
plainSocketFactory = Mockito.mock(SchemeSocketFactory.class);
|
||||
Mockito.when(plainSocketFactory.createSocket(Mockito.<HttpParams>any())).thenReturn(socket);
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.apache.http.HttpHost;
|
|||
import org.apache.http.conn.ConnectTimeoutException;
|
||||
import org.apache.http.conn.DnsResolver;
|
||||
import org.apache.http.conn.HttpInetSocketAddress;
|
||||
import org.apache.http.conn.SocketClientConnection;
|
||||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.scheme.SchemeLayeredSocketFactory;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
|
@ -49,7 +50,7 @@ import org.mockito.Mockito;
|
|||
|
||||
public class TestHttpClientConnectionOperator {
|
||||
|
||||
private DefaultClientConnection conn;
|
||||
private SocketClientConnection conn;
|
||||
private Socket socket;
|
||||
private SchemeSocketFactory plainSocketFactory;
|
||||
private SchemeLayeredSocketFactory sslSocketFactory;
|
||||
|
@ -59,7 +60,7 @@ public class TestHttpClientConnectionOperator {
|
|||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
conn = Mockito.mock(DefaultClientConnection.class);
|
||||
conn = Mockito.mock(SocketClientConnection.class);
|
||||
socket = Mockito.mock(Socket.class);
|
||||
plainSocketFactory = Mockito.mock(SchemeSocketFactory.class);
|
||||
sslSocketFactory = Mockito.mock(SchemeLayeredSocketFactory.class);
|
||||
|
@ -97,8 +98,7 @@ public class TestHttpClientConnectionOperator {
|
|||
Mockito.verify(plainSocketFactory).connectSocket(socket,
|
||||
new InetSocketAddress(ip1, 80),
|
||||
new InetSocketAddress(local, 0), params);
|
||||
Mockito.verify(conn).opening(socket, host);
|
||||
Mockito.verify(conn).openCompleted(false, params);
|
||||
Mockito.verify(conn, Mockito.times(2)).bind(socket);
|
||||
}
|
||||
|
||||
@Test(expected=ConnectTimeoutException.class)
|
||||
|
@ -146,8 +146,7 @@ public class TestHttpClientConnectionOperator {
|
|||
Mockito.verify(plainSocketFactory).connectSocket(socket,
|
||||
new HttpInetSocketAddress(host, ip2, 80),
|
||||
new InetSocketAddress(local, 0), params);
|
||||
Mockito.verify(conn, Mockito.times(2)).opening(socket, host);
|
||||
Mockito.verify(conn).openCompleted(false, params);
|
||||
Mockito.verify(conn, Mockito.times(3)).bind(socket);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -164,7 +163,7 @@ public class TestHttpClientConnectionOperator {
|
|||
|
||||
connectionOperator.upgrade(conn, host, context, params);
|
||||
|
||||
Mockito.verify(conn).update(socket, host, false, params);
|
||||
Mockito.verify(conn).bind(socket);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
|
|
Loading…
Reference in New Issue