Android Open Source - dbpendler Abstract Client Resource






From Project

Back to project page dbpendler.

License

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

package de.marcusschiesser.dbpendler.client.services.resources;
//w  w  w .ja  va 2s.c o  m
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

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() {
    super();
    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", "10.0.2.2", 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",
          e);
    } catch (ClientProtocolException e) {
      Log.e(ConnectionClientResource.class.toString(), "protocol error",
          e);
    } catch (IOException e) {
      Log.e(ConnectionClientResource.class.toString(), "i/o error", e);
    }
    return null;
  }

}




Java Source Code List

de.marcusschiesser.dbpendler.client.Confirmation.java
de.marcusschiesser.dbpendler.client.DBPendler.java
de.marcusschiesser.dbpendler.client.EditConnection.java
de.marcusschiesser.dbpendler.client.Preferences.java
de.marcusschiesser.dbpendler.client.adapters.ConnectionOverviewAdapter.java
de.marcusschiesser.dbpendler.client.adapters.EditConnectionAdapter.java
de.marcusschiesser.dbpendler.client.adapters.StationAdapter.java
de.marcusschiesser.dbpendler.client.model.ConnectionsDb.java
de.marcusschiesser.dbpendler.client.services.ConnectionService.java
de.marcusschiesser.dbpendler.client.services.resources.AbstractClientResource.java
de.marcusschiesser.dbpendler.client.services.resources.ConnectionClientResource.java
de.marcusschiesser.dbpendler.client.services.resources.mocks.ConnectionMockResource.java
de.marcusschiesser.dbpendler.client.services.resources.mocks.StationMockResource.java
de.marcusschiesser.dbpendler.common.resources.BookingResource.java
de.marcusschiesser.dbpendler.common.resources.ConnectionResource.java
de.marcusschiesser.dbpendler.common.resources.StationResource.java
de.marcusschiesser.dbpendler.common.vo.CommitVO.java
de.marcusschiesser.dbpendler.common.vo.ConnectionVO.java
de.marcusschiesser.dbpendler.common.vo.StationVO.java