/** * this handles rest calls. each request creates a different httpClient object */ public HttpResponse doRequest(HttpRequestBase request, String username, String password) { HttpClientBuilder clientBuilder = HttpClients.custom(); HttpClientContext clientContext = HttpClientContext.create(); // configures the clientBuilder and clientContext if (username != null) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(bindAddress, restPort), new UsernamePasswordCredentials(username, password)); clientBuilder.setDefaultCredentialsProvider(credsProvider); } try { if (useSsl) { SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(new KeyManager[0], new TrustManager[] {new DefaultTrustManager()}, new SecureRandom()); clientBuilder.setSSLContext(ctx); clientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier()); } return clientBuilder.build().execute(host, request, clientContext); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }
public static CloseableHttpClient build(DefaultBotOptions options) { HttpClientBuilder httpClientBuilder = HttpClientBuilder.create() .setSSLHostnameVerifier(new NoopHostnameVerifier()) .setConnectionManager(createConnectionManager(options)) .setConnectionTimeToLive(70, TimeUnit.SECONDS) .setMaxConnTotal(100); return httpClientBuilder.build(); }
public static HttpClientBuilder builder(HttpEnvironmentRepositoryProperties environmentProperties) throws GeneralSecurityException { SSLContextBuilder sslContextBuilder = new SSLContextBuilder(); HttpClientBuilder httpClientBuilder = HttpClients.custom(); if (environmentProperties.isSkipSslValidation()) { sslContextBuilder.loadTrustMaterial(null, (certificate, authType) -> true); httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier()); } if (!CollectionUtils.isEmpty(environmentProperties.getProxy())) { ProxyHostProperties httpsProxy = environmentProperties.getProxy().get(ProxyHostProperties.ProxyForScheme.HTTPS); ProxyHostProperties httpProxy = environmentProperties.getProxy().get(ProxyHostProperties.ProxyForScheme.HTTP); httpClientBuilder.setRoutePlanner(new SchemeBasedRoutePlanner(httpsProxy, httpProxy)); httpClientBuilder.setDefaultCredentialsProvider(new ProxyHostCredentialsProvider(httpProxy, httpsProxy)); } else { httpClientBuilder.setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault())); httpClientBuilder.setDefaultCredentialsProvider(new SystemDefaultCredentialsProvider()); } int timeout = environmentProperties.getTimeout() * 1000; return httpClientBuilder .setSSLContext(sslContextBuilder.build()) .setDefaultRequestConfig(RequestConfig.custom() .setSocketTimeout(timeout) .setConnectTimeout(timeout) .build()); } }
protected static HttpClientBuilder getClientBuilder(boolean skipSslValidation) { HttpClientBuilder builder = HttpClients.custom() .useSystemProperties() .setRedirectStrategy(new DefaultRedirectStrategy()); if (skipSslValidation) { builder.setSslcontext(getNonValidatingSslContext()); builder.setSSLHostnameVerifier(new NoopHostnameVerifier()); } builder.setConnectionReuseStrategy(NoConnectionReuseStrategy.INSTANCE); return builder; }
@Override protected TTransport newTransport(String uri, HttpHeaders headers) throws TTransportException { final SSLContext sslContext; try { sslContext = SSLContextBuilder.create() .loadTrustMaterial((TrustStrategy) (chain, authType) -> true) .build(); } catch (GeneralSecurityException e) { throw new TTransportException("failed to initialize an SSL context", e); } final THttpClient client = new THttpClient( uri, HttpClientBuilder.create() .setSSLHostnameVerifier((hostname, session) -> true) .setSSLContext(sslContext) .build()); client.setCustomHeaders( headers.names().stream() .collect(toImmutableMap(AsciiString::toString, name -> String.join(", ", headers.getAll(name))))); return client; }
private Executor executor() { if (executor == null) { if (this.host.startsWith("https://")) { Try.run(() -> { SSLContext sslContext = SSLContexts.custom() .loadTrustMaterial(null, (chain, authType) -> true) .build(); builder.setSSLContext(sslContext); builder.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE); }).throwException(); } client = builder.build(); executor = Executor.newInstance(client); if (creds != null) { executor.auth(creds); } } return executor; }
builder.setSSLHostnameVerifier(verifier);
static TimeoutRestTemplate createRestTemplate(int readTimeout, int connectTimeout) { HttpComponentsClientHttpRequestFactory factory = new TimeoutHttpComponentsClientHttpRequestFactory(); factory.setReadTimeout(readTimeout); factory.setConnectTimeout(connectTimeout); SSLContext sslContext = DefaultSSLVerifier.getSSLContext(DefaultSSLVerifier.trustAllCerts); if (sslContext != null) { factory.setHttpClient(HttpClients.custom() .setSSLHostnameVerifier(new NoopHostnameVerifier()) .setSSLContext(sslContext) .build()); } TimeoutRestTemplate template = new TimeoutRestTemplate(factory); StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(StandardCharsets.UTF_8); stringHttpMessageConverter.setWriteAcceptCharset(true); for (int i = 0; i < template.getMessageConverters().size(); i++) { if (template.getMessageConverters().get(i) instanceof StringHttpMessageConverter) { template.getMessageConverters().remove(i); template.getMessageConverters().add(i, stringHttpMessageConverter); break; } } return template; } }
/** * @param hostnameVerifier * @return This object (for method chaining). * @see HttpClientBuilder#setSSLHostnameVerifier(HostnameVerifier) */ public RestClientBuilder sslHostnameVerifier(HostnameVerifier hostnameVerifier) { httpClientBuilder.setSSLHostnameVerifier(hostnameVerifier); return this; }
public CloseableHttpClient build() { if (null != hostnameVerifier) { super.setSSLHostnameVerifier(hostnameVerifier); } if (null != sslContext) { super.setSSLSocketFactory(new SSLConnectionSocketFactory(sslContext, hostnameVerifier)); } return super.build(); }
public static CloseableHttpClient get(SSLContext ssl, CookieStore cookieStore, boolean hostVerificationEnabled) { RequestConfig defaultRequestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build(); HttpClientBuilder builder = HttpClients.custom().setSSLContext(ssl).setDefaultCookieStore(cookieStore) .setDefaultRequestConfig(defaultRequestConfig); if (hostVerificationEnabled) { builder.setSSLHostnameVerifier(new DefaultHostnameVerifier()); } else { builder.setSSLHostnameVerifier(new NoopHostnameVerifier()); } return builder.build(); }
@NotNull private static Client createClient(@NotNull AuthProvider auth, @NotNull CmdArgs cmd) throws GeneralSecurityException { final HttpClientBuilder httpBuilder = HttpClients.custom(); httpBuilder.setUserAgent("git-lfs-migrate"); if (cmd.noCheckCertificate) { httpBuilder.setSSLHostnameVerifier((hostname, session) -> true); httpBuilder.setSSLContext(SSLContexts.custom() .loadTrustMaterial((chain, authType) -> true) .build()); } return new Client(auth, httpBuilder.build()); }
public static HttpClient build() { SSLContext sslContext = buildSslContext(); return HttpClientBuilder.create() .setSSLContext(sslContext) .setSSLHostnameVerifier(new NoopHostnameVerifier()) .build(); }
public static CloseableHttpClient build(DefaultBotOptions options) { HttpClientBuilder httpClientBuilder = HttpClientBuilder.create() .setSSLHostnameVerifier(new NoopHostnameVerifier()) .setConnectionManager(createConnectionManager(options)) .setConnectionTimeToLive(70, TimeUnit.SECONDS) .setMaxConnTotal(100); return httpClientBuilder.build(); }
/** * Sets the client's {@link javax.net.ssl.SSLContext} to use * {@link HttpUtils#buildCertificateIgnoringSslContext()}. * * @return a reference to {@code this} to enable chained method invocation */ public HttpClientConfigurer skipTlsCertificateVerification() { httpClientBuilder.setSSLContext(HttpUtils.buildCertificateIgnoringSslContext()); httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier()); return this; }
/** * Sets the client's {@link javax.net.ssl.SSLContext} to use * {@link HttpUtils#buildCertificateIgnoringSslContext()}. * * @return a reference to {@code this} to enable chained method invocation */ public HttpClientConfigurer skipTlsCertificateVerification() { httpClientBuilder.setSSLContext(HttpUtils.buildCertificateIgnoringSslContext()); httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier()); return this; }
/** * Sets the client's {@link javax.net.ssl.SSLContext} to use * {@link HttpUtils#buildCertificateIgnoringSslContext()}. * * @return a reference to {@code this} to enable chained method invocation */ public HttpClientConfigurer skipTlsCertificateVerification() { httpClientBuilder.setSSLContext(HttpUtils.buildCertificateIgnoringSslContext()); httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier()); return this; }
/** * Sets the client's {@link javax.net.ssl.SSLContext} to use * {@link HttpUtils#buildCertificateIgnoringSslContext()}. * * @return a reference to {@code this} to enable chained method invocation */ public HttpClientConfigurer skipTlsCertificateVerification() { httpClientBuilder.setSSLContext(HttpUtils.buildCertificateIgnoringSslContext()); httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier()); return this; }
private HttpResponse createTestUser(String appId) throws IOException, URISyntaxException { URL url = new URL(getURLCreateUser(appId)); CloseableHttpClient httpClient = HttpClientBuilder.create() .disableAutomaticRetries() .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE) .build(); HttpPost httpPost = getHttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(getParams(), StandardCharsets.UTF_8)); return httpClient.execute(httpPost); }
private static CloseableHttpClient getDefaultClient() { return HttpClientBuilder.create() .disableCookieManagement() .disableConnectionState() .disableAutomaticRetries() .setDefaultRequestConfig(REQUEST_CONFIG) .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE) .build(); } }