Exemple #1
0
 private void printObj(JSONObject jObj, PrintWriter writer) {
   try {
     // System.out.println(jObj.toString(3));
     writer.print(jObj.toString(3));
   } catch (JSONException e) {
     System.out.println("could to to string json object");
   }
 }
  public Resolution getUniqueValues() throws JSONException {
    JSONObject json = new JSONObject();
    json.put("success", Boolean.FALSE);

    try {
      Layer layer = applicationLayer.getService().getSingleLayer(applicationLayer.getLayerName());
      if (layer != null && layer.getFeatureType() != null) {
        SimpleFeatureType sft = layer.getFeatureType();
        List<String> beh = sft.calculateUniqueValues(attribute);
        json.put("uniqueValues", new JSONArray(beh));
        json.put("success", Boolean.TRUE);
      }
    } catch (Exception e) {
      json.put("msg", e.toString());
    }
    return new StreamingResolution("application/json", new StringReader(json.toString()));
  }
 @POST
 @Path("/view/{id}")
 @Consumes(MediaType.APPLICATION_JSON)
 @Produces(MediaType.APPLICATION_JSON)
 public String viewNote(String inputData, @PathParam("id") int id) {
   JSONObject inputJSON = new JSONObject(inputData);
   if ((inputJSON.has("sessionID"))
       && UsersController.checkLogin(inputJSON.getString("sessionID"))) {
     hibernate.controllers.NotesController notesController =
         new hibernate.controllers.NotesController();
     Note note = notesController.readNote(id);
     if (note != null) {
       JSONObject jsonNote = getJSONNote(note);
       return jsonNote.toString();
     } else {
       return "No subject of ID == " + id + "!";
     }
   } else return "Invalid session!";
 }
  public void doRequest(int type) {
    switch (type) {
      case REQUEST_SESSION:
        {
          String time = new Long(new Date().getTime()).toString();
          String timestamp = time.substring(0, time.length() - 3);
          String postParam =
              "application_id="
                  + PUSH_APP_ID
                  + "&auth_key="
                  + PUSH_AUTH_KEY
                  + "&nonce="
                  + nonce
                  + "&timestamp="
                  + timestamp;
          String signature = "";
          try {
            signature = QBUtils.hmacsha1(PUSH_AUTH_SECRET, postParam);
          } catch (Exception ex) {
            DebugStorage.getInstance().Log(0, "<PushAuthScreen> doRequest REQUEST_SESSION ", ex);
            break;
          }

          JSONObject postObject = new JSONObject();
          try {
            postObject.put("application_id", PUSH_APP_ID);
            postObject.put("auth_key", PUSH_AUTH_KEY);
            postObject.put("nonce", nonce);
            postObject.put("timestamp", timestamp);
            postObject.put("signature", signature);
          } catch (Exception ex) {
            DebugStorage.getInstance().Log(0, "<PushAuthScreen> doRequest REQUEST_SESSION ", ex);
          }
          BigVector postData = new BigVector();
          postData.addElement(postObject.toString());

          QBHTTPConnManager man =
              new QBHTTPConnManager(POST, PUSH_SERVER_API + "session.json", postData, type, this);
          break;
        }
      case REQUEST_SIGN_UP_USER:
        {
          String pin = Integer.toHexString(DeviceInfo.getDeviceId()).toUpperCase();

          JSONObject credentialsObject = new JSONObject();
          JSONObject postObject = new JSONObject();
          try {
            credentialsObject.put("login", pin);
            credentialsObject.put("password", TextUtils.reverse(pin));
            postObject.put("user", credentialsObject);
          } catch (Exception ex) {
          }
          BigVector postData = new BigVector();
          postData.addElement(TOKEN);
          postData.addElement(postObject.toString());

          DebugStorage.getInstance().Log(0, "Post data: " + postObject.toString());

          QBHTTPConnManager man =
              new QBHTTPConnManager(POST, PUSH_SERVER_API + "users.json", postData, type, this);
          break;
        }
      case REQUEST_SESSION_WITH_USER_AND_DEVICE_PARAMS:
        {
          JSONObject postObject = new JSONObject();
          JSONObject userObject = new JSONObject();
          JSONObject deviceObject = new JSONObject();
          try {
            String pin = Integer.toHexString(DeviceInfo.getDeviceId()).toUpperCase();
            String postParam =
                "application_id="
                    + PUSH_APP_ID
                    + "&auth_key="
                    + PUSH_AUTH_KEY
                    + "&device[platform]="
                    + "blackberry"
                    + "&device[udid]="
                    + pin
                    + "&nonce="
                    + nonce
                    + "&timestamp="
                    + timestamp
                    + "&user[login]="
                    + pin
                    + "&user[password]="
                    + TextUtils.reverse(pin);

            String signature = "";
            try {
              signature = QBUtils.hmacsha1(PUSH_AUTH_SECRET, postParam);
            } catch (Exception ex) {
              System.out.println("QBUtils.hmacsha1(PUSH_AUTH_SECRET, postParam) exception = " + ex);
            }

            postObject.put("application_id", PUSH_APP_ID);
            postObject.put("auth_key", PUSH_AUTH_KEY);
            postObject.put("timestamp", timestamp);
            postObject.put("nonce", nonce);
            postObject.put("signature", signature);

            userObject.put("login", pin);
            userObject.put("password", TextUtils.reverse(pin));
            postObject.put("user", userObject);

            deviceObject.put("platform", "blackberry");
            deviceObject.put("udid", pin);
            postObject.put("device", deviceObject);

          } catch (Exception ex) {
            DebugStorage.getInstance().Log(0, "<PushAuthScreen> doRequest REQUEST_SESSION ", ex);
            onClose();
          }
          BigVector postData = new BigVector();
          postData.addElement(postObject.toString());

          QBHTTPConnManager man =
              new QBHTTPConnManager(POST, PUSH_SERVER_API + "session.json", postData, type, this);
          break;
        }

      case REQUEST_PUSH_TOKEN:
        {
          String pin = Integer.toHexString(DeviceInfo.getDeviceId()).toUpperCase();
          JSONObject credentialsObject = new JSONObject();
          JSONObject postObject = new JSONObject();
          try {
            // credentialsObject.put("environment", "production");
            credentialsObject.put("environment", "development");
            credentialsObject.put("client_identification_sequence", pin);

            postObject.put("push_token", credentialsObject);
          } catch (Exception ex) {
            System.out.println("-----<doRequest><REQUEST_PUSH_TOKEN> Exception = " + ex);
          }
          BigVector postData = new BigVector();
          postData.addElement(TOKEN);
          postData.addElement(postObject.toString());

          QBHTTPConnManager man =
              new QBHTTPConnManager(
                  POST, PUSH_SERVER_API + "push_tokens.json", postData, type, this);
          break;
        }

        //    REQUEST_PUSH_SUBSCRIBE

      case REQUEST_PUSH_SUBSCRIBE:
        {
          System.out.println("-----<doRequest><REQUEST_PUSH_SUBSCRIBE>");
          JSONObject postObject = new JSONObject();
          try {
            postObject.put("notification_channels", "bbps");
          } catch (Exception ex) {
            System.out.println("-----<doRequest><REQUEST_PUSH_SUBSCRIBE> Exception = " + ex);
          }
          BigVector postData = new BigVector();
          postData.addElement(TOKEN);
          postData.addElement(postObject.toString());

          QBHTTPConnManager man =
              new QBHTTPConnManager(
                  POST, PUSH_SERVER_API + "subscriptions.json", postData, type, this);
          break;
        }

      default:
        break;
    }
  }