Example usage for org.apache.http.client.fluent Request execute

List of usage examples for org.apache.http.client.fluent Request execute

Introduction

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

Prototype

public Response execute() throws ClientProtocolException, IOException 

Source Link

Usage

From source file:org.elasticsearch.packaging.util.ServerUtils.java

public static String makeRequest(Request request) throws IOException {
    final HttpResponse response = request.execute().returnResponse();
    final String body = EntityUtils.toString(response.getEntity());

    if (response.getStatusLine().getStatusCode() >= 300) {
        throw new RuntimeException("Request failed:\n" + response.getStatusLine().toString() + "\n" + body);
    }/*from  w w  w  .  ja v  a  2s  . c  o m*/

    return body;

}

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

/**
 * Request to string/*from   www . j  a  v  a  2  s .co  m*/
 * @param request The request object
 * @return The response string
 * @throws IOException
 */
public static String toString(Request request) throws IOException {
    return toString(request.execute(), -1);
}

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

/**
 * Request to string/*from   w ww . j a  v  a  2s  .  c o  m*/
 * @param request The request object
 * @param maxbyte Max bytes to fetch
 * @return The response string
 * @throws IOException
 */
public static String toString(Request request, int maxbyte) throws IOException {
    return toString(request.execute(), 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();/*  ww w  . j av  a  2s  .  c  o  m*/
    return z.toString();
}

From source file:org.kie.smoke.wb.util.RestUtil.java

public static <T, G> T get(URL deploymentUrl, String relativeUrl, String mediaType, int status, String user,
        String password, Class... responseTypes) {
    String uriStr = createBaseUriString(deploymentUrl, relativeUrl);

    ResponseHandler<T> rh = createResponseHandler(mediaType, status, responseTypes);

    // @formatter:off
    Request request = Request.Get(uriStr).addHeader(HttpHeaders.ACCEPT, mediaType.toString())
            .addHeader(HttpHeaders.AUTHORIZATION, basicAuthenticationHeader(user, password));
    // @formatter:on

    Response resp = null;/* w  w  w. j av a  2  s .  com*/
    try {
        logOp("GET", uriStr);
        resp = request.execute();
    } catch (Exception e) {
        logAndFail("[GET] " + uriStr, e);
    }

    try {
        return resp.handleResponse(rh);
    } catch (Exception e) {
        logAndFail("Failed retrieving response from [GET] " + uriStr, e);
    }

    // never happens
    return null;
}

From source file:org.kie.remote.tests.base.RestUtil.java

public static <T, G> T get(URL deploymentUrl, String relativeUrl, String mediaType, int status, String user,
        String password, Class... responseTypes) {
    String uriStr = createBaseUriString(deploymentUrl, relativeUrl);

    ResponseHandler<T> rh = createResponseHandler(mediaType, status, responseTypes);

    // @formatter:off
    Request request = Request.Get(uriStr).addHeader(HttpHeaders.ACCEPT, mediaType.toString())
            .addHeader(HttpHeaders.AUTHORIZATION, basicAuthenticationHeader(user, password));
    // @formatter:off

    Response resp = null;/*from  w w  w .ja va  2s. com*/
    try {
        logOp("GET", uriStr);
        resp = request.execute();
    } catch (Exception e) {
        failAndLog("[GET] " + uriStr, e);
    }

    try {
        return resp.handleResponse(rh);
    } catch (Exception e) {
        failAndLog("Failed retrieving response from [GET] " + uriStr, e);
    }

    // never happens
    return null;
}

From source file:org.kie.smoke.wb.util.RestUtil.java

public static <T> T post(URL deploymentUrl, String relativeUrl, String mediaType, int status, String user,
        String password, Class<T>... responseTypes) {

    String uriStr = createBaseUriString(deploymentUrl, relativeUrl);

    ResponseHandler<T> rh = createResponseHandler(mediaType, status, responseTypes);

    // @formatter:off
    Request request = Request.Post(uriStr).addHeader(HttpHeaders.ACCEPT, mediaType.toString())
            .addHeader(HttpHeaders.AUTHORIZATION, basicAuthenticationHeader(user, password));
    // @formatter:on

    Response resp = null;//w  w w .ja  va2  s  .  co m
    try {
        logOp("POST", uriStr);
        resp = request.execute();
    } catch (Exception e) {
        logAndFail("[GET] " + uriStr, e);
    }

    try {
        return resp.handleResponse(rh);
    } catch (Exception e) {
        logAndFail("Failed retrieving response from [GET] " + uriStr, e);
    }

    // never happens
    return null;
}

From source file:org.kie.remote.tests.base.RestUtil.java

public static <T> T post(URL deploymentUrl, String relativeUrl, String mediaType, int status, String user,
        String password, Class<T>... responseTypes) {

    String uriStr = createBaseUriString(deploymentUrl, relativeUrl);

    ResponseHandler<T> rh = createResponseHandler(mediaType, status, responseTypes);

    // @formatter:off
    Request request = Request.Post(uriStr).addHeader(HttpHeaders.ACCEPT, mediaType.toString())
            .addHeader(HttpHeaders.AUTHORIZATION, basicAuthenticationHeader(user, password));
    // @formatter:on

    Response resp = null;/*w w  w .  j av  a  2 s . co  m*/
    try {
        logOp("POST", uriStr);
        resp = request.execute();
    } catch (Exception e) {
        failAndLog("[GET] " + uriStr, e);
    }

    try {
        return resp.handleResponse(rh);
    } catch (Exception e) {
        failAndLog("Failed retrieving response from [GET] " + uriStr, e);
    }

    // never happens
    return null;
}

From source file:org.kie.smoke.wb.util.RestUtil.java

public static <T, G> T delete(URL deploymentUrl, String relativeUrl, String mediaType, int status, String user,
        String password, Class... responseTypes) {
    String uriStr = createBaseUriString(deploymentUrl, relativeUrl);

    ResponseHandler<T> rh = createResponseHandler(mediaType, status, responseTypes);

    // @formatter:off
    Request request = Request.Delete(uriStr).addHeader(HttpHeaders.ACCEPT, mediaType.toString())
            .addHeader(HttpHeaders.AUTHORIZATION, basicAuthenticationHeader(user, password));
    // @formatter:off

    Response resp = null;/*ww  w  .j  a  va  2s  .c  o  m*/
    try {
        logOp("DELETE", uriStr);
        resp = request.execute();
    } catch (Exception e) {
        logAndFail("[GET] " + uriStr, e);
    }

    try {
        return resp.handleResponse(rh);
    } catch (Exception e) {
        logAndFail("Failed retrieving response from [GET] " + uriStr, e);
    }

    // never happens
    return null;
}

From source file:org.kie.remote.tests.base.RestUtil.java

public static <T, G> T delete(URL deploymentUrl, String relativeUrl, String mediaType, int status, String user,
        String password, Class... responseTypes) {
    String uriStr = createBaseUriString(deploymentUrl, relativeUrl);

    ResponseHandler<T> rh = createResponseHandler(mediaType, status, responseTypes);

    // @formatter:off
    Request request = Request.Delete(uriStr).addHeader(HttpHeaders.ACCEPT, mediaType.toString())
            .addHeader(HttpHeaders.AUTHORIZATION, basicAuthenticationHeader(user, password));
    // @formatter:off

    Response resp = null;/*from   w w w . ja v  a 2s . c om*/
    try {
        logOp("DELETE", uriStr);
        resp = request.execute();
    } catch (Exception e) {
        failAndLog("[GET] " + uriStr, e);
    }

    try {
        return resp.handleResponse(rh);
    } catch (Exception e) {
        failAndLog("Failed retrieving response from [GET] " + uriStr, e);
    }

    // never happens
    return null;
}