Java Code Examples for org.codehaus.jettison.json.JSONException#printStackTrace()
The following examples show how to use
org.codehaus.jettison.json.JSONException#printStackTrace() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LivyRestExecutor.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
private List<String> getLogs(JSONObject logInfo) { List<String> logs = Lists.newArrayList(); if (logInfo.has("log")) { try { JSONArray logArray = logInfo.getJSONArray("log"); for (int i=0; i<logArray.length(); i++) { logs.add(logArray.getString(i)); } } catch (JSONException e) { e.printStackTrace(); } } return logs; }
Example 2
Source File: Translation.java From ezScrum with GNU General Public License v2.0 | 6 votes |
public static String translateTaskboardTaskToJson(TaskObject task) { JSONObject responseText = new JSONObject(); try { responseText.put("success", true); JSONObject jsonIssue = new JSONObject(); // 若需要其他欄位請再新增 jsonIssue.put("Id", task.getId()); jsonIssue.put("Link", ""); jsonIssue.put("Name", task.getName()); jsonIssue.put("Handler", task.getHandler() == null ? "" : task .getHandler().getUsername()); jsonIssue.put("Partners", task.getPartnersUsername()); responseText.put("Issue", jsonIssue); } catch (JSONException e) { e.printStackTrace(); } return responseText.toString(); }
Example 3
Source File: AzkabanWorkflowClient.java From dr-elephant with Apache License 2.0 | 6 votes |
/** * Authenticates Dr. Elephant in Azkaban and sets the sessionId * * @param userName The username of the user * @param password The password of the user */ @Override public void login(String userName, String password) { this._username = userName; this._password = password; List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("action", "login")); urlParameters.add(new BasicNameValuePair("username", userName)); urlParameters.add(new BasicNameValuePair("password", password)); try { JSONObject jsonObject = fetchJson(urlParameters, _workflowExecutionUrl); if (!jsonObject.has("session.id")) { throw new RuntimeException("Login attempt failed. The session ID could not be obtained."); } this._sessionId = jsonObject.get("session.id").toString(); logger.debug("Session ID is " + this._sessionId); } catch (JSONException e) { e.printStackTrace(); } }
Example 4
Source File: AzkabanWorkflowClient.java From dr-elephant with Apache License 2.0 | 6 votes |
/** * Returns the jobs from the flow * @return The jobs from the flow */ public Map<String, String> getJobsFromFlow() { List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("session.id", _sessionId)); urlParameters.add(new BasicNameValuePair("ajax", "fetchexecflow")); urlParameters.add(new BasicNameValuePair("execid", _executionId)); try { JSONObject jsonObject = fetchJson(urlParameters, _workflowExecutionUrl); JSONArray jobs = jsonObject.getJSONArray("nodes"); Map<String, String> jobMap = new HashMap<String, String>(); for (int i = 0; i < jobs.length(); i++) { JSONObject job = jobs.getJSONObject(i); jobMap.put(job.get("id").toString(), job.get("status").toString()); } return jobMap; } catch (JSONException e) { e.printStackTrace(); } return null; }
Example 5
Source File: AzkabanWorkflowClient.java From dr-elephant with Apache License 2.0 | 6 votes |
/** * Returns the azkaban flow log * @param offset The offset from which logs should be found * @param maximumlLogLengthLimit The maximum log length limit * @return The azkaban flow logs */ public String getAzkabanFlowLog(String offset, String maximumlLogLengthLimit) { List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("session.id", _sessionId)); urlParameters.add(new BasicNameValuePair("ajax", "fetchExecFlowLogs")); urlParameters.add(new BasicNameValuePair("execid", _executionId)); urlParameters.add(new BasicNameValuePair("offset", offset)); urlParameters.add(new BasicNameValuePair("length", maximumlLogLengthLimit)); try { JSONObject jsonObject = fetchJson(urlParameters, _workflowExecutionUrl); if (jsonObject.getLong("length") == 0) { throw new RuntimeException("No log found for given execution url!."); } return jsonObject.get("data").toString(); } catch (JSONException e) { e.printStackTrace(); } return null; }
Example 6
Source File: AzkabanWorkflowClient.java From dr-elephant with Apache License 2.0 | 6 votes |
/** * Returns the Azkaban Job log for given Azkaban job id. * * @param jobId Azkaban job id * @param offset Offset of log from the start * @param length Maximum limit on length of log * @return Azkaban job log in the form of string */ public String getAzkabanJobLog(String jobId, String offset, String length) { List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("session.id", _sessionId)); urlParameters.add(new BasicNameValuePair("ajax", "fetchExecJobLogs")); urlParameters.add(new BasicNameValuePair("execid", _executionId)); urlParameters.add(new BasicNameValuePair("jobId", jobId)); urlParameters.add(new BasicNameValuePair("offset", offset)); urlParameters.add(new BasicNameValuePair("length", length)); try { JSONObject jsonObject = fetchJson(urlParameters, _workflowExecutionUrl); if (jsonObject.getLong("length") == 0) { // To do: If length ==0 throw exception logger.info("No log found for azkaban job" + jobId); } return jsonObject.get("data").toString(); } catch (JSONException e) { e.printStackTrace(); } return null; }
Example 7
Source File: Translation.java From ezScrum with GNU General Public License v2.0 | 6 votes |
public static String translateTaskboardStoryToJson(StoryObject story) { JSONObject responseText = new JSONObject(); try { responseText.put("success", true); JSONObject jsonIssue = new JSONObject(); // 若需要其他欄位請再新增 jsonIssue.put("Id", story.getId()); jsonIssue.put("Link", ""); jsonIssue.put("Name", story.getName()); jsonIssue.put("Estimate", story.getEstimate()); jsonIssue.put("Handler", ""); jsonIssue.put("Partners", ""); responseText.put("Issue", jsonIssue); } catch (JSONException e) { e.printStackTrace(); } return responseText.toString(); }
Example 8
Source File: WebpackTemplate.java From vue-for-idea with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public Collection<VirtualFile> generateProject(@NotNull VueProjectWizardData data, @NotNull Module module, @NotNull VirtualFile baseDir) throws IOException { VirtualFile packagejson = baseDir.findChild("package.json"); if(packagejson!=null){ JsonParser jsonParser = new JsonParser(); JsonElement je= jsonParser.parse(new FileReader(packagejson.getName())); try { JSONObject json = new JSONObject(je.toString()); json.put("name",module.getName()); json.put("private",false); je= jsonParser.parse(json.toString()); } catch (JSONException e) { e.printStackTrace(); } packagejson.setBinaryContent(new GsonBuilder().setPrettyPrinting().create().toJson(je).getBytes());; } return Collections.EMPTY_LIST; }
Example 9
Source File: KafkaSimpleTestProducer.java From hadoop-mini-clusters with Apache License 2.0 | 6 votes |
public void produceMessages() { KafkaProducer<String, String> producer = new KafkaProducer<String, String>(createConfig()); int count = 0; while(count < getMessageCount()) { // Create the JSON object JSONObject obj = new JSONObject(); try { obj.put("id", String.valueOf(count)); obj.put("msg", "test-message" + 1); obj.put("dt", GenerateRandomDay.genRandomDay()); } catch(JSONException e) { e.printStackTrace(); } String payload = obj.toString(); producer.send(new ProducerRecord<String, String>(getTopic(), payload)); LOG.info("Sent message: {}", payload.toString()); count++; } }
Example 10
Source File: LivyRestExecutor.java From kylin with Apache License 2.0 | 6 votes |
private List<String> getLogs(JSONObject logInfo) { List<String> logs = Lists.newArrayList(); if (logInfo.has("log")) { try { JSONArray logArray = logInfo.getJSONArray("log"); for (int i=0; i<logArray.length(); i++) { logs.add(logArray.getString(i)); } } catch (JSONException e) { e.printStackTrace(); } } return logs; }
Example 11
Source File: Translation.java From ezScrum with GNU General Public License v2.0 | 6 votes |
public static String translateTaskboardIssueToJson(IIssue issue) { TranslateSpecialChar translateChar = new TranslateSpecialChar(); JSONObject responseText = new JSONObject(); try { responseText.put("success", true); JSONObject jsonIssue = new JSONObject(); // 若需要其他欄位請再新增 jsonIssue.put("Id", issue.getIssueID()); jsonIssue.put("Link", translateChar.TranslateJSONChar(issue.getIssueLink())); jsonIssue.put("Name", translateChar.TranslateJSONChar((issue.getSummary()))); jsonIssue.put("Handler", issue.getAssignto()); jsonIssue.put("Partners", issue.getPartners()); responseText.put("Issue", jsonIssue); } catch (JSONException e) { e.printStackTrace(); } return responseText.toString(); }
Example 12
Source File: ReleasePlanHelper.java From ezScrum with GNU General Public License v2.0 | 6 votes |
private JSONObject updateJsonInfo(JSONObject jsonInfo) { try { // JSON是call by reference!!! 查memory=>System.identityHashCode(Object // x) JSONArray sprintJsonArray = (JSONArray) jsonInfo.get("Sprints"); int sprintCount = jsonInfo.getInt("TotalSprintCount"); int storyCount = jsonInfo.getInt("TotalStoryCount"); int storyRemaining = jsonInfo.getInt("TotalStoryCount"); double idealRange = (double) storyCount / sprintCount; for (int i = 0; i < sprintJsonArray.length(); i++) { JSONObject sprintJson = sprintJsonArray.getJSONObject(i); storyRemaining -= sprintJson.getInt("StoryDoneCount"); sprintJson.put("StoryRemainingCount", storyRemaining); sprintJson.put("StoryIdealCount", storyCount - (idealRange * (i + 1))); } jsonInfo.put("Sprints", sprintJsonArray); } catch (JSONException e) { e.printStackTrace(); } return jsonInfo; }
Example 13
Source File: Translation.java From ezScrum with GNU General Public License v2.0 | 5 votes |
public static String translateBurndownChartDataToJson( LinkedHashMap<Date, Double> ideal, LinkedHashMap<Date, Double> real) { JSONObject responseText = new JSONObject(); try { responseText.put("success", true); JSONArray array = new JSONArray(); DateFormat formatter = new SimpleDateFormat("yyyy/MM/dd"); Object[] idealPointArray = ideal.keySet().toArray(); for (int i = 0; i < idealPointArray.length; i++) { JSONObject obj = new JSONObject(); obj.put("Date", formatter.format(idealPointArray[i])); obj.put("IdealPoint", ideal.get(idealPointArray[i])); if (real.get(idealPointArray[i]) != null) { obj.put("RealPoint", real.get(idealPointArray[i])); } else { obj.put("RealPoint", "null"); } if (i == 0) { obj.put("RealPoint", ideal.get(idealPointArray[0])); } array.put(obj); } responseText.put("Points", array); } catch (JSONException e) { e.printStackTrace(); } return responseText.toString(); }
Example 14
Source File: ReleasePlanHelper.java From ezScrum with GNU General Public License v2.0 | 5 votes |
/** * from AjaxGetVelocityAction, 將被選到的release plans拿出他們的sprint * point並算出velocity,算出平均值再轉成JSON */ public String getSprintVelocityToJson(ArrayList<ReleaseObject> releases, SprintBacklogHelper sprintPlanHelper) { JSONObject velocityJson = new JSONObject(); JSONArray sprintJsonArray = new JSONArray(); HashMap<String, Integer> storyInfoMap; double totalVelocity = 0; int sprintCount = 0; // 計算被選的release內的sprint總數 try { for (ReleaseObject release : releases) { if (release == null) { break; } for (SprintObject sprint : release.getSprints()) { JSONObject sprintplan = new JSONObject(); sprintplan.put("ID", String.valueOf(sprint.getId())); sprintplan.put("Name", "Sprint" + String.valueOf(sprint.getId())); storyInfoMap = getStoryInfo(String.valueOf(sprint.getId()), sprintPlanHelper); sprintplan.put("Velocity", storyInfoMap.get("StoryPoint")); sprintJsonArray.put(sprintplan); totalVelocity += storyInfoMap.get("StoryPoint"); sprintCount++; } } velocityJson.put("Sprints", sprintJsonArray); if (sprintCount != 0) { velocityJson.put("Average", totalVelocity / sprintCount); } else { velocityJson.put("Average", ""); } } catch (JSONException e) { e.printStackTrace(); } return velocityJson.toString(); }
Example 15
Source File: ReleasePlanHelper.java From ezScrum with GNU General Public License v2.0 | 5 votes |
/** * from AjaxGetReleasePlanAction, 將release讀出並列成list再轉成JSON */ public String setReleaseListToJson(List<ReleaseObject> releases) { JSONObject releaseJson = new JSONObject(); JSONArray releaseJsonArray = new JSONArray(); try { for (ReleaseObject release : releases) { releaseJsonArray.put(release.toJSON()); } releaseJson.put("Releases", releaseJsonArray); } catch (JSONException e) { e.printStackTrace(); } return releaseJson.toString(); }
Example 16
Source File: RestTestClientTest.java From netbeans with Apache License 2.0 | 5 votes |
/** * Test for GET request */ @Test public void testGetResponseFormat() { // show test UI for 'customers/{customerId}' resource tc.expand("customers"); //NOI18N tc.clickOn("customerId"); //NOI18N // GET and application/xml should be selected by default - let's check it // XXX - should the default mime be app/json? IZ #156896 assertEquals("GET", tc.getSelectedRMethod()); //NOI18N assertEquals("application/xml", tc.getSelectedMIMEType()); //NOI18N //should have three options: // GET, PUT, DELETE assertEquals(3, tc.getAvailableRMethods().length); // set an ID of a customer tc.setTestArg("resourceId", "1"); //NOI18N tc.doTest(); String s = tc.getContentFromView("raw"); //NOI18N try { Utils.readXml(s); } catch (SAXParseException se) { se.printStackTrace(System.err); fail("invalid xml response [" + s + "]"); //NOI18N } // check app/json response format tc.setSelectedMIMEType("application/json"); //NOI18N assertEquals("application/json", tc.getSelectedMIMEType()); //NOI18N tc.doTest(); s = tc.getContentFromView("raw"); //NOI18N try { JSONObject json = new JSONObject(s); } catch (JSONException ex) { ex.printStackTrace(System.err); fail("invalid JSON string: [" + s + "]"); //NOI18N } }
Example 17
Source File: Translation.java From ezScrum with GNU General Public License v2.0 | 4 votes |
public static String translateStoriesToJson(ArrayList<StoryObject> stories) { TranslateSpecialChar translateChar = new TranslateSpecialChar(); JSONObject responseText = new JSONObject(); try { responseText.put("success", true); responseText.put("Total", stories.size()); JSONArray jsonStroies = new JSONArray(); for (int i = 0; i < stories.size(); i++) { JSONObject jsonStory = new JSONObject(); jsonStory.put("Id", stories.get(i).getId()); jsonStory.put("Type", "Story"); jsonStory.put("Name", translateChar.TranslateJSONChar((stories.get(i).getName()))); jsonStory.put("Value", stories.get(i).getValue()); jsonStory.put("Estimate", stories.get(i).getEstimate()); jsonStory.put("Importance", stories.get(i).getImportance()); jsonStory.put("Tag", translateChar.TranslateJSONChar(Join(stories.get(i).getTags(), ","))); jsonStory.put("Status", stories.get(i).getStatusString()); jsonStory.put("Notes", translateChar.TranslateJSONChar(stories.get(i).getNotes())); jsonStory.put("HowToDemo", translateChar.TranslateJSONChar(stories.get(i).getHowToDemo())); jsonStory.put("Link", ""); jsonStory.put("Release", ""); if (stories.get(i).getSprintId() == StoryObject.NO_PARENT) { jsonStory.put("Sprint", "None"); } else { jsonStory.put("Sprint", stories.get(i).getSprintId()); } jsonStory.put("FilterType", getFilterType(stories.get(i))); if (stories.get(i).getAttachFiles().size() == 0) jsonStory.put("Attach", false); else jsonStory.put("Attach", true); ArrayList<AttachFileObject> attachFiles = stories.get(i).getAttachFiles(); JSONArray jsonAttachFiles = new JSONArray(); for (AttachFileObject attachFile : attachFiles) { JSONObject jsonAttachFile = new JSONObject(); jsonAttachFile.put("IssueId", attachFile.getIssueId()); jsonAttachFile.put("FileId", attachFile.getId()); jsonAttachFile.put("FileName", translateChar.TranslateJSONChar(attachFile.getName())); // parse Dateformat as Gson Default DateFormat (TaskBoard // page) DateFormat dateFormat = DateFormat.getDateTimeInstance( DateFormat.DEFAULT, DateFormat.DEFAULT); Date date = new Date(attachFile.getCreateTime()); String attachTime = dateFormat.format(date); ProjectObject project = ProjectObject.get(stories.get(i) .getId()); jsonAttachFile.put("UploadDate", attachTime); jsonAttachFile.put("FilePath", "fileDownload.do?projectName=" + project.getName() + "&fileId=" + attachFile.getId() + "&fileName=" + attachFile.getName()); jsonAttachFiles.put(jsonAttachFile); } jsonStory.put("AttachFileList", jsonAttachFiles); jsonStroies.put(jsonStory); } responseText.put("Stories", jsonStroies); } catch (JSONException e) { e.printStackTrace(); } return responseText.toString(); }
Example 18
Source File: Extractor.java From OSTMap with Apache License 2.0 | 4 votes |
public static Double[] extractLocation(JSONObject obj) { Double longitude = 0.0; Double latitude = 0.0; try { if (!obj.isNull("coordinates")) { if (!obj.getJSONObject("coordinates").isNull("coordinates")) { JSONArray coords = obj.getJSONObject("coordinates").getJSONArray("coordinates"); longitude = coords.getDouble(0); latitude = coords.getDouble(1); } } else { //System.out.println("In places"); JSONArray places = obj.getJSONObject("place").getJSONObject("bounding_box").getJSONArray("coordinates").getJSONArray(0); if (places.length() > 2) { Double topLeftLong = places.getJSONArray(0).getDouble(0); Double topLeftLat = places.getJSONArray(0).getDouble(1); Double lowerLeftLong = places.getJSONArray(1).getDouble(0); Double lowerLeftLat = places.getJSONArray(1).getDouble(1); Double topRightLong = places.getJSONArray(2).getDouble(0); Double topRightLat = places.getJSONArray(2).getDouble(1); Double lowerRightLong = places.getJSONArray(3).getDouble(0); Double lowerRightLat = places.getJSONArray(3).getDouble(1); longitude = (topLeftLong + lowerLeftLong + topRightLong + lowerRightLong) / 4; latitude = (topLeftLat + lowerLeftLat + topRightLat + lowerRightLat) / 4; } } Double[] longLat = {longitude, latitude}; return longLat; } catch (JSONException e) { System.err.println("No Correct JSON File"); e.printStackTrace(); return null; } }
Example 19
Source File: Translation.java From ezScrum with GNU General Public License v2.0 | 4 votes |
public static String translateSprintBacklogToJson( ArrayList<StoryObject> stories, long currentSprintId, double currentPoint, double limitedPoint, double taskPoint, long releaseId, String sprintGoal) { TranslateSpecialChar translateChar = new TranslateSpecialChar(); JSONObject responseText = new JSONObject(); try { responseText.put("success", true); responseText.put("Total", stories.size()); JSONObject sprint = new JSONObject(); sprint.put("Id", currentSprintId); sprint.put( "Name", "Sprint #" + translateChar.TranslateJSONChar(String .valueOf(currentSprintId))); sprint.put("CurrentPoint", currentPoint); sprint.put("LimitedPoint", limitedPoint); sprint.put("TaskPoint", taskPoint); sprint.put( "ReleaseID", "Release #" + translateChar.HandleNullString(Long .toString(releaseId))); sprint.put("SprintGoal", sprintGoal); responseText.put("Sprint", sprint); JSONArray jsonStories = new JSONArray(); for (StoryObject story : stories) { JSONObject jsonStory = new JSONObject(); jsonStory.put("Id", story.getId()); jsonStory.put("Link", ""); jsonStory.put("Name", translateChar.TranslateJSONChar(story.getName())); jsonStory.put("Value", story.getValue()); jsonStory.put("Importance", story.getImportance()); jsonStory.put("Estimate", story.getEstimate()); jsonStory.put("Status", story.getStatusString()); jsonStory.put("Notes", translateChar.TranslateJSONChar(story.getNotes())); jsonStory.put("Tag", translateChar.TranslateJSONChar(Join( story.getTags(), ","))); jsonStory.put("HowToDemo", translateChar.TranslateJSONChar(story.getHowToDemo())); jsonStory.put("Release", ""); jsonStory.put("Sprint", story.getSprintId()); if (story.getAttachFiles().size() == 0) { jsonStory.put("Attach", false); } else { jsonStory.put("Attach", true); } ArrayList<AttachFileObject> files = story.getAttachFiles(); JSONArray jsonFiles = new JSONArray(); for (AttachFileObject file : files) { JSONObject jsonFile = new JSONObject(); jsonFile.put("IssueId", file.getIssueId()); jsonFile.put("FileId", file.getId()); jsonFile.put("FileName", translateChar .TranslateXMLChar(translateChar .TranslateJSONChar(file.getName()))); jsonFile.put( "DownloadPath", "fileDownload.do?projectName=" + ProjectObject.get(story.getProjectId()) .getName() + "&fileId=" + file.getId() + "&fileName=" + file.getName()); jsonFiles.put(jsonFile); } jsonStory.put("AttachFileList", jsonFiles); jsonStories.put(jsonStory); } responseText.put("Stories", jsonStories); } catch (JSONException e) { e.printStackTrace(); } return responseText.toString(); }
Example 20
Source File: AjaxGetSprintIndexInfoAction.java From ezScrum with GNU General Public License v2.0 | 4 votes |
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { ProjectObject project = SessionManager.getProjectObject(request); String result = ""; String sprintIdString = request.getParameter("sprintID"); long sprintId = -1; if (sprintIdString != null && !sprintIdString.isEmpty()) { sprintId = Long.parseLong(sprintIdString); } SprintBacklogLogic sprintBacklogLogic = new SprintBacklogLogic(project, sprintId); SprintBacklogMapper sprintBacklogMapper = sprintBacklogLogic.getSprintBacklogMapper(); TaskBoard board = new TaskBoard(sprintBacklogLogic, sprintBacklogMapper); // 建立 thisSprintStore 的資料 long currentSprintId = 0; long releaseId = 0; double initialPoint = 0.0d; double currentPoint = 0.0d; double initialHours = 0.0d; double currentHours = 0.0d; String SprintGoal = ""; String StoryChartUrl = ""; String TaskChartUrl = ""; boolean isCurrentSprint=false; //如果Sprint存在的話,那麼就取出此Sprint的資料以回傳 if ( (sprintBacklogMapper != null) && (sprintBacklogMapper.getSprintId() > 0) ) { currentSprintId = sprintBacklogMapper.getSprintId(); SprintObject sprint = sprintBacklogMapper.getSprint(); initialPoint = sprint.getTotalStoryPoints(); currentPoint = sprint.getStoryUnclosedPoints(); initialHours = sprint.getTotalTaskPoints(); currentHours = sprint.getTaskRemainsPoints(); ReleasePlanHelper releasePlanHelper = new ReleasePlanHelper(project); releaseId = releasePlanHelper.getReleaseIdBySprintId(currentSprintId); SprintGoal = sprintBacklogMapper.getSprintGoal(); StoryChartUrl = board.getStoryChartLink(); TaskChartUrl = board.getTaskChartLink(); if(sprintBacklogMapper.getSprintEndDate().getTime() > (new Date()).getTime()) isCurrentSprint = true; } try { result = Translation.translateSprintInfoToJson( currentSprintId, initialPoint, currentPoint, initialHours, currentHours, releaseId, SprintGoal, StoryChartUrl, TaskChartUrl, isCurrentSprint); response.setContentType("text/html; charset=utf-8"); response.getWriter().write(result); response.getWriter().close(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e1) { e1.printStackTrace(); } return null; }