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.OverrideRequestContentGatewayTest.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("Request content overriden by policy", 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(OverrideRequestContentPolicy.STREAM_POLICY_CONTENT, responseContent); }
From source file:io.gravitee.gateway.standalone.PostContentGatewayTest.java
@Test public void call_case3_raw() throws Exception { String testCase = "case3"; InputStream is = this.getClass().getClassLoader().getResourceAsStream(testCase + "/request_content.json"); Request request = Request.Post("http://localhost:8082/test/my_team?mode=chunk&case=" + testCase) .bodyStream(is, ContentType.APPLICATION_JSON); try {//from w w w . j a v a 2 s .c o m Response response = request.execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode()); // Set chunk mode in request but returns raw because of the size of the content assertEquals(null, returnResponse.getFirstHeader(HttpHeaders.TRANSFER_ENCODING)); String responseContent = StringUtils.copy(returnResponse.getEntity().getContent()); assertEquals(70, responseContent.length()); } catch (Exception e) { e.printStackTrace(); assertTrue(false); } }
From source file:io.gravitee.gateway.standalone.TransformRequestContentGatewayTest.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()); String[] parts = responseContent.split(":"); assertTrue(responseContent.startsWith(BODY_CONTENT)); assertTrue(UUID.fromString(parts[1].substring(1)) != null); }
From source file:org.mule.module.http.functional.listener.HttpListenerPersistentConnectionsTestCase.java
private HttpResponse doPerformRequest(int port, HttpVersion httpVersion, boolean keepAlive) throws IOException, ClientProtocolException { String url = String.format("http://localhost:%s/", port); Request request = Request.Get(url).version(httpVersion).connectTimeout(GET_TIMEOUT); if (keepAlive) { request = request.addHeader(CONNECTION, KEEP_ALIVE); }//from w w w .j a v a 2 s .c o m HttpResponse response = request.execute().returnResponse(); assertThat(response.getStatusLine().getStatusCode(), is(HTTP_OK)); return response; }
From source file:org.vas.test.rest.RestImpl.java
@Override public <T> Response<T> delete(String uri, Class<T> klass, Object... args) { uri = formattedUri(uri, args);/* www .ja va 2s . c om*/ Request request = httpDelete(uri); try { org.apache.http.client.fluent.Response response = request.execute(); return extractResponse(klass, response); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.apache.james.jmap.methods.integration.cucumber.UploadStepdefs.java
@When("^\"([^\"]*)\" upload a content without content type$") public void userUploadContentWithoutContentType(String username) throws Throwable { AccessToken accessToken = userStepdefs.tokenByUser.get(username); Request request = Request.Post(uploadUri).bodyByteArray("some text".getBytes(Charsets.UTF_8)); if (accessToken != null) { request.addHeader("Authorization", accessToken.serialize()); }/*from w w w.j a v a 2 s . co m*/ response = request.execute().returnResponse(); }
From source file:io.gravitee.gateway.standalone.OverrideResponseContentGatewayTest.java
@Test public void call_override_response_content() throws Exception { org.apache.http.client.fluent.Request request = org.apache.http.client.fluent.Request .Post("http://localhost:8082/echo/helloworld"); request.bodyString("This content should normally be returned by echo backend", 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(OverrideResponseContentPolicy.STREAM_POLICY_CONTENT, responseContent); }
From source file:org.apache.james.jmap.methods.integration.cucumber.UploadStepdefs.java
@Then("^\"([^\"]*)\" should be able to retrieve the content$") public void contentShouldBeRetrievable(String username) throws Exception { AccessToken accessToken = userStepdefs.tokenByUser.get(username); Request request = Request .Get(mainStepdefs.baseUri().setPath("/download/" + _1M_ZEROED_FILE_BLOB_ID).build()); if (accessToken != null) { request.addHeader("Authorization", accessToken.serialize()); }/*www . j av a2s .co m*/ response = request.execute().returnResponse(); httpAuthorizedStatus(); }
From source file:org.vas.test.rest.RestImpl.java
@Override public <T> Response<T> put(String uri, Map<String, String> datas, Class<T> klass, Object... args) { uri = formattedUri(uri, args);//www . ja v a 2 s. c o m Request request = httpPut(uri); request.bodyForm(nameValuePairOf(datas)); try { org.apache.http.client.fluent.Response response = request.execute(); return extractResponse(klass, response); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.vas.test.rest.RestImpl.java
@Override public <T> Response<T> post(String uri, Map<String, String> datas, Class<T> klass, Object... args) { uri = formattedUri(uri, args);// w w w .j a v a2s . c om Request request = httpPost(uri); request.bodyForm(nameValuePairOf(datas)); try { org.apache.http.client.fluent.Response response = request.execute(); return extractResponse(klass, response); } catch (Exception e) { throw new RuntimeException(e); } }