List of usage examples for org.apache.http.impl.client BasicCredentialsProvider BasicCredentialsProvider
public BasicCredentialsProvider()
From source file:hu.dolphio.tprttapi.service.TrackingFlushServiceTpImpl.java
public TrackingFlushServiceTpImpl(String dateFrom, String dateTo) { this.dateFrom = dateFrom; this.dateTo = dateTo; targetHost = new HttpHost(propertyReader.getTpHost(), 80, "http"); credsProvider = new BasicCredentialsProvider(); Credentials credentials = new UsernamePasswordCredentials(propertyReader.getTpUserName(), propertyReader.getTpPassword()); credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), credentials); config = RequestConfig.custom().setSocketTimeout(propertyReader.getConnectionTimeout()) .setConnectTimeout(propertyReader.getConnectionTimeout()).build(); AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); clientContext.setAuthCache(authCache); }
From source file:org.hawkular.client.RestFactory.java
public T createAPI(URI uri, String userName, String password) { HttpClient httpclient = null;/*from ww w .ja v a 2s . c o m*/ if (uri.toString().startsWith("https")) { httpclient = getHttpClient(); } else { httpclient = HttpClientBuilder.create().build(); } ResteasyClient client = null; if (userName != null) { HttpHost targetHost = new HttpHost(uri.getHost(), uri.getPort()); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(userName, password)); // 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 context = HttpClientContext.create(); context.setCredentialsProvider(credsProvider); context.setAuthCache(authCache); ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpclient, context); client = new ResteasyClientBuilder().httpEngine(engine).build(); } else { ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(getHttpClient()); client = new ResteasyClientBuilder().httpEngine(engine).build(); } client.register(JacksonJaxbJsonProvider.class); client.register(JacksonObjectMapperProvider.class); client.register(RestRequestFilter.class); client.register(RestResponseFilter.class); client.register(HCJacksonJson2Provider.class); ProxyBuilder<T> proxyBuilder = client.target(uri).proxyBuilder(apiClassType); if (classLoader != null) { proxyBuilder = proxyBuilder.classloader(classLoader); } return proxyBuilder.build(); }
From source file:edu.si.services.camel.fcrepo.FcrepoIntegrationTest.java
@BeforeClass public static void loadObjectsIntoFedora() throws IOException, InterruptedException { BasicCredentialsProvider provider = new BasicCredentialsProvider(); provider.setCredentials(ANY, new UsernamePasswordCredentials(System.getProperty("si.fedora.user"), System.getProperty("si.fedora.password"))); httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build(); ingest(PID, Paths.get(BUILD_DIR, TEST_FOXML)); }
From source file:org.superbiz.AuthBeanTest.java
private String get(final String user, final String password) { final BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider(); basicCredentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password)); final CloseableHttpClient client = HttpClients.custom() .setDefaultCredentialsProvider(basicCredentialsProvider).build(); final HttpHost httpHost = new HttpHost(webapp.getHost(), webapp.getPort(), webapp.getProtocol()); final AuthCache authCache = new BasicAuthCache(); final BasicScheme basicAuth = new BasicScheme(); authCache.put(httpHost, basicAuth);/*from ww w. j a va 2s. com*/ final HttpClientContext context = HttpClientContext.create(); context.setAuthCache(authCache); final HttpGet get = new HttpGet(webapp.toExternalForm() + "servlet"); CloseableHttpResponse response = null; try { response = client.execute(httpHost, get, context); return response.getStatusLine().getStatusCode() + " " + EntityUtils.toString(response.getEntity()); } catch (final IOException e) { throw new IllegalStateException(e); } finally { try { IO.close(response); } catch (final IOException e) { // no-op } } }
From source file:org.sonatype.nexus.httpclient.HttpClientPlan.java
public void addCredentials(final AuthScope authScope, final Credentials credentials) { // lazy initialized to allow null state to indicate non-customized if (this.credentials == null) { this.credentials = new BasicCredentialsProvider(); }/*w ww . ja v a 2 s . c o m*/ this.credentials.setCredentials(authScope, credentials); }
From source file:com.ibm.watson.apis.conversation_enhanced.utils.HttpSolrClientUtils.java
/** * Creates the {@link HttpClient} to use with the Solrj * * @param url the Solr server url//w ww. j av a2 s . c o m * @param username the {@link RetrieveAndRank} service username * @param password the {@link RetrieveAndRank} service password * @return the {@link HttpClient} */ private static HttpClient createHttpClient(String url, String username, String password) { final URI scopeUri = URI.create(url); logger.info(Messages.getString("HttpSolrClientUtils.CREATING_HTTP_CLIENT")); //$NON-NLS-1$ final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(scopeUri.getHost(), scopeUri.getPort()), new UsernamePasswordCredentials(username, password)); final HttpClientBuilder builder = HttpClientBuilder.create().setMaxConnTotal(128).setMaxConnPerRoute(32) .setDefaultRequestConfig( RequestConfig.copy(RequestConfig.DEFAULT).setRedirectsEnabled(true).build()) .setDefaultCredentialsProvider(credentialsProvider) .addInterceptorFirst(new PreemptiveAuthInterceptor()); return builder.build(); }
From source file:org.springframework.cloud.dataflow.rest.util.HttpClientConfigurer.java
private CredentialsProvider getOrInitializeCredentialsProvider() { if (this.credentialsProvider == null) { this.credentialsProvider = new BasicCredentialsProvider(); }/*from ww w . ja v a2s . c o m*/ return this.credentialsProvider; }
From source file:com.blazemeter.bamboo.plugin.api.HttpUtility.java
public HttpUtility() { this.httpClient = HttpClients.createDefault(); useProxy = Boolean.parseBoolean(System.getProperty(Constants.USE_PROXY)); proxyHost = System.getProperty(Constants.PROXY_HOST); try {/*from w w w. j av a 2s . com*/ this.proxyPort = Integer.parseInt(System.getProperty(Constants.PROXY_PORT)); } catch (NumberFormatException nfe) { logger.error("Failed to read http.proxyPort: ", nfe); } if (useProxy && !org.apache.commons.lang3.StringUtils.isBlank(this.proxyHost)) { this.proxy = new HttpHost(proxyHost, proxyPort); this.proxyUser = System.getProperty(Constants.PROXY_USER); this.proxyPass = System.getProperty(Constants.PROXY_PASS); if (!org.apache.commons.lang3.StringUtils.isEmpty(this.proxyUser) && !org.apache.commons.lang3.StringUtils.isEmpty(this.proxyPass)) { Credentials cr = new UsernamePasswordCredentials(proxyUser, proxyPass); AuthScope aus = new AuthScope(proxyHost, proxyPort); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(aus, cr); this.httpClient = HttpClients.custom().setProxy(proxy).setDefaultCredentialsProvider(credsProvider) .build(); } else { this.httpClient = HttpClients.custom().setProxy(proxy).build(); } } }