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:net.volcore.wtvmaster.user.RemoteUserDatabase.java

public int isValidUploadAccount(String username, String password) {
    try {/*from w  w  w . j a v a  2s.com*/
        HttpClient httpclient = new DefaultHttpClient();
        logger.info("Checking user credentials for " + username + "...");
        //logger.info( "TMP with pass "+password+"...");

        HttpGet httpget = new HttpGet(url + "?u=" + username + "&p=" + password);
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = httpclient.execute(httpget, responseHandler);
        //logger.info( "response "+responseBody+"...");

        Gson gson = new Gson();
        RemoteUserBean userbean = gson.fromJson(responseBody, RemoteUserBean.class);

        if (userbean.getValid() == false) {
            logger.info("Invalid login!");
            return INVALID_USERID;
        }

        if (userbean.getCanupload() == false) {
            logger.info("Not a recorder login!");
            return INVALID_USERID;
        }

        logger.trace("Authed user " + username + " (" + userbean.getUserid() + ")");

        return userbean.getUserid();
    } catch (Exception e) {
        logger.error("Exception in isValidUploadAccount: " + e);
        e.printStackTrace();
    }

    return INVALID_USERID;
}

From source file:eu.over9000.skadi.remote.VersionRetriever.java

public static RemoteVersionResult getLatestVersion() {
    try {/*from www .j  a  va 2s.  c o  m*/
        final URI URL = new URI(API_URL);
        final HttpResponse response = httpClient.execute(new HttpGet(URL));

        final String responseString = new BasicResponseHandler().handleResponse(response);

        final JsonArray tagsArray = parser.parse(responseString).getAsJsonArray();
        final JsonObject latest = tagsArray.get(0).getAsJsonObject();
        final JsonObject latestFiles = latest.getAsJsonArray("assets").get(0).getAsJsonObject();

        final String downloadURL = latestFiles.get("browser_download_url").getAsString();
        final int downloadSize = latestFiles.get("size").getAsInt();
        final String version = latest.get("tag_name").getAsString();
        final String published = latest.get("published_at").getAsString();
        final String changeLog = latest.get("body").getAsString();

        return new RemoteVersionResult(version, published, downloadURL, changeLog, downloadSize);

    } catch (Exception e) {
        LOGGER.error("VersionRetriever exception", e);
        return null;
    }
}

From source file:com.devdungeon.simplejson.DecodeJson.java

public static String getJsonFromUrl(String url) {
    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(url);
    httpget.setHeader("User-Agent", "Java Reddit Test Client 0.0.1");
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String responseBody = null;/*from  w  ww  .j  ava 2s .c o m*/
    try {
        responseBody = httpclient.execute(httpget, responseHandler);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    httpclient.getConnectionManager().shutdown();
    return responseBody;
}

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

public static String get(PlatformID platformID, String target) throws CiliaException {

    String url = getURL(platformID, target);
    HttpUriRequest httpRequest = new HttpGet(url);
    HttpClient httpClient = getClient();
    ResponseHandler<String> responseHandler = new BasicResponseHandler();

    try {/*from  w w  w . j  av a  2 s.com*/
        String retval = httpClient.execute(httpRequest, responseHandler);
        httpClient.getConnectionManager().shutdown();
        return retval;
    } catch (ConnectTimeoutException e) {
        httpClient.getConnectionManager().shutdown();
        throw new CiliaException("Can't joint " + url + " before timeout (" + timeout + "ms)");
    } catch (ClientProtocolException e) {
        httpClient.getConnectionManager().shutdown();
        throw new CiliaException("Can't joint " + url, e);
    } catch (IOException e) {
        httpClient.getConnectionManager().shutdown();
        throw new CiliaException("Can't joint " + url, e);
    }
}

From source file:net.sf.appstatus.demo.check.AbstractHttpCheck.java

protected String doHttpGet(String url) throws ClientProtocolException, IOException {

    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(url);
    ResponseHandler<String> responseHandler = new BasicResponseHandler();

    try {/*from   www. java 2s. co  m*/
        String responseBody = httpclient.execute(httpget, responseHandler);
        return responseBody;
    } finally {
        httpclient.getConnectionManager().shutdown();
    }

}

From source file:functional.CookieTest.java

/**
 * Now call one that should return a Cookie
 *
 * @throws Exception/*  w  w  w  .  j a  va  2s .c o m*/
 */
@Test
public void testReceiveCookie() throws Exception {
    HttpGet httpget = new HttpGet("http://localhost:8080/sendCookie");
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    httpclient.execute(httpget, responseHandler);
    CookieStore cookies = httpclient.getCookieStore();
    assertEquals(1, cookies.getCookies().size());
    assertEquals("test", cookies.getCookies().get(0).getName());
    assertEquals("test", cookies.getCookies().get(0).getValue());
}

From source file:edu.mit.media.funf.IOUtils.java

public static String httpGet(String uri, HttpParams params) {
    String responseBody = null;/*  w  ww . j  a v  a2  s .co  m*/
    HttpClient httpclient = new DefaultHttpClient();
    StringBuilder uriBuilder = new StringBuilder(uri);
    HttpGet httpget = new HttpGet(uriBuilder.toString());
    if (params != null) {
        httpget.setParams(params);
    }
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    try {
        responseBody = httpclient.execute(httpget, responseHandler);
    } catch (ClientProtocolException e) {
        Log.e(TAG, "HttpGet Error: ", e);
        responseBody = null;
    } catch (IOException e) {
        Log.e(TAG, "HttpGet Error: ", e);
        responseBody = null;
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
    return responseBody;
}

From source file:com.bricolsoftconsulting.geocoderplus.util.http.HttpRetriever.java

public String retrieve(String url) throws ClientProtocolException, IOException {
    // Declare//from   w w  w  .j a v  a 2 s  . com
    String response = null;

    // Connect to server and get JSON response
    HttpGet request = new HttpGet(url);
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    response = httpclient.execute(request, responseHandler);

    // Return
    return response;
}

From source file:com.sanjaydalvi.spacestationlocator.LoadISSLocation.java

@Override
protected String doInBackground(HttpUriRequest... params) {
    try {//from w  w  w.  j av a2 s .  c o m
        HttpUriRequest request = params[0];
        HttpResponse serverResponse = mClient.execute(request);
        BasicResponseHandler handler = new BasicResponseHandler();
        return handler.handleResponse(serverResponse);
    } catch (Exception e) {
        // TODO handle this properly
        e.printStackTrace();
        return "";
    }
}

From source file:org.fastcatsearch.util.HTMLTagRemoverTest.java

public void test1() {
    HttpClient httpclient = new DefaultHttpClient();
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    HttpPost httpost = new HttpPost("http://www.fastcatsearch.org/");
    HttpGet httpGet = new HttpGet("http://www.fastcatsearch.org/");
    List<NameValuePair> nvps = new ArrayList<NameValuePair>();

    try {/*from w  w w.  ja  va 2 s  .co m*/
        httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

        String responseBody = httpclient.execute(httpGet, responseHandler);

        System.out.println(HTMLTagRemover.clean(responseBody));

    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}