Example usage for org.apache.http.conn.ssl NoopHostnameVerifier INSTANCE

List of usage examples for org.apache.http.conn.ssl NoopHostnameVerifier INSTANCE

Introduction

In this page you can find the example usage for org.apache.http.conn.ssl NoopHostnameVerifier INSTANCE.

Prototype

NoopHostnameVerifier INSTANCE

To view the source code for org.apache.http.conn.ssl NoopHostnameVerifier INSTANCE.

Click Source Link

Usage

From source file:org.springframework.cloud.contract.wiremock.WireMockRestTemplateConfiguration.java

@Bean
@ConditionalOnClass(SSLContextBuilder.class)
public RestTemplateCustomizer restTemplateCustomizer() {
    return new RestTemplateCustomizer() {
        @Override/*from  w  w  w  .  j a va 2s  .co m*/
        public void customize(RestTemplate restTemplate) {
            HttpComponentsClientHttpRequestFactory factory = (HttpComponentsClientHttpRequestFactory) restTemplate
                    .getRequestFactory();
            factory.setHttpClient(createSslHttpClient());
        }

        private HttpClient createSslHttpClient() {
            try {
                SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
                        new SSLContextBuilder().loadTrustMaterial(null, TrustSelfSignedStrategy.INSTANCE)
                                .build(),
                        NoopHostnameVerifier.INSTANCE);
                return HttpClients.custom().setSSLSocketFactory(socketFactory).build();
            } catch (Exception ex) {
                throw new IllegalStateException("Unable to create SSL HttpClient", ex);
            }
        }
    };
}

From source file:com.ibm.connectors.splunklog.SplunkHttpConnection.java

public void createHttpClient() {
    PlainConnectionSocketFactory sf = PlainConnectionSocketFactory.getSocketFactory();
    SSLContext sslContext = SSLContexts.createSystemDefault();
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext,
            NoopHostnameVerifier.INSTANCE);

    Registry<ConnectionSocketFactory> r = RegistryBuilder.<ConnectionSocketFactory>create().register("http", sf)
            .register("https", sslsf).build();

    this.cm = new PoolingHttpClientConnectionManager(r);
}

From source file:com.adobe.ags.curly.ConnectionManager.java

private void createNewConnectionManager() {
    try {// w  w w .  j av  a  2s  .com
        SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(new TrustSelfSignedStrategy());

        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(),
                NoopHostnameVerifier.INSTANCE);
        Registry<ConnectionSocketFactory> r = RegistryBuilder.<ConnectionSocketFactory>create()
                .register("http", new PlainConnectionSocketFactory()).register("https", sslsf).build();
        connectionManager = new PoolingHttpClientConnectionManager(r);
        connectionManager.setValidateAfterInactivity(500);
        sharedContext = ThreadLocal.withInitial(HttpClientContext::new);
    } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException ex) {
        Logger.getLogger(ConnectionManager.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:org.syslog_ng.elasticsearch_v2.client.http.ESHttpsClient.java

private HostnameVerifier getNoopHostnameVerifier() {
    return NoopHostnameVerifier.INSTANCE;
}

From source file:org.springframework.http.server.reactive.ServerHttpsRequestIntegrationTests.java

@Before
public void setup() throws Exception {
    this.server.setHandler(new CheckRequestHandler());
    this.server.afterPropertiesSet();
    this.server.start();

    // Set dynamically chosen port
    this.port = this.server.getPort();

    SSLContextBuilder builder = new SSLContextBuilder();
    builder.loadTrustMaterial(new TrustSelfSignedStrategy());
    SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(builder.build(),
            NoopHostnameVerifier.INSTANCE);
    CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(
            httpclient);/*from  w w w.  j a  va 2s. c  om*/
    this.restTemplate = new RestTemplate(requestFactory);
}

From source file:io.apicurio.studio.fe.servlet.servlets.DownloadServlet.java

@PostConstruct
protected void postConstruct() {
    try {/*from w ww  . j  ava2s  .  c o  m*/
        if (uiConfig.isDisableHubApiTrustManager()) {
            SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy())
                    .build();
            SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext,
                    NoopHostnameVerifier.INSTANCE);
            httpClient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
        } else {
            httpClient = HttpClients.createSystem();
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.mirth.connect.connectors.http.DefaultHttpConfiguration.java

@Override
public void configureSocketFactoryRegistry(ConnectorPluginProperties properties,
        RegistryBuilder<ConnectionSocketFactory> registry) throws Exception {
    String[] enabledProtocols = MirthSSLUtil
            .getEnabledHttpsProtocols(configurationController.getHttpsClientProtocols());
    String[] enabledCipherSuites = MirthSSLUtil
            .getEnabledHttpsCipherSuites(configurationController.getHttpsCipherSuites());
    SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(
            SSLContexts.createSystemDefault(), enabledProtocols, enabledCipherSuites,
            NoopHostnameVerifier.INSTANCE);
    registry.register("https", sslConnectionSocketFactory);
}

From source file:org.wso2.appcloud.integration.test.utils.clients.LogsClient.java

public String[] getSnapshotLogs(String applicationKey, String applicationRevision)
        throws AppCloudIntegrationTestException {
    HttpClient httpclient = null;/*from  w w w.  j  a va  2 s.  c  om*/
    org.apache.http.HttpResponse response = null;
    try {
        httpclient = HttpClients.custom().setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build();
        int timeout = (int) AppCloudIntegrationTestUtils.getTimeOutPeriod();
        RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(timeout)
                .setConnectTimeout(timeout).build();
        HttpPost httppost = new HttpPost(this.endpoint);
        httppost.setConfig(requestConfig);
        List<NameValuePair> params = new ArrayList<NameValuePair>(3);
        params.add(new BasicNameValuePair(PARAM_NAME_ACTION, "getSnapshotLogs"));
        params.add(new BasicNameValuePair(PARAM_NAME_APPLICATION_HASH_ID, applicationKey));
        params.add(new BasicNameValuePair(PARAM_NAME_APPLICATION_REVISION, applicationRevision));
        httppost.setEntity(new UrlEncodedFormEntity(params, UTF_8_ENCODING));
        httppost.setHeader(HEADER_COOKIE, getRequestHeaders().get(HEADER_COOKIE));
        response = httpclient.execute(httppost);
        String[] resultArray = new String[2];
        resultArray[0] = String.valueOf(response.getStatusLine().getStatusCode());
        resultArray[1] = EntityUtils.toString(response.getEntity());
        return resultArray;
    } catch (IOException e) {
        log.error("Failed to invoke app icon update API.", e);
        throw new AppCloudIntegrationTestException("Failed to invoke app icon update API.", e);
    } finally {
        HttpClientUtils.closeQuietly(response);
        HttpClientUtils.closeQuietly(httpclient);
    }

}

From source file:org.nekorp.workflow.desktop.rest.util.RestTemplateFactory.java

@PostConstruct
public void init() {
    targetHost = new HttpHost(host, port, protocol);
    //connectionPool = new PoolingHttpClientConnectionManager();
    //connectionPool.setDefaultMaxPerRoute(10);
    //connectionPool.setMaxTotal(20);

    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()),
            new UsernamePasswordCredentials(username, password));
    //wildcard ssl certificate
    SSLContext sslContext = SSLContexts.createDefault();
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext,
            NoopHostnameVerifier.INSTANCE);

    httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider)
            //.setConnectionManager(connectionPool)
            .setSSLSocketFactory(sslsf).build();
    // Create AuthCache instance
    AuthCache authCache = new BasicAuthCache();
    // Generate BASIC scheme object and add it to the local
    // auth cache
    BasicScheme basicAuth = new BasicScheme();
    authCache.put(targetHost, basicAuth);

    // Add AuthCache to the execution context
    HttpClientContext localContext = HttpClientContext.create();
    localContext.setAuthCache(authCache);

    HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactoryBasicAuth(
            httpclient, localContext);//w  w  w  .  j  ava 2  s .  c  om
    this.template = new RestTemplate();
    template.getMessageConverters().add(new BufferedImageHttpMessageConverter());
    template.setRequestFactory(factory);
}

From source file:org.elasticsearch.xpack.ssl.SSLClientAuthTests.java

public void testThatHttpFailsWithoutSslClientAuth() throws IOException {
    SSLIOSessionStrategy sessionStrategy = new SSLIOSessionStrategy(SSLContexts.createDefault(),
            NoopHostnameVerifier.INSTANCE);
    try (RestClient restClient = createRestClient(
            httpClientBuilder -> httpClientBuilder.setSSLStrategy(sessionStrategy), "https")) {
        restClient.performRequest("GET", "/");
        fail("Expected SSLHandshakeException");
    } catch (IOException e) {
        Throwable t = ExceptionsHelper.unwrap(e, CertPathBuilderException.class);
        assertThat(t, instanceOf(CertPathBuilderException.class));
        assertThat(t.getMessage(),//from w ww.ja va  2s .  c  o  m
                containsString("unable to find valid certification path to requested target"));
    }
}