List of usage examples for org.apache.http.client.fluent Response returnResponse
public HttpResponse returnResponse() throws IOException
From source file:org.apache.infra.reviewboard.ReviewBoard.java
public static void main(String... args) throws IOException { URL url = new URL(REVIEW_BOARD_URL); HttpHost host = new HttpHost(url.getHost(), url.getPort(), url.getProtocol()); Executor executor = Executor.newInstance().auth(host, REVIEW_BOARD_USERNAME, REVIEW_BOARD_PASSWORD) .authPreemptive(host);//from w w w .j ava2s.c o m Request request = Request.Get(REVIEW_BOARD_URL + "/api/review-requests/"); Response response = executor.execute(request); request = Request.Get(REVIEW_BOARD_URL + "/api/review-requests/"); response = executor.execute(request); ObjectMapper mapper = new ObjectMapper(); JsonNode json = mapper.readTree(response.returnResponse().getEntity().getContent()); JsonFactory factory = new JsonFactory(); JsonGenerator generator = factory.createGenerator(new PrintWriter(System.out)); generator.setPrettyPrinter(new DefaultPrettyPrinter()); mapper.writeTree(generator, json); }
From source file:org.aksw.simba.cetus.fox.FoxBasedTypeSearcher.java
public static void main(String[] args) throws UnsupportedCharsetException, ClientProtocolException, JSONException, IOException { Response response = Request.Post(FOX_SERVICE).addHeader("Content-type", "application/json") .addHeader("Accept-Charset", "UTF-8") .body(new StringEntity(new JSONObject().put("input", "Brian Banner is a fictional villain from the Marvel Comics Universe created by Bill Mantlo and Mike Mignola and first appearing in print in late 1985.") .put("type", "text").put("task", "ner").put("output", "JSON-LD").toString(), ContentType.APPLICATION_JSON)) .execute();/*ww w . j a va 2s . c o m*/ HttpResponse httpResponse = response.returnResponse(); HttpEntity entry = httpResponse.getEntity(); String content = IOUtils.toString(entry.getContent(), "UTF-8"); System.out.println(content); }
From source file:io.bitgrillr.gocddockerexecplugin.utils.GoTestUtils.java
/** * Schedules the named pipeline to run.//ww w. jav a 2 s . c o m * * @param pipeline Name of the Pipeline to run. * @return Counter of the pipeline instance scheduled. * @throws GoError If Go.CD returns a non 2XX response. * @throws IOException If a communication error occurs. * @throws InterruptedException If something has gone horribly wrong. */ public static int runPipeline(String pipeline) throws GoError, IOException, InterruptedException { final Response scheduleResponse = executor .execute(Request.Post(PIPELINES + pipeline + "/schedule").addHeader("Confirm", "true")); final int scheduleStatus = scheduleResponse.returnResponse().getStatusLine().getStatusCode(); if (scheduleStatus != HttpStatus.SC_ACCEPTED) { throw new GoError(scheduleStatus); } Thread.sleep(5 * 1000); final HttpResponse historyResponse = executor.execute(Request.Get(PIPELINES + pipeline + "/history")) .returnResponse(); final int historyStatus = historyResponse.getStatusLine().getStatusCode(); if (historyStatus != HttpStatus.SC_OK) { throw new GoError(historyStatus); } final JsonArray pipelineInstances = Json.createReader(historyResponse.getEntity().getContent()).readObject() .getJsonArray("pipelines"); JsonObject lastPipelineInstance = pipelineInstances.getJsonObject(0); for (JsonValue pipelineInstance : pipelineInstances) { if (pipelineInstance.asJsonObject().getInt("counter") > lastPipelineInstance.getInt("counter")) { lastPipelineInstance = pipelineInstance.asJsonObject(); } } return lastPipelineInstance.getInt("counter"); }
From source file:org.mule.module.http.functional.proxy.HttpProxyExpectHeaderTestCase.java
@Test public void handlesExpectationFailedResponse() throws Exception { startExpectFailedServer();/*w w w . j ava 2 s . co m*/ Response response = sendRequest(); assertThat(response.returnResponse().getStatusLine().getStatusCode(), is(INTERNAL_SERVER_ERROR.getStatusCode())); stopServer(); }
From source file:io.gravitee.gateway.standalone.SimpleGatewayTest.java
@Test public void call_get_started_api() throws Exception { Request request = Request.Get("http://localhost:8082/test/my_team"); Response response = request.execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode()); }
From source file:io.gravitee.gateway.standalone.UnreachableTest.java
@Test public void call_unreachable_api() throws Exception { Request request = Request.Post("http://localhost:8082/unreachable"); Response response = request.execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_BAD_GATEWAY, returnResponse.getStatusLine().getStatusCode()); }
From source file:io.gravitee.gateway.standalone.ReadTimeoutTest.java
@Test public void call_read_timeout_api() throws Exception { Request request = Request.Get("http://localhost:8082/team/my_team"); Response response = request.execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_GATEWAY_TIMEOUT, returnResponse.getStatusLine().getStatusCode()); }
From source file:io.gravitee.gateway.standalone.ConnectionTimeoutTest.java
@Test public void call_unreachable_api() throws Exception { Request request = Request.Post("http://localhost:8082/unreachable"); Response response = request.execute(); HttpResponse returnResponse = response.returnResponse(); assertTrue(returnResponse.getStatusLine().getStatusCode() == HttpStatus.SC_GATEWAY_TIMEOUT || returnResponse.getStatusLine().getStatusCode() == HttpStatus.SC_BAD_GATEWAY); }
From source file:io.gravitee.gateway.standalone.MultiTenantGatewayTest.java
@Test public void call_get_query_params() throws Exception { Request request = Request.Get("http://localhost:8082/test/my_team"); Response response = request.execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode()); }
From source file:io.gravitee.gateway.standalone.NotFoundGatewayTest.java
@Test public void call_no_api() throws IOException { Request request = Request.Get("http://localhost:8082/unknow"); Response response = request.execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatusCode.NOT_FOUND_404, returnResponse.getStatusLine().getStatusCode()); }