List of usage examples for org.apache.http.impl.client HttpClientBuilder create
public static HttpClientBuilder create()
From source file:com.epam.reportportal.gateway.CompositeInfoEndpoint.java
@SuppressWarnings("SpringJavaAutowiringInspection") @Autowired/*ww w. j a v a2s. co m*/ public CompositeInfoEndpoint(RestTemplate loadBalancedRestTemplate, DiscoveryClient discoveryClient, EurekaClient eurekaClient) { this.restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory( HttpClientBuilder.create().setSSLHostnameVerifier((s, sslSession) -> true).build())); this.loadBalancedRestTemplate = loadBalancedRestTemplate; this.discoveryClient = discoveryClient; this.eurekaClient = eurekaClient; }
From source file:eu.fusepool.p3.webid.proxy.ProxyServlet.java
/** * Initializes the servlet by setting up the HTTP-client. *//*from ww w. ja va 2s. c o m*/ public ProxyServlet() { final HttpClientBuilder hcb = HttpClientBuilder.create(); hcb.setRedirectStrategy(new NeverRedirectStrategy()); httpclient = hcb.build(); targetBaseUri = null; }
From source file:ch.ralscha.extdirectspring_itest.InfoControllerTest.java
@Test public void testApiDebug() throws IOException { CloseableHttpClient client = HttpClientBuilder.create().build(); CloseableHttpResponse response = null; try {/*from ww w . j av a 2s. c om*/ HttpGet g = new HttpGet("http://localhost:9998/controller/api-debug.js?group=itest_info"); response = client.execute(g); String responseString = EntityUtils.toString(response.getEntity()); String contentType = response.getFirstHeader("Content-Type").getValue(); ApiControllerTest.compare(responseString, contentType, api(), ApiRequestParams.builder().build()); SimpleServiceTest.assertCacheHeaders(response, false); } finally { IOUtils.closeQuietly(response); IOUtils.closeQuietly(client); } }
From source file:db.dao.Dao.java
public JSONArray listAllHttpClient(String url) { url = checkIfLocal(url);/*from w w w. j a va2 s . co m*/ HttpClient client = HttpClientBuilder.create().build(); HttpGet getRequest = new HttpGet(url); String usernamepassword = "Pepijn:Mores"; String encoded = Base64.encodeBase64String(usernamepassword.getBytes()); getRequest.addHeader("accept", "application/json"); getRequest.setHeader("Authorization", encoded); ; HttpResponse response = null; try { response = client.execute(getRequest); } catch (IOException ex) { Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex); } if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); } JSONArray json = null; try (BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()))) { String inputLine; StringBuilder responseString = new StringBuilder(); while ((inputLine = in.readLine()) != null) { responseString.append(inputLine); } json = new JSONArray(responseString.toString()); } catch (IOException ex) { Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex); } catch (JSONException ex) { Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex); } return json; }
From source file:com.turn.splicer.SuggestHttpWorker.java
@Override public String call() throws Exception { LinkedBlockingQueue<String> TSDs; //TODO: have it implement its own RegionChecker to get hbase locality looking for metric names //lets have it just pick a random host String hostname = getRandomHost(); TSDs = HttpWorker.TSDMap.get(hostname); if (TSDs == null) { LOG.error("We are not running TSDs on regionserver={}. Choosing a random host failed", hostname); return "{'error': 'Choice of hostname=" + hostname + " failed.'}"; }/*from ww w .j ava2 s .c o m*/ String server = TSDs.take(); String uri = "http://" + server + "/api/suggest?" + suggestQuery; CloseableHttpClient postman = HttpClientBuilder.create().build(); try { HttpGet getRequest = new HttpGet(uri); LOG.info("Sending query=" + uri + " to TSD running on host=" + hostname); HttpResponse response = postman.execute(getRequest); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException( "Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); } List<String> dl = IOUtils.readLines(response.getEntity().getContent()); String result = StringUtils.join(dl, ""); LOG.info("Result={}", result); return result; } finally { IOUtils.closeQuietly(postman); TSDs.put(server); LOG.info("Returned {} into the available queue", server); } }
From source file:org.apache.sling.hapi.client.impl.AbstractHtmlClientImpl.java
public AbstractHtmlClientImpl(String baseUrl) throws URISyntaxException { this(HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build(), baseUrl); }
From source file:org.ssc.txtproc.TextProcessor.java
public Result process(@NotNull String text, @NotNull Options opt) throws IOException { HttpGet connMethod = buildRequest(opt); connMethod.setHeader("doc", text); HttpClient client = HttpClientBuilder.create().build(); HttpResponse response = client.execute(connMethod); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String output = ""; String line = null;/*from w w w . java 2 s. c om*/ while ((line = rd.readLine()) != null) { output += line; } JsonParser parser = new JsonParser(); JsonElement rootElement = parser.parse(output); JsonObject obj = rootElement.getAsJsonObject(); if (obj == null) return null; Result res = new Result(); JsonElement origMbr = obj.get("original"); if (origMbr != null) { res.setOriginalText(origMbr.getAsString()); } res.setTokens(getAsStringArray(obj.get("tokens"))); res.setTokens(getAsStringArray(obj.get("stops"))); res.setTokens(getAsStringArray(obj.get("non_stops"))); JsonObject stemmedMbr = obj.getAsJsonObject("stemmed"); if (stemmedMbr != null) { res.setPorterStems(getAsStringArray(stemmedMbr.get("porter"))); res.setLancasterStems(getAsStringArray(stemmedMbr.get("lancaster"))); } JsonObject normalizedMbr = obj.getAsJsonObject("normalized"); if (normalizedMbr != null) { JsonElement porterChild = normalizedMbr.get("porter"); if (porterChild != null) res.setNormalizedByPorter(porterChild.getAsString()); JsonElement lancasterChild = normalizedMbr.get("lancaster"); if (lancasterChild != null) res.setNormalizedByLancaster(lancasterChild.getAsString()); } JsonObject distancesMbr = obj.getAsJsonObject("distances"); if (distancesMbr != null) { res.setLevenshtineDist(getAsDoubleArray(distancesMbr.get("levenshtine"))); res.setJaroWinkler(getAsDoubleArray(distancesMbr.get("jaro_winkler"))); } JsonArray ngramsMbr = obj.getAsJsonArray("ngrams"); if (ngramsMbr != null) { ArrayList<List<String>> arrayOfNGrams = new ArrayList<List<String>>(); for (JsonElement singleNGram : ngramsMbr) { List<String> words = getAsStringArray(singleNGram); arrayOfNGrams.add(words); } res.setNGrams(arrayOfNGrams); } return res; }
From source file:ch.ralscha.extdirectspring_itest.InfoServiceTest.java
@Test public void testApi() throws IOException { CloseableHttpClient client = HttpClientBuilder.create().build(); CloseableHttpResponse response = null; try {// ww w . j a v a 2 s. co m HttpGet g = new HttpGet("http://localhost:9998/controller/api.js?group=itest_info_service"); response = client.execute(g); String responseString = EntityUtils.toString(response.getEntity()); String contentType = response.getFirstHeader("Content-Type").getValue(); ApiControllerTest.compare(responseString, contentType, api(), ApiRequestParams.builder().build()); SimpleServiceTest.assertCacheHeaders(response, false); } finally { IOUtils.closeQuietly(response); IOUtils.closeQuietly(client); } }
From source file:com.jive.myco.seyren.core.service.notification.PushoverNotificationService.java
@Override public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException { String pushoverAppApiToken = StringUtils.trimToNull(seyrenConfig.getPushoverAppApiToken()); String pushoverUserKey = StringUtils.trimToNull(subscription.getTarget()); String pushoverMsgTitle = formatMsgTitle(check); String pushoverMsgBody = "Check details : " + seyrenConfig.getBaseUrl() + "/#/checks/" + check.getId(); String pushoverMsgPriority = getMsgPriority(check); if (pushoverAppApiToken == null) { LOGGER.warn("Pushover App API Token must be provided"); return;/* w w w . j av a 2 s . c om*/ } if (pushoverUserKey == null || pushoverUserKey.length() != 30) { LOGGER.warn("Invalid or missing Pushover user key"); return; } HttpClient client = HttpClientBuilder.create().build(); HttpPost post = new HttpPost("https://api.pushover.net/1/messages.json"); try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("token", pushoverAppApiToken)); nameValuePairs.add(new BasicNameValuePair("user", pushoverUserKey)); nameValuePairs.add(new BasicNameValuePair("title", pushoverMsgTitle)); nameValuePairs.add(new BasicNameValuePair("message", pushoverMsgBody)); nameValuePairs.add(new BasicNameValuePair("priority", pushoverMsgPriority)); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); client.execute(post); } catch (IOException e) { throw new NotificationFailedException("Sending notification to Pushover failed.", e); } finally { HttpClientUtils.closeQuietly(client); } }