Android Open Source - spotastop Linker Request






From Project

Back to project page spotastop.

License

The source code is released under:

MIT License

If you think the Android project spotastop 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 requests;
//ww w .j  a  v  a2s . c  om
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.util.ArrayList;

import com.google.gson.Gson;
import com.nicfix.gsoncompatibility.GsonConfigurator;

import resources.Resource;
import responses.AsyncCallback;
import responses.beContentResponse;
import rest.RestApi;

public class LinkerRequest extends beContentRequest {

  public LinkerRequest(Criteria c, ArrayList<Resource> data,
      ArrayList<Link> rels) {
    super(c, data, rels);
  }

  @Override
  public beContentResponse doSync() {
    String responseString = "";
    String urlString = buildRequest();

    HttpURLConnection urlConnection = null;
    URL url = null;

    try {
      url = new URL(urlString.toString());
      Gson parser = GsonConfigurator.getInstance().build();

      /**
       * Sending data to load resources
       */
      String urlParameters = "data=" + parser.toJson(this.sendingData);

      System.out.println(urlParameters);

      urlConnection = (HttpURLConnection) url.openConnection();
      urlConnection.setRequestMethod("POST");
      urlConnection.setDoOutput(true);
      urlConnection.setDoInput(true);
      urlConnection.setRequestProperty("Content-Type",
          "application/x-www-form-urlencoded");
      urlConnection.setRequestProperty("charset", "utf-8");
      urlConnection.setRequestProperty("Content-Length",
          "" + Integer.toString(urlParameters.getBytes().length));
      urlConnection.setUseCaches(false);

      urlConnection.connect();

      DataOutputStream wr = new DataOutputStream(
          urlConnection.getOutputStream());
      wr.writeBytes(urlParameters);
      wr.flush();
      wr.close();

      InputStream inStream = urlConnection.getInputStream();

      // ///PERFORMANCE CRITICAL
      BufferedInputStream bis = new BufferedInputStream(inStream);
      ByteArrayOutputStream buf = new ByteArrayOutputStream();
      int result = bis.read();
      while (result != -1) {
        byte b = (byte) result;
        buf.write(b);
        result = bis.read();
      }
      responseString = buf.toString();
      // ///PERFORMANCE CRITICAL

      inStream.close();
      urlConnection.disconnect();

      System.out.println("RESPONSE   " + responseString);
      this.responseHandler = parser.fromJson(responseString,
          beContentResponse.class);

    } catch (MalformedURLException e) {
    } catch (ProtocolException e) {
    } catch (IOException e) {
    }
    return this.responseHandler;
  }

  @Override
  public void doAsync(AsyncCallback callback) {
    String responseString = "";
    String urlString = buildRequest();

    HttpURLConnection urlConnection = null;
    URL url = null;

    try {
      url = new URL(urlString.toString());
      Gson parser = GsonConfigurator.getInstance().build();

      /**
       * Sending data to load resources
       */
      String urlParameters = "data=" + parser.toJson(this.sendingData);

      System.out.println(urlParameters);

      urlConnection = (HttpURLConnection) url.openConnection();
      urlConnection.setRequestMethod("POST");
      urlConnection.setDoOutput(true);
      urlConnection.setDoInput(true);
      urlConnection.setRequestProperty("Content-Type",
          "application/x-www-form-urlencoded");
      urlConnection.setRequestProperty("charset", "utf-8");
      urlConnection.setRequestProperty("Content-Length",
          "" + Integer.toString(urlParameters.getBytes().length));
      urlConnection.setUseCaches(false);

      urlConnection.connect();

      DataOutputStream wr = new DataOutputStream(
          urlConnection.getOutputStream());
      wr.writeBytes(urlParameters);
      wr.flush();
      wr.close();

      InputStream inStream = urlConnection.getInputStream();

      // ///PERFORMANCE CRITICAL
      BufferedInputStream bis = new BufferedInputStream(inStream);
      ByteArrayOutputStream buf = new ByteArrayOutputStream();
      int result = bis.read();
      while (result != -1) {
        byte b = (byte) result;
        buf.write(b);
        result = bis.read();
      }
      responseString = buf.toString();
      // ///PERFORMANCE CRITICAL

      inStream.close();
      urlConnection.disconnect();

      this.responseHandler = parser.fromJson(responseString,
          beContentResponse.class);

    } catch (MalformedURLException e) {
    } catch (ProtocolException e) {
    } catch (IOException e) {
    }

    callback.callback(responseHandler);

  }

  @Override
  public String buildRequest() {

    String url = RestApi.getServerUrl() + "/linker.php?";

    return url;

  }

}




Java Source Code List

.LoaderTester.java
com.cipciop.spotastop.ErrorActivity.java
com.cipciop.spotastop.LoginActivity.java
com.cipciop.spotastop.RegisterActivity.java
com.cipciop.spotastop.SelectBusLine.java
com.cipciop.spotastop.SpotActivity.java
com.cipciop.spotastop.StopSpotApp.java
com.cipciop.spotastop.domain.BusStop.java
com.cipciop.spotastop.domain.GeoPos.java
com.cipciop.spotastop.domain.Line.java
com.cipciop.spotastop.domain.User.java
com.cipciop.spotastop.presentation.BusLineItem.java
com.cipciop.spotastop.services.JarvisDynDnsService.java
com.cipciop.spotastop.services.LoginService.java
com.cipciop.spotastop.services.RegistrationService.java
com.cipciop.spotastop.services.RetrieveLinesListService.java
com.cipciop.spotastop.services.SpotBusStopService.java
com.nicfix.gsoncompatibility.GsonConfigurator.java
requests.CreatorRequest.java
requests.Criteria.java
requests.Data.java
requests.EditorRequest.java
requests.Link.java
requests.LinkerRequest.java
requests.LoaderRequest.java
requests.StorerRequest.java
requests.Unlink.java
requests.beContentRequest.java
resources.Resource.java
resources.ResourcesCache.java
resources.ResourcesMapper.java
responses.AsyncCallback.java
responses.beContentResponse.java
rest.RestApi.java
settings.Settings.java