Example usage for org.apache.commons.httpclient.protocol SecureProtocolSocketFactory createSocket

List of usage examples for org.apache.commons.httpclient.protocol SecureProtocolSocketFactory createSocket

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.protocol SecureProtocolSocketFactory createSocket.

Prototype

public abstract Socket createSocket(Socket paramSocket, String paramString, int paramInt, boolean paramBoolean)
            throws IOException, UnknownHostException;

Source Link

Usage

From source file:eu.eidas.node.auth.metadata.NodeMetadataFetcher.java

/**
 * Override this method to plug your own SSLSocketFactory.
 * <p>//from   ww  w.j  a  v a 2s . c  om
 * This default implementation relies on the default one from the JVM, i.e. using the default trustStore
 * ($JRE/lib/security/cacerts).
 *
 * @return the SecureProtocolSocketFactory instance to be used to connect to https metadata URLs.
 */
@Nonnull
@Override
protected SecureProtocolSocketFactory newSslSocketFactory() {
    final SecureProtocolSocketFactory hubLocalSslCertificateProtocolSocketFactory = hubLocalSslSocketFactory();

    final SecureProtocolSocketFactory parentSslFactory = super.newSslSocketFactory();

    return new SecureProtocolSocketFactory() {
        @Override
        public Socket createSocket(Socket socket, String s, int i, boolean b) throws IOException {
            try {
                return parentSslFactory.createSocket(socket, s, i, b);
            } catch (IOException e) {
                return hubLocalSslCertificateProtocolSocketFactory.createSocket(socket, s, i, b);
            }
        }

        @Override
        public Socket createSocket(String s, int i, InetAddress inetAddress, int i1) throws IOException {
            try {
                return parentSslFactory.createSocket(s, i, inetAddress, i1);
            } catch (IOException e) {
                return hubLocalSslCertificateProtocolSocketFactory.createSocket(s, i, inetAddress, i1);
            }
        }

        @Override
        public Socket createSocket(String s, int i, InetAddress inetAddress, int i1,
                HttpConnectionParams httpConnectionParams) throws IOException {
            try {
                return parentSslFactory.createSocket(s, i, inetAddress, i1, httpConnectionParams);
            } catch (IOException e) {
                return hubLocalSslCertificateProtocolSocketFactory.createSocket(s, i, inetAddress, i1,
                        httpConnectionParams);
            }
        }

        @Override
        public Socket createSocket(String s, int i) throws IOException {
            try {
                return parentSslFactory.createSocket(s, i);
            } catch (IOException e) {
                return hubLocalSslCertificateProtocolSocketFactory.createSocket(s, i);
            }
        }
    };

}