Class EasySSLProtocolSocketFactory

  • All Implemented Interfaces:
    org.apache.http.conn.socket.ConnectionSocketFactory

    public class EasySSLProtocolSocketFactory
    extends java.lang.Object
    implements org.apache.http.conn.socket.ConnectionSocketFactory
    EasySSLProtocolSocketFactory can be used to creats SSL Sockets 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

    Example of using custom protocol socket factory for a specific host:

     Protocol easyhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443);
    
     HttpClient client = new HttpClient();
     client.getHostConfiguration().setHost("localhost", 443, easyhttps);
     // use relative url only
     GetMethod httpget = new GetMethod("/");
     client.executeMethod(httpget);
     

    Example of using custom protocol socket factory per default instead of the standard one:

     Protocol easyhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443);
     Protocol.registerProtocol("https", easyhttps);
    
     HttpClient client = new HttpClient();
     GetMethod httpget = new GetMethod("https://localhost/");
     client.executeMethod(httpget);
     
    Author:
    Oleg Kalnichevski

    DISCLAIMER: HttpClient developers DO NOT actively support this component. The component is provided as a reference material, which may be inappropriate for use without additional customization.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.net.Socket connectSocket​(int connectTimeout, java.net.Socket sock, org.apache.http.HttpHost host, java.net.InetSocketAddress remoteAddress, java.net.InetSocketAddress localAddress, org.apache.http.protocol.HttpContext context)
      java.net.Socket createSocket​(org.apache.http.protocol.HttpContext context)
      boolean equals​(java.lang.Object obj)  
      int hashCode()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • EasySSLProtocolSocketFactory

        public EasySSLProtocolSocketFactory()
        Constructor for EasySSLProtocolSocketFactory.
    • Method Detail

      • createSocket

        public java.net.Socket createSocket​(org.apache.http.protocol.HttpContext context)
                                     throws java.io.IOException
        Specified by:
        createSocket in interface org.apache.http.conn.socket.ConnectionSocketFactory
        Throws:
        java.io.IOException
      • connectSocket

        public java.net.Socket connectSocket​(int connectTimeout,
                                             java.net.Socket sock,
                                             org.apache.http.HttpHost host,
                                             java.net.InetSocketAddress remoteAddress,
                                             java.net.InetSocketAddress localAddress,
                                             org.apache.http.protocol.HttpContext context)
                                      throws java.io.IOException
        Specified by:
        connectSocket in interface org.apache.http.conn.socket.ConnectionSocketFactory
        Throws:
        java.io.IOException
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object