List of usage examples for org.apache.http.client.fluent Request execute
public Response execute() throws ClientProtocolException, IOException
From source file:io.gravitee.gateway.standalone.PostContentGatewayTest.java
@Test public void call_post_content() throws Exception { InputStream is = this.getClass().getClassLoader().getResourceAsStream("case1/request_content.json"); String content = StringUtils.copy(is); Request request = Request.Post("http://localhost:8082/test/my_team").bodyString(content, ContentType.APPLICATION_JSON); Response response = request.execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode()); String responseContent = StringUtils.copy(returnResponse.getEntity().getContent()); assertEquals(content, responseContent); }
From source file:hulop.cm.util.LogHelper.java
public boolean saveLog(String clientId, JSONObject log) throws Exception { if (mApiKey == null) { return false; }//from w ww.java2 s. c o m JSONObject data = new JSONObject(); data.put("event", "conversation"); data.put("client", clientId); data.put("timestamp", System.currentTimeMillis()); data.put("log", log); Request request = Request.Post(new URI(mEndpoint)).bodyForm(Form.form().add("action", "insert") .add("auditor_api_key", mApiKey).add("data", new JSONArray().put(data).toString()).build()); HttpResponse response = request.execute().returnResponse(); return response.getStatusLine().getStatusCode() == 200; }
From source file:nebula.plugin.metrics.dispatcher.SplunkMetricsDispatcher.java
@Override protected void postPayload(String requestBody) { try {//from w ww . ja v a 2 s. co m Request postReq = Request.Post(extension.getSplunkUri()); postReq.bodyString(requestBody, ContentType.APPLICATION_JSON); addHeaders(postReq); StatusLine status = postReq.execute().returnResponse().getStatusLine(); if (SC_OK != status.getStatusCode()) { error = String.format("%s (status code: %s)", status.getReasonPhrase(), status.getStatusCode()); } } catch (IOException e) { error = e.getMessage(); } }
From source file:nebula.plugin.metrics.dispatcher.RestMetricsDispatcher.java
protected void postPayload(String payload) { checkNotNull(payload);//from w w w. j a v a 2 s. com try { Request postReq = Request.Post(extension.getRestUri()); postReq.bodyString(payload, ContentType.APPLICATION_JSON); addHeaders(postReq); postReq.execute(); } catch (IOException e) { throw new RuntimeException("Unable to POST to " + extension.getRestUri(), e); } }
From source file:io.gravitee.gateway.standalone.PostContentGatewayTest.java
@Test public void call_case1_raw() throws Exception { String testCase = "case1"; InputStream is = this.getClass().getClassLoader().getResourceAsStream(testCase + "/request_content.json"); String content = StringUtils.copy(is); Request request = Request.Post("http://localhost:8082/test/my_team?case=" + testCase).bodyString(content, ContentType.APPLICATION_JSON); Response response = request.execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode()); String responseContent = StringUtils.copy(returnResponse.getEntity().getContent()); assertEquals(content, responseContent); }
From source file:org.apache.james.jmap.methods.integration.cucumber.UploadStepdefs.java
@When("^\"([^\"]*)\" checks for the availability of the upload endpoint$") public void optionUpload(String username) throws Throwable { AccessToken accessToken = userStepdefs.tokenByUser.get(username); Request request = Request.Options(uploadUri); if (accessToken != null) { request.addHeader("Authorization", accessToken.serialize()); }/* w w w . java 2s. c om*/ response = request.execute().returnResponse(); }
From source file:io.gravitee.gateway.standalone.PostContentGatewayTest.java
@Test public void call_case1_chunked_request() throws Exception { String testCase = "case1"; InputStream is = this.getClass().getClassLoader().getResourceAsStream(testCase + "/request_content.json"); Request request = Request.Post("http://localhost:8082/test/my_team?case=" + testCase).bodyStream(is, ContentType.APPLICATION_JSON); try {/*from ww w .j av a 2 s. c om*/ Response response = request.execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode()); // Not a chunked response because body content is to small assertEquals(null, returnResponse.getFirstHeader(HttpHeaders.TRANSFER_ENCODING)); } catch (Exception e) { e.printStackTrace(); assertTrue(false); } }
From source file:io.gravitee.gateway.standalone.PostContentGatewayTest.java
@Test public void call_case2_chunked() throws Exception { String testCase = "case2"; InputStream is = this.getClass().getClassLoader().getResourceAsStream(testCase + "/request_content.json"); Request request = Request.Post("http://localhost:8082/test/my_team?case=" + testCase).bodyStream(is, ContentType.APPLICATION_JSON); try {/*from w w w . j a v a 2 s . co m*/ Response response = request.execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode()); assertEquals(HttpHeadersValues.TRANSFER_ENCODING_CHUNKED, returnResponse.getFirstHeader(HttpHeaders.TRANSFER_ENCODING).getValue()); String responseContent = StringUtils.copy(returnResponse.getEntity().getContent()); assertEquals(652051, responseContent.length()); } catch (Exception e) { e.printStackTrace(); assertTrue(false); } }
From source file:io.gravitee.gateway.standalone.DynamicRoutingGatewayTest.java
@Test public void call_dynamic_api() throws Exception { String initialTarget = api.getProxy().getEndpoints().get(0).getTarget(); String dynamicTarget = create(URI.create("http://localhost:8080/team"), new URL(initialTarget).getPort()) .toString();//from w w w . j a v a 2s.com org.apache.http.client.fluent.Request request = org.apache.http.client.fluent.Request .Get("http://localhost:8082/test/my_team"); request.addHeader("X-Dynamic-Routing-URI", dynamicTarget); org.apache.http.client.fluent.Response response = request.execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode()); }
From source file:io.gravitee.gateway.standalone.TransformResponseContentUsingBuilderGatewayTest.java
@Test public void call_override_request_content() throws Exception { org.apache.http.client.fluent.Request request = org.apache.http.client.fluent.Request .Post("http://localhost:8082/echo/helloworld"); request.bodyString(BODY_CONTENT + " {#request.id}", ContentType.TEXT_PLAIN); org.apache.http.client.fluent.Response response = request.execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode()); String responseContent = StringUtils.copy(returnResponse.getEntity().getContent()); assertEquals("A new content", responseContent); }