List of usage examples for org.apache.http.impl.client HttpClients custom
public static HttpClientBuilder custom()
From source file:com.tremolosecurity.unison.proxy.auth.openidconnect.loadUser.LoadAttributesFromWS.java
public Map loadUserAttributesFromIdP(HttpServletRequest request, HttpServletResponse response, ConfigManager cfg, HashMap<String, Attribute> authParams, Map accessToken) throws Exception { String bearerTokenName = authParams.get("bearerTokenName").getValues().get(0); String url = authParams.get("restURL").getValues().get(0); BasicHttpClientConnectionManager bhcm = new BasicHttpClientConnectionManager( GlobalEntries.getGlobalEntries().getConfigManager().getHttpClientSocketRegistry()); RequestConfig rc = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build(); CloseableHttpClient http = HttpClients.custom().setConnectionManager(bhcm).setDefaultRequestConfig(rc) .build();// w w w . ja v a 2 s . c o m HttpGet get = new HttpGet(url); get.addHeader("Authorization", "Bearer " + request.getSession().getAttribute(bearerTokenName)); CloseableHttpResponse httpResp = http.execute(get); BufferedReader in = new BufferedReader(new InputStreamReader(httpResp.getEntity().getContent())); StringBuffer token = new StringBuffer(); String line = null; while ((line = in.readLine()) != null) { token.append(line); } httpResp.close(); bhcm.close(); Map jwtNVP = com.cedarsoftware.util.io.JsonReader.jsonToMaps(token.toString()); return jwtNVP; }
From source file:ch.ifocusit.livingdoc.plugin.publish.confluence.client.ConfluenceRestClient.java
private static CloseableHttpClient httpClient() { RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(20 * 1000) .setConnectTimeout(20 * 1000).build(); return HttpClients.custom().setDefaultRequestConfig(requestConfig).build(); }
From source file:com.kurtraschke.wsf.gtfsrealtime.services.WSFVesselLocationService.java
public List<VesselLocationResponse> getAllVessels() throws URISyntaxException, IOException, JAXBException { ImmutableList.Builder<VesselLocationResponse> allVessels = ImmutableList.builder(); URI endpoint = new URIBuilder("http://www.wsdot.wa.gov/ferries/api/vessels/rest/vessellocations") .addParameter("apiaccesscode", _apiAccessCode).build(); CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(_connectionManager).build(); HttpGet request = new HttpGet(endpoint); request.addHeader("Accept", "text/xml"); try (CloseableHttpResponse response = httpclient.execute(request)) { HttpEntity entity = response.getEntity(); if (entity != null) { try (InputStream instream = entity.getContent()) { JAXBElement<ArrayOfVesselLocationResponse> responseArray; responseArray = _um.unmarshal(new StreamSource(instream), ArrayOfVesselLocationResponse.class); allVessels.addAll(responseArray.getValue().getVesselLocationResponse()); }/*from ww w . j a va2s .c om*/ } } return allVessels.build(); }
From source file:net.sf.jasperreports.phantomjs.ProcessConnection.java
public ProcessConnection(ProcessDirector director, PhantomJSProcess process) { this.process = process; HttpClientBuilder clientBuilder = HttpClients.custom(); // single connection BasicHttpClientConnectionManager connManager = new BasicHttpClientConnectionManager(); clientBuilder.setConnectionManager(connManager); RequestConfig requestConfig = RequestConfig.custom() // ignore cookies for now .setCookieSpec(CookieSpecs.IGNORE_COOKIES).setSocketTimeout(director.getRequestTimeout()).build(); clientBuilder.setDefaultRequestConfig(requestConfig); this.httpClient = clientBuilder.build(); }
From source file:com.jaspersoft.studio.data.adapter.JSSBuiltinDataFileServiceFactory.java
@Override public DataFileService createService(JasperReportsContext context, DataFile dataFile) { if (dataFile instanceof RepositoryDataLocation) { return new RepositoryDataLocationService(context, (RepositoryDataLocation) dataFile); }// w ww. j a va2 s . c o m if (dataFile instanceof HttpDataLocation) { return new HttpDataService(context, (HttpDataLocation) dataFile) { @Override protected CloseableHttpClient createHttpClient(Map<String, Object> parameters) { HttpClientBuilder clientBuilder = HttpClients.custom(); HttpUtils.setupProxy(clientBuilder); // single connection BasicHttpClientConnectionManager connManager = new BasicHttpClientConnectionManager(); clientBuilder.setConnectionManager(connManager); // ignore cookies for now RequestConfig requestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES) .build(); clientBuilder.setDefaultRequestConfig(requestConfig); HttpClientContext clientContext = HttpClientContext.create(); setAuthentication(parameters, clientContext); CloseableHttpClient client = clientBuilder.build(); return client; } }; } return null; }
From source file:org.commonjava.indy.metrics.zabbix.api.IndyZabbixApi.java
@Override public void init() { if (httpClient == null) { httpClient = HttpClients.custom().build(); } }
From source file:org.wildfly.test.integration.elytron.http.PasswordMechTestBase.java
@Test public void testSuccess() throws Exception { HttpGet request = new HttpGet(new URI(url.toExternalForm() + "role1")); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("user1", "password1"); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, credentials); try (CloseableHttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider) .build()) {//from w w w. j a va 2 s. c o m try (CloseableHttpResponse response = httpClient.execute(request)) { int statusCode = response.getStatusLine().getStatusCode(); assertEquals("Unexpected status code in HTTP response.", SC_OK, statusCode); assertEquals("Unexpected content of HTTP response.", SimpleServlet.RESPONSE_BODY, EntityUtils.toString(response.getEntity())); } } }
From source file:com.jwm123.loggly.reporter.Client.java
public List<Map<String, Object>> getReport() throws Exception { final Integer rows = 500; CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(config.getAccount() + ".loggly.com", 80), new UsernamePasswordCredentials(config.getUsername(), config.getPassword())); CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); String url = "http://" + config.getAccount() + ".loggly.com/api/search?rows=" + rows + "&q=" + URLEncoder.encode(query, "UTF8"); if (StringUtils.isNotBlank(from)) { url += "&from=" + URLEncoder.encode(from, "UTF8"); }//from w w w . j av a 2 s. c o m if (StringUtils.isNotBlank(to)) { url += "&until=" + URLEncoder.encode(to, "UTF8"); } HttpGet get = new HttpGet(url); CloseableHttpResponse resp = null; List<Map<String, Object>> results = new ArrayList<Map<String, Object>>(); Integer offset = 0 - rows; Integer numFound = 0; try { do { offset += rows; try { get = new HttpGet(url + "&start=" + offset); resp = client.execute(get); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { String response = EntityUtils.toString(resp.getEntity()); Map<String, Object> responseMap = new Gson().fromJson(response, new TypeToken<Map<String, Object>>() { }.getType()); if (responseMap.containsKey("numFound")) { numFound = ((Number) responseMap.get("numFound")).intValue(); } if (responseMap.containsKey("data")) { Collection<?> dataCol = (Collection<?>) responseMap.get("data"); if (!dataCol.isEmpty()) { for (Object dataItem : dataCol) { if (dataItem instanceof Map) { results.add((Map<String, Object>) dataItem); } } } } } else { System.out.println("status: " + resp.getStatusLine().getStatusCode() + " Response: [" + EntityUtils.toString(resp.getEntity()) + "]"); break; } } finally { get.releaseConnection(); IOUtils.closeQuietly(resp); } } while (numFound >= offset + rows); } finally { IOUtils.closeQuietly(client); } return results; }
From source file:org.eclipse.cft.server.core.internal.ExternalRestTemplate.java
protected ClientHttpRequestFactory createRequestFactory() { HttpClientBuilder httpClientBuilder = HttpClients.custom().useSystemProperties(); HttpClient httpClient = httpClientBuilder.build(); HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory( httpClient);//from w ww . j a va2s.c o m return requestFactory; }