List of usage examples for org.apache.http.impl.client HttpClientBuilder create
public static HttpClientBuilder create()
From source file:org.mycontroller.standalone.restclient.RestFactory.java
public T createAPI(URI uri, String userName, String password) { CloseableHttpClient httpclient = HttpClientBuilder.create().build(); 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);/*from ww w . j ava 2 s .c om*/ ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpclient, context); ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build(); client.register(JacksonJaxbJsonProvider.class); client.register(RequestLogger.class); client.register(ResponseLogger.class); ProxyBuilder<T> proxyBuilder = client.target(uri).proxyBuilder(proxyClazz); return proxyBuilder.build(); }
From source file:com.wso2telco.claims.RemoteClaimsTelco.java
@Override public Map<String, Object> getTotalClaims(String operatorEndPoint, CustomerInfo customerInfo) { Map<String, Object> totalClaims = new HashedMap(); Customer customer = new Customer(); try {/*from ww w.j av a2s . c o m*/ String url = operatorEndPoint + "?msisdn=" + customerInfo.getMsisdn(); HttpClient client = HttpClientBuilder.create().build(); HttpGet request = new HttpGet(url); HttpResponse response = client.execute(request); log.info("Response Code : " + response.getStatusLine().getStatusCode()); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuilder jsonString = new StringBuilder(); String line = ""; while ((line = rd.readLine()) != null) { jsonString.append(line); } Gson g = new Gson(); customer = g.fromJson(jsonString.toString(), Customer.class); } catch (Exception ex) { log.error(ex); } totalClaims.put("name", customer.getFirstName()); totalClaims.put("sub", customer.getSub()); totalClaims.put("updated_at", customer.getUpdatedAt()); totalClaims.put("title", customer.getTitle()); totalClaims.put("given_name", customer.getGivenName()); totalClaims.put("family_name", customer.getFamilyName()); totalClaims.put("middle_name", customer.getMiddleName()); totalClaims.put("gender", customer.getGender()); totalClaims.put("birthdate", customer.getDob()); totalClaims.put("AgeVerificationStatus", customer.isAgeVerificationStatus()); totalClaims.put("street_address", customer.getStreetAddress()); totalClaims.put("postal_code", customer.getPostalCode()); totalClaims.put("country", customer.getCountry()); totalClaims.put("locale", customer.getLocale()); totalClaims.put("phone_number_alternate", customer.getPhoneNumberAlternate()); totalClaims.put("email", customer.getEmail()); totalClaims.put("email_verified", customer.getEmailVerified()); totalClaims.put("phone_number", customer.getPhoneNumber()); totalClaims.put("phone_number_country_code", customer.getPhoneNumberCountryCode()); totalClaims.put("zoneinfo", customer.getZoneinfo()); totalClaims.put("BillingSegment", customer.getBilingSegment()); totalClaims.put("is_lost_stolen", customer.getIsLostStolen()); totalClaims.put("id_hash", customer.getIdHash()); totalClaims.put("SubscriptionActivity", customer.getSubscriptionActivity()); totalClaims.put("LengthOfTenure", customer.getLengthOfTenure()); totalClaims.put("pairing_change", customer.getPairingChange()); totalClaims.put("is_roaming", customer.getIsRoaming()); totalClaims.put("roaming_country", customer.getRoamingCountry()); totalClaims.put("is_divert_set", customer.getIsDivertSet()); totalClaims.put("location_country", customer.getLocationCountry()); totalClaims.put("device_change", customer.getDeviceChange()); totalClaims.put("msisdn", customer.getMsisdn()); return totalClaims; }
From source file:com.comcast.cdn.traffic_control.traffic_router.core.external.CoverageZoneTest.java
@Before public void before() throws LifecycleException { closeableHttpClient = HttpClientBuilder.create().build(); }
From source file:org.springframework.cloud.dataflow.shell.command.support.HttpClientUtils.java
/** * Ensures that the passed-in {@link RestTemplate} is using the Apache HTTP Client. If the optional {@code username} AND * {@code password} are not empty, then a {@link BasicCredentialsProvider} will be added to the {@link CloseableHttpClient}. * * Furthermore, you can set the underlying {@link SSLContext} of the {@link HttpClient} allowing you to accept self-signed * certificates./* ww w .ja va 2 s.c om*/ * * @param restTemplate Must not be null * @param username Can be null * @param password Can be null * @param skipSslValidation Use with caution! If true certificate warnings will be ignored. */ public static void prepareRestTemplate(RestTemplate restTemplate, URI host, String username, String password, boolean skipSslValidation) { Assert.notNull(restTemplate, "The provided RestTemplate must not be null."); final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); if (StringUtils.hasText(username) && StringUtils.hasText(password)) { final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); } if (skipSslValidation) { httpClientBuilder.setSSLContext(HttpClientUtils.buildCertificateIgnoringSslContext()); httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier()); } final CloseableHttpClient httpClient = httpClientBuilder.build(); final HttpHost targetHost = new HttpHost(host.getHost(), host.getPort(), host.getScheme()); final HttpComponentsClientHttpRequestFactory requestFactory = new PreemptiveBasicAuthHttpComponentsClientHttpRequestFactory( httpClient, targetHost); restTemplate.setRequestFactory(requestFactory); }
From source file:com.comcast.cdn.traffic_control.traffic_router.core.external.StatsTest.java
@Before public void before() throws LifecycleException { httpClient = HttpClientBuilder.create().build(); }
From source file:org.opendaylight.alto.manager.AltoManager.java
protected HttpClient initiateHttpClient() { CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("admin:admin")); return HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build(); }
From source file:basedefense.client.version.ModificationVersionCheck.java
public ModificationVersionCheck() { HttpClientBuilder builder = HttpClientBuilder.create(); builder.disableCookieManagement();//from w w w.ja v a 2 s. c o m builder.disableRedirectHandling(); builder.setUserAgent(String.format(USER_AGENT_PATTERN, BaseDefenseModification.getInstance().getVersion())); builder.setDefaultHeaders(Lists.newArrayList(new BasicHeader("Accept", "application/vnd.github.v3+json"))); this.httpClient = builder.build(); }
From source file:mydropbox.Client.java
private void initHttp() { try { httpClient = HttpClientBuilder.create().build(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.wso2.mdm.qsg.utils.HTTPInvoker.java
private static HttpClient createHttpClient() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { HttpClientBuilder b = HttpClientBuilder.create(); // setup a Trust Strategy that allows all certificates. ////w w w . j a v a 2 s . c om SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { return true; } }).build(); b.setSSLContext(sslContext); //b.setSSLHostnameVerifier(new NoopHostnameVerifier()); // don't check Hostnames, either. // -- use SSLConnectionSocketFactory.getDefaultHostnameVerifier(), if you don't want to weaken HostnameVerifier hostnameVerifier = SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; // here's the special part: // -- need to create an SSL Socket Factory, to use our weakened "trust strategy"; // -- and create a Registry, to register it. // SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier); Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", sslSocketFactory).build(); // now, we create connection-manager using our Registry. // -- allows multi-threaded use PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry); b.setConnectionManager(connMgr); // finally, build the HttpClient; // -- done! CloseableHttpClient client = b.build(); return client; }
From source file:com.github.triceo.robozonky.ApiProvider.java
private static ResteasyClientBuilder newResteasyClientBuilder() { final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); final CloseableHttpClient closeableHttpClient = HttpClientBuilder.create().setConnectionManager(cm).build(); final ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(closeableHttpClient); final ResteasyClientBuilder clientBuilder = new ResteasyClientBuilder().httpEngine(engine); clientBuilder.providerFactory(ApiProvider.RESTEASY); return clientBuilder; }