List of usage examples for org.json.simple.parser ParseException getMessage
public String getMessage()
From source file:io.personium.client.ODataResponse.java
/** * This method returns the response in JSON format. * @return JSON object/* w ww. j a v a 2s . c o m*/ * @throws DaoException Exception thrown */ public final JSONObject bodyAsJson() throws DaoException { String res = bodyAsString(); try { return (JSONObject) new JSONParser().parse(res); } catch (ParseException e) { throw DaoException.create("parse exception: " + e.getMessage(), 0); } }
From source file:edu.vt.vbi.patric.common.ExpressionDataCollection.java
public void read(String input) throws FileNotFoundException { List<String> temp = null; if (input.equals(CONTENT_SAMPLE)) { temp = sampleFileName;//ww w.ja v a 2s. co m } else if (input.equals(CONTENT_EXPRESSION)) { temp = expressionFileName; } assert temp != null; for (String aTemp : temp) { try { String strLine = readFileContent(aTemp); JSONObject tmp = (JSONObject) new JSONParser().parse(strLine); AddToCurrentSet((JSONArray) tmp.get(input), input); } catch (ParseException e) { LOGGER.error(e.getMessage(), e); } } }
From source file:emcali.ami.control.webservice.IPTVAMIWebService.java
/** * This is a sample web service operation * * @param args/* www.j a va 2s . c o m*/ * @return */ @WebMethod(operationName = "execute") public String execute(@WebParam(name = "args") String args) { JSONObject jsonResponse = new JSONObject(); try { JSONParser parser = new JSONParser(); Object obj = parser.parse(args); JSONObject jsonRequest = (JSONObject) obj; String user = (String) jsonRequest.get("user"); String password = (String) jsonRequest.get("password"); Credentials credentials = new Credentials(); String message = credentials.authenticate(user, password); switch (message) { case "user unauthorized": jsonResponse.put("type", "error"); jsonResponse.put("message", message); break; case "wrong password": jsonResponse.put("type", "error"); jsonResponse.put("message", message); break; case "success": jsonResponse.put("type", "info"); jsonResponse.put("message", message); if (((String) jsonRequest.get("command")).equals("getData")) { jsonResponse = this.getData(jsonRequest, jsonResponse); } break; } return jsonResponse.toJSONString(); } catch (ParseException ex) { jsonResponse.put("type", "error"); jsonResponse.put("message", "JSON Format error: " + ex.getMessage()); return jsonResponse.toJSONString(); } }
From source file:hudson.plugins.memegen.MemegeneratorResponseException.java
public boolean instanceCreate(Meme meme) { boolean ret = false; HashMap<String, String> vars = new HashMap(); vars.put("username", username); vars.put("password", password); vars.put("text0", meme.getUpperText()); vars.put("text1", meme.getLowerText()); vars.put("generatorID", "" + meme.getGeneratorID()); vars.put("imageID", "" + meme.getImageID()); try {/*from w w w. j a v a2 s. co m*/ URL url = buildURL("Instance_Create", vars); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); HttpURLConnection.setFollowRedirects(true); conn.setDoOutput(true); JSONObject obj = parseResponse(conn); JSONObject result = (JSONObject) obj.get("result"); String memeUrl = (String) result.get("instanceImageUrl"); if (memeUrl.matches("^http(.*)") == false) { memeUrl = APIURL + memeUrl; } //Debug the JSON to logs //System.err.println(obj.toJSONString()+", AND "+result.toJSONString()); meme.setImageURL(memeUrl); ret = true; } catch (MalformedURLException me) { String log_warn_prefix = "Memegenerator API malformed URL: "; System.err.println(log_warn_prefix.concat(me.getMessage())); } catch (IOException ie) { String log_warn_prefix = "Memegenerator API IO exception: "; System.err.println(log_warn_prefix.concat(ie.getMessage())); } catch (ParseException pe) { String log_warn_prefix = "Memegenerator API malformed response: "; System.err.println(log_warn_prefix.concat(pe.getMessage())); } catch (MemegeneratorResponseException mre) { String log_warn_prefix = "Memegenerator API failure: "; System.err.println(log_warn_prefix.concat(mre.getMessage())); } catch (MemegeneratorJSONException mje) { String log_warn_prefix = "Memegenerator API malformed JSON: "; System.err.println(log_warn_prefix.concat(mje.getMessage())); } return ret; }
From source file:com.fujitsu.dc.test.utils.TResponse.java
/** * ?JSON??./*from w w w .ja v a2 s.c om*/ * @return JSON */ public JSONObject bodyAsJson() { String res = null; res = this.bodyWriter.toString(); JSONObject jsonobject = null; try { jsonobject = (JSONObject) new JSONParser().parse(res); } catch (ParseException e) { fail(e.getMessage()); } return jsonobject; }
From source file:com.conwet.xjsp.session.Negotiator.java
/** * Consume available data and returns a new state when a transition is * reached.//from w ww .j a va 2s. c om * * TODO: violates the least-surprise principle * * @param buffer * @return State to transit to or null * @throws ConnectionException */ private NegotiationPhase consumeData(StringBuilder buffer) throws ConnectionException { Matcher m; switch (phase) { case start: m = START_PATTERN.matcher(buffer); if (m.find()) { buffer.replace(0, m.end(), ""); return NegotiationPhase.header; } return null; case header: try { String header = JSONUtil.extractStanza(buffer); if (header == null) { return null; } JSONObject jsonHeader = (JSONObject) parser.parse(header); validateHeader(jsonHeader); extractFeaturePrefixes(jsonHeader); return NegotiationPhase.messages; } catch (ParseException ex) { throw new ConnectionException(ConnError.ProtocolSyntaxError, "Invalid header: " + ex.getMessage()); } case messages: m = MESSAGE_PATTERN.matcher(buffer); if (m.find()) { buffer.replace(0, m.end(), ""); return NegotiationPhase.finished; } return null; case finished: return null; default: // should never reach this point throw new IllegalStateException("Unexpected exception"); } }
From source file:com.michaeljones.hellohadoop.restclient.HadoopHdfsRestClient.java
public String[] ListDirectorySimple(String remoteRelativePath) { try {//from www . j a v a2s .co m // %1 nameNodeHost, %2 username %3 resource. String uri = String.format(BASIC_URL_FORMAT, nameNodeHost, username, remoteRelativePath); List<Pair<String, String>> queryParams = new ArrayList(); queryParams.add(new Pair<>("user.name", username)); queryParams.add(new Pair<>("op", "LISTSTATUS")); String content = restImpl.GetStringContent(uri, queryParams); JSONParser parser = new JSONParser(); JSONObject jsonObject = (JSONObject) parser.parse(content); JSONObject listStatus = (JSONObject) jsonObject.get("FileStatuses"); JSONArray fileList = (JSONArray) listStatus.get("FileStatus"); String[] directoryListing = new String[fileList.size()]; int directoryIndex = 0; for (Object listing : fileList) { JSONObject jsonListing = (JSONObject) listing; String pathname = jsonListing.get("pathSuffix").toString(); directoryListing[directoryIndex++] = pathname; } return directoryListing; } catch (ParseException ex) { LOGGER.error("Hadoop List directory failed: " + ex.getMessage()); throw new RuntimeException("Hadoop List directory failed :" + ex.getMessage()); } finally { restImpl.Close(); } }
From source file:com.stackmob.example.SendGrid.java
@Override public ResponseToProcess execute(ProcessedAPIRequest request, SDKServiceProvider serviceProvider) { int responseCode = 0; String responseBody = ""; String username = ""; String subject = ""; String text = ""; String from = ""; String to = ""; String toname = ""; String body = ""; String url = ""; LoggerService logger = serviceProvider.getLoggerService(SendGrid.class); //Log the JSON object passed to the StackMob Logs logger.debug(request.getBody());//from ww w .j a v a 2 s . c o m JSONParser parser = new JSONParser(); try { Object obj = parser.parse(request.getBody()); JSONObject jsonObject = (JSONObject) obj; //We use the username passed to query the StackMob datastore //and retrieve the user's name and email address username = (String) jsonObject.get("username"); // The following values could be static or dynamic subject = (String) jsonObject.get("subject"); text = (String) jsonObject.get("text"); from = (String) jsonObject.get("from"); } catch (ParseException e) { logger.error(e.getMessage(), e); responseCode = -1; responseBody = e.getMessage(); } if (username == null || username.isEmpty()) { HashMap<String, String> errParams = new HashMap<String, String>(); errParams.put("error", "the username passed was empty or null"); return new ResponseToProcess(HttpURLConnection.HTTP_BAD_REQUEST, errParams); // http 400 - bad request } // get the StackMob datastore service and assemble the query DataService dataService = serviceProvider.getDataService(); // build a query List<SMCondition> query = new ArrayList<SMCondition>(); query.add(new SMEquals("username", new SMString(username))); SMObject userObject; List<SMObject> result; try { // return results from user query result = dataService.readObjects("user", query); if (result != null && result.size() == 1) { userObject = result.get(0); to = userObject.getValue().get("email").toString(); toname = userObject.getValue().get("name").toString(); } else { HashMap<String, String> errMap = new HashMap<String, String>(); errMap.put("error", "no user found"); errMap.put("detail", "no matches for the username passed"); return new ResponseToProcess(HttpURLConnection.HTTP_OK, errMap); // http 500 - internal server error } } catch (InvalidSchemaException e) { HashMap<String, String> errMap = new HashMap<String, String>(); errMap.put("error", "invalid_schema"); errMap.put("detail", e.toString()); return new ResponseToProcess(HttpURLConnection.HTTP_INTERNAL_ERROR, errMap); // http 500 - internal server error } catch (DatastoreException e) { HashMap<String, String> errMap = new HashMap<String, String>(); errMap.put("error", "datastore_exception"); errMap.put("detail", e.toString()); return new ResponseToProcess(HttpURLConnection.HTTP_INTERNAL_ERROR, errMap); // http 500 - internal server error } catch (Exception e) { HashMap<String, String> errMap = new HashMap<String, String>(); errMap.put("error", "unknown"); errMap.put("detail", e.toString()); return new ResponseToProcess(HttpURLConnection.HTTP_INTERNAL_ERROR, errMap); // http 500 - internal server error } if (subject == null || subject.equals("")) { logger.error("Subject is missing"); } //Encode any parameters that need encoding (i.e. subject, toname, text) try { subject = URLEncoder.encode(subject, "UTF-8"); text = URLEncoder.encode(text, "UTF-8"); toname = URLEncoder.encode(toname, "UTF-8"); } catch (UnsupportedEncodingException e) { logger.error(e.getMessage(), e); } String queryParams = "api_user=" + API_USER + "&api_key=" + API_KEY + "&to=" + to + "&toname=" + toname + "&subject=" + subject + "&text=" + text + "&from=" + from; url = "https://www.sendgrid.com/api/mail.send.json?" + queryParams; Header accept = new Header("Accept-Charset", "utf-8"); Header content = new Header("Content-Type", "application/x-www-form-urlencoded"); Set<Header> set = new HashSet(); set.add(accept); set.add(content); try { HttpService http = serviceProvider.getHttpService(); PostRequest req = new PostRequest(url, set, body); HttpResponse resp = http.post(req); responseCode = resp.getCode(); responseBody = resp.getBody(); } catch (TimeoutException e) { logger.error(e.getMessage(), e); responseCode = -1; responseBody = e.getMessage(); } catch (AccessDeniedException e) { logger.error(e.getMessage(), e); responseCode = -1; responseBody = e.getMessage(); } catch (MalformedURLException e) { logger.error(e.getMessage(), e); responseCode = -1; responseBody = e.getMessage(); } catch (ServiceNotActivatedException e) { logger.error(e.getMessage(), e); responseCode = -1; responseBody = e.getMessage(); } Map<String, Object> map = new HashMap<String, Object>(); map.put("response_body", responseBody); return new ResponseToProcess(responseCode, map); }
From source file:com.fujitsu.dc.client.http.DcResponse.java
/** * This method is used to the response body in JSON format. * @return JSONObject/* w ww .j a va 2 s.com*/ * @throws DaoException Exception thrown */ public JSONObject bodyAsJson() throws DaoException { String res = bodyAsString(); try { return (JSONObject) new JSONParser().parse(res); } catch (ParseException e) { throw DaoException.create("parse exception: " + e.getMessage(), 0); } }
From source file:com.capitalone.dashboard.datafactory.versionone.VersionOneDataFactoryImpl.java
/** * Mutator method for JSON response output array. * * @return JSON response array from VersionOne *//*from w w w .jav a2 s. c o m*/ private void setJsonOutputArray(String stringResult) { JSONParser parser = new JSONParser(); Object nativeRs = null; try { nativeRs = parser.parse(stringResult); } catch (ParseException e) { LOGGER.error("There was a problem parsing the JSONArray response value from the source system:\n" + e.getMessage() + " | " + e.getCause()); } JSONArray canonicalRs = (JSONArray) nativeRs; this.jsonOutputArray = canonicalRs; }