List of usage examples for org.json.simple.parser ParseException printStackTrace
public void printStackTrace()
From source file:com.lifetime.util.TimeOffUtil.java
protected static List<RepliconTimeOff> createTimeOffList(String response) throws ParseException { JSONParser parser = new JSONParser(); JSONObject jsonObject = (JSONObject) parser.parse(response); JSONObject d = (JSONObject) jsonObject.get("d"); JSONArray rows = (JSONArray) d.get("rows"); List<RepliconTimeOff> list = new ArrayList<RepliconTimeOff>(); for (Object row : rows) { JSONArray cells = (JSONArray) ((JSONObject) row).get("cells"); JSONObject owner = (JSONObject) cells.get(0); String employeeName = (String) owner.get("textValue"); JSONObject department = (JSONObject) cells.get(1); String departmentName = (String) department.get("textValue"); JSONObject ptoType = (JSONObject) cells.get(2); String ptoTypeName = (String) ptoType.get("textValue"); SimpleDateFormat dateFormat = new SimpleDateFormat("MMM d, yyyy"); JSONObject startDateJson = (JSONObject) cells.get(3); String startDateString = (String) startDateJson.get("textValue"); Date startDate = null;/*w w w . ja v a 2 s . c o m*/ try { startDate = dateFormat.parse(startDateString); } catch (java.text.ParseException e) { e.printStackTrace(); } JSONObject endDateJson = (JSONObject) cells.get(3); String endDateString = (String) endDateJson.get("textValue"); Date endDate = null; try { endDate = dateFormat.parse(endDateString); } catch (java.text.ParseException e) { e.printStackTrace(); } JSONObject approvedJson = (JSONObject) cells.get(5); String approvedString = (String) approvedJson.get("textValue"); boolean approved = approvedString.equals("Approved") ? true : false; RepliconTimeOff repliconTimeOff = new RepliconTimeOffImpl(employeeName, departmentName, startDate, endDate, ptoTypeName, approved); list.add(repliconTimeOff); } return list; }
From source file:io.github.casnix.spawnerdropper.SpawnerStack.java
public static long GetSpawnersInService(String spawnerType) { try {//from www. j a va 2 s .c o m // Read entire ./SpawnerDropper.SpawnerStack.json into a string String spawnerStack = new String( Files.readAllBytes(Paths.get("./plugins/SpawnerDropper/SpawnerStack.json"))); // get the value of JSON->{spawnerType} JSONParser parser = new JSONParser(); Object obj = parser.parse(spawnerStack); JSONObject jsonObj = (JSONObject) obj; long number = (Long) jsonObj.get(spawnerType); // System.out.println("[SD DBG MSG] GSIS numberInServer("+number+")"); return number; } catch (ParseException e) { Bukkit.getLogger().warning("[SpawnerDropper] Caught ParseException in GetSpawnersInService(String)"); e.printStackTrace(); return -1; } catch (FileNotFoundException e) { Bukkit.getLogger() .warning("[SpawnerDropper] Could not find ./plugins/SpawnerDropper/SpawnerStack.json"); e.printStackTrace(); return -1; } catch (IOException e) { Bukkit.getLogger().warning("[SpawnerDropper] Caught IOException in GetSpawnersInService(String)"); e.printStackTrace(); return -1; } }
From source file:it.polimi.logging.LogMessageUtils.java
public static JSONObject getStatus(String message) { JSONObject jsonMsg;//from w w w . j a va 2s. co m JSONParser parser = new JSONParser(); try { jsonMsg = (JSONObject) parser.parse(message); JSONObject status = (JSONObject) jsonMsg.get(JsonStrings.STATUS); return status; } catch (ParseException e) { e.printStackTrace(); } return null; }
From source file:it.polimi.logging.LogMessageUtils.java
public static boolean getValidBitFromMessage(String message) { JSONObject jsonMsg;//w ww. j a va 2 s . co m JSONParser parser = new JSONParser(); String type = getEventType(message); if (type.equals(MessageType.CHECK_OUT.ordinal())) { try { jsonMsg = (JSONObject) parser.parse(message); return (Boolean) jsonMsg.get(JsonStrings.VALID); } catch (ParseException e) { e.printStackTrace(); } } return false; }
From source file:com.wattzap.model.social.SelfLoopsAPI.java
public static int uploadActivity(String email, String passWord, String fileName, String note) throws IOException { JSONObject jsonObj = null;//from w ww . j av a2s.c o m FileInputStream in = null; GZIPOutputStream out = null; CloseableHttpClient httpClient = HttpClients.createDefault(); try { HttpPost httpPost = new HttpPost(url); httpPost.setHeader("enctype", "multipart/mixed"); in = new FileInputStream(fileName); // Create stream to compress data and write it to the to file. ByteArrayOutputStream obj = new ByteArrayOutputStream(); out = new GZIPOutputStream(obj); // Copy bytes from one stream to the other byte[] buffer = new byte[4096]; int bytes_read; while ((bytes_read = in.read(buffer)) != -1) { out.write(buffer, 0, bytes_read); } out.close(); in.close(); ByteArrayBody bin = new ByteArrayBody(obj.toByteArray(), ContentType.create("application/x-gzip"), fileName); HttpEntity reqEntity = MultipartEntityBuilder.create() .addPart("email", new StringBody(email, ContentType.TEXT_PLAIN)) .addPart("pw", new StringBody(passWord, ContentType.TEXT_PLAIN)).addPart("tcxfile", bin) .addPart("note", new StringBody(note, ContentType.TEXT_PLAIN)).build(); httpPost.setEntity(reqEntity); CloseableHttpResponse response = null; try { response = httpClient.execute(httpPost); int code = response.getStatusLine().getStatusCode(); switch (code) { case 200: HttpEntity respEntity = response.getEntity(); if (respEntity != null) { // EntityUtils to get the response content String content = EntityUtils.toString(respEntity); //System.out.println(content); JSONParser jsonParser = new JSONParser(); jsonObj = (JSONObject) jsonParser.parse(content); } break; case 403: throw new RuntimeException( "Authentification failure " + email + " " + response.getStatusLine()); default: throw new RuntimeException("Error " + code + " " + response.getStatusLine()); } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (response != null) { response.close(); } } int activityId = ((Long) jsonObj.get("activity_id")).intValue(); // parse error code int error = ((Long) jsonObj.get("error_code")).intValue(); if (activityId == -1) { String message = (String) jsonObj.get("message"); switch (error) { case 102: throw new RuntimeException("Empty TCX file " + fileName); case 103: throw new RuntimeException("Invalide TCX Format " + fileName); case 104: throw new RuntimeException("TCX Already Present " + fileName); case 105: throw new RuntimeException("Invalid XML " + fileName); case 106: throw new RuntimeException("invalid compression algorithm"); case 107: throw new RuntimeException("Invalid file mime types"); default: throw new RuntimeException(message + " " + error); } } return activityId; } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } httpClient.close(); } }
From source file:io.github.casnix.spawnerdropper.SpawnerStack.java
public static boolean PutSpawnerIntoService(String spawnerType) { // Read ./SpawnerDropper.SpawnerStack.json into a string // get the value of JSON->{spawnerType} and add 1 to it. // Write file back to disk try {//from w ww .jav a2 s . c om // Read entire ./SpawnerDropper.SpawnerStack.json into a string String spawnerStack = new String( Files.readAllBytes(Paths.get("./plugins/SpawnerDropper/SpawnerStack.json"))); // get the value of JSON->{spawnerType} JSONParser parser = new JSONParser(); Object obj = parser.parse(spawnerStack); JSONObject jsonObj = (JSONObject) obj; long numberInService = (Long) jsonObj.get(spawnerType); if (numberInService < 0) { numberInService = 0; } // System.out.println("[SD DBG MSG] PSIS numberInServer("+numberInService+")"); numberInService += 1; jsonObj.put(spawnerType, new Long(numberInService)); FileWriter file = new FileWriter("./plugins/SpawnerDropper/SpawnerStack.json"); file.write(jsonObj.toJSONString()); file.flush(); file.close(); return true; } catch (ParseException e) { Bukkit.getLogger().warning("[SpawnerDropper] Caught ParseException in PutSpawnerIntoService(String)"); e.printStackTrace(); return false; } catch (FileNotFoundException e) { Bukkit.getLogger() .warning("[SpawnerDropper] Could not find ./plugins/SpawnerDropper/SpawnerStack.json"); e.printStackTrace(); return false; } catch (IOException e) { Bukkit.getLogger().warning("[SpawnerDropper] Caught IOException in PutSpawnerIntoService(String)"); e.printStackTrace(); return false; } }
From source file:io.github.casnix.spawnerdropper.SpawnerStack.java
public static boolean TakeSpawnerOutOfService(String spawnerType) { // Read ./SpawnerDropper.SpawnerStack.json into a string // get the value of JSON->{spawnerType} and subtract 1 to it unless it is 0. // If it's zero, return false // Write file back to disk try {/*from w w w . java 2 s . co m*/ // Read entire ./SpawnerDropper.SpawnerStack.json into a string String spawnerStack = new String( Files.readAllBytes(Paths.get("./plugins/SpawnerDropper/SpawnerStack.json"))); // get the value of JSON->{spawnerType} JSONParser parser = new JSONParser(); Object obj = parser.parse(spawnerStack); JSONObject jsonObj = (JSONObject) obj; long numberInService = (Long) jsonObj.get(spawnerType); if (numberInService <= 0) { return false; } else { // System.out.println("[SD DBG MSG] TSOOS numberInServer("+numberInService+")"); numberInService -= 1; jsonObj.put(spawnerType, new Long(numberInService)); FileWriter file = new FileWriter("./plugins/SpawnerDropper/SpawnerStack.json"); file.write(jsonObj.toJSONString()); file.flush(); file.close(); return true; } } catch (ParseException e) { Bukkit.getLogger().warning("[SpawnerDropper] Caught ParseException in TakeSpawnerOutOfService(String)"); e.printStackTrace(); return false; } catch (FileNotFoundException e) { Bukkit.getLogger() .warning("[SpawnerDropper] Could not find ./plugins/SpawnerDropper/SpawnerStack.json"); e.printStackTrace(); return false; } catch (IOException e) { Bukkit.getLogger().warning("[SpawnerDropper] Caught IOException in TakeSpawnerOutOfService(String)"); e.printStackTrace(); return false; } }
From source file:it.polimi.logging.LogMessageUtils.java
public static String getSenderID(String msgJson) { JSONParser parser = new JSONParser(); JSONObject jsonMsg;// w ww . j a va 2 s. co m String senderID = ""; try { jsonMsg = (JSONObject) parser.parse(msgJson); senderID = (String) jsonMsg.get(JsonStrings.SENDER); return senderID; } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:it.polimi.logging.LogMessageUtils.java
public static String getLogId(String message) { JSONParser parser = new JSONParser(); JSONObject jsonMsg;//from w w w. ja v a 2 s .c om String logId = ""; try { jsonMsg = (JSONObject) parser.parse(message); logId = (String) jsonMsg.get(JsonStrings.LOG_ID); return logId; } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:it.polimi.logging.LogMessageUtils.java
public static String getTopicReply(String message) { JSONParser parser = new JSONParser(); JSONObject jsonMsg;//from w w w.j a va 2 s . com String topic = ""; try { jsonMsg = (JSONObject) parser.parse(message); topic = (String) jsonMsg.get(JsonStrings.TOPIC_REPLY); return topic; } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }