/** * Pop an array or object scope. * @param c The scope to close. * @throws JSONException If nesting is wrong. */ private void pop(char c) throws JSONException { if (this.top <= 0 || this.stack[this.top - 1] != c) { throw new JSONException("Nesting error."); } this.top -= 1; this.mode = this.top == 0 ? 'd' : this.stack[this.top - 1]; }
/** * {@inheritDoc} */ public String getErrorJSON(final String msg) { final JSONObject json = new JSONObject(); try { json.put("status", "error"); json.put("msg", msg); return json.toString(); } catch (JSONException e) { log.error("Error creating JSON Error response message: {}", e.getMessage()); return JSON_EXCEPTION_MSG; } }
e.printStackTrace(); throw new NoMatchingJsonSchemaException();
@Override public JSONObject handleResponse(HttpResponse httpResponse) throws ClientProtocolException, IOException { String json = handler.handleResponse(httpResponse); if (json == null) { return null; } try { return new JSONObject(json); } catch (JSONException e) { JSONObject jsonObject = new JSONObject(); try { jsonObject.put("error", e.getMessage()); } catch (JSONException e1) { log.error("Could not form a JSON error response", e); } return jsonObject; } } }
e.printStackTrace(); throw new NoMatchingJsonSchemaException();
@Override public final void doPost(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws IOException { final ResourceResolver resourceResolver = request.getResourceResolver(); final boolean preview = Boolean.parseBoolean(request.getParameter("preview")); log.debug("Preview mode: {}", preview); final ValueMap properties = this.getProperties(request); try { final List<PathFilterSet> paths = this.findPaths(resourceResolver, properties.get("authorizableIds", new String[0])); doPackaging(request, response, preview, properties, paths); } catch (RepositoryException ex) { log.error("Repository error while creating Query Package", ex); response.getWriter().print(packageHelper.getErrorJSON(ex.getMessage())); } catch (IOException ex) { log.error("IO error while creating Query Package", ex); response.getWriter().print(packageHelper.getErrorJSON(ex.getMessage())); } catch (JSONException ex) { log.error("JSON error while creating Query Package response", ex); response.getWriter().print(packageHelper.getErrorJSON(ex.getMessage())); } }
/** * Push an array or object scope. * @param c The scope to open. * @throws JSONException If nesting is too deep. */ private void push(char c) throws JSONException { if (this.top >= maxdepth) { throw new JSONException("Nesting too deep (maximum is " + maxdepth + " levels)"); } this.stack[this.top] = c; this.mode = c; this.top += 1; }
@Override public final void doPost(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws IOException { final ResourceResolver resourceResolver = request.getResourceResolver(); final boolean preview = Boolean.parseBoolean(request.getParameter("preview")); log.trace("Preview mode: {}", preview); final ValueMap properties = this.getProperties(request); final String[] principalNames = properties.get(PRINCIPAL_NAMES, new String[]{}); final List<PathFilterSet> packageResources = this.findResources(resourceResolver, Arrays.asList(principalNames), toPatterns(Arrays.asList(properties.get(INCLUDE_PATTERNS, new String[]{})))); try { // Add Principals if (properties.get(INCLUDE_PRINCIPALS, DEFAULT_INCLUDE_PRINCIPALS)) { packageResources.addAll(this.getPrincipalResources(resourceResolver, principalNames)); } doPackaging(request, response, preview, properties, packageResources); } catch (RepositoryException ex) { log.error(ex.getMessage()); response.getWriter().print(packageHelper.getErrorJSON(ex.getMessage())); } catch (IOException ex) { log.error(ex.getMessage()); response.getWriter().print(packageHelper.getErrorJSON(ex.getMessage())); } catch (JSONException ex) { log.error(ex.getMessage()); response.getWriter().print(packageHelper.getErrorJSON(ex.getMessage())); } }
/** * Throw an exception if the object is an NaN or infinite number. * @param o The object to test. * @throws JSONException If o is a non-finite number. */ public void testNumberValidity(Object o) throws JSONException { if (o != null) { if (o instanceof Double) { if (((Double)o).isInfinite() || ((Double)o).isNaN()) { throw new JSONException( "JSON does not allow non-finite numbers"); } } else if (o instanceof Float) { if (((Float)o).isInfinite() || ((Float)o).isNaN()) { throw new JSONException( "JSON does not allow non-finite numbers."); } } } }
@SuppressWarnings("unchecked") @Override protected final void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { final JSONObject json = new JSONObject(); try { json.put("slowQueries", this.compositeQueryDataToJSON((Collection<CompositeData>) queryStatManagerMBean .getSlowQueries().values()) ); } catch (JSONException e) { log.error("Unable to serial Slow Queries into JSON: {}", e.getMessage()); } try { json.put("popularQueries", this.compositeQueryDataToJSON((Collection<CompositeData>) queryStatManagerMBean .getPopularQueries().values())); } catch (JSONException e) { log.error("Unable to serial Popular Queries into JSON: {}", e.getMessage()); } response.setContentType("application/json"); response.getWriter().print(json.toString()); }
/** * Make a JSONException to signal a syntax error. * * @param message The error message. * @return A JSONException object, suitable for throwing */ public JSONException syntaxError(String message) { return new JSONException(message + toString()); }
response.getWriter().write(json.toString(2)); } catch (JSONException e) { log.error(e.getMessage()); this.sendJSONError(response, "Form errors",
throw new JSONException("Null pointer"); throw new JSONException(e); return this; throw new JSONException("Value out of sequence.");
} catch (JSONException ex) { log.error("JSON error while creating Query Package response", ex); response.getWriter().print(packageHelper.getErrorJSON(ex.getMessage()));
/** * Get the object value associated with an index. * @param index * The index must be between 0 and length() - 1. * @return An object value. * @throws JSONException If there is no value for the index. */ public Object get(int index) throws JSONException { Object o = opt(index); if (o == null) { throw new JSONException("JSONArray[" + index + "] not found."); } return o; }
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } catch (JSONException e) { log.error(e.getMessage()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } finally {
/** * End something. * @param m Mode * @param c Closing character * @return this * @throws JSONException If unbalanced. */ private JSONWriter end(char m, char c) throws JSONException { if (this.mode != m) { throw new JSONException(m == 'o' ? "Misplaced endObject." : "Misplaced endArray."); } this.pop(m); try { if (tidy) { this.writer.write('\n'); this.writer.write(INDENTS[top]); } this.writer.write(c); } catch (IOException e) { throw new JSONException(e); } this.comma = true; return this; }
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid JSON data: " + ex.getMessage()); return;
throw new JSONException("Null key."); return this; } catch (IOException e) { throw new JSONException(e); throw new JSONException("Misplaced key.");
"Could not collect Bulk Workflow status.", e.getMessage());