Android Open Source - dbpendler Abstract Client Resource

From Project

Back to project page dbpendler.


The source code is released under:

Copyright 2013 Marcus Schiesser Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Softw...

If you think the Android project dbpendler listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

//w  w  w .ja  va 2s.c o  m

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;

import android.util.Log;

public class AbstractClientResource {

  private DefaultHttpClient client;
  private ResponseHandler<String> responseHandler;

  public AbstractClientResource() {
    client = new DefaultHttpClient();
    responseHandler = new BasicResponseHandler();

  public String doGet(String path, String query) {
    try {
      // TODO: wie geht es parameter zu ?bergeben?
      URI uri;
      uri = URIUtils.createURI("http", "", 8888,
          "rest/" + path, query, null);
      HttpGet get = new HttpGet(uri);
      HttpResponse response = client.execute(get);
      int statusCode = response.getStatusLine().getStatusCode();
      if (statusCode == HttpStatus.SC_OK) {
        return responseHandler.handleResponse(response);
      } else {
        Log.e(ConnectionClientResource.class.toString(), "wrong http status: " + statusCode);
    } catch (URISyntaxException e) {
      Log.e(ConnectionClientResource.class.toString(), "uri syntax error",
    } catch (ClientProtocolException e) {
      Log.e(ConnectionClientResource.class.toString(), "protocol error",
    } catch (IOException e) {
      Log.e(ConnectionClientResource.class.toString(), "i/o error", e);
    return null;


Java Source Code List