List of usage examples for org.apache.http.client.fluent Request execute
public Response execute() throws ClientProtocolException, IOException
From source file:hulop.cm.util.LogHelper.java
public JSONArray getLog(String clientId, String start, String end, String skip, String limit) throws Exception { if (mApiKey == null) { return new JSONArray(); }//www . j a v a 2 s . c om Form form = Form.form().add("action", "get").add("auditor_api_key", mApiKey).add("event", "conversation"); if (clientId != null) { form.add("clientId", clientId); } if (start != null) { form.add("start", start); } if (end != null) { form.add("end", end); } if (skip != null) { form.add("skip", skip); } if (limit != null) { form.add("limit", limit); } Request request = Request.Post(new URI(mEndpoint)).bodyForm(form.build()); return (new JSONArray(request.execute().returnContent().asString())); }
From source file:org.mule.module.http.functional.listener.HttpListenerEncodingTestCase.java
@Test public void testEncoding() throws Exception { final String url = String.format("http://localhost:%s/test", port.getNumber()); Request request = Request.Post(url).bodyString(testMessage, ContentType.create("text/plain", Charset.forName(encoding))); request.execute(); MuleMessage result = muleContext.getClient().request("vm://out", 2000); assertThat(result.getPayloadAsString(), is(testMessage)); }
From source file:io.gravitee.gateway.standalone.RoundRobinLoadBalancingMultipleTest.java
@Test public void call_round_robin_lb_multiple_endpoints() throws Exception { Request request = Request.Get("http://localhost:8082/echo/helloworld"); int calls = 20; for (int i = 0; i < calls; i++) { Response response = request.execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode()); String workerHeader = returnResponse.getFirstHeader("worker").getValue(); assertEquals("worker#" + (i % 2), workerHeader); }// ww w. ja v a 2 s .c o m }
From source file:io.gravitee.gateway.standalone.RoundRobinLoadBalancingSingleTest.java
@Test public void call_round_robin_lb_single_endpoint() throws Exception { Request request = Request.Get("http://localhost:8082/echo/helloworld"); int calls = 20; for (int i = 0; i < calls; i++) { Response response = request.execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode()); String workerHeader = returnResponse.getFirstHeader("worker").getValue(); assertEquals("worker#0", workerHeader); }//from ww w. j av a2 s . c o m }
From source file:edu.jhuapl.dorset.http.apache.ApacheHttpClient.java
private Response get(HttpRequest request) throws IOException { Request apacheRequest = Request.Get(request.getUrl()); prepareRequest(apacheRequest);/*from w ww .ja va2 s .c om*/ return apacheRequest.execute(); }
From source file:edu.jhuapl.dorset.http.apache.ApacheHttpClient.java
private Response delete(HttpRequest request) throws IOException { Request apacheRequest = Request.Delete(request.getUrl()); prepareRequest(apacheRequest);// w w w. j a v a2s . c o m return apacheRequest.execute(); }
From source file:io.gravitee.gateway.standalone.OverrideMethodGatewayTest.java
@Test public void call_override_method() throws Exception { org.apache.http.client.fluent.Request request = org.apache.http.client.fluent.Request .Get("http://localhost:8082/echo/helloworld"); org.apache.http.client.fluent.Response response = request.execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode()); assertEquals(HttpMethod.POST.name(), returnResponse.getFirstHeader("method").getValue()); }
From source file:info.losd.galen.client.ApiClient.java
public ApiResponse execute(ApiRequest req) { try {/*from w ww .j a va 2s. com*/ Request request = request(req); req.getHeaders().forEach((header, value) -> request.addHeader(header, value)); long start = System.nanoTime(); HttpResponse response = request.execute().returnResponse(); long end = System.nanoTime(); HealthcheckDetails stat = HealthcheckDetails.tag(req.getTag()).duration((end - start) / 1000000) .statusCode(response.getStatusLine().getStatusCode()).build(); healthcheckRepo.save(stat); return ApiResponse.statusCode(response.getStatusLine().getStatusCode()).body(getResponseBody(response)) .build(); } catch (IOException e) { logger.error("IO Exception", e); throw new RuntimeException(e); } }
From source file:io.gravitee.gateway.standalone.WeightedRoundRobinLoadBalancingTest.java
@Test public void call_weighted_lb_multiple_endpoints() throws Exception { Request request = Request.Get("http://localhost:8082/echo/helloworld"); Map<String, Integer> counts = new HashMap<>(); int calls = 10; for (int i = 0; i < calls; i++) { Response response = request.execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode()); String workerHeader = returnResponse.getFirstHeader("worker").getValue(); Integer workerCount = counts.get(workerHeader); if (workerCount == null) { workerCount = 1;/* ww w . j a va2 s . com*/ } else { ++workerCount; } counts.put(workerHeader, workerCount); } assertEquals(3, (int) counts.get("worker#0")); assertEquals(7, (int) counts.get("worker#1")); }
From source file:org.mule.module.http.functional.listener.HttpListenerExpressionFilterTestCase.java
private void sendRequestAndAssertResponse(boolean filterExpression, String expectedBody) throws IOException { Request request = Request.Post(String.format("http://localhost:%s", listenPort.getValue())) .body(new StringEntity(TEST_MESSAGE)) .addHeader("filterExpression", Boolean.toString(filterExpression)); HttpResponse response = request.execute().returnResponse(); assertThat(response.getStatusLine().getStatusCode(), equalTo(200)); assertThat(IOUtils.toString(response.getEntity().getContent()), equalTo(expectedBody)); }