diff --git a/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSchemeSocketFactory.java b/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSchemeSocketFactory.java
index 77ecc34ad..abedca18f 100644
--- a/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSchemeSocketFactory.java
+++ b/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSchemeSocketFactory.java
@@ -35,7 +35,10 @@ import java.net.UnknownHostException;
* Extended {@link SchemeSocketFactory} interface for layered sockets such as SSL/TLS.
*
* @since 4.1
+ *
+ * @deprecated use {@link SchemeLayeredSocketFactory}
*/
+@Deprecated
public interface LayeredSchemeSocketFactory extends SchemeSocketFactory {
/**
diff --git a/httpclient/src/main/java/org/apache/http/conn/scheme/Scheme.java b/httpclient/src/main/java/org/apache/http/conn/scheme/Scheme.java
index ec200404f..7dbb4176a 100644
--- a/httpclient/src/main/java/org/apache/http/conn/scheme/Scheme.java
+++ b/httpclient/src/main/java/org/apache/http/conn/scheme/Scheme.java
@@ -81,6 +81,7 @@ public final class Scheme {
*
* @since 4.1
*/
+ @SuppressWarnings("deprecation")
public Scheme(final String name, final int port, final SchemeSocketFactory factory) {
if (name == null) {
throw new IllegalArgumentException("Scheme name may not be null");
@@ -92,9 +93,17 @@ public final class Scheme {
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;
+ if (factory instanceof SchemeLayeredSocketFactory) {
+ this.layered = true;
+ this.socketFactory = factory;
+ } else if (factory instanceof LayeredSchemeSocketFactory) {
+ this.layered = true;
+ this.socketFactory = new SchemeLayeredSocketFactoryAdaptor2((LayeredSchemeSocketFactory) factory);
+ } else {
+ this.layered = false;
+ this.socketFactory = factory;
+ }
}
/**
@@ -130,7 +139,7 @@ public final class Scheme {
this.name = name.toLowerCase(Locale.ENGLISH);
if (factory instanceof LayeredSocketFactory) {
- this.socketFactory = new LayeredSchemeSocketFactoryAdaptor(
+ this.socketFactory = new SchemeLayeredSocketFactoryAdaptor(
(LayeredSocketFactory) factory);
this.layered = true;
} else {
diff --git a/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeLayeredSocketFactory.java b/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeLayeredSocketFactory.java
new file mode 100644
index 000000000..7ede8cd53
--- /dev/null
+++ b/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeLayeredSocketFactory.java
@@ -0,0 +1,65 @@
+/*
+ * ====================================================================
+ * 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
+ * .
+ *
+ */
+
+package org.apache.http.conn.scheme;
+
+import java.io.IOException;
+import java.net.Socket;
+import java.net.UnknownHostException;
+
+import org.apache.http.params.HttpParams;
+
+/**
+ * Extended {@link SchemeSocketFactory} interface for layered sockets such as SSL/TLS.
+ *
+ * @since 4.2
+ */
+public interface SchemeLayeredSocketFactory 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 params HTTP parameters
+ *
+ * @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,
+ HttpParams params) throws IOException, UnknownHostException;
+
+}
diff --git a/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSchemeSocketFactoryAdaptor.java b/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeLayeredSocketFactoryAdaptor.java
similarity index 81%
rename from httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSchemeSocketFactoryAdaptor.java
rename to httpclient/src/main/java/org/apache/http/conn/scheme/SchemeLayeredSocketFactoryAdaptor.java
index 29a649ac4..39aef843f 100644
--- a/httpclient/src/main/java/org/apache/http/conn/scheme/LayeredSchemeSocketFactoryAdaptor.java
+++ b/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeLayeredSocketFactoryAdaptor.java
@@ -31,13 +31,15 @@ import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
+import org.apache.http.params.HttpParams;
+
@Deprecated
-class LayeredSchemeSocketFactoryAdaptor extends SchemeSocketFactoryAdaptor
- implements LayeredSchemeSocketFactory {
+class SchemeLayeredSocketFactoryAdaptor extends SchemeSocketFactoryAdaptor
+ implements SchemeLayeredSocketFactory {
private final LayeredSocketFactory factory;
- LayeredSchemeSocketFactoryAdaptor(final LayeredSocketFactory factory) {
+ SchemeLayeredSocketFactoryAdaptor(final LayeredSocketFactory factory) {
super(factory);
this.factory = factory;
}
@@ -45,8 +47,8 @@ class LayeredSchemeSocketFactoryAdaptor extends SchemeSocketFactoryAdaptor
public Socket createLayeredSocket(
final Socket socket,
final String target, int port,
- boolean autoClose) throws IOException, UnknownHostException {
- return this.factory.createSocket(socket, target, port, autoClose);
+ final HttpParams params) throws IOException, UnknownHostException {
+ return this.factory.createSocket(socket, target, port, true);
}
}
diff --git a/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeLayeredSocketFactoryAdaptor2.java b/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeLayeredSocketFactoryAdaptor2.java
new file mode 100644
index 000000000..3e2e9fd6e
--- /dev/null
+++ b/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeLayeredSocketFactoryAdaptor2.java
@@ -0,0 +1,71 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+
+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;
+
+@Deprecated
+class SchemeLayeredSocketFactoryAdaptor2 implements SchemeLayeredSocketFactory {
+
+ private final LayeredSchemeSocketFactory factory;
+
+ SchemeLayeredSocketFactoryAdaptor2(final LayeredSchemeSocketFactory factory) {
+ super();
+ this.factory = factory;
+ }
+
+ public Socket createSocket(final HttpParams params) throws IOException {
+ return this.factory.createSocket(params);
+ }
+
+ public Socket connectSocket(
+ final Socket sock,
+ final InetSocketAddress remoteAddress,
+ final InetSocketAddress localAddress,
+ final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
+ return this.factory.connectSocket(sock, remoteAddress, localAddress, params);
+ }
+
+ public boolean isSecure(Socket sock) throws IllegalArgumentException {
+ return this.factory.isSecure(sock);
+ }
+
+ public Socket createLayeredSocket(
+ final Socket socket,
+ final String target, int port,
+ final HttpParams params) throws IOException, UnknownHostException {
+ return this.factory.createLayeredSocket(socket, target, port, true);
+ }
+
+}
diff --git a/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java b/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java
index 17b31bf3d..d736c8fd2 100644
--- a/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java
+++ b/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java
@@ -35,6 +35,7 @@ import org.apache.http.conn.HttpInetSocketAddress;
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.conn.scheme.SchemeLayeredSocketFactory;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
@@ -146,7 +147,8 @@ import java.security.cert.CertificateException;
*/
@SuppressWarnings("deprecation")
@ThreadSafe
-public class SSLSocketFactory implements LayeredSchemeSocketFactory, LayeredSocketFactory {
+public class SSLSocketFactory implements SchemeLayeredSocketFactory,
+ LayeredSchemeSocketFactory, LayeredSocketFactory {
public static final String TLS = "TLS";
public static final String SSL = "SSL";
@@ -595,7 +597,28 @@ public class SSLSocketFactory implements LayeredSchemeSocketFactory, LayeredSock
}
/**
- * @since 4.1
+ * @since 4.2
+ */
+ public Socket createLayeredSocket(
+ final Socket socket,
+ final String host,
+ final int port,
+ final HttpParams params) throws IOException, UnknownHostException {
+ SSLSocket sslSocket = (SSLSocket) this.socketfactory.createSocket(
+ socket,
+ host,
+ port,
+ true);
+ prepareSocket(sslSocket);
+ if (this.hostnameVerifier != null) {
+ this.hostnameVerifier.verify(host, sslSocket);
+ }
+ // verifyHostName() didn't blowup - good!
+ return sslSocket;
+ }
+
+ /**
+ * @deprecated use {@link #createLayeredSocket(Socket, String, int, HttpParams)}
*/
public Socket createLayeredSocket(
final Socket socket,
diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java b/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java
index b78596a6a..19d40b64a 100644
--- a/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java
+++ b/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java
@@ -48,7 +48,7 @@ import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.conn.HttpInetSocketAddress;
import org.apache.http.conn.OperatedClientConnection;
import org.apache.http.conn.ClientConnectionOperator;
-import org.apache.http.conn.scheme.LayeredSchemeSocketFactory;
+import org.apache.http.conn.scheme.SchemeLayeredSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.scheme.SchemeSocketFactory;
@@ -220,17 +220,17 @@ public class DefaultClientConnectionOperator implements ClientConnectionOperator
}
final Scheme schm = schemeRegistry.getScheme(target.getSchemeName());
- if (!(schm.getSchemeSocketFactory() instanceof LayeredSchemeSocketFactory)) {
+ if (!(schm.getSchemeSocketFactory() instanceof SchemeLayeredSocketFactory)) {
throw new IllegalArgumentException
("Target scheme (" + schm.getName() +
") must have layered socket factory.");
}
- LayeredSchemeSocketFactory lsf = (LayeredSchemeSocketFactory) schm.getSchemeSocketFactory();
+ SchemeLayeredSocketFactory lsf = (SchemeLayeredSocketFactory) schm.getSchemeSocketFactory();
Socket sock;
try {
sock = lsf.createLayeredSocket(
- conn.getSocket(), target.getHostName(), target.getPort(), true);
+ conn.getSocket(), target.getHostName(), target.getPort(), params);
} catch (ConnectException ex) {
throw new HttpHostConnectException(target, ex);
}
diff --git a/httpclient/src/test/java/org/apache/http/mockup/SecureSocketFactoryMockup.java b/httpclient/src/test/java/org/apache/http/mockup/SecureSocketFactoryMockup.java
index 1756865b2..85d01e4f4 100644
--- a/httpclient/src/test/java/org/apache/http/mockup/SecureSocketFactoryMockup.java
+++ b/httpclient/src/test/java/org/apache/http/mockup/SecureSocketFactoryMockup.java
@@ -29,16 +29,17 @@ package org.apache.http.mockup;
import java.net.Socket;
-import org.apache.http.conn.scheme.LayeredSchemeSocketFactory;
+import org.apache.http.conn.scheme.SchemeLayeredSocketFactory;
+import org.apache.http.params.HttpParams;
/**
* {@link LayeredSchemeSocketFactory} mockup implementation.
*/
public class SecureSocketFactoryMockup extends SocketFactoryMockup
- implements LayeredSchemeSocketFactory {
+ implements SchemeLayeredSocketFactory {
/* A default instance of this mockup. */
- public final static LayeredSchemeSocketFactory INSTANCE = new SecureSocketFactoryMockup("INSTANCE");
+ public final static SchemeLayeredSocketFactory INSTANCE = new SecureSocketFactoryMockup("INSTANCE");
public SecureSocketFactoryMockup(String name) {
super(name);
@@ -53,7 +54,7 @@ public class SecureSocketFactoryMockup extends SocketFactoryMockup
public Socket createLayeredSocket(Socket socket, String host, int port,
- boolean autoClose) {
+ HttpParams params) {
throw new UnsupportedOperationException("I'm a mockup!");
}
diff --git a/src/docbkx/connmgmt.xml b/src/docbkx/connmgmt.xml
index 839666d24..37c6ac02c 100644
--- a/src/docbkx/connmgmt.xml
+++ b/src/docbkx/connmgmt.xml
@@ -253,7 +253,7 @@ sf.connectSocket(socket, address, null, params);
]]>
Secure socket layering
- LayeredSchemeSocketFactory is an extension of
+ SchemeLayeredSocketFactory is an extension of
the SchemeSocketFactory interface. Layered socket
factories are capable of creating sockets layered over an existing plain socket.
Socket layering is used primarily for creating secure sockets through proxies.