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:com.universalmind.core.components.mockup.loremipsum.BaseballIpsumService.java

@Test
public void testService() {
    Integer paragraphs = 2;/*from  w w w. j a v a2s.  c o  m*/

    String loremText = null;
    String url = null;
    url = "http://baseballipsum.apphb.com/api/?startwithlorem=true&paras=" + paragraphs;

    HttpClient httpclient = new DefaultHttpClient();
    try {
        HttpGet httpget = new HttpGet(url);

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

        loremText = parseBaseballIpsum(responseBody);

        Assert.assertNotNull(loremText);
        Assert.assertTrue(loremText.length() > 100);
    } catch (Exception jse) {
        //do nothing
        jse.printStackTrace();
    } finally {
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:net.yama.android.managers.connection.ApiKeyConnectionManager.java

public String makeRequest(AbstractRequest request) throws ApplicationException {

    String apiKey = ConfigurationManager.instance.getApiKey();
    request.addParameter(Constants.PARAM_KEY, apiKey);
    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(request.getURL());

    // Create a response handler
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String responseBody = null;// w  w  w  .j a va2 s.c  o  m

    try {

        responseBody = httpclient.execute(httpget, responseHandler);
        httpclient.getConnectionManager().shutdown();

    } catch (Exception e) {
        throw new ApplicationException(e);
    }

    return responseBody;
}

From source file:org.labkey.freezerpro.export.ExportSampleUserFieldsCommand.java

public FreezerProCommandResonse execute(HttpClient client, PipelineJob job) {
    HttpPost post = new HttpPost(_url);

    try {// ww w  .j a  v a2 s.  c  o  m
        List<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("method", "sample_userfields"));
        params.add(new BasicNameValuePair("username", _username));
        params.add(new BasicNameValuePair("password", _password));
        params.add(new BasicNameValuePair("id", _sampleId));

        post.setEntity(new UrlEncodedFormEntity(params));

        ResponseHandler<String> handler = new BasicResponseHandler();

        HttpResponse response = client.execute(post);
        StatusLine status = response.getStatusLine();

        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
            return new ExportUserFieldsResponse(_export, handler.handleResponse(response),
                    status.getStatusCode(), job);
        else
            return new ExportUserFieldsResponse(_export, status.getReasonPhrase(), status.getStatusCode(), job);
    } catch (Exception e) {
        _export.getJob().error(
                "An error was encountered trying to get user defined fields for sample : " + _sampleId, e);
        return null;
    }
}

From source file:com.uc.dca.util.HttpHandler.java

public String post(String uri, List<NameValuePair> nvps) throws IOException {
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(uri);
    httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
    Log.d(TAG, "executing post " + httpPost.getURI());
    // Create a response handler
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String responseBody = httpClient.execute(httpPost, responseHandler);
    //        Log.d(TAG, responseBody);
    return responseBody;

}

From source file:dk.i2m.drupal.resource.UserResource.java

public void login() throws HttpResponseException, IOException {
    URLBuilder builder = new URLBuilder(getDc().getHostname());
    builder.add(getDc().getEndpoint());//  w  w w  .  ja v  a2  s  . c o  m
    builder.add(getAlias());
    builder.add("login");

    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    nvps.add(new BasicNameValuePair("username", username));
    nvps.add(new BasicNameValuePair("password", password));

    HttpPost method = new HttpPost(builder.toURI());
    method.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));

    ResponseHandler<String> handler = new BasicResponseHandler();
    getDc().getHttpClient().execute(method, handler);
}

From source file:amazonechoapi.AmazonEchoApi.java

public String httpGet(String url) {
    String output = "";
    try {// w  w w  .  ja va  2 s  . c om

        HttpGet httpGet = new HttpGet(BASE_URL + url);
        httpGet.setHeader(HttpHeaders.USER_AGENT,
                "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13");
        HttpResponse httpResponse = httpclient.execute(httpGet);
        StatusLine responseStatus = httpResponse.getStatusLine();
        int statusCode = responseStatus.getStatusCode();
        if (statusCode == 200) {
            httpResponse.getEntity();
            output = new BasicResponseHandler().handleResponse(httpResponse);
        }
    } catch (Exception e) {
        System.err.println("httpGet Error: " + e.getMessage());
    }

    return output;

}

From source file:org.statmantis.mport.retro.RetrosheetFlatCsvEnumReader.java

@Override
public Map<String, T> read() throws IOException {
    HttpClient client = new DefaultHttpClient();
    return read(new ByteArrayInputStream(
            client.execute(new HttpGet(getUrl()), new BasicResponseHandler()).getBytes()));
}

From source file:org.labkey.freezerpro.export.GetFreezerSamplesCommand.java

public FreezerProCommandResonse execute(HttpClient client, PipelineJob job) {
    HttpPost post = new HttpPost(_url);

    try {// ww  w .j  a  v  a 2s . c  om
        List<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("method", "freezer_samples"));
        params.add(new BasicNameValuePair("username", _username));
        params.add(new BasicNameValuePair("password", _password));
        params.add(new BasicNameValuePair("id", _typeId));
        params.add(new BasicNameValuePair("limit", "10000"));

        post.setEntity(new UrlEncodedFormEntity(params));

        ResponseHandler<String> handler = new BasicResponseHandler();

        HttpResponse response = client.execute(post);
        StatusLine status = response.getStatusLine();

        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
            return new GetFreezerSamplesResponse(_export, handler.handleResponse(response),
                    status.getStatusCode(), job);
        else
            return new GetFreezerSamplesResponse(_export, status.getReasonPhrase(), status.getStatusCode(),
                    job);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.labkey.freezerpro.export.ExportLocationCommand.java

public FreezerProCommandResonse execute(HttpClient client, PipelineJob job) {
    HttpPost post = new HttpPost(_url);

    try {//from w w  w  . j  a  v a2 s  .co  m
        List<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("method", "vials_sample"));
        params.add(new BasicNameValuePair("username", _username));
        params.add(new BasicNameValuePair("password", _password));
        params.add(new BasicNameValuePair("start", String.valueOf(_start)));
        params.add(new BasicNameValuePair("limit", String.valueOf(_limit)));

        post.setEntity(new UrlEncodedFormEntity(params));

        ResponseHandler<String> handler = new BasicResponseHandler();

        HttpResponse response = client.execute(post);
        StatusLine status = response.getStatusLine();

        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
            return new ExportLocationResponse(_export, handler.handleResponse(response), status.getStatusCode(),
                    job);
        else
            return new ExportLocationResponse(_export, status.getReasonPhrase(), status.getStatusCode(), job);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:de.jlo.talendcomp.tac.TACConnection.java

public String execute(String uri) throws Exception {
    HttpGet get = new HttpGet(uri);
    ResponseHandler<String> handler = new BasicResponseHandler();
    return client.execute(get, handler);
}