// El string debe estar em formato json public boolean updateRegistry(String dataJson) { try { // Crea objeto json con string por parametro JSONObject json = new JSONObject(dataJson); // Obtiene el array de Registos JSONArray arr = json.getJSONArray("Registry"); // Recorre el array for (int i = 0; i < arr.length(); i++) { // Obtiene los datos idSensor y value int idSensor = arr.getJSONObject(i).getInt("idSensor"); int value = arr.getJSONObject(i).getInt("value"); // Recorre la configuracion de registro for (RegistryConf reg : registryConf) { // Se fija si el registro corresponde a esta configuracion if (reg.getIdSensor() == idSensor) { // Checkea el criterio para guardar, o no en la BD // Checkea tambien si el valor es igual al anterior if (reg.getSaveTypeString() == "ONCHANGE" && lastRead.get(idSensor) != value) { // Actualizo la ultima lectura y guardo en la BD lastRead.put(idSensor, value); saveRegistry(idSensor, value); } else if (reg.getSaveTypeString() == "ONTIME") { // Variables auxiliares, para checkear tiempo Long auxLong = System.currentTimeMillis() / 1000; int now = auxLong.intValue(); int timeToSave = lastRead.get(idSensor) + reg.getValue(); // Checkea si ya es tiempo para guerdar un nuevo registro if (now >= timeToSave) { // Actualizo el ultimo guardado lastRead.put(idSensor, now); saveRegistry(idSensor, value); } } } } } } catch (Exception e) { e.printStackTrace(); } return false; }
/** * Main Class Routine that reads in URL specs from a file and a duration (in miliseconds) of how * long to run the test. * * <p>USAGE: java RunLoadTest [Duration in seconds]</b> */ public static void main(String[] args) { if (args.length == 1) { // Record Start of Test Run Date testStart = new Date(); // Load and run tests loadThread("Test Group #1"); loadThread("Test Group #2"); loadThread("Test Group #3"); loadThread("Test Group #4"); loadThread("Test Group #5"); loadThread("Test Group #6"); loadThread("Test Group #7"); loadThread("Test Group #8"); loadThread("Test Group #9"); loadThread("Test Group #10"); // Set Timer to stop testing Timer timer = new Timer(); TimerTask task = new TimerTask() { public void run() { Date testStop = new Date(); RunLoadTest.setOutOfTime(); try { Thread.sleep(5000); } catch (Exception e) { } // Pause to allow all threads to stop. System.out.println("Start Test Run: " + testStart.toString()); System.out.println("Stop Test Run: " + testStop.toString()); long secondsBetween = (testStop.getTime() - testStart.getTime()) / 1000; System.out.println("Total Seconds: " + secondsBetween); } }; // Schedule Test Run according to the duration given long curDate = new Date().getTime(); long milis = Long.parseLong(args[0]) * 1000; timer.schedule(task, new Date(curDate + milis)); } else { System.out.println("USAGE: java RunLoadTest [Duration in seconds]"); } }
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int userId = Integer.parseInt(request.getSession().getAttribute("userId").toString()); int documentId = Integer.parseInt(request.getSession().getAttribute("documentId").toString()); long documentDate = Long.parseLong(request.getSession().getAttribute("documentDate").toString()); int lawyerId = Integer.parseInt(request.getParameter("lawyerid")); DocumentPath path = new DocumentPath(); String filesource = path.getDocumentPath(userId, documentId, documentDate); UserAccount account = new UserAccount(); User user = account.findUserbyId(userId); LawyerAccount lawyeraccount = new LawyerAccount(); Lawyer lawyer = lawyeraccount.getLawyerById(lawyerId); Mail mail = new Mail(); // sending file to lawyer String lcontent = "Request came from user :"******" " + user.getLast_name() + "\n" + "contact no : " + user.getPhone_number() + "\n" + "email : " + user.getEmail() + "\n" + "address : \n " + user.getStreet_address() + "\n" + user.getCity() + "\n" + user.getState() + "\n Document is attached"; mail.sendemail( lawyer.getEmail(), user.getEmail(), "Request for validation", lcontent, filesource); response.sendRedirect("../response.jsp?id=7"); }
private void jButton5ActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton5ActionPerformed // TODO add your handling code here: String requesturl = "http://localhost:8080/SA-Service/sa/addRoute"; JSONObject body = new JSONObject(); JSONArray stops = new JSONArray(); for (int i = 0; i < current_line.getRowCount(); i++) { stops.put(Long.parseLong(current_line.getValueAt(i, 0).toString())); } try { // TODO: error check body.put("name", route_name.getText()); body.put("stations", stops); workclass.sendHTTPPost(requesturl, body); } catch (JSONException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } } // GEN-LAST:event_jButton5ActionPerformed