Example usage for org.apache.http.impl.client BasicResponseHandler BasicResponseHandler

List of usage examples for org.apache.http.impl.client BasicResponseHandler BasicResponseHandler

Introduction

In this page you can find the example usage for org.apache.http.impl.client BasicResponseHandler BasicResponseHandler.

Prototype

BasicResponseHandler

Source Link

Usage

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.waku.common.http.MyHttpClient.java

private static String getResponse(HttpClient httpclient, HttpRequestBase http) {
    try {/*from   ww  w.  java  2  s .c o  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:org.android.CPForAndroidPlusPlus.HttpClient.java

public static String makeRequest(String path) throws Exception {
    final String TAG = "HttpClient"; //Used in logging etc.
    String str = "";

    try {//w ww. jav a  2 s.  c o m
        DefaultHttpClient httpclient = new DefaultHttpClient();
        //HttpParams params = new BasicHttpParams();
        //params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 1000L);
        //httpclient.setParams(params);
        HttpGet httpost = new HttpGet(path);

        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        str = (String) httpclient.execute(httpost, responseHandler);
    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
    }
    return str;
}

From source file:com.datatorrent.demos.mapreduce.Util.java

public static String getJsonForURL(String url) {
    HttpClient httpclient = new DefaultHttpClient();
    logger.debug(url);//from  w w  w .j  ava 2s . co  m
    try {

        HttpGet httpget = new HttpGet(url);

        // Create a response handler
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody;
        try {
            responseBody = httpclient.execute(httpget, responseHandler);

        } catch (ClientProtocolException e) {
            logger.debug(e.getMessage());
            return null;

        } catch (IOException e) {
            logger.debug(e.getMessage());
            return null;
        } catch (Exception e) {
            logger.debug(e.getMessage());
            return null;
        }
        return responseBody.trim();
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:com.android.isoma.enc.ServerCommunicator.java

public static String executePost(ArrayList<NameValuePair> postParameters) {
    String ServerResponse = null;
    HttpClient httpClient = getHttpClient();

    ResponseHandler<String> response = new BasicResponseHandler();
    HttpPost request = new HttpPost(url);
    try {//w  w w . j av  a 2  s.c  o  m
        request.setHeader("Content-Type", "application/x-www-form-urlencoded");

        request.setEntity(new UrlEncodedFormEntity(postParameters, HTTP.UTF_8));

        ServerResponse = httpClient.execute(request, response);

    } catch (UnsupportedEncodingException e) {

        e.printStackTrace();
    } catch (ClientProtocolException e) {

        e.printStackTrace();
    } catch (IOException e) {

        e.printStackTrace();
    }

    return ServerResponse;
}

From source file:com.codebutler.rsp.Util.java

public static String getURL(URL url, String password) throws Exception {
    Log.i("Util.getURL", url.toString());

    DefaultHttpClient client = new DefaultHttpClient();

    if (password != null && password.length() > 0) {
        UsernamePasswordCredentials creds;
        creds = new UsernamePasswordCredentials("user", password);
        client.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
    }/*from   w  w w.  j a  v  a  2  s . com*/

    HttpGet method = new HttpGet(url.toURI());
    BasicResponseHandler responseHandler = new BasicResponseHandler();
    return client.execute(method, responseHandler);
}

From source file:functional.CookieTest.java

/**
 * Call a handler that will return no cookie
 *
 * @throws Exception/*from   www.  j a va  2 s .  com*/
 */
@Test
public void testNoCookies() throws Exception {
    HttpGet httpget = new HttpGet("http://localhost:8080/noCookie");
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    httpclient.execute(httpget, responseHandler);

    CookieStore cookies = httpclient.getCookieStore();
    assertEquals(0, cookies.getCookies().size());
}

From source file:com.datatorrent.demos.mrmonitor.MRUtil.java

/**
 * This method returns the response content for a given url
 * @param url/*www.  ja v a  2  s .  c o m*/
 * @return
 */
public static String getJsonForURL(String url) {
    HttpClient httpclient = new DefaultHttpClient();
    logger.debug(url);
    try {

        HttpGet httpget = new HttpGet(url);

        // Create a response handler
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody;
        try {
            responseBody = httpclient.execute(httpget, responseHandler);

        } catch (ClientProtocolException e) {
            logger.debug(e.getMessage());
            return null;

        } catch (IOException e) {
            logger.debug(e.getMessage());
            return null;
        } catch (Exception e) {
            logger.debug(e.getMessage());
            return null;
        }
        return responseBody.trim();
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:edu.ucsd.ccdb.cil.xml2json.ElasticsearchClient.java

public void xputElastic(String index, String type, String ID, File f) throws Exception {

    DefaultHttpClient httpClient = new DefaultHttpClient();
    String url = "http://localhost:9200/" + index + "/" + type + "/" + ID;
    System.out.println(url);/*  ww  w .ja  v a  2s  . c o m*/
    HttpPut put = new HttpPut(url); //-X PUT
    put.setEntity(new FileEntity(f, "application/json")); //@ - absolute path
    BasicResponseHandler responseHandler = new BasicResponseHandler();

    String o = httpClient.execute(put, responseHandler);
    /* System.err.println("----------"+o+"----------");
     if(o == null || o.trim().length() == 0)
     {
         System.err.println(o);
         System.exit(1);
     } */

}

From source file:hotandcold.HNCAPI.java

public String register(String user, double lon, double lat, boolean set) {

    String request = servIP + "verb=r&user=" + user;

    if (set)/*from www .  j av  a2 s  .  c  o m*/
        request += "&long=" + lon + "&lat=" + lat;

    HttpClient client = new DefaultHttpClient();

    HttpGet get = new HttpGet(request);

    ResponseHandler<String> responseHandler = new BasicResponseHandler();

    String responseBody;
    try {
        responseBody = client.execute(get, responseHandler);
        return responseBody;
    } catch (IOException ex) {
        Logger.getLogger(HNCAPI.class.getName()).log(Level.SEVERE, null, ex);
    }

    return null;
}