NTCredentials ntCreds = new NTCredentials(ntUsername, ntPassword,localMachineName, domainName ); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials( new AuthScope(proxyHost,proxyPort), ntCreds ); HttpClientBuilder clientBuilder = HttpClientBuilder.create(); clientBuilder.useSystemProperties(); clientBuilder.setProxy(new HttpHost(pxInfo.getProxyURL(), pxInfo.getProxyPort())); clientBuilder.setDefaultCredentialsProvider(credsProvider); clientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); CloseableHttpClient client = clientBuilder.build();
private CloseableHttpClient createHttpClient(HttpClientConnectionManager connectionManager) { return configureHttpClient( HttpClients.custom() .setConnectionManager(connectionManager) .setDefaultRequestConfig(getRequestConfig()) .setProxyAuthenticationStrategy(httpClientConfig.getProxyAuthenticationStrategy()) .setRoutePlanner(getRoutePlanner()) .setDefaultCredentialsProvider(httpClientConfig.getCredentialsProvider()) ).build(); }
.build()) .setDefaultCredentialsProvider(droidClientConfig.getCredentialsProvider()) .setProxyAuthenticationStrategy(droidClientConfig.getProxyAuthenticationStrategy()) .setRoutePlanner(droidClientConfig.getHttpRoutePlanner());
public synchronized HttpClient getNativeHttpClient() { if (myHttpClient == null) { //FIXME potential resoource leak PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); connectionManager.setMaxTotal(getPoolMaxTotal()); connectionManager.setDefaultMaxPerRoute(getPoolMaxPerRoute()); // @formatter:off //TODO: Use of a deprecated method should be resolved. RequestConfig defaultRequestConfig = RequestConfig.custom().setSocketTimeout(getSocketTimeout()) .setConnectTimeout(getConnectTimeout()).setConnectionRequestTimeout(getConnectionRequestTimeout()) .setStaleConnectionCheckEnabled(true).setProxy(myProxy).build(); HttpClientBuilder builder = HttpClients.custom().setConnectionManager(connectionManager) .setDefaultRequestConfig(defaultRequestConfig).disableCookieManagement(); if (myProxy != null && StringUtils.isNotBlank(getProxyUsername()) && StringUtils.isNotBlank(getProxyPassword())) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(myProxy.getHostName(), myProxy.getPort()), new UsernamePasswordCredentials(getProxyUsername(), getProxyPassword())); builder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); builder.setDefaultCredentialsProvider(credsProvider); } myHttpClient = builder.build(); // @formatter:on } return myHttpClient; }
public static void main(String[] args) { /* * This is out ot date - Just keeping * it in case it's helpful... */ final String authUser = "username"; final String authPassword = "password"; CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope("10.10.10.10", 8080), new UsernamePasswordCredentials(authUser, authPassword)); HttpHost myProxy = new HttpHost("10.10.10.10", 8080); HttpClientBuilder clientBuilder = HttpClientBuilder.create(); clientBuilder .setProxy(myProxy) .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()) .setDefaultCredentialsProvider(credsProvider) .disableCookieManagement(); CloseableHttpClient httpClient = clientBuilder.build(); FhirContext ctx = FhirContext.forDstu2(); String serverBase = "http://spark.furore.com/fhir/"; ctx.getRestfulClientFactory().setHttpClient(httpClient); IGenericClient client = ctx.newRestfulGenericClient(serverBase); IdDt id = new IdDt("Patient", "123"); client.read(Patient.class, id); }
/** * @param proxyAuthStrategy * @return This object (for method chaining). * @see HttpClientBuilder#setProxyAuthenticationStrategy(AuthenticationStrategy) */ public RestClientBuilder proxyAuthenticationStrategy(AuthenticationStrategy proxyAuthStrategy) { httpClientBuilder.setProxyAuthenticationStrategy(proxyAuthStrategy); return this; }
/** * @param proxyAuthStrategy * @return This object (for method chaining). * @see HttpClientBuilder#setProxyAuthenticationStrategy(AuthenticationStrategy) */ public RestClientBuilder proxyAuthenticationStrategy(AuthenticationStrategy proxyAuthStrategy) { httpClientBuilder.setProxyAuthenticationStrategy(proxyAuthStrategy); return this; }
/** * Assigns {@link AuthenticationStrategy} instance for proxy * authentication. */ public final CustomHttpClientBuilder setProxyAuthenticationStrategy( final AuthenticationStrategy proxyAuthStrategy) { this.builder.setProxyAuthenticationStrategy( proxyAuthStrategy ); return this; }
/** * @param proxyAuthStrategy * @return This object (for method chaining). * @see HttpClientBuilder#setProxyAuthenticationStrategy(AuthenticationStrategy) */ public RestClientBuilder proxyAuthenticationStrategy(AuthenticationStrategy proxyAuthStrategy) { httpClientBuilder.setProxyAuthenticationStrategy(proxyAuthStrategy); return this; }
public static HttpClient getHtpClient(AuthenticationStrategy proxy) { RequestConfig requestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD_STRICT).build(); CloseableHttpClient httpClient = HttpClients .custom() .setConnectionManager(cm) .setProxyAuthenticationStrategy(proxy) .setRedirectStrategy(new LaxRedirectStrategy()) .setDefaultRequestConfig(requestConfig) .build(); return httpClient; }
/** * Configures the {@link HttpClientBuilder} with a proxy host. If the * {@code proxyUsername} and {@code proxyPassword} are not {@code null} * then a {@link CredentialsProvider} is also configured for the proxy host. * * @param proxyUri Must not be null and must be configured with a scheme (http or https). * @param proxyUsername May be null * @param proxyPassword May be null * @return a reference to {@code this} to enable chained method invocation */ public HttpClientConfigurer withProxyCredentials(URI proxyUri, String proxyUsername, String proxyPassword) { Assert.notNull(proxyUri, "The proxyUri must not be null."); Assert.hasText(proxyUri.getScheme(), "The scheme component of the proxyUri must not be empty."); httpClientBuilder .setProxy(new HttpHost(proxyUri.getHost(), proxyUri.getPort(), proxyUri.getScheme())); if (proxyUsername !=null && proxyPassword != null) { final CredentialsProvider credentialsProvider = this.getOrInitializeCredentialsProvider(); credentialsProvider.setCredentials( new AuthScope(proxyUri.getHost(), proxyUri.getPort()), new UsernamePasswordCredentials(proxyUsername, proxyPassword)); httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider) .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); } return this; }
/** * Configures the {@link HttpClientBuilder} with a proxy host. If the * {@code proxyUsername} and {@code proxyPassword} are not {@code null} * then a {@link CredentialsProvider} is also configured for the proxy host. * * @param proxyUri Must not be null and must be configured with a scheme (http or https). * @param proxyUsername May be null * @param proxyPassword May be null * @return a reference to {@code this} to enable chained method invocation */ public HttpClientConfigurer withProxyCredentials(URI proxyUri, String proxyUsername, String proxyPassword) { Assert.notNull(proxyUri, "The proxyUri must not be null."); Assert.hasText(proxyUri.getScheme(), "The scheme component of the proxyUri must not be empty."); httpClientBuilder .setProxy(new HttpHost(proxyUri.getHost(), proxyUri.getPort(), proxyUri.getScheme())); if (proxyUsername !=null && proxyPassword != null) { final CredentialsProvider credentialsProvider = this.getOrInitializeCredentialsProvider(); credentialsProvider.setCredentials( new AuthScope(proxyUri.getHost(), proxyUri.getPort()), new UsernamePasswordCredentials(proxyUsername, proxyPassword)); httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider) .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); } return this; }
HttpClientBuilder clientBuilder = HttpClientBuilder.create(); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(USERNAME, PASSWORD)); clientBuilder.useSystemProperties(); clientBuilder.setProxy(new HttpHost(HOST, PORT)); clientBuilder.setDefaultCredentialsProvider(credsProvider); clientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); Lookup<AuthSchemeProvider> authProviders = RegistryBuilder.<AuthSchemeProvider>create() .register(AuthSchemes.BASIC, new BasicSchemeFactory()) .build(); clientBuilder.setDefaultAuthSchemeRegistry(authProviders); Unirest.setClient(clientBuilder.build());
RestTemplate restTemplate = new RestTemplate(); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials( new AuthScope("proxyHost", "proxyPort"), new UsernamePasswordCredentials("proxyUser", "proxyPass") ); HttpClientBuilder clientBuilder = HttpClientBuilder.create(); clientBuilder.useSystemProperties(); clientBuilder.setProxy(new HttpHost("proxyHost", "proxyPort")); clientBuilder.setDefaultCredentialsProvider(credsProvider); clientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); CloseableHttpClient client = clientBuilder.build(); HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(); factory.setHttpClient(client); restTemplate.setRequestFactory(factory);
protected CloseableHttpClient createHttpClient(HttpClientConnectionManager connectionManager) { return HttpClients.custom() .setConnectionManager(connectionManager) .setDefaultRequestConfig(getRequestConfig()) .setProxyAuthenticationStrategy(httpClientConfig.getProxyAuthenticationStrategy()) .setRoutePlanner(getRoutePlanner()) .setDefaultCredentialsProvider(httpClientConfig.getCredentialsProvider()) .build(); }
private CloseableHttpClient createHttpClient(HttpClientConnectionManager connectionManager) { return configureHttpClient( HttpClients.custom() .setConnectionManager(connectionManager) .setDefaultRequestConfig(getRequestConfig()) .setProxyAuthenticationStrategy(httpClientConfig.getProxyAuthenticationStrategy()) .setRoutePlanner(getRoutePlanner()) .setDefaultCredentialsProvider(httpClientConfig.getCredentialsProvider()) ).build(); }
CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials(proxyUser, proxyPassword)); builder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); builder.setDefaultCredentialsProvider(credentialsProvider);
public synchronized HttpClient getNativeHttpClient() { if (myHttpClient == null) { //FIXME potential resoource leak PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); connectionManager.setMaxTotal(getPoolMaxTotal()); connectionManager.setDefaultMaxPerRoute(getPoolMaxPerRoute()); // @formatter:off //TODO: Use of a deprecated method should be resolved. RequestConfig defaultRequestConfig = RequestConfig.custom().setSocketTimeout(getSocketTimeout()) .setConnectTimeout(getConnectTimeout()).setConnectionRequestTimeout(getConnectionRequestTimeout()) .setStaleConnectionCheckEnabled(true).setProxy(myProxy).build(); HttpClientBuilder builder = HttpClients.custom().setConnectionManager(connectionManager) .setDefaultRequestConfig(defaultRequestConfig).disableCookieManagement(); if (myProxy != null && StringUtils.isNotBlank(getProxyUsername()) && StringUtils.isNotBlank(getProxyPassword())) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(myProxy.getHostName(), myProxy.getPort()), new UsernamePasswordCredentials(getProxyUsername(), getProxyPassword())); builder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); builder.setDefaultCredentialsProvider(credsProvider); } myHttpClient = builder.build(); // @formatter:on } return myHttpClient; }
private void configureProxy(HttpClientBuilder builder, URL url) { Jenkins jenkins = Jenkins.getInstance(); if (jenkins == null) { return; } ProxyConfiguration proxyConfig = jenkins.proxy; if (proxyConfig == null) { return; } Proxy proxy = proxyConfig.createProxy(url.getHost()); if (proxy == null || proxy.type() != Proxy.Type.HTTP) { return; } SocketAddress addr = proxy.address(); if (addr == null || !(addr instanceof InetSocketAddress)) { return; } InetSocketAddress proxyAddr = (InetSocketAddress) addr; HttpHost proxyHost = new HttpHost(proxyAddr.getAddress().getHostAddress(), proxyAddr.getPort()); builder.setProxy(proxyHost); String proxyUser = proxyConfig.getUserName(); if (proxyUser != null) { String proxyPass = proxyConfig.getPassword(); BasicCredentialsProvider cred = new BasicCredentialsProvider(); cred.setCredentials(new AuthScope(proxyHost), new org.apache.http.auth.UsernamePasswordCredentials(proxyUser, proxyPass)); builder.setDefaultCredentialsProvider(cred) .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); } }
builder.setProxy(proxyHost); if(!isEmpty(proxySettings.getUsername()) && !isEmpty(proxySettings.getPassword())) { builder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(