Exemple #1
0
  private void showRoute(String json) {
    route = Utility.convertRouteFromJson(json);

    if (route.getAuthor().equals(prefs.getLogin())) {
      isAuthor = true;
    }
    fillMap();
    centerOnRoute();
  }
Exemple #2
0
  // HTTP Get Method
  @GET
  @Path("/requestRoutesList")
  // Produces JSON as response
  @Produces(MediaType.APPLICATION_JSON)
  public String requestRoutesList(
      @QueryParam("login") String login, @QueryParam("sessionId") String sessionId) {

    if (sg.checkSession(login, sessionId)) {
      if (extractRoutesList()) {

        // return routeResponse;
        System.out.println("Route List response " + routeResponse);
        return Utility.constructDataJSON("request", true, routeResponse);
      } else {
        return (Utility.constructJSON("request", false, "Database exception(Request route list)"));
      }
    } else System.out.println("Credentials problem");
    return Utility.constructJSON("request", false, "Credentials problem");
  }
Exemple #3
0
 // HTTP Get Method
 @GET
 @Path("/requestRoute")
 // Produces JSON as response
 @Produces(MediaType.APPLICATION_JSON)
 public String requestRoute(
     @QueryParam("login") String login,
     @QueryParam("sessionId") String sessionId,
     @QueryParam("id") String routeId) {
   System.out.println("Inside requestRoute");
   System.out.println("Params: " + login + " " + sessionId + " " + routeId);
   if (sg.checkSession(login, sessionId)) {
     if (extractRoute(Long.parseLong(routeId))) {
       System.out.println("Route response " + routeResponse);
       // return routeResponse;
       return Utility.constructDataJSON("request", true, routeResponse);
     } else {
       return (Utility.constructJSON("request", false, "Database exception(Request route)"));
     }
   } else System.out.println("Credentials problem");
   return Utility.constructJSON("request", false, "Credentials problem");
 }
Exemple #4
0
  private void restInvokeUpdate() {
    // Make RESTful webservice call using AsyncHttpClient object
    AsyncHttpClient client = new AsyncHttpClient();

    StringEntity entity = null;
    try {
      entity = new StringEntity(Utility.convertToJson(route), "UTF-8");
    } catch (UnsupportedEncodingException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
    client.addHeader(Consts.PARAM_LOGIN, prefs.getLogin());
    client.addHeader(Consts.PARAM_SESSIONID, prefs.getSessionID());

    client.put(
        getApplicationContext(),
        domainAdress + UPDATE_ROUTE,
        null,
        entity,
        Consts.JSON,
        new AsyncHttpResponseHandler() {
          // When the response returned by REST has Http response code
          // '200'
          @Override
          public void onSuccess(int StatusCode, String answer) {

            // Hide Progress Dialog
            // prgDialog.hide();
            try {
              // JSON Object
              JSONObject jO = new JSONObject(answer);
              // When the JSON response has status boolean value
              // assigned with true
              if (jO.getBoolean(Consts.MSG_STATUS)) {
                Toast.makeText(
                        getApplicationContext(),
                        jO.getString(Consts.MSG_INFO) + StatusCode,
                        Toast.LENGTH_LONG)
                    .show();
              } else {
                Toast.makeText(
                        getApplicationContext(),
                        jO.getString(Consts.MSG_INFO) + StatusCode,
                        Toast.LENGTH_LONG)
                    .show();
              }
            } catch (JSONException e) {
              Toast.makeText(getApplicationContext(), R.string.invalidJSON, Toast.LENGTH_LONG)
                  .show();
              e.printStackTrace();
            }
          }

          // When the response returned by REST has Http response code
          // other than '200'
          @Override
          public void onFailure(int statusCode, Throwable error, String content) {

            // Hide Progress Dialog
            // prgDialog.hide();
            // When Http response code is '404'
            if (statusCode == 404) {
              Toast.makeText(getApplicationContext(), R.string.err404, Toast.LENGTH_LONG).show();
            }
            // When Http response code is '500'
            else if (statusCode == 500) {
              Toast.makeText(getApplicationContext(), R.string.err500, Toast.LENGTH_LONG).show();
            }
            // When Http response code other than 404, 500
            else {
              Toast.makeText(getApplicationContext(), R.string.otherErr, Toast.LENGTH_LONG).show();
            }
          }
        });
  }