HTTPCLIENT-1160: Deprecated LayeredSchemeSocketFactory in favor of SchemeLayeredSocketFactory whose #createLayeredSocket() method takes HttpParams as an additional parameter
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1240721 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2737e5f066
commit
39117086b3
|
@ -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 {
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
||||
* <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;
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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!");
|
||||
}
|
||||
|
||||
|
|
|
@ -253,7 +253,7 @@ sf.connectSocket(socket, address, null, params);
|
|||
]]></programlisting>
|
||||
<section>
|
||||
<title>Secure socket layering</title>
|
||||
<para><interfacename>LayeredSchemeSocketFactory</interfacename> is an extension of
|
||||
<para><interfacename>SchemeLayeredSocketFactory</interfacename> is an extension of
|
||||
the <interfacename>SchemeSocketFactory</interfacename> 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.
|
||||
|
|
Loading…
Reference in New Issue