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:uk.co.petertribble.jkstat.client.JKhttpClient.java

private String doGet(String request) throws IOException {
    return httpclient.execute(new HttpGet(baseURL + request), new BasicResponseHandler());
}

From source file:edu.emory.library.utils.EULHttpUtils.java

/**
 *  Utility method to POST to a URL and read the result into a string
 *  @param url      url to be read//from  www.  j  av a 2  s.co m
 *  @param headers  HashMap of request headers
 *  @param parameters  HashMap of parameters
 */
public static String postUrlContents(String url, HashMap<String, String> headers,
        HashMap<String, String> parameters) throws Exception {
    String response = null;
    HttpClient client = new DefaultHttpClient();
    HttpPost postMethod = new HttpPost(url);

    // add any request headers specified
    for (Map.Entry<String, String> header : headers.entrySet()) {
        postMethod.addHeader(header.getKey(), header.getValue());
    }

    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    for (Map.Entry<String, String> param : parameters.entrySet()) {
        nvps.add(new BasicNameValuePair(param.getKey(), param.getValue()));
    }
    postMethod.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    // returns the response content as string on success
    response = client.execute(postMethod, responseHandler); // could throw HttpException or IOException
    // TODO: catch/handle errors (esp. periodic 503 when Spotlight is unavailable)
    postMethod.releaseConnection();

    return response;
}

From source file:org.opendatakit.briefcase.reused.http.CommonsHttp.java

private static String readBody(HttpResponse res) {
    return Optional.ofNullable(res.getEntity()).map(e -> uncheckedHandleEntity(new BasicResponseHandler(), e))
            .orElse("");
}

From source file:co.tuzza.clicksend4j.http.HttpClientUtilsTest.java

/**
 * Test of getHttpClient method, of class HttpClientUtils.
 *//*  w ww.j  a v a2 s  .  co  m*/
@Test
public void testGetHttpClient() throws ProtocolException, UnsupportedEncodingException, IOException {
    System.out.println("getHttpClient");
    HttpClientUtils instance = new HttpClientUtils(10000, 10000);
    HttpClient expResult = null;
    HttpClient httpClient = instance.getHttpClient();

    // https://api.clicksend.com/rest/v2/send.json?method=rest&message=This%20is%20the%20message&to=%2B8611111111111%2C%2B61411111111%20
    String loginPassword = "tuzzmaniandevil:5C148EA8-D97B-B5F8-1A3F-1BE0658F4DF5";
    String auth = Base64.encodeBase64String(loginPassword.getBytes());
    HttpUriRequest method;

    List<NameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair("method", "rest"));
    params.add(new BasicNameValuePair("to", "+61411111111"));
    params.add(new BasicNameValuePair("message", "This is a test message"));

    HttpPost httpPost = new HttpPost("https://api.clicksend.com/rest/v2/send.json");
    httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
    httpPost.setHeader("Authorization", "Basic " + auth);

    method = httpPost;

    String url = "https://api.clicksend.com/rest/v2/send.json" + "?" + URLEncodedUtils.format(params, "utf-8");

    HttpResponse httpResponse = httpClient.execute(method);
    int status = httpResponse.getStatusLine().getStatusCode();

    String response = new BasicResponseHandler().handleResponse(httpResponse);
}

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  a2  s . c  o m*/
    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:de.topicmapslab.couchtm.internal.utils.SysDB.java

public SysDB(String url, int port, String dbName, ITopicMapSystem sys) throws TMAPIException {
    this.url = url;
    this.port = port;
    this.dbName = dbName;
    HttpParams params = new BasicHttpParams();
    params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    client = new DefaultHttpClient(params);
    responseHandler = new BasicResponseHandler();
    if (!dbUp())//  w ww.j av a  2s.  c om
        throw new TMAPIException("Database not reachable");
    topicMaps = null;
    if (sys == null)
        updateTopicMapDB();
}

From source file:com.commonsware.android.strict.WeatherDemo.java

private void updateForecast(Location loc) {
    String url = String.format(format, loc.getLatitude(), loc.getLongitude());
    HttpGet getMethod = new HttpGet(url);

    try {//from   w  w  w .  java  2  s  . c  o  m
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = client.execute(getMethod, responseHandler);
        buildForecasts(responseBody);

        String page = generatePage();

        browser.loadDataWithBaseURL(null, page, "text/html", "UTF-8", null);
    } catch (Throwable t) {
        android.util.Log.e("WeatherDemo", "Exception fetching data", t);
        Toast.makeText(this, "Request failed: " + t.toString(), Toast.LENGTH_LONG).show();
    }
}

From source file:org.andstatus.app.net.http.HttpConnectionOAuthApache.java

@Override
public void httpApachePostRequest(HttpPost post, HttpReadResult result) throws ConnectionException {
    try {/*from  w  w  w . ja  va 2 s .c  o  m*/
        // TODO: Redo like for get request
        if (result.authenticate) {
            signRequest(post);
        }
        result.strResponse = HttpConnectionApacheCommon.getHttpClient(data.sslMode).execute(post,
                new BasicResponseHandler());
    } catch (Exception e) {
        // We don't catch other exceptions because in fact it's vary difficult to tell
        // what was a real cause of it. So let's make code clearer.
        result.e1 = e;
    }
}

From source file:acromusashi.stream.example.spout.HttpGetSpout.java

/**
 * ???Bolt???// w ww.j a v  a2  s. c  om
 */
@Override
public void nextTuple() {
    String response = null;

    try {
        response = this.client.execute(this.httpget, new BasicResponseHandler());
    } catch (IOException ex) {
        String logFormat = "Http get failed. Skip target get. : TargetUrl={0}";
        logger.warn(MessageFormat.format(logFormat, this.targetUrl), ex);
        return;
    }

    Header header = new Header();
    header.setMessageId(UUID.randomUUID().toString());
    header.setTimestamp(System.currentTimeMillis());
    header.setType("http");

    Message message = new Message();
    message.setHeader(header);
    message.setBody(response);

    getCollector().emit(new Values(message));

    try {
        TimeUnit.MILLISECONDS.sleep(this.interval);
    } catch (InterruptedException iex) {
        if (logger.isDebugEnabled() == true) {
            logger.debug("Occur interrupt. Ignore interrupt.", iex);
        }
    }
}