Example usage for org.apache.hadoop.security.ssl SSLFactory destroy

List of usage examples for org.apache.hadoop.security.ssl SSLFactory destroy

Introduction

In this page you can find the example usage for org.apache.hadoop.security.ssl SSLFactory destroy.

Prototype

public void destroy() 

Source Link

Document

Releases any resources being used.

Usage

From source file:org.apache.tez.dag.api.client.TimelineReaderFactory.java

License:Apache License

private static ConnectionConfigurator getNewSSLConnectionConf(final Configuration conf, final int connTimeout)
        throws IOException {
    final SSLFactory sslFactory;
    final SSLSocketFactory sslSocketFactory;
    final HostnameVerifier hostnameVerifier;

    sslFactory = new SSLFactory(CLIENT, conf);
    try {/*from w  w w  . j a v a  2s .c o m*/
        sslFactory.init();
        sslSocketFactory = sslFactory.createSSLSocketFactory();
    } catch (GeneralSecurityException e) {
        sslFactory.destroy();
        throw new IOException("Failed to initialize ssl factory");
    }
    hostnameVerifier = sslFactory.getHostnameVerifier();

    return new ConnectionConfigurator() {
        @Override
        public HttpURLConnection configure(HttpURLConnection httpURLConnection) throws IOException {
            if (!(httpURLConnection instanceof HttpsURLConnection)) {
                throw new IOException("Expected https connection");
            }
            HttpsURLConnection httpsURLConnection = (HttpsURLConnection) httpURLConnection;
            httpsURLConnection.setSSLSocketFactory(sslSocketFactory);
            httpsURLConnection.setHostnameVerifier(hostnameVerifier);
            setTimeouts(httpsURLConnection, connTimeout);

            return httpsURLConnection;
        }
    };
}