예제 #1
0
  public void applySettingStatusReport(JSONObject js) {
    /**
     * This breaks the mold a bit.. but its more efficient. This gets called off the top of
     * ParseJson if it has an "SR" in it. Sr's are called so often that instead of walking the
     * normal parsing tree.. this skips to the end
     */
    try {
      Iterator ii = js.keySet().iterator();
      // This is a special multi single value response object
      while (ii.hasNext()) {
        String key = ii.next().toString();

        responseCommand rc =
            new responseCommand(MNEMONIC_GROUP_SYSTEM, key.toString(), js.get(key).toString());
        TinygDriver.getInstance().machine.applyJsonStatusReport(rc);
        //                _applySettings(rc.buildJsonObject(), rc.getSettingParent()); //we will
        // supply the parent object name for each key pair
      }
      setChanged();
      message[0] = "STATUS_REPORT";
      message[1] = null;
      notifyObservers(message);

    } catch (Exception ex) {
      logger.error("[!] Error in applySettingStatusReport(JsonOBject js) : " + ex.getMessage());
      logger.error("[!]js.tostring " + js.toString());
      setChanged();
      message[0] = "STATUS_REPORT";
      message[1] = null;
      notifyObservers(message);
    }
  }
예제 #2
0
 /** Helper method for main to load tests into a thread group and start each test case. */
 private static void loadThread(String name) {
   try {
     ThreadGroup myThreadGroup = new ThreadGroup(name);
     String urlSpec = "http://54.201.122.231:8181/v4/gumball";
     // String urlSpec = "http://localhost:8080/v4/gumball" ;
     RunLoadTest test = new RunLoadTest(myThreadGroup, urlSpec);
     test.runTest(); // Run The Test in its own thread
     myThreadGroup.list();
   } catch (Exception e) {
     System.out.println("ERROR: " + e.getMessage());
   }
 }
예제 #3
0
  @RequestMapping(
      value = "/home",
      method = {RequestMethod.GET, RequestMethod.POST})
  public String getCity(HttpServletRequest request, ModelMap model) {

    try {
      List<City> cityList = cityService.getCity();
      utilities.setSuccessResponse(response, cityList);
    } catch (Exception ex) {
      logger.error("getCity :" + ex.getMessage());
    }
    model.addAttribute("model", response);
    return "home";
  }
  @DELETE
  @Path("/{id}")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces("text/plain")
  public String deleteNote(String inputData, @PathParam("id") int id) {
    JSONObject inputJSON = new JSONObject(inputData);
    if ((inputJSON.has("sessionID"))
        && UsersController.checkLogin(inputJSON.getString("sessionID"))) {
      try {
        hibernate.controllers.NotesController notesController =
            new hibernate.controllers.NotesController();
        notesController.deleteNote(id);

        return "OK";
      } catch (Exception ex) {
        return ex.getMessage();
      }
    } else return "Invalid session!";
  }
예제 #5
0
  @RequestMapping(
      value = "/getCityApi",
      method = {RequestMethod.GET, RequestMethod.POST})
  public String getCityApi(
      HttpServletRequest request,
      @RequestParam(value = "locationname") String locationname,
      ModelMap model) {

    Map<Object, Object> map = new HashMap<Object, Object>();
    JSONArray jSONArray = new JSONArray();
    try {
      String status = "active";
      List<City> cityList = cityService.getCityApi(locationname, status);
      if (cityList != null && cityList.size() > 0) {
        for (int i = 0; i < cityList.size(); i++) {
          City city = (City) cityList.get(i);
          String cityName = (String) city.getCity();
          String stateName = (String) city.getState();

          int ID = (Integer) (city.getId());
          JSONObject jSONObject = new JSONObject();

          jSONObject.put("id", ID);
          jSONObject.put("text", cityName);
          jSONArray.put(jSONObject);
        }
        utilities.setSuccessResponse(response, jSONArray.toString());
      } else {
        throw new ConstException(ConstException.ERR_CODE_NO_DATA, ConstException.ERR_MSG_NO_DATA);
      }
    } catch (Exception ex) {
      logger.error("getCity :" + ex.getMessage());
      utilities.setErrResponse(ex, response);
    }
    model.addAttribute("model", jSONArray.toString());
    return "home";
  }
예제 #6
0
  public void applySetting(JSONObject js) {
    try {
      if (js.length() == 0) {
        // This is a blank object we just return and move on
      } else if (js.keySet().size() > 1) { // If there are more than one object in the json response
        Iterator ii = js.keySet().iterator();
        // This is a special multi single value response object
        while (ii.hasNext()) {
          String key = ii.next().toString();
          switch (key) {
            case "f":
              parseFooter(js.getJSONArray("f"));
              // This is very important.
              // We break out our response footer.. error codes.. bytes availble in hardware buffer
              // etc.
              break;

            case "msg":
              message[0] = "TINYG_USER_MESSAGE";
              message[1] = (String) js.get(key) + "\n";
              logger.info("[+]TinyG Message Sent:  " + js.get(key) + "\n");
              setChanged();
              notifyObservers(message);
              break;
            case "rx":
              TinygDriver.getInstance().serialWriter.setBuffer(js.getInt(key));
              break;
            default:
              if (TinygDriver.getInstance().mneManager.isMasterGroupObject(key)) {
                //                            logger.info("Group Status Report Detected: " + key);
                applySettingMasterGroup(js.getJSONObject(key), key);
                continue;
              }
              responseCommand rc = TinygDriver.getInstance().mneManager.lookupSingleGroup(key);
              rc.setSettingValue(js.get(key).toString());
              _applySettings(
                  rc.buildJsonObject(),
                  rc.getSettingParent()); // we will supply the parent object name for each key pair
              break;
          }
        }
      } else {
        /* This else follows:
         * Contains a single object in the JSON response
         */
        if (js.keySet().contains("f")) {
          /** This is a single response footer object: Like So: {"f":[1,0,5,3330]} */
          parseFooter(js.getJSONArray("f"));
        } else {
          /**
           * Contains a single object in the json response I am not sure this else is needed any
           * longer.
           */
          _applySettings(js, js.keys().next().toString());
        }
      }
    } catch (JSONException ex) {
      logger.error("[!] Error in applySetting(JsonOBject js) : " + ex.getMessage());
      logger.error("[!]JSON String Was: " + js.toString());
      logger.error("Error in Line: " + js);
    } catch (Exception ex) {
      logger.error("[!] Error in applySetting(JsonOBject js) : " + ex.getMessage());
      logger.error(ex.getClass().toString());
    }
  }