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

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

Introduction

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

Prototype

SecureProtocolSocketFactory

Source Link

Usage

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

/**
 * Override this method to plug your own SSLSocketFactory.
 * <p>/*from w  w  w. ja  va 2 s . co  m*/
 * 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);
            }
        }
    };

}