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 2010/04/07 19:28:16 UTC
svn commit: r931624 [1/2] - in /httpcomponents/httpclient/trunk:
httpclient/src/main/java/org/apache/http/conn/
httpclient/src/main/java/org/apache/http/conn/scheme/
httpclient/src/main/java/org/apache/http/conn/ssl/
httpclient/src/main/java/org/apache...
Author: olegk
Date: Wed Apr 7 17:28:15 2010
New Revision: 931624
URL: http://svn.apache.org/viewvc?rev=931624&view=rev
Log:
HTTPCLIENT-898: Refactored socket factory API (new socket factory interfaces are better suited for multihome hosts)
Added:
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSchemeSocketFactory.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSchemeSocketFactoryAdaptor.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSocketFactoryAdaptor.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeSocketFactory.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeSocketFactoryAdaptor.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SocketFactoryAdaptor.java
Modified:
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ClientConnectionOperator.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/MultihomePlainSocketFactory.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/HostNameResolver.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSocketFactory.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/Scheme.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SocketFactory.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RedirectLocations.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionReuse.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestScheme.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/scheme/TestScheme.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestContentCodings.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestRequestRetryHandler.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestProxySelRoutePlanner.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestTSCCMNoServer.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestTSCCMWithServer.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/tsccm/TestSpuriousWakeup.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/ServerTestBase.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SecureSocketFactoryMockup.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SocketFactoryMockup.java
httpcomponents/httpclient/trunk/src/docbkx/connmgmt.xml
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ClientConnectionOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ClientConnectionOperator.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ClientConnectionOperator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ClientConnectionOperator.java Wed Apr 7 17:28:15 2010
@@ -32,7 +32,7 @@ import java.net.InetAddress;
import java.net.Socket;
import org.apache.http.HttpHost;
-import org.apache.http.conn.scheme.SocketFactory;
+import org.apache.http.conn.scheme.SchemeSocketFactory;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
@@ -40,7 +40,7 @@ import org.apache.http.protocol.HttpCont
* ClientConnectionOperator represents a strategy for creating
* {@link OperatedClientConnection} instances and updating the underlying
* {@link Socket} of those objects. Implementations will most likely make use
- * of {@link SocketFactory}s to create {@link Socket} instances.
+ * of {@link SchemeSocketFactory}s to create {@link Socket} instances.
* <p>
* The methods in this interface allow the creation of plain and layered
* sockets. Creating a tunnelled connection through a proxy, however,
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/MultihomePlainSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/MultihomePlainSocketFactory.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/MultihomePlainSocketFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/MultihomePlainSocketFactory.java Wed Apr 7 17:28:15 2010
@@ -39,6 +39,7 @@ import java.util.Arrays;
import org.apache.http.annotation.Immutable;
+import org.apache.http.conn.scheme.SchemeSocketFactory;
import org.apache.http.conn.scheme.SocketFactory;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
@@ -51,7 +52,11 @@ import org.apache.http.params.HttpParams
* {@link #createSocket()} method.
*
* @since 4.0
+ *
+ * @deprecated Do not use. For multihome support socket factories must implement
+ * {@link SchemeSocketFactory} interface.
*/
+@Deprecated
@Immutable
public final class MultihomePlainSocketFactory implements SocketFactory {
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/HostNameResolver.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/HostNameResolver.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/HostNameResolver.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/HostNameResolver.java Wed Apr 7 17:28:15 2010
@@ -34,7 +34,10 @@ import java.net.InetAddress;
* Hostname to IP address resolver.
*
* @since 4.0
+ *
+ * @deprecated Do not use
*/
+@Deprecated
public interface HostNameResolver {
/**
Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSchemeSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSchemeSocketFactory.java?rev=931624&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSchemeSocketFactory.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSchemeSocketFactory.java Wed Apr 7 17:28:15 2010
@@ -0,0 +1,66 @@
+/*
+ * ====================================================================
+ * 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.conn.scheme;
+
+import java.io.IOException;
+import java.net.Socket;
+import java.net.UnknownHostException;
+
+/**
+ * A {@link SocketFactory SocketFactory} for layered sockets (SSL/TLS).
+ * See there for things to consider when implementing a socket factory.
+ *
+ * @since 4.1
+ */
+public interface LayeredSchemeSocketFactory extends SchemeSocketFactory {
+
+ /**
+ * Returns a socket connected to the given host that is layered over an
+ * existing socket. Used primarily for creating secure sockets through
+ * proxies.
+ *
+ * @param socket the existing socket
+ * @param target the name of the target host.
+ * @param port the port to connect to on the target host
+ * @param autoClose a flag for closing the underling socket when the created
+ * socket is closed
+ *
+ * @return Socket a new socket
+ *
+ * @throws IOException if an I/O error occurs while creating the socket
+ * @throws UnknownHostException if the IP address of the host cannot be
+ * determined
+ */
+ Socket createLayeredSocket(
+ Socket socket,
+ String target,
+ int port,
+ boolean autoClose
+ ) throws IOException, UnknownHostException;
+
+}
Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSchemeSocketFactoryAdaptor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSchemeSocketFactoryAdaptor.java?rev=931624&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSchemeSocketFactoryAdaptor.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSchemeSocketFactoryAdaptor.java Wed Apr 7 17:28:15 2010
@@ -0,0 +1,52 @@
+/*
+ * ====================================================================
+ * 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.conn.scheme;
+
+import java.io.IOException;
+import java.net.Socket;
+import java.net.UnknownHostException;
+
+@Deprecated
+class LayeredSchemeSocketFactoryAdaptor extends SchemeSocketFactoryAdaptor
+ implements LayeredSchemeSocketFactory {
+
+ private final LayeredSocketFactory factory;
+
+ LayeredSchemeSocketFactoryAdaptor(final LayeredSocketFactory factory) {
+ super(factory);
+ this.factory = factory;
+ }
+
+ public Socket createLayeredSocket(
+ final Socket socket,
+ final String target, int port,
+ boolean autoClose) throws IOException, UnknownHostException {
+ return this.factory.createSocket(socket, target, port, autoClose);
+ }
+
+}
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSocketFactory.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSocketFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSocketFactory.java Wed Apr 7 17:28:15 2010
@@ -36,7 +36,10 @@ import java.net.UnknownHostException;
* See there for things to consider when implementing a socket factory.
*
* @since 4.0
+ *
+ * @deprecated use {@link SchemeSocketFactory}
*/
+@Deprecated
public interface LayeredSocketFactory extends SocketFactory {
/**
Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSocketFactoryAdaptor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSocketFactoryAdaptor.java?rev=931624&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSocketFactoryAdaptor.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSocketFactoryAdaptor.java Wed Apr 7 17:28:15 2010
@@ -0,0 +1,50 @@
+/*
+ * ====================================================================
+ * 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.conn.scheme;
+
+import java.io.IOException;
+import java.net.Socket;
+import java.net.UnknownHostException;
+
+@Deprecated
+class LayeredSocketFactoryAdaptor extends SocketFactoryAdaptor implements LayeredSocketFactory {
+
+ private final LayeredSchemeSocketFactory factory;
+
+ LayeredSocketFactoryAdaptor(final LayeredSchemeSocketFactory factory) {
+ super(factory);
+ this.factory = factory;
+ }
+
+ public Socket createSocket(
+ final Socket socket,
+ final String host, int port, boolean autoClose) throws IOException, UnknownHostException {
+ return this.factory.createLayeredSocket(socket, host, port, autoClose);
+ }
+
+}
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java Wed Apr 7 17:28:15 2010
@@ -32,6 +32,7 @@ import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketTimeoutException;
+import java.net.UnknownHostException;
import org.apache.http.annotation.Immutable;
@@ -50,14 +51,14 @@ import org.apache.http.params.HttpParams
*
* @since 4.0
*/
+@SuppressWarnings("deprecation")
@Immutable
-public final class PlainSocketFactory implements SocketFactory {
+public final class PlainSocketFactory implements SocketFactory, SchemeSocketFactory {
/**
* The default factory.
*/
- private static final
- PlainSocketFactory DEFAULT_FACTORY = new PlainSocketFactory();
+ private static final PlainSocketFactory DEFAULT_FACTORY = new PlainSocketFactory();
private final HostNameResolver nameResolver;
@@ -71,58 +72,48 @@ public final class PlainSocketFactory im
return DEFAULT_FACTORY;
}
+ @Deprecated
public PlainSocketFactory(final HostNameResolver nameResolver) {
super();
this.nameResolver = nameResolver;
}
-
public PlainSocketFactory() {
- this(null);
+ super();
+ this.nameResolver = null;
}
public Socket createSocket() {
return new Socket();
}
- public Socket connectSocket(Socket sock, String host, int port,
- InetAddress localAddress, int localPort,
- HttpParams params)
- throws IOException {
-
- if (host == null) {
- throw new IllegalArgumentException("Target host may not be null.");
+ /**
+ * @since 4.1
+ */
+ public Socket connectSocket(
+ final Socket socket,
+ final InetSocketAddress remoteAddress,
+ final InetSocketAddress localAddress,
+ final HttpParams params) throws IOException, ConnectTimeoutException {
+ if (remoteAddress == null) {
+ throw new IllegalArgumentException("Remote address may not be null");
}
if (params == null) {
- throw new IllegalArgumentException("Parameters may not be null.");
+ throw new IllegalArgumentException("HTTP parameters may not be null");
}
-
- if (sock == null)
+ Socket sock = socket;
+ if (sock == null) {
sock = createSocket();
-
- if ((localAddress != null) || (localPort > 0)) {
-
- // we need to bind explicitly
- if (localPort < 0)
- localPort = 0; // indicates "any"
-
- InetSocketAddress isa =
- new InetSocketAddress(localAddress, localPort);
- sock.bind(isa);
}
-
- int timeout = HttpConnectionParams.getConnectionTimeout(params);
-
- InetSocketAddress remoteAddress;
- if (this.nameResolver != null) {
- remoteAddress = new InetSocketAddress(this.nameResolver.resolve(host), port);
- } else {
- remoteAddress = new InetSocketAddress(host, port);
+ if (localAddress != null) {
+ sock.bind(localAddress);
}
+ int timeout = HttpConnectionParams.getConnectionTimeout(params);
try {
sock.connect(remoteAddress, timeout);
} catch (SocketTimeoutException ex) {
- throw new ConnectTimeoutException("Connect to " + remoteAddress + " timed out");
+ throw new ConnectTimeoutException("Connect to " + remoteAddress.getHostName() + "/"
+ + remoteAddress.getAddress() + " timed out");
}
return sock;
}
@@ -152,4 +143,31 @@ public final class PlainSocketFactory im
return false;
}
+ /**
+ * @deprecated Use {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams)}
+ */
+ @Deprecated
+ public Socket connectSocket(
+ final Socket socket,
+ final String host, int port,
+ final InetAddress localAddress, int localPort,
+ final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
+ InetSocketAddress local = null;
+ if (localAddress != null || localPort > 0) {
+ // we need to bind explicitly
+ if (localPort < 0) {
+ localPort = 0; // indicates "any"
+ }
+ local = new InetSocketAddress(localAddress, localPort);
+ }
+ InetAddress remoteAddress;
+ if (this.nameResolver != null) {
+ remoteAddress = this.nameResolver.resolve(host);
+ } else {
+ remoteAddress = InetAddress.getByName(host);
+ }
+ InetSocketAddress remote = new InetSocketAddress(remoteAddress, port);
+ return connectSocket(socket, remote, local, params);
+ }
+
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/Scheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/Scheme.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/Scheme.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/Scheme.java Wed Apr 7 17:28:15 2010
@@ -33,21 +33,16 @@ import org.apache.http.annotation.Immuta
import org.apache.http.util.LangUtils;
/**
- * Encapsulates specifics of a protocol scheme such as "http" or "https".
- * Schemes are identified by lowercase names.
- * Supported schemes are typically collected in a
- * {@link SchemeRegistry SchemeRegistry}.
- *
+ * Encapsulates specifics of a protocol scheme such as "http" or "https". Schemes are identified
+ * by lowercase names. Supported schemes are typically collected in a {@link SchemeRegistry
+ * SchemeRegistry}.
* <p>
- * For example, to configure support for "https://" URLs,
- * you could write code like the following:
- * </p>
+ * For example, to configure support for "https://" URLs, you could write code like the following:
* <pre>
- * Scheme https = new Scheme("https", new MySecureSocketFactory(), 443);
+ * Scheme https = new Scheme("https", 443, new MySecureSocketFactory());
* SchemeRegistry.DEFAULT.register(https);
* </pre>
*
- *
* @since 4.0
*/
@Immutable
@@ -57,7 +52,7 @@ public final class Scheme {
private final String name;
/** The socket factory for this scheme */
- private final SocketFactory socketFactory;
+ private final SchemeSocketFactory socketFactory;
/** The default port for this scheme */
private final int defaultPort;
@@ -65,7 +60,6 @@ public final class Scheme {
/** Indicates whether this scheme allows for layered connections */
private final boolean layered;
-
/** A string representation, for {@link #toString toString}. */
private String stringRep;
/*
@@ -74,6 +68,34 @@ public final class Scheme {
* need to synchronize, and it does not affect immutability.
*/
+ /**
+ * Creates a new scheme.
+ * Whether the created scheme allows for layered connections
+ * depends on the class of <code>factory</code>.
+ *
+ * @param name the scheme name, for example "http".
+ * The name will be converted to lowercase.
+ * @param port the default port for this scheme
+ * @param factory the factory for creating sockets for communication
+ * with this scheme
+ *
+ * @since 4.1
+ */
+ public Scheme(final String name, final int port, final SchemeSocketFactory factory) {
+ if (name == null) {
+ throw new IllegalArgumentException("Scheme name may not be null");
+ }
+ if ((port <= 0) || (port > 0xffff)) {
+ throw new IllegalArgumentException("Port is invalid: " + port);
+ }
+ if (factory == null) {
+ throw new IllegalArgumentException("Socket factory may not be null");
+ }
+ this.name = name.toLowerCase(Locale.ENGLISH);
+ this.socketFactory = factory;
+ this.defaultPort = port;
+ this.layered = factory instanceof LayeredSchemeSocketFactory;
+ }
/**
* Creates a new scheme.
@@ -85,7 +107,10 @@ public final class Scheme {
* @param factory the factory for creating sockets for communication
* with this scheme
* @param port the default port for this scheme
+ *
+ * @deprecated Use {@link #Scheme(String, int, SchemeSocketFactory)}
*/
+ @Deprecated
public Scheme(final String name,
final SocketFactory factory,
final int port) {
@@ -104,12 +129,17 @@ public final class Scheme {
}
this.name = name.toLowerCase(Locale.ENGLISH);
- this.socketFactory = factory;
+ if (factory instanceof LayeredSocketFactory) {
+ this.socketFactory = new LayeredSchemeSocketFactoryAdaptor(
+ (LayeredSocketFactory) factory);
+ this.layered = true;
+ } else {
+ this.socketFactory = new SchemeSocketFactoryAdaptor(factory);
+ this.layered = false;
+ }
this.defaultPort = port;
- this.layered = (factory instanceof LayeredSocketFactory);
}
-
/**
* Obtains the default port.
*
@@ -126,11 +156,35 @@ public final class Scheme {
* {@link LayeredSocketFactory LayeredSocketFactory}.
*
* @return the socket factory for this scheme
+ *
+ * @deprecated Use {@link #getSchemeSocketFactory()}
*/
+ @Deprecated
public final SocketFactory getSocketFactory() {
- return socketFactory;
+ if (this.socketFactory instanceof SchemeSocketFactoryAdaptor) {
+ return ((SchemeSocketFactoryAdaptor) this.socketFactory).getFactory();
+ } else {
+ if (this.layered) {
+ return new LayeredSocketFactoryAdaptor(
+ (LayeredSchemeSocketFactory) this.socketFactory);
+ } else {
+ return new SocketFactoryAdaptor(this.socketFactory);
+ }
+ }
}
+ /**
+ * Obtains the socket factory.
+ * If this scheme is {@link #isLayered layered}, the factory implements
+ * {@link LayeredSocketFactory LayeredSchemeSocketFactory}.
+ *
+ * @return the socket factory for this scheme
+ *
+ * @since 4.1
+ */
+ public final SchemeSocketFactory getSchemeSocketFactory() {
+ return this.socketFactory;
+ }
/**
* Obtains the scheme name.
@@ -141,7 +195,6 @@ public final class Scheme {
return name;
}
-
/**
* Indicates whether this scheme allows for layered connections.
*
@@ -152,7 +205,6 @@ public final class Scheme {
return layered;
}
-
/**
* Resolves the correct port for this scheme.
* Returns the given port if it is valid, the default port otherwise.
@@ -166,7 +218,6 @@ public final class Scheme {
return port <= 0 ? defaultPort : port;
}
-
/**
* Return a string representation of this object.
*
@@ -184,34 +235,21 @@ public final class Scheme {
return stringRep;
}
-
- /**
- * Compares this scheme to an object.
- *
- * @param obj the object to compare with
- *
- * @return <code>true</code> iff the argument is equal to this scheme
- */
@Override
public final boolean equals(Object obj) {
if (obj == null) return false;
if (this == obj) return true;
- if (!(obj instanceof Scheme)) return false;
-
- Scheme s = (Scheme) obj;
- return (name.equals(s.name) &&
- defaultPort == s.defaultPort &&
- layered == s.layered &&
- socketFactory.equals(s.socketFactory)
- );
- } // equals
-
+ if (obj instanceof Scheme) {
+ Scheme that = (Scheme) obj;
+ return this.name.equals(that.name)
+ && this.defaultPort == that.defaultPort
+ && this.layered == that.layered
+ && this.socketFactory.equals(that.socketFactory);
+ } else {
+ return false;
+ }
+ }
- /**
- * Obtains a hash code for this scheme.
- *
- * @return the hash code
- */
@Override
public int hashCode() {
int hash = LangUtils.HASH_SEED;
@@ -222,4 +260,4 @@ public final class Scheme {
return hash;
}
-} // class Scheme
+}
Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeSocketFactory.java?rev=931624&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeSocketFactory.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeSocketFactory.java Wed Apr 7 17:28:15 2010
@@ -0,0 +1,110 @@
+/*
+ * ====================================================================
+ * 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.conn.scheme;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+
+import org.apache.http.conn.ConnectTimeoutException;
+import org.apache.http.params.HttpParams;
+
+/**
+ * A factory for creating, initializing and connecting sockets. The factory encapsulates the logic
+ * for establishing a socket connection.
+ *
+ * @since 4.1
+ */
+public interface SchemeSocketFactory {
+
+ /**
+ * Creates a new, unconnected socket. The socket should subsequently be passed to
+ * {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams)}.
+ *
+ * @return a new socket
+ *
+ * @throws IOException if an I/O error occurs while creating the socket
+ */
+ Socket createSocket() throws IOException;
+
+ /**
+ * Connects a socket to the target host with the given remote address.
+ *
+ * @param sock the socket to connect, as obtained from
+ * {@link #createSocket() createSocket}.
+ * <code>null</code> indicates that a new socket
+ * should be created and connected.
+ * @param remoteAddress the remote address to connect to
+ * @param localAddress the local address to bind the socket to, or
+ * <code>null</code> for any
+ * @param params additional {@link HttpParams parameters} for connecting
+ *
+ * @return the connected socket. The returned object may be different
+ * from the <code>sock</code> argument if this factory supports
+ * a layered protocol.
+ *
+ * @throws IOException if an I/O error occurs
+ * @throws UnknownHostException if the IP address of the target host
+ * can not be determined
+ * @throws ConnectTimeoutException if the socket cannot be connected
+ * within the time limit defined in the <code>params</code>
+ */
+ Socket connectSocket(
+ Socket sock,
+ InetSocketAddress remoteAddress,
+ InetSocketAddress localAddress,
+ HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException;
+
+ /**
+ * Checks whether a socket provides a secure connection. The socket must be
+ * {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams) connected}
+ * by this factory. The factory will <i>not</i> perform I/O operations in this method.
+ * <p>
+ * As a rule of thumb, plain sockets are not secure and TLS/SSL sockets are secure. However,
+ * there may be application specific deviations. For example, a plain socket to a host in the
+ * same intranet ("trusted zone") could be considered secure. On the other hand, a TLS/SSL
+ * socket could be considered insecure based on the cipher suite chosen for the connection.
+ *
+ * @param sock the connected socket to check
+ *
+ * @return <code>true</code> if the connection of the socket
+ * should be considered secure, or
+ * <code>false</code> if it should not
+ *
+ * @throws IllegalArgumentException
+ * if the argument is invalid, for example because it is
+ * not a connected socket or was created by a different
+ * socket factory.
+ * Note that socket factories are <i>not</i> required to
+ * check these conditions, they may simply return a default
+ * value when called with an invalid socket argument.
+ */
+ boolean isSecure(Socket sock) throws IllegalArgumentException;
+
+}
Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeSocketFactoryAdaptor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeSocketFactoryAdaptor.java?rev=931624&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeSocketFactoryAdaptor.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeSocketFactoryAdaptor.java Wed Apr 7 17:28:15 2010
@@ -0,0 +1,93 @@
+/*
+ * ====================================================================
+ * 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.conn.scheme;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+
+import org.apache.http.conn.ConnectTimeoutException;
+import org.apache.http.params.HttpParams;
+
+@Deprecated
+class SchemeSocketFactoryAdaptor implements SchemeSocketFactory {
+
+ private final SocketFactory factory;
+
+ SchemeSocketFactoryAdaptor(final SocketFactory factory) {
+ super();
+ this.factory = factory;
+ }
+
+ public Socket connectSocket(
+ final Socket sock,
+ final InetSocketAddress remoteAddress,
+ final InetSocketAddress localAddress,
+ final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
+ String host = remoteAddress.getHostName();
+ int port = remoteAddress.getPort();
+ InetAddress local = null;
+ int localPort = 0;
+ if (localAddress != null) {
+ local = localAddress.getAddress();
+ localPort = localAddress.getPort();
+ }
+ return this.factory.connectSocket(sock, host, port, local, localPort, params);
+ }
+
+ public Socket createSocket() throws IOException {
+ return this.factory.createSocket();
+ }
+
+ public boolean isSecure(final Socket sock) throws IllegalArgumentException {
+ return this.factory.isSecure(sock);
+ }
+
+ public SocketFactory getFactory() {
+ return this.factory;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == null) return false;
+ if (this == obj) return true;
+ if (obj instanceof SchemeSocketFactoryAdaptor) {
+ return this.factory.equals(((SchemeSocketFactoryAdaptor)obj).factory);
+ } else {
+ return this.factory.equals(obj);
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return this.factory.hashCode();
+ }
+
+}
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SocketFactory.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SocketFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SocketFactory.java Wed Apr 7 17:28:15 2010
@@ -40,7 +40,10 @@ import org.apache.http.params.HttpParams
* The factory encapsulates the logic for establishing a socket connection.
*
* @since 4.0
+ *
+ * @deprecated use {@link SchemeSocketFactory}
*/
+@Deprecated
public interface SocketFactory {
/**
Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SocketFactoryAdaptor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SocketFactoryAdaptor.java?rev=931624&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SocketFactoryAdaptor.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SocketFactoryAdaptor.java Wed Apr 7 17:28:15 2010
@@ -0,0 +1,95 @@
+/*
+ * ====================================================================
+ * 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.conn.scheme;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+
+import org.apache.http.conn.ConnectTimeoutException;
+import org.apache.http.params.HttpParams;
+
+@Deprecated
+class SocketFactoryAdaptor implements SocketFactory {
+
+ private final SchemeSocketFactory factory;
+
+ SocketFactoryAdaptor(final SchemeSocketFactory factory) {
+ super();
+ this.factory = factory;
+ }
+
+ public Socket createSocket() throws IOException {
+ return this.factory.createSocket();
+ }
+
+ public Socket connectSocket(
+ final Socket socket,
+ final String host, int port,
+ final InetAddress localAddress, int localPort,
+ final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
+ InetSocketAddress local = null;
+ if (localAddress != null || localPort > 0) {
+ // we need to bind explicitly
+ if (localPort < 0) {
+ localPort = 0; // indicates "any"
+ }
+ local = new InetSocketAddress(localAddress, localPort);
+ }
+ InetAddress remoteAddress = InetAddress.getByName(host);
+ InetSocketAddress remote = new InetSocketAddress(remoteAddress, port);
+ return this.factory.connectSocket(socket, remote, local, params);
+ }
+
+ public boolean isSecure(final Socket socket) throws IllegalArgumentException {
+ return this.factory.isSecure(socket);
+ }
+
+ public SchemeSocketFactory getFactory() {
+ return this.factory;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == null) return false;
+ if (this == obj) return true;
+ if (obj instanceof SocketFactoryAdaptor) {
+ return this.factory.equals(((SocketFactoryAdaptor)obj).factory);
+ } else {
+ return this.factory.equals(obj);
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return this.factory.hashCode();
+ }
+
+}
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java Wed Apr 7 17:28:15 2010
@@ -27,10 +27,11 @@
package org.apache.http.conn.ssl;
-import org.apache.http.annotation.NotThreadSafe;
+import org.apache.http.annotation.ThreadSafe;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.scheme.HostNameResolver;
+import org.apache.http.conn.scheme.LayeredSchemeSocketFactory;
import org.apache.http.conn.scheme.LayeredSocketFactory;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
@@ -144,8 +145,9 @@ import java.security.UnrecoverableKeyExc
*
* @since 4.0
*/
-@NotThreadSafe // [gs]etHostNameVerifier
-public class SSLSocketFactory implements LayeredSocketFactory {
+@SuppressWarnings("deprecation")
+@ThreadSafe
+public class SSLSocketFactory implements LayeredSchemeSocketFactory, LayeredSocketFactory {
public static final String TLS = "TLS";
public static final String SSL = "SSL";
@@ -178,10 +180,13 @@ public class SSLSocketFactory implements
private final SSLContext sslcontext;
private final javax.net.ssl.SSLSocketFactory socketfactory;
private final HostNameResolver nameResolver;
-
- // volatile is needed to guarantee thread-safety of the setter/getter methods under all usage scenarios
- private volatile X509HostnameVerifier hostnameVerifier = BROWSER_COMPATIBLE_HOSTNAME_VERIFIER;
+ // TODO: make final
+ private volatile X509HostnameVerifier hostnameVerifier;
+ /**
+ * @deprecated Use {@link #SSLSocketFactory(String, KeyStore, String, KeyStore, SecureRandom, X509HostnameVerifier)}
+ */
+ @Deprecated
public SSLSocketFactory(
String algorithm,
final KeyStore keystore,
@@ -206,42 +211,87 @@ public class SSLSocketFactory implements
this.sslcontext = SSLContext.getInstance(algorithm);
this.sslcontext.init(keymanagers, trustmanagers, random);
this.socketfactory = this.sslcontext.getSocketFactory();
+ this.hostnameVerifier = BROWSER_COMPATIBLE_HOSTNAME_VERIFIER;
this.nameResolver = nameResolver;
}
+ /**
+ * @since 4.1
+ */
+ public SSLSocketFactory(
+ String algorithm,
+ final KeyStore keystore,
+ final String keystorePassword,
+ final KeyStore truststore,
+ final SecureRandom random,
+ final X509HostnameVerifier hostnameVerifier)
+ throws NoSuchAlgorithmException, KeyManagementException,
+ KeyStoreException, UnrecoverableKeyException {
+ super();
+ if (algorithm == null) {
+ algorithm = TLS;
+ }
+ KeyManager[] keymanagers = null;
+ if (keystore != null) {
+ keymanagers = createKeyManagers(keystore, keystorePassword);
+ }
+ TrustManager[] trustmanagers = null;
+ if (truststore != null) {
+ trustmanagers = createTrustManagers(truststore);
+ }
+ this.sslcontext = SSLContext.getInstance(algorithm);
+ this.sslcontext.init(keymanagers, trustmanagers, random);
+ this.socketfactory = this.sslcontext.getSocketFactory();
+ this.hostnameVerifier = hostnameVerifier;
+ this.nameResolver = null;
+ }
+
public SSLSocketFactory(
final KeyStore keystore,
final String keystorePassword,
final KeyStore truststore)
throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException
{
- this(TLS, keystore, keystorePassword, truststore, null, null);
+ this(TLS, keystore, keystorePassword, truststore, null, BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
}
public SSLSocketFactory(final KeyStore keystore, final String keystorePassword)
throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException
{
- this(TLS, keystore, keystorePassword, null, null, null);
+ this(TLS, keystore, keystorePassword, null, null, BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
}
public SSLSocketFactory(final KeyStore truststore)
throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException
{
- this(TLS, null, null, truststore, null, null);
+ this(TLS, null, null, truststore, null, BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
}
- public SSLSocketFactory(
- final SSLContext sslContext,
- final HostNameResolver nameResolver)
- {
+ /**
+ * @deprecated Use {@link #SSLSocketFactory(SSLContext)}
+ */
+ @Deprecated
+ public SSLSocketFactory(final SSLContext sslContext, final HostNameResolver nameResolver) {
+ super();
this.sslcontext = sslContext;
this.socketfactory = this.sslcontext.getSocketFactory();
+ this.hostnameVerifier = BROWSER_COMPATIBLE_HOSTNAME_VERIFIER;
this.nameResolver = nameResolver;
}
- public SSLSocketFactory(final SSLContext sslContext)
- {
- this(sslContext, null);
+ /**
+ * @since 4.1
+ */
+ public SSLSocketFactory(final SSLContext sslContext, final X509HostnameVerifier hostnameVerifier) {
+ super();
+ this.sslcontext = sslContext;
+ this.socketfactory = this.sslcontext.getSocketFactory();
+ this.hostnameVerifier = hostnameVerifier;
+ this.nameResolver = null;
+ }
+
+ public SSLSocketFactory(final SSLContext sslContext) {
+ this(sslContext, BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
}
/**
@@ -278,72 +328,51 @@ public class SSLSocketFactory implements
return tmfactory.getTrustManagers();
}
-
- // non-javadoc, see interface org.apache.http.conn.SocketFactory
@SuppressWarnings("cast")
- public Socket createSocket()
- throws IOException {
-
+ public Socket createSocket() throws IOException {
// the cast makes sure that the factory is working as expected
return (SSLSocket) this.socketfactory.createSocket();
}
-
- // non-javadoc, see interface org.apache.http.conn.SocketFactory
+ /**
+ * @since 4.1
+ */
public Socket connectSocket(
- final Socket sock,
- final String host,
- final int port,
- final InetAddress localAddress,
- int localPort,
- final HttpParams params
- ) throws IOException {
-
- if (host == null) {
- throw new IllegalArgumentException("Target host may not be null.");
+ final Socket sock,
+ final InetSocketAddress remoteAddress,
+ final InetSocketAddress localAddress,
+ final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
+ if (remoteAddress == null) {
+ throw new IllegalArgumentException("Remote address may not be null");
}
if (params == null) {
- throw new IllegalArgumentException("Parameters may not be null.");
+ throw new IllegalArgumentException("HTTP parameters may not be null");
}
-
- SSLSocket sslsock = (SSLSocket)
- ((sock != null) ? sock : createSocket());
-
- if ((localAddress != null) || (localPort > 0)) {
-
- // we need to bind explicitly
- if (localPort < 0)
- localPort = 0; // indicates "any"
-
- InetSocketAddress isa =
- new InetSocketAddress(localAddress, localPort);
- sslsock.bind(isa);
+ SSLSocket sslsock = (SSLSocket) (sock != null ? sock : createSocket());
+ if (localAddress != null) {
+ sslsock.bind(localAddress);
}
int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
int soTimeout = HttpConnectionParams.getSoTimeout(params);
- InetSocketAddress remoteAddress;
- if (this.nameResolver != null) {
- remoteAddress = new InetSocketAddress(this.nameResolver.resolve(host), port);
- } else {
- remoteAddress = new InetSocketAddress(host, port);
- }
try {
sslsock.connect(remoteAddress, connTimeout);
} catch (SocketTimeoutException ex) {
- throw new ConnectTimeoutException("Connect to " + remoteAddress + " timed out");
+ throw new ConnectTimeoutException("Connect to " + remoteAddress.getHostName() + "/"
+ + remoteAddress.getAddress() + " timed out");
}
sslsock.setSoTimeout(soTimeout);
- try {
- hostnameVerifier.verify(host, sslsock);
- // verifyHostName() didn't blowup - good!
- } catch (IOException iox) {
- // close the socket before re-throwing the exception
- try { sslsock.close(); } catch (Exception x) { /*ignore*/ }
- throw iox;
+ if (this.hostnameVerifier != null) {
+ try {
+ this.hostnameVerifier.verify(remoteAddress.getHostName(), sslsock);
+ // verifyHostName() didn't blowup - good!
+ } catch (IOException iox) {
+ // close the socket before re-throwing the exception
+ try { sslsock.close(); } catch (Exception x) { /*ignore*/ }
+ throw iox;
+ }
}
-
return sslsock;
}
@@ -362,45 +391,43 @@ public class SSLSocketFactory implements
*
* @throws IllegalArgumentException if the argument is invalid
*/
- public boolean isSecure(Socket sock)
- throws IllegalArgumentException {
-
+ public boolean isSecure(final Socket sock) throws IllegalArgumentException {
if (sock == null) {
- throw new IllegalArgumentException("Socket may not be null.");
+ throw new IllegalArgumentException("Socket may not be null");
}
// This instanceof check is in line with createSocket() above.
if (!(sock instanceof SSLSocket)) {
- throw new IllegalArgumentException
- ("Socket not created by this factory.");
+ throw new IllegalArgumentException("Socket not created by this factory");
}
// This check is performed last since it calls the argument object.
if (sock.isClosed()) {
- throw new IllegalArgumentException("Socket is closed.");
+ throw new IllegalArgumentException("Socket is closed");
}
-
return true;
+ }
- } // isSecure
-
-
- // non-javadoc, see interface LayeredSocketFactory
- public Socket createSocket(
+ /**
+ * @since 4.1
+ */
+ public Socket createLayeredSocket(
final Socket socket,
final String host,
final int port,
- final boolean autoClose
- ) throws IOException, UnknownHostException {
+ final boolean autoClose) throws IOException, UnknownHostException {
SSLSocket sslSocket = (SSLSocket) this.socketfactory.createSocket(
socket,
host,
port,
autoClose
);
- hostnameVerifier.verify(host, sslSocket);
+ if (this.hostnameVerifier != null) {
+ this.hostnameVerifier.verify(host, sslSocket);
+ }
// verifyHostName() didn't blowup - good!
return sslSocket;
}
+ @Deprecated
public void setHostnameVerifier(X509HostnameVerifier hostnameVerifier) {
if ( hostnameVerifier == null ) {
throw new IllegalArgumentException("Hostname verifier may not be null");
@@ -409,7 +436,45 @@ public class SSLSocketFactory implements
}
public X509HostnameVerifier getHostnameVerifier() {
- return hostnameVerifier;
+ return this.hostnameVerifier;
+ }
+
+ /**
+ * @deprecated Use {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams)}
+ */
+ @Deprecated
+ public Socket connectSocket(
+ final Socket socket,
+ final String host, int port,
+ final InetAddress localAddress, int localPort,
+ final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
+ InetSocketAddress local = null;
+ if (localAddress != null || localPort > 0) {
+ // we need to bind explicitly
+ if (localPort < 0) {
+ localPort = 0; // indicates "any"
+ }
+ local = new InetSocketAddress(localAddress, localPort);
+ }
+ InetAddress remoteAddress;
+ if (this.nameResolver != null) {
+ remoteAddress = this.nameResolver.resolve(host);
+ } else {
+ remoteAddress = InetAddress.getByName(host);
+ }
+ InetSocketAddress remote = new InetSocketAddress(remoteAddress, port);
+ return connectSocket(socket, remote, local, params);
+ }
+
+ /**
+ * @deprecated Use {@link #createLayeredSocket(Socket, String, int, boolean)}
+ */
+ @Deprecated
+ public Socket createSocket(
+ final Socket socket,
+ final String host, int port,
+ boolean autoClose) throws IOException, UnknownHostException {
+ return createLayeredSocket(socket, host, port, autoClose);
}
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java Wed Apr 7 17:28:15 2010
@@ -221,9 +221,9 @@ public class DefaultHttpClient extends A
protected ClientConnectionManager createClientConnectionManager() {
SchemeRegistry registry = new SchemeRegistry();
registry.register(
- new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
+ new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
registry.register(
- new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
+ new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
ClientConnectionManager connManager = null;
HttpParams params = getParams();
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RedirectLocations.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RedirectLocations.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RedirectLocations.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RedirectLocations.java Wed Apr 7 17:28:15 2010
@@ -86,7 +86,7 @@ public class RedirectLocations {
}
/**
- * Returns all redirect {@Link URI}s in the order they were added to the collection.
+ * Returns all redirect {@link URI}s in the order they were added to the collection.
*
* @return list of all URIs
*
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java Wed Apr 7 17:28:15 2010
@@ -29,6 +29,7 @@ package org.apache.http.impl.conn;
import java.io.IOException;
import java.net.ConnectException;
+import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.InetAddress;
@@ -42,14 +43,14 @@ import org.apache.http.protocol.HttpCont
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.conn.OperatedClientConnection;
import org.apache.http.conn.ClientConnectionOperator;
-import org.apache.http.conn.scheme.LayeredSocketFactory;
+import org.apache.http.conn.scheme.LayeredSchemeSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.scheme.SocketFactory;
+import org.apache.http.conn.scheme.SchemeSocketFactory;
/**
* Default implementation of a {@link ClientConnectionOperator}. It uses
- * a {@link SchemeRegistry} to look up {@link SocketFactory} objects.
+ * a {@link SchemeRegistry} to look up {@link SchemeSocketFactory} objects.
* <p>
* The following parameters can be used to customize the behavior of this
* class:
@@ -113,16 +114,21 @@ public class DefaultClientConnectionOper
("Connection must not be open.");
}
- final Scheme schm = schemeRegistry.getScheme(target.getSchemeName());
- final SocketFactory sf = schm.getSocketFactory();
+ Scheme schm = schemeRegistry.getScheme(target.getSchemeName());
+ SchemeSocketFactory sf = schm.getSchemeSocketFactory();
Socket sock = sf.createSocket();
conn.opening(sock, target);
+ InetAddress address = InetAddress.getByName(target.getHostName());
+ int port = schm.resolvePort(target.getPort());
+ InetSocketAddress remoteAddress = new InetSocketAddress(address, port);
+ InetSocketAddress localAddress = null;
+ if (local != null) {
+ localAddress = new InetSocketAddress(local, 0);
+ }
try {
- Socket connsock = sf.connectSocket(sock, target.getHostName(),
- schm.resolvePort(target.getPort()),
- local, 0, params);
+ Socket connsock = sf.connectSocket(sock, remoteAddress, localAddress, params);
if (sock != connsock) {
sock = connsock;
conn.opening(sock, target);
@@ -159,17 +165,17 @@ public class DefaultClientConnectionOper
}
final Scheme schm = schemeRegistry.getScheme(target.getSchemeName());
- if (!(schm.getSocketFactory() instanceof LayeredSocketFactory)) {
+ if (!(schm.getSchemeSocketFactory() instanceof LayeredSchemeSocketFactory)) {
throw new IllegalArgumentException
("Target scheme (" + schm.getName() +
") must have layered socket factory.");
}
- final LayeredSocketFactory lsf = (LayeredSocketFactory) schm.getSocketFactory();
- final Socket sock;
+ LayeredSchemeSocketFactory lsf = (LayeredSchemeSocketFactory) schm.getSchemeSocketFactory();
+ Socket sock;
try {
- sock = lsf.createSocket
- (conn.getSocket(), target.getHostName(), target.getPort(), true);
+ sock = lsf.createLayeredSocket(
+ conn.getSocket(), target.getHostName(), target.getPort(), true);
} catch (ConnectException ex) {
throw new HttpHostConnectException(target, ex);
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java Wed Apr 7 17:28:15 2010
@@ -135,7 +135,7 @@ public class ThreadSafeClientConnManager
*
* @return the connection pool to use
*
- * @deprecated use {@link #createConnectionPool(ConnPerRouteBean)}
+ * @deprecated use {@link #createConnectionPool()}
*/
@Deprecated
protected AbstractConnPool createConnectionPool(final HttpParams params) {
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionReuse.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionReuse.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionReuse.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionReuse.java Wed Apr 7 17:28:15 2010
@@ -47,7 +47,7 @@ import org.apache.http.client.methods.Ht
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.scheme.SocketFactory;
+import org.apache.http.conn.scheme.SchemeSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.localserver.LocalTestServer;
@@ -110,8 +110,8 @@ public class TestConnectionReuse extends
HttpConnectionParams.setStaleCheckingEnabled(params, false);
SchemeRegistry supportedSchemes = new SchemeRegistry();
- SocketFactory sf = PlainSocketFactory.getSocketFactory();
- supportedSchemes.register(new Scheme("http", sf, 80));
+ SchemeSocketFactory sf = PlainSocketFactory.getSocketFactory();
+ supportedSchemes.register(new Scheme("http", 80, sf));
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(supportedSchemes);
mgr.setMaxTotalConnections(5);
@@ -180,8 +180,8 @@ public class TestConnectionReuse extends
HttpConnectionParams.setStaleCheckingEnabled(params, false);
SchemeRegistry supportedSchemes = new SchemeRegistry();
- SocketFactory sf = PlainSocketFactory.getSocketFactory();
- supportedSchemes.register(new Scheme("http", sf, 80));
+ SchemeSocketFactory sf = PlainSocketFactory.getSocketFactory();
+ supportedSchemes.register(new Scheme("http", 80, sf));
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(supportedSchemes);
mgr.setMaxTotalConnections(5);
@@ -240,8 +240,8 @@ public class TestConnectionReuse extends
HttpConnectionParams.setStaleCheckingEnabled(params, false);
SchemeRegistry supportedSchemes = new SchemeRegistry();
- SocketFactory sf = PlainSocketFactory.getSocketFactory();
- supportedSchemes.register(new Scheme("http", sf, 80));
+ SchemeSocketFactory sf = PlainSocketFactory.getSocketFactory();
+ supportedSchemes.register(new Scheme("http", 80, sf));
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(supportedSchemes);
mgr.setMaxTotalConnections(5);
@@ -301,8 +301,8 @@ public class TestConnectionReuse extends
HttpConnectionParams.setStaleCheckingEnabled(params, false);
SchemeRegistry supportedSchemes = new SchemeRegistry();
- SocketFactory sf = PlainSocketFactory.getSocketFactory();
- supportedSchemes.register(new Scheme("http", sf, 80));
+ SchemeSocketFactory sf = PlainSocketFactory.getSocketFactory();
+ supportedSchemes.register(new Scheme("http", 80, sf));
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(supportedSchemes);
mgr.setMaxTotalConnections(1);
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestScheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestScheme.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestScheme.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestScheme.java Wed Apr 7 17:28:15 2010
@@ -61,48 +61,41 @@ public class TestScheme extends TestCase
}
public void testConstructor() {
- Scheme http = new Scheme
- ("http", PlainSocketFactory.getSocketFactory(), 80);
+ Scheme http = new Scheme("http", 80, PlainSocketFactory.getSocketFactory());
assertEquals("http", http.getName());
assertEquals(80, http.getDefaultPort());
- assertSame(PlainSocketFactory.getSocketFactory(),
- http.getSocketFactory());
+ assertSame(PlainSocketFactory.getSocketFactory(), http.getSchemeSocketFactory());
assertFalse(http.isLayered());
- Scheme https = new Scheme
- ("https", SecureSocketFactoryMockup.INSTANCE, 443);
- // ("https", SSLSocketFactory.getSocketFactory(), 443);
+ Scheme https = new Scheme("https", 443, SecureSocketFactoryMockup.INSTANCE);
assertEquals("https", https.getName());
assertEquals(443, https.getDefaultPort());
- assertSame(//SSLSocketFactory.getSocketFactory()
- SecureSocketFactoryMockup.INSTANCE,
- https.getSocketFactory());
+ assertSame(SecureSocketFactoryMockup.INSTANCE, https.getSchemeSocketFactory());
assertTrue(https.isLayered());
- Scheme hTtP = new Scheme
- ("hTtP", PlainSocketFactory.getSocketFactory(), 80);
+ Scheme hTtP = new Scheme("hTtP", 80, PlainSocketFactory.getSocketFactory());
assertEquals("http", hTtP.getName());
// the rest is no different from above
try {
- new Scheme(null, PlainSocketFactory.getSocketFactory(), 80);
+ new Scheme(null, 80, PlainSocketFactory.getSocketFactory());
fail("IllegalArgumentException should have been thrown");
} catch (IllegalArgumentException ex) {
// expected
}
try {
- new Scheme("http", null, 80);
+ new Scheme("http", 80, null);
fail("IllegalArgumentException should have been thrown");
} catch (IllegalArgumentException ex) {
// expected
}
try {
- new Scheme("http", PlainSocketFactory.getSocketFactory(), -1);
+ new Scheme("http", -1, PlainSocketFactory.getSocketFactory());
fail("IllegalArgumentException should have been thrown");
} catch (IllegalArgumentException ex) {
// expected
}
try {
- new Scheme("http", PlainSocketFactory.getSocketFactory(), 70000);
+ new Scheme("http", 70000, PlainSocketFactory.getSocketFactory());
fail("IllegalArgumentException should have been thrown");
} catch (IllegalArgumentException ex) {
// expected
@@ -112,13 +105,9 @@ public class TestScheme extends TestCase
public void testRegisterUnregister() {
SchemeRegistry schmreg = new SchemeRegistry();
- Scheme http = new Scheme
- ("http", PlainSocketFactory.getSocketFactory(), 80);
- Scheme https = new Scheme
- ("https", SecureSocketFactoryMockup.INSTANCE, 443);
- // ("https", SSLSocketFactory.getSocketFactory(), 443);
- Scheme myhttp = new Scheme
- ("http", PlainSocketFactory.getSocketFactory(), 80);
+ Scheme http = new Scheme("http", 80, PlainSocketFactory.getSocketFactory());
+ Scheme https = new Scheme("https", 443, SecureSocketFactoryMockup.INSTANCE);
+ Scheme myhttp = new Scheme("http", 80, PlainSocketFactory.getSocketFactory());
HttpHost host = new HttpHost("www.test.invalid", -1, "http");
HttpHost hosts = new HttpHost("www.test.invalid", -1, "https");
@@ -151,11 +140,8 @@ public class TestScheme extends TestCase
assertNotNull(names);
assertTrue(names.isEmpty());
- Scheme http = new Scheme
- ("http", PlainSocketFactory.getSocketFactory(), 80);
- Scheme https = new Scheme
- ("https", SecureSocketFactoryMockup.INSTANCE, 443);
- // ("https", SSLSocketFactory.getSocketFactory(), 443);
+ Scheme http = new Scheme("http", 80, PlainSocketFactory.getSocketFactory());
+ Scheme https = new Scheme("https", 443, SecureSocketFactoryMockup.INSTANCE);
schmreg.register(http);
schmreg.register(https);
@@ -227,34 +213,25 @@ public class TestScheme extends TestCase
}
public void testResolvePort() {
- Scheme http = new Scheme
- ("http", PlainSocketFactory.getSocketFactory(), 80);
+ Scheme http = new Scheme("http", 80, PlainSocketFactory.getSocketFactory());
assertEquals(8080, http.resolvePort(8080));
assertEquals(80, http.resolvePort(-1));
}
public void testHashCode() {
- Scheme http = new Scheme
- ("http", PlainSocketFactory.getSocketFactory(), 80);
- Scheme myhttp = new Scheme
- ("http", PlainSocketFactory.getSocketFactory(), 80);
- Scheme https = new Scheme
- ("https", SecureSocketFactoryMockup.INSTANCE, 443);
- // ("https", SSLSocketFactory.getSocketFactory(), 443);
+ Scheme http = new Scheme("http", 80, PlainSocketFactory.getSocketFactory());
+ Scheme myhttp = new Scheme("http", 80, PlainSocketFactory.getSocketFactory());
+ Scheme https = new Scheme("https", 443, SecureSocketFactoryMockup.INSTANCE);
assertTrue(http.hashCode() != https.hashCode()); // not guaranteed
assertTrue(http.hashCode() == myhttp.hashCode());
}
public void testEquals() {
- Scheme http = new Scheme
- ("http", PlainSocketFactory.getSocketFactory(), 80);
- Scheme myhttp = new Scheme
- ("http", PlainSocketFactory.getSocketFactory(), 80);
- Scheme https = new Scheme
- ("https", SecureSocketFactoryMockup.INSTANCE, 443);
- // ("https", SSLSocketFactory.getSocketFactory(), 443);
+ Scheme http = new Scheme("http", 80, PlainSocketFactory.getSocketFactory());
+ Scheme myhttp = new Scheme("http", 80, PlainSocketFactory.getSocketFactory());
+ Scheme https = new Scheme("https", 443, SecureSocketFactoryMockup.INSTANCE);
assertFalse(http.equals(https));
assertFalse(http.equals(null));
@@ -265,8 +242,7 @@ public class TestScheme extends TestCase
}
public void testToString() {
- Scheme http = new Scheme
- ("http", PlainSocketFactory.getSocketFactory(), 80);
+ Scheme http = new Scheme("http", 80, PlainSocketFactory.getSocketFactory());
// test it twice, the result is cached
assertEquals("http:80", http.toString());
assertEquals("http:80", http.toString());
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/scheme/TestScheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/scheme/TestScheme.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/scheme/TestScheme.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/scheme/TestScheme.java Wed Apr 7 17:28:15 2010
@@ -50,7 +50,7 @@ public class TestScheme extends TestCase
}
public void testPortResolution() {
- Scheme http = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
+ Scheme http = new Scheme("http", 80, PlainSocketFactory.getSocketFactory());
assertEquals(80, http.resolvePort(0));
assertEquals(80, http.resolvePort(-1));
assertEquals(8080, http.resolvePort(8080));
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java Wed Apr 7 17:28:15 2010
@@ -168,10 +168,9 @@ public class TestSSLSocketFactory extend
TestX509HostnameVerifier hostnameVerifier = new TestX509HostnameVerifier();
- SSLSocketFactory socketFactory = new SSLSocketFactory(sslcontext);
- socketFactory.setHostnameVerifier(hostnameVerifier);
+ SSLSocketFactory socketFactory = new SSLSocketFactory(sslcontext, hostnameVerifier);
- Scheme https = new Scheme("https", socketFactory, 443);
+ Scheme https = new Scheme("https", 443, socketFactory);
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getConnectionManager().getSchemeRegistry().register(https);
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestContentCodings.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestContentCodings.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestContentCodings.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestContentCodings.java Wed Apr 7 17:28:15 2010
@@ -185,7 +185,7 @@ public class TestContentCodings extends
int clients = 100;
SchemeRegistry schemeRegistry = new SchemeRegistry();
- schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
+ schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(schemeRegistry);
cm.setMaxTotalConnections(clients);
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java Wed Apr 7 17:28:15 2010
@@ -150,7 +150,7 @@ public class TestDefaultClientRequestDir
CountDownLatch releaseLatch = new CountDownLatch(1);
SchemeRegistry registry = new SchemeRegistry();
- registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
+ registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
SingleClientConnManager conMan = new SingleClientConnManager(registry);
final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
@@ -190,7 +190,7 @@ public class TestDefaultClientRequestDir
this.localServer.register("*", new BasicService());
SchemeRegistry registry = new SchemeRegistry();
- registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
+ registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
SingleClientConnManager conMan = new SingleClientConnManager(registry);
final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
@@ -236,7 +236,7 @@ public class TestDefaultClientRequestDir
this.localServer.register("*", new BasicRedirectService(port));
SchemeRegistry registry = new SchemeRegistry();
- registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
+ registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
CountDownLatch connLatch = new CountDownLatch(1);
CountDownLatch awaitLatch = new CountDownLatch(1);
@@ -295,7 +295,7 @@ public class TestDefaultClientRequestDir
this.localServer.register("*", new ThrowingService());
SchemeRegistry registry = new SchemeRegistry();
- registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
+ registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
ConnMan3 conMan = new ConnMan3(registry);
DefaultHttpClient client = new DefaultHttpClient(conMan, new BasicHttpParams());
@@ -474,7 +474,7 @@ public class TestDefaultClientRequestDir
public SchemeRegistry getSchemeRegistry() {
SchemeRegistry registry = new SchemeRegistry();
- registry.register(new Scheme("http", new SocketFactoryMockup(null), 80));
+ registry.register(new Scheme("http", 80, new SocketFactoryMockup(null)));
return registry;
}
@@ -549,7 +549,7 @@ public class TestDefaultClientRequestDir
public SchemeRegistry getSchemeRegistry() {
SchemeRegistry registry = new SchemeRegistry();
- registry.register(new Scheme("http", new SocketFactoryMockup(null), 80));
+ registry.register(new Scheme("http", 80, new SocketFactoryMockup(null)));
return registry;
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestRequestRetryHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestRequestRetryHandler.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestRequestRetryHandler.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestRequestRetryHandler.java Wed Apr 7 17:28:15 2010
@@ -48,7 +48,7 @@ public class TestRequestRetryHandler ext
throws Exception {
SchemeRegistry schemeRegistry = new SchemeRegistry();
- schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
+ schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
ClientConnectionManager connManager = new ThreadSafeClientConnManager(schemeRegistry);
assertOnRetry(connManager);
@@ -58,14 +58,14 @@ public class TestRequestRetryHandler ext
throws Exception {
SchemeRegistry schemeRegistry = new SchemeRegistry();
- schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
+ schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
ClientConnectionManager connManager = new SingleClientConnManager(schemeRegistry);
assertOnRetry(connManager);
}
protected void assertOnRetry(ClientConnectionManager connManager) throws Exception {
SchemeRegistry schemeRegistry = new SchemeRegistry();
- schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
+ schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
DefaultHttpClient client = new DefaultHttpClient(connManager);
TestHttpRequestRetryHandler testRetryHandler = new TestHttpRequestRetryHandler();
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestProxySelRoutePlanner.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestProxySelRoutePlanner.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestProxySelRoutePlanner.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestProxySelRoutePlanner.java Wed Apr 7 17:28:15 2010
@@ -27,7 +27,6 @@
package org.apache.http.impl.conn;
-
import java.net.Proxy;
import java.net.InetAddress;
import java.net.InetSocketAddress;
@@ -48,12 +47,9 @@ import org.apache.http.conn.routing.Http
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.scheme.SocketFactory;
import org.apache.http.mockup.ProxySelectorMockup;
-
-
/**
* Tests for <code>ProxySelectorRoutePlanner</code>.
*/
@@ -81,8 +77,7 @@ public class TestProxySelRoutePlanner ex
public SchemeRegistry createSchemeRegistry() {
SchemeRegistry schreg = new SchemeRegistry();
- SocketFactory sf = PlainSocketFactory.getSocketFactory();
- schreg.register(new Scheme("http", sf, 80));
+ schreg.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
return schreg;
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestTSCCMNoServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestTSCCMNoServer.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestTSCCMNoServer.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestTSCCMNoServer.java Wed Apr 7 17:28:15 2010
@@ -43,7 +43,6 @@ import org.apache.http.conn.routing.Http
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.scheme.SocketFactory;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
@@ -122,8 +121,7 @@ public class TestTSCCMNoServer extends T
public SchemeRegistry createSchemeRegistry() {
SchemeRegistry schreg = new SchemeRegistry();
- SocketFactory sf = PlainSocketFactory.getSocketFactory();
- schreg.register(new Scheme("http", sf, 80));
+ schreg.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
return schreg;
}