FileDocCategorySizeDatePackage
EasySSLProtocolSocketFactory.javaAPI DocExample7647Sun Dec 05 23:04:44 GMT 2004org.apache.commons.httpclient.contrib.ssl

EasySSLProtocolSocketFactory

public class EasySSLProtocolSocketFactory extends Object implements org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory

EasySSLProtocolSocketFactory can be used to creats SSL {@link Socket}s that accept self-signed certificates.

This socket factory SHOULD NOT be used for productive systems due to security reasons, unless it is a concious decision and you are perfectly aware of security implications of accepting self-signed certificates

author
Oleg Kalnichevski DISCLAIMER: HttpClient developers DO NOT actively support this component. The component is provided as a reference material, which may be inappropriate to be used without additional customization.

Fields Summary
private static final Log
LOG
Log object for this class.
private static com.sun.net.ssl.SSLContext
SSL_CONTEXT_SINGLETON
Constructors Summary
public EasySSLProtocolSocketFactory()
Constructor for EasySSLProtocolSocketFactory. Code sample:
Protocol easyhttps = new Protocol( "https", new EasySSLProtocolSocketFactory(), 443); HttpClient client = new HttpClient(); client.getHostConfiguration().setHost("localhost", 443, easyhttps);

                                                                 
      
        super();
    
Methods Summary
private static com.sun.net.ssl.SSLContextcreateEasySSLContext()

        try {
            SSLContext context = SSLContext.getInstance("SSL");
            context.init(
              null, 
              new TrustManager[] {new EasyX509TrustManager(null)}, 
              null);
            return context;
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            throw new HttpClientError(e.toString());
        }
    
public java.net.SocketcreateSocket(java.lang.String host, int port, java.net.InetAddress clientHost, int clientPort)

see
SecureProtocolSocketFactory#createSocket(java.lang.String,int,java.net.InetAddress,int)


        Socket socket = getEasySSLSocketFactory().createSocket(
            host,
            port,
            clientHost,
            clientPort
        );
        return socket;
    
public java.net.SocketcreateSocket(java.lang.String host, int port, java.net.InetAddress localAddress, int localPort, org.apache.commons.httpclient.params.HttpConnectionParams params)
Attempts to get a new socket connection to the given host within the given time limit.

This method employs several techniques to circumvent the limitations of older JREs that do not support connect timeout. When running in JRE 1.4 or above reflection is used to call Socket#connect(SocketAddress endpoint, int timeout) method. When executing in older JREs a controller thread is executed. The controller thread attempts to create a new socket within the given limit of time. If socket constructor does not return until the timeout expires, the controller terminates and throws an {@link ConnectTimeoutException}

param
host the host name/IP
param
port the port on the host
param
clientHost the local host name/IP to bind the socket to
param
clientPort the port on the local machine
param
params {@link HttpConnectionParams Http connection 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

        if (params == null) {
            throw new IllegalArgumentException("Parameters may not be null");
        }
        int timeout = params.getConnectionTimeout();
        if (timeout == 0) {
            return createSocket(host, port, localAddress, localPort);
        } else {
            // To be eventually deprecated when migrated to Java 1.4 or above
            Socket socket = ReflectionSocketFactory.createSocket(
                "javax.net.ssl.SSLSocketFactory", host, port, localAddress, localPort, timeout);
            if (socket == null) {
                socket = ControllerThreadSocketFactory.createSocket(
                    this, host, port, localAddress, localPort, timeout);
            }
            return socket;
        }
    
public java.net.SocketcreateSocket(java.lang.String host, int port)

see
SecureProtocolSocketFactory#createSocket(java.lang.String,int)

        return getEasySSLSocketFactory().createSocket(
            host,
            port
        );
    
public java.net.SocketcreateSocket(java.net.Socket socket, java.lang.String host, int port, boolean autoClose)

see
SecureProtocolSocketFactory#createSocket(java.net.Socket,java.lang.String,int,boolean)

        return getEasySSLSocketFactory().createSocket(
            socket,
            host,
            port,
            autoClose
        );
    
public booleanequals(java.lang.Object obj)

        return ((obj != null) && obj.getClass().equals(EasySSLProtocolSocketFactory.class));
    
private static javax.net.ssl.SSLSocketFactorygetEasySSLSocketFactory()

        if (SSL_CONTEXT_SINGLETON == null) {
            SSL_CONTEXT_SINGLETON = createEasySSLContext();
        }
        return SSL_CONTEXT_SINGLETON.getSocketFactory();
    
public inthashCode()

        return EasySSLProtocolSocketFactory.class.hashCode();