Example usage for org.apache.http.client HttpClient execute

List of usage examples for org.apache.http.client HttpClient execute

Introduction

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

Prototype

<T> T execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler)
        throws IOException, ClientProtocolException;

Source Link

Document

Executes HTTP request using the default context and processes the response using the given response handler.

Usage

From source file:com.github.rnewson.couchdb.lucene.couchdb.HttpUtils.java

public static final int delete(final HttpClient httpClient, final String url) throws IOException {
    return httpClient.execute(new HttpDelete(url), new StatusCodeResponseHandler());
}

From source file:no.kantega.kwashc.server.test.HttpClientUtil.java

static String getPageText(String address) throws IOException {
    HttpClient httpclient = getHttpClient();
    HttpGet request = new HttpGet(address);
    return httpclient.execute(request, new BasicResponseHandler());
}

From source file:com.github.rnewson.couchdb.lucene.couchdb.HttpUtils.java

public static final String execute(final HttpClient httpClient, final HttpUriRequest request)
        throws IOException {
    return httpClient.execute(request, new ErrorPreservingResponseHandler());
}

From source file:fr.liglab.adele.cilia.workbench.restmonitoring.utils.http.HttpHelper.java

public static void put(PlatformID platformID, String target, String data) throws CiliaException {
    String url = getURL(platformID, target);
    HttpPut httpRequest = new HttpPut(url);

    // entity// w  w w.  j av a  2 s . com
    StringEntity entity = new StringEntity(data, ContentType.create("text/plain", "UTF-8"));
    httpRequest.setEntity(entity);

    // HTTP request
    HttpClient httpClient = getClient();
    try {
        httpClient.execute(httpRequest, new BasicResponseHandler());
        httpClient.getConnectionManager().shutdown();
    } catch (Exception e) {
        httpClient.getConnectionManager().shutdown();
        throw new CiliaException("can't perform HTTP PUT request", e);
    }
}

From source file:fr.liglab.adele.cilia.workbench.restmonitoring.utils.http.HttpHelper.java

public static void post(PlatformID platformID, String path, String paramName, InputStream data)
        throws CiliaException {

    String url = getURL(platformID, path);

    HttpPost httppost = new HttpPost(url);

    MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

    InputStreamBody bin = new InputStreamBody(data, paramName);
    reqEntity.addPart(paramName, bin);/*from  w w w.j av a  2  s .  c  o  m*/

    httppost.setEntity(reqEntity);

    // HTTP request
    HttpClient httpClient = getClient();
    try {
        httpClient.execute(httppost, new BasicResponseHandler());
        httpClient.getConnectionManager().shutdown();
    } catch (Exception e) {
        httpClient.getConnectionManager().shutdown();
        throw new CiliaException("can't perform HTTP PUT request", e);
    }
}

From source file:com.waku.common.http.MyHttpClient.java

private static String getResponse(HttpClient httpclient, HttpRequestBase http) {
    try {/*from   w  w  w  . j  a v a2 s.co m*/
        logger.info("Executing ---> " + http.getRequestLine());
        return httpclient.execute(http, new BasicResponseHandler());
    } catch (Throwable e) {
        logger.info("Exception got ->", e);
        if (e.getMessage().equalsIgnoreCase("Internal Server Error")) {
            logger.info("Internal Server Error, seems not recovery-able!");
            return null;
        }
        logger.info("======== Retry will start after 10 sec ----->");
        try {
            Thread.sleep(10000);
        } catch (InterruptedException ie) {
            ie.printStackTrace();
        }
        return getResponse(httpclient, http);
    }
}

From source file:com.music.tools.SongDBDownloader.java

private static String getResponseAsString(String urlString, HttpClient client, HttpContext ctx)
        throws IOException {
    HttpUriRequest req = new HttpGet(urlString);
    InputStream is = client.execute(req, ctx).getEntity().getContent();
    String result = CharStreams.toString(new InputStreamReader(is));
    is.close();//from w w  w  .j  av a 2  s .  c o m
    req.abort();
    return result;
}

From source file:kontrol.HttpUtil.java

public static String getUrlAsString(URI url, int timeout, Locale locale) throws IOException {

    HttpGet httpget = createHttpGet(url, locale);
    HttpContext context = new BasicHttpContext();
    HttpClient httpClient = getCookielessHttpClient(timeout);
    HttpResponse httpResponse = httpClient.execute(httpget, context);

    return IOUtils.toString(httpResponse.getEntity().getContent());

}

From source file:kontrol.HttpUtil.java

public static InputStream getUrlAsStream(URI url, int timeout, Locale locale) throws IOException {
    log.debug("Trying to get URL " + url);
    HttpGet httpget = createHttpGet(url, locale);
    HttpContext context = new BasicHttpContext();
    HttpClient httpClient = getCookielessHttpClient(timeout);
    HttpResponse httpResponse = httpClient.execute(httpget, context);
    if (httpResponse.getStatusLine().getStatusCode() < 300) {
        log.debug("Got it, size was {} status was {}", httpResponse.getEntity().getContentLength(),
                httpResponse.getStatusLine().getStatusCode());
        return httpResponse.getEntity().getContent();
    } else {/*w  ww. ja  va2  s . c o  m*/
        throw new IOException("HTTP Error " + httpResponse.getStatusLine().getStatusCode() + " with reason '"
                + httpResponse.getStatusLine().getReasonPhrase() + "'");
    }

}

From source file:Main.java

protected static synchronized InputStream getAWebPage(URL url) throws ClientProtocolException, IOException {
    HttpClient httpClient = new DefaultHttpClient();
    HttpContext localContext = new BasicHttpContext();
    HttpGet httpGet = new HttpGet(url.toString());
    try {//from   w w  w . jav  a 2s .  c  om
        //do the request
        HttpResponse response = httpClient.execute(httpGet, localContext);
        StatusLine status = response.getStatusLine();
        if (status.getStatusCode() != HTTP_STATUS_OK) {
            throw new IOException("Invalid response from the IKSU server! " + status.toString());
        }
        //InputStream ist = response.getEntity().getContent();

        return response.getEntity().getContent();
    } catch (Exception e) {
        e.printStackTrace();
        throw new ClientProtocolException("Protocol Exception! " + e.toString());
    }
}