Example usage for org.apache.http.client.fluent Response returnContent

List of usage examples for org.apache.http.client.fluent Response returnContent

Introduction

In this page you can find the example usage for org.apache.http.client.fluent Response returnContent.

Prototype

public Content returnContent() throws ClientProtocolException, IOException 

Source Link

Usage

From source file:edu.xjtu.qxcamerabridge.JSONActionWrapper.java

public static JSONObject jsonrpc(String service, String methodName, List<Object> params) {

    JSONArray paramArray = new JSONArray(params);

    JSONObject requstjson = new JSONObject();
    requstjson.put("method", methodName);
    requstjson.put("params", paramArray);
    requstjson.put("id", idGenerator());
    requstjson.put("version", "1.0");

    String requestjson = requstjson.toString();
    System.out.println(requestjson);
    try {//from  w  w w  .  java  2 s.  c o m

        Response reply = Request.Post(endPointURL(service)).bodyByteArray(requestjson.getBytes()).execute();
        String replyContent = reply.returnContent().asString();
        return new JSONObject(replyContent);

    } catch (IOException iOException) {
        iOException.printStackTrace();
    } catch (JSONException jSONException) {
        jSONException.printStackTrace();
    }
    return null;
}

From source file:edu.xjtu.qxcamerabridge.JSONActionWrapper.java

public static Response httpPostTest(String content) throws IOException {
    Response reply = Request.Put("http://posttestserver.com/post.php").bodyByteArray(content.getBytes())
            .execute();// w w  w . j  a  va2 s. c  o  m
    System.out.println(reply.returnContent().asString());
    return reply;
}

From source file:eu.anynet.java.util.HttpClient.java

/**
 * Response to String//from ww  w.j  a va2s .  com
 * @param response -The response object
 * @param maxbyte Max bytes to fetch
 * @return The string
 * @throws IOException
 */
public static String toString(Response response, int maxbyte) throws IOException {
    Content content = response.returnContent();
    return toString(content.asStream(), maxbyte);
}

From source file:net.palette_software.pet.restart.HelperHttpClient.java

static String getPage(String targetURL) throws Exception {
    Request x = Request.Get(targetURL);
    Response y = x.execute();
    Content z = y.returnContent();
    return z.toString();
}

From source file:org.apache.james.jmap.HttpJmapAuthentication.java

public static AccessToken authenticateJamesUser(URIBuilder uriBuilder, String username, String password)
        throws ClientProtocolException, IOException, URISyntaxException {
    String continuationToken = getContinuationToken(uriBuilder, username);

    Response response = Request.Post(uriBuilder.setPath("/authentication").build())
            .bodyString("{\"token\": \"" + continuationToken + "\", \"method\": \"password\", \"password\": \""
                    + password + "\"}", ContentType.APPLICATION_JSON)
            .setHeader("Accept", ContentType.APPLICATION_JSON.getMimeType()).execute();

    return AccessToken.fromString(JsonPath.parse(response.returnContent().asString()).read("accessToken"));
}

From source file:org.apache.james.jmap.HttpJmapAuthentication.java

private static String getContinuationToken(URIBuilder uriBuilder, String username)
        throws ClientProtocolException, IOException, URISyntaxException {
    Response response = Request.Post(uriBuilder.setPath("/authentication").build())
            .bodyString("{\"username\": \"" + username
                    + "\", \"clientName\": \"Mozilla Thunderbird\", \"clientVersion\": \"42.0\", \"deviceName\": \"Joe Bloggs iPhone\"}",
                    ContentType.APPLICATION_JSON)
            .setHeader("Accept", ContentType.APPLICATION_JSON.getMimeType()).execute();
    return JsonPath.parse(response.returnContent().asString()).read("continuationToken");
}

From source file:org.mule.module.http.functional.proxy.HttpProxyExpectHeaderTestCase.java

@Test
public void handlesContinueResponse() throws Exception {
    startExpectContinueServer();//from   ww w.j a  va 2  s  .  co  m
    Response response = sendRequest();
    assertThat(response.returnContent().asString(), equalTo(TEST_MESSAGE));
    stopServer();
}

From source file:com.triage.radium.testweb.it.ITTestWeb.java

@Test
public void testThatEchoServletReturnsUnsanitizedContent() throws Exception {
    String unsanitizedInput = "<xml>Unsantized!</xml>";
    URI uri = new URIBuilder(WEBAPP_BASE_URL + "/echo").addParameter("in", unsanitizedInput).build();
    Response resp = Request.Get(uri).execute();
    String resultText = resp.returnContent().toString().trim();

    assertEquals(resultText, "SUCCESS\n" + unsanitizedInput);

}

From source file:org.mule.module.http.functional.listener.HttpAllInterfacesTestCase.java

@Test
public void testAllInterfaces() throws IOException {
    final String url = String.format("http://localhost:%s/%s", listenPort.getNumber(), PATH);
    final Response response = Request.Get(url).connectTimeout(1000).execute();
    assertThat(response.returnContent().asString(), is(PATH));
}

From source file:com.triage.radium.testweb.it.ITTestWeb.java

@Test
public void testRuntimeExecListsDirectory() throws Exception {
    Response resp = Request.Get(WEBAPP_BASE_URL + "/runtimeExec").execute();
    String resultText = resp.returnContent().toString();
    assertTrue(resultText.contains("SUCCESS"));
}