List of usage examples for org.apache.http.impl.client HttpClientBuilder create
public static HttpClientBuilder create()
From source file:juzu.plugin.jackson.AbstractJacksonResponseTestCase.java
@Test public void testResponse() throws Exception { HttpGet get = new HttpGet(applicationURL().toString()); HttpClient client = HttpClientBuilder.create().build(); HttpResponse response = client.execute(get); assertEquals(200, response.getStatusLine().getStatusCode()); assertNotNull(response.getEntity()); assertEquals("application/json;charset=ISO-8859-1", response.getEntity().getContentType().getValue()); ObjectMapper mapper = new ObjectMapper(); JsonNode tree = mapper.readTree(response.getEntity().getContent()); JsonNodeFactory factory = JsonNodeFactory.instance; JsonNode expected = factory.objectNode().set("foo", factory.textNode("bar")); assertEquals(expected, tree);/*ww w .jav a 2 s .c o m*/ }
From source file:com.bekioui.jaxrs.client.factory.ResteasyClientFactory.java
public ResteasyClientFactory(String uri) { this.target = new ResteasyClientBuilder() // .httpEngine(new ApacheHttpClient4Engine(HttpClientBuilder.create() .setConnectionManager(new PoolingHttpClientConnectionManager()).build())) // .register(AuthorizationFilter.class) // .register(ErrorFilter.class) // .build() // .target(uri);/* w ww . ja va2s. c om*/ }
From source file:org.wso2.iot.refarch.rpi.agent.connector.HttpService.java
public void sendPayload(JSONObject data) throws IOException, ExecutionException, InterruptedException { JSONObject dataObj = new JSONObject(); dataObj.put("data", data); HttpClient client = HttpClientBuilder.create().build(); System.out.println("Created HTTP Client"); HttpPost post = new HttpPost(address); post.setHeader("content-type", "application/json"); BasicHttpEntity he = new BasicHttpEntity(); he.setContent(new ByteArrayInputStream(dataObj.toString().getBytes())); post.setEntity(he);//w w w . j ava 2 s . c o m client.execute(post); System.out.println("Payload sent"); }
From source file:org.ado.biblio.desktop.BookInfoLoader.java
@Override public HttpClient getHttpClient() { return HttpClientBuilder.create().build(); }
From source file:uk.ac.bbsrc.tgac.miso.integration.util.IntegrationUtils.java
public static String makePostRequest(String host, int port, String query) throws IntegrationException { if (query == null || query.isEmpty()) { throw new IntegrationException("Query must be populated when calling makePostRequest."); }//from w w w.j a va2 s . c o m String rtn = null; HttpClient httpclient = HttpClientBuilder.create().build(); String url = "http://" + host + ":" + port + "/miso/"; try { HttpPost httpPost = new HttpPost(url); // Request parameters and other properties. httpPost.setHeader("content-type", "application/x-www-form-urlencoded"); System.out.println(query); httpPost.setEntity(new StringEntity(query)); // Execute and get the response. HttpResponse response = httpclient.execute(httpPost); rtn = EntityUtils.toString(response.getEntity()); if (rtn.charAt(0) == '"' && rtn.charAt(rtn.length() - 1) == '"') { System.out.println("Removing quotes"); rtn = rtn.substring(1, rtn.length() - 1); } } catch (IOException ex) { ex.printStackTrace(); throw new IntegrationException("Cannot connect to " + url + " Cause: " + ex.getMessage()); } return rtn; }
From source file:uk.ac.bbsrc.tgac.miso.core.util.TaxonomyUtils.java
public static String checkScientificNameAtNCBI(String scientificName) { try {//from w w w . j ava2 s . co m String query = ncbiEntrezUtilsURL + "db=taxonomy&term=" + URLEncoder.encode(scientificName, "UTF-8"); final HttpClient httpclient = HttpClientBuilder.create().build(); HttpGet httpget = new HttpGet(query); try { HttpResponse response = httpclient.execute(httpget); String out = parseEntity(response.getEntity()); log.info(out); try { DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document d = docBuilder.newDocument(); TransformerFactory.newInstance().newTransformer() .transform(new StreamSource(new UnicodeReader(out)), new DOMResult(d)); NodeList nl = d.getElementsByTagName("Id"); for (int i = 0; i < nl.getLength(); i++) { Element e = (Element) nl.item(i); return e.getTextContent(); } } catch (ParserConfigurationException e) { log.error("check scientific name at NCBI", e); } catch (TransformerException e) { log.error("check scientific name at NCBI", e); } } catch (ClientProtocolException e) { log.error("check scientific name at NCBI", e); } catch (IOException e) { log.error("check scientific name at NCBI", e); } } catch (UnsupportedEncodingException e) { log.error("check scientific name at NCBI", e); } return null; }
From source file:com.wso2.raspberrypi.apicalls.HttpClient.java
public HttpClient() { client = HttpClientBuilder.create().build(); }
From source file:com.navercorp.pinpoint.demo.gateway.configuration.GatewayConfiguration.java
@Bean public CloseableHttpClient httpClient() { return HttpClientBuilder.create().build(); }
From source file:ng.logentries.logs.LogReader.java
public <T extends LogEntryData> List<T> readLogs(Class<? extends LogEntryData> cls, Account account, FilterOptions options) throws Exception { List<T> list = new ArrayList<>(); LogEntryData instance = cls.newInstance(); CloseableHttpClient httpClient = HttpClientBuilder.create().build(); try {/*from w w w . j a va2s. co m*/ URIBuilder uriBuilder = new URIBuilder().setScheme("https").setHost("pull.logentries.com/") .setPath(account.getAccessKey() + "/hosts/" + account.getLogSetName() + "/" + account.getLogName() + "/"); if (options.getLimit() != -1) { uriBuilder.addParameter("limit", "" + options.getLimit()); } uriBuilder.addParameter("filter", instance.getPattern()); if (options.getsTime() != -1) { uriBuilder.addParameter("start", "" + options.getsTime()); } if (options.geteTime() != -1) { uriBuilder.addParameter("end", "" + options.geteTime()); System.out.println(options.geteTime()); } HttpGet get = new HttpGet(uriBuilder.build()); HttpResponse httpResponse = httpClient.execute(get); HttpEntity entity = httpResponse.getEntity(); Scanner in = new Scanner(entity.getContent()); while (in.hasNext()) { T parse = (T) LogDataMapper.parse(in.nextLine(), cls); list.add(parse); //System.out.println(parse); } } catch (Exception e) { System.out.println("Error while trying to read logs: " + e); } finally { if (httpClient != null) { httpClient.close(); } } return list; }
From source file:com.whatsthatlight.teamcity.hipchat.test.SimpleServerTest.java
@Test public void testTestServer() throws Exception { // Test parameters String expectedResponse = "<h1>Hello World</h1>"; int expectedStatusCode = HttpServletResponse.SC_OK; int port = 8080; URI uri = new URI(String.format("http://localhost:%s/", port)); // Setup//from w ww .j av a 2s . co m SimpleServer server = new SimpleServer(port, new SimpleHandler(expectedResponse, expectedStatusCode)); server.start(); // Make request HttpClient client = HttpClientBuilder.create().build(); HttpGet getRequest = new HttpGet(uri.toString()); HttpResponse getResponse = client.execute(getRequest); int actualStatusCode = getResponse.getStatusLine().getStatusCode(); String actualResponse = EntityUtils.toString(getResponse.getEntity()); // Clean up server.stop(); // Test assertEquals(expectedStatusCode, actualStatusCode); assertEquals(expectedResponse, actualResponse); }