List of usage examples for java.lang Exception toString
public String toString()
From source file:com.keybox.manage.db.ProfileDB.java
/** * deletes profile//from w w w . j a v a 2 s. c o m * * @param profileId profile id */ public static void deleteProfile(Long profileId) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement("delete from profiles where id=?"); stmt.setLong(1, profileId); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } finally { DBUtils.closeConn(con); } }
From source file:com.photon.phresco.nativeapp.eshop.json.JSONHelper.java
/** * POST the JSON object to the specified URL, and get the response back * * @param url/*from w w w . j av a2s .co m*/ * @return JSONObject * @throws Exception */ public static JSONObject postJSONObjectToURL(String url, String jsonParam) throws IOException { InputStream is = null; String result = null; JSONObject jObject = null; // Post json data to server, and get the response try { // jObject = new JSONObject(); jObject = new JSONObject(jsonParam); // jObject.getJSONObject(jsonParam); PhrescoLogger.info(TAG + "JSON POST OBJECT: " + jObject); } catch (Exception ex) { PhrescoLogger.info(TAG + "postJSONObjectToURL: " + ex.toString()); PhrescoLogger.warning(ex); } try { is = HttpRequest.post(url, jObject); } catch (ClientProtocolException ex) { PhrescoLogger.info(TAG + "postJSONObjectToURL - ClientProtocolException: " + ex.toString()); PhrescoLogger.warning(ex); } catch (MalformedURLException ex) { PhrescoLogger.info(TAG + "postJSONObjectToURL - MalformedURLException: " + ex.toString()); PhrescoLogger.warning(ex); } catch (UnsupportedEncodingException ex) { PhrescoLogger.info(TAG + "postJSONObjectToURL - UnsupportedEncodingException: " + ex.toString()); PhrescoLogger.warning(ex); } catch (IllegalStateException ex) { PhrescoLogger.info(TAG + "postJSONObjectToURL - IllegalStateException: " + ex.toString()); PhrescoLogger.warning(ex); } // Convert the input stream in to string try { BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), Integer.parseInt("8")); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); reader.close(); result = sb.toString(); // PhrescoLogger.info(TAG + "JSON Response String: " + result); } catch (Exception ex) { PhrescoLogger.info(TAG + ex.toString()); PhrescoLogger.warning(ex); } // Parse the string to a JSON object try { jObject = new JSONObject(result); } catch (Exception ex) { PhrescoLogger.info(TAG + "postJSONObjectToURL() - JSONException: " + ex.toString()); PhrescoLogger.warning(ex); } return jObject; }
From source file:com.keybox.manage.db.ProfileDB.java
/** * inserts new profile//ww w . jav a2s .c o m * * @param profile profile object */ public static void insertProfile(Profile profile) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement("insert into profiles (nm, desc) values (?,?)"); stmt.setString(1, profile.getNm()); stmt.setString(2, profile.getDesc()); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } finally { DBUtils.closeConn(con); } }
From source file:com.keybox.manage.db.ProfileDB.java
/** * updates profile//from ww w . j a v a2 s . c o m * * @param profile profile object */ public static void updateProfile(Profile profile) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement("update profiles set nm=?, desc=? where id=?"); stmt.setString(1, profile.getNm()); stmt.setString(2, profile.getDesc()); stmt.setLong(3, profile.getId()); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } finally { DBUtils.closeConn(con); } }
From source file:eionet.gdem.conversion.ssr.SaveHandler.java
static void handleWorkqueue(HttpServletRequest req, String action) { AppUser user = SecurityUtil.getUser(req, Names.USER_ATT); String user_name = null;//from www. j a va2 s.c o m if (user != null) { user_name = user.getUserName(); } if (action.equals(Names.WQ_DEL_ACTION)) { try { if (!SecurityUtil.hasPerm(user_name, "/" + Names.ACL_WQ_PATH, "d")) { req.setAttribute(Names.ERROR_ATT, "You don't have permissions to delete jobs!"); return; } } catch (Exception e) { req.setAttribute(Names.ERROR_ATT, "Cannot read permissions: " + e.toString()); return; } StringBuffer err_buf = new StringBuffer(); // String del_id = (String)req.getParameter("ID"); String[] jobs = req.getParameterValues("jobID"); try { if (jobs.length > 0) { // delete also result files from file system tmp folder try { for (int i = 0; i < jobs.length; i++) { String jobData[] = GDEMServices.getDaoService().getXQJobDao().getXQJobData(jobs[i]); if (jobData == null || jobData.length < 3) { continue; } String resultFile = jobData[2]; try { Utils.deleteFile(resultFile); } catch (Exception e) { LOGGER.error( "Could not delete job result file: " + resultFile + "." + e.getMessage()); } // delete xquery files, if they are stored in tmp folder String xqFile = jobData[1]; try { // Important!!!: delete only, when the file is stored in tmp folder if (xqFile.startsWith(Properties.tmpFolder)) { Utils.deleteFile(xqFile); } } catch (Exception e) { LOGGER.error( "Could not delete XQuery script file: " + xqFile + "." + e.getMessage()); } } } catch (Exception e) { LOGGER.error("Could not delete job result files!" + e.getMessage()); } GDEMServices.getDaoService().getXQJobDao().endXQJobs(jobs); } } catch (Exception e) { err_buf.append("Cannot delete job: " + e.toString() + jobs); } if (err_buf.length() > 0) { req.setAttribute(Names.ERROR_ATT, err_buf.toString()); } } else if (action.equals(Names.WQ_RESTART_ACTION)) { try { if (!SecurityUtil.hasPerm(user_name, "/" + Names.ACL_WQ_PATH, "u")) { req.setAttribute(Names.ERROR_ATT, "You don't have permissions to restart the jobs!"); return; } } catch (Exception e) { req.setAttribute(Names.ERROR_ATT, "Cannot read permissions: " + e.toString()); return; } StringBuffer err_buf = new StringBuffer(); String[] jobs = req.getParameterValues("jobID"); try { if (jobs.length > 0) { GDEMServices.getDaoService().getXQJobDao().changeXQJobsStatuses(jobs, Constants.XQ_RECEIVED); } } catch (Exception e) { err_buf.append("Cannot restart jobs: " + e.toString() + jobs); } if (err_buf.length() > 0) { req.setAttribute(Names.ERROR_ATT, err_buf.toString()); } } }
From source file:eu.sisob.uma.restserver.services.crawler.CrawlerTask.java
public static boolean launch(String user, String pass, String task_code, String code_task_folder, String email, StringWriter message) {//from w w w . ja va 2 s . c o m if (message == null) { return false; } boolean success = false; message.getBuffer().setLength(0); File code_task_folder_dir = new File(code_task_folder); File csv_data_source_file = FileSystemManager.getFileIfExists(code_task_folder_dir, input_data_source_filename_prefix_csv, input_data_source_filename_ext_csv); boolean validate = csv_data_source_file != null; if (!validate) { success = false; message.write("You have not uploaded 'data-researchers-urls.csv' file"); //FIXME } org.dom4j.Document document = null; String middle_data_folder = code_task_folder + File.separator + AuthorizationManager.middle_data_dirname; File middle_data_dir = null; try { middle_data_dir = FileSystemManager.createFileAndIfExistsDelete(middle_data_folder); } catch (Exception ex) { ProjectLogger.LOGGER.error(ex.toString(), ex); message.append("The file couldn't be created " + middle_data_dir.getName() + "\r\n"); return false; } String results_data_folder = code_task_folder + File.separator + AuthorizationManager.results_dirname; File results_data_dir = null; try { results_data_dir = FileSystemManager.createFileAndIfExistsDelete(results_data_folder); } catch (Exception ex) { ProjectLogger.LOGGER.error(ex.toString(), ex); message.append("The file couldn't be created " + results_data_dir.getName() + "\r\n"); return false; } try { File middle_data_source_file = new File(middle_data_dir, middle_data_source_filename_xml); validate = FileFormatConversor.createResearchersXMLFileFromCSV(csv_data_source_file, middle_data_source_file); } catch (Exception ex) { ProjectLogger.LOGGER.error(ex.getMessage(), ex); validate = false; } if (!validate) { message.append("The format of '" + csv_data_source_file.getName() + "' does not seems be correct. Please check the headers of the csv file (read in the instructions which are optionals) and be sure that the field separators are ';'. Please read the intructions of the task." + "\r\n"); return false; } try { File xmlFile = new File(middle_data_folder, middle_data_source_filename_xml); org.dom4j.io.SAXReader reader = new org.dom4j.io.SAXReader(); document = reader.read(xmlFile); } catch (Exception ex) { message.write("The format of '" + csv_data_source_file.getName() + "' does not seems be correct"); //FIXME ProjectLogger.LOGGER.error(message.toString(), ex); return false; } String out_filename = csv_data_source_file.getName().replace(input_data_source_filename_prefix_csv, output_data_source_filename_csv); File csv_data_output_file = new File(results_data_dir, out_filename); ResearchersCrawlerTaskInRest task = new ResearchersCrawlerTaskInRest(document, new File(ResearchersCrawlerService.CRAWLER_DATA_PATH), middle_data_dir, results_data_dir, csv_data_output_file, user, pass, task_code, code_task_folder, email); try { ResearchersCrawlerService.getInstance().addExecution(new CallbackableTaskExecution(task)); success = true; message.write(TheResourceBundle.getString("Jsp Task Executed Msg")); } catch (InterruptedException ex) { message.write(TheResourceBundle.getString("Jsp Task Executed Error Msg")); ProjectLogger.LOGGER.error(message.toString(), ex); return false; } return true; }
From source file:com.nbos.phonebook.sync.client.User.java
/** * Creates and returns an instance of the user from the provided JSON data. * /*from www . j ava 2 s . co m*/ * @param user The JSONObject containing user data * @return user The new instance of Voiper user created from the JSON data. */ public static User valueOf(JSONObject user) { try { // final String userName = user.getString("u"); final String firstName = user.has("name") ? user.getString("name") : null; // final String lastName = user.has("l") ? user.getString("l") : null; final String cellPhone = user.has("number") ? user.getString("number") : null; //final String officePhone = // user.has("o") ? user.getString("o") : null; //final String homePhone = user.has("h") ? user.getString("h") : null; //final String email = user.has("e") ? user.getString("e") : null; //final boolean deleted = // user.has("d") ? user.getBoolean("d") : false; final int userId = user.getInt("id"); String picId = user.getString("pic"); Log.i(tag, "name: " + firstName + ", picId is: " + picId); User u = new User(firstName, cellPhone, new Integer(userId).toString()); u.setPicId(picId); return u; } catch (final Exception ex) { Log.i(tag, "Error parsing JSON user object" + ex.toString()); } return null; }
From source file:com.topsec.tsm.sim.util.TalVersionUtil.java
public static String getVersionInfo() { String endpoint;// ww w . j ava 2s . co m IpAddress addr = IpAddress.getLocalIp(); if (addr.isIpv4Compatible()) endpoint = new StringBuilder().append("jnp://localhost:").append(CheckResource.JNDI_PORT).toString(); else endpoint = new StringBuilder().append("jnp://[").append(addr.toString()).append("]").toString(); String haspID = ""; String expireTime = null; String max_tal_num = "0"; String license_valid = null; String license_error = null; try { JMXWrapper jmxWrapper = new JMXWrapper(endpoint, "topsec.deployment:type=ServicesDeployer"); BasicServicesDeployerMBean mbean = jmxWrapper.getProxy(BasicServicesDeployerMBean.class); String ret = mbean.getInfo("Test"); String ttt[] = ret.substring(1, ret.length() - 1).split(","); for (int i = 0; i < ttt.length; i++) { if (ttt[i].trim().indexOf("EXPIRE_TIME") != -1) { expireTime = ttt[i].split("=")[1]; } if (ttt[i].trim().indexOf("TSM_ASSET_NUM") != -1) { max_tal_num = ttt[i].split("=")[1]; } if (ttt[i].trim().indexOf("HASP_ID") != -1) { haspID = ttt[i].split("=")[1]; } if (ttt[i].trim().indexOf("LICENSE_VALID") != -1) { license_valid = ttt[i].split("=")[1]; } if (ttt[i].trim().indexOf("LICENSE_STATE") != -1) { license_error = ttt[i].split("=")[1]; } } } catch (Exception e) { System.err.println(e.toString()); } if (license_valid == null) { haspID = ""; expireTime = ""; max_tal_num = "0()"; } else if (license_valid.equals("0")) { haspID = ""; expireTime = ""; if (license_error != null) { if (license_error.equals(LicenceStateConstants.LICENCE_FILE_INVALID)) { max_tal_num = "0()"; } else { max_tal_num = "0(License Key )"; } } } if ("-1".equals(haspID) && expireTime != null) { return " (:" + expireTime + ")"; } return ""; }
From source file:eu.sisob.uma.restserver.services.gate.GateTask.java
public static boolean launch(String user, String pass, String task_code, String code_task_folder, String email, StringWriter message, boolean verbose, boolean split_by_keyword) { if (message == null) { return false; }/* w w w .ja v a2s . c o m*/ boolean success = false; message.getBuffer().setLength(0); File code_task_folder_dir = new File(code_task_folder); File documents_dir = code_task_folder_dir; File csv_data_source_file = FileSystemManager.getFileIfExists(code_task_folder_dir, input_data_source_filename_prefix_csv, input_data_source_filename_ext_csv); boolean validate = csv_data_source_file != null; if (!validate) { success = false; message.write("You have not uploaded any file like this '" + input_data_source_filename_prefix_csv + "*" + input_data_source_filename_ext_csv + "' file"); } else { String middle_data_folder = code_task_folder + File.separator + AuthorizationManager.middle_data_dirname; File middle_data_dir = null; try { middle_data_dir = FileSystemManager.createFileAndIfExistsDelete(middle_data_folder); } catch (Exception ex) { ProjectLogger.LOGGER.error(ex.toString(), ex); message.append("The file couldn't be created " + middle_data_dir.getName() + "\r\n"); } String results_data_folder = code_task_folder + File.separator + AuthorizationManager.results_dirname; File results_data_dir = null; try { results_data_dir = FileSystemManager.createFileAndIfExistsDelete(results_data_folder); } catch (Exception ex) { ProjectLogger.LOGGER.error(ex.toString(), ex); message.append("The file couldn't be created " + results_data_dir.getName() + "\r\n"); } File zip_file = new File(code_task_folder_dir, input_data_documents_in_zip); if (zip_file.exists()) { documents_dir = new File(code_task_folder_dir, AuthorizationManager.middle_data_dirname); if (!ZipUtil.unZipItToSameFolder(zip_file, documents_dir)) { success = false; message.write(input_data_documents_in_zip + " cannot bet unziped"); //FIXME return success; } else { } } RepositoryPreprocessDataMiddleData preprocessedRep = null; try { File verbose_dir = null; if (verbose) { verbose_dir = new File(code_task_folder_dir, AuthorizationManager.verbose_dirname); if (!verbose_dir.exists()) verbose_dir.mkdir(); } HashMap<String, String[]> blocks_and_keywords = null; if (split_by_keyword) { blocks_and_keywords = GateDataExtractorService.getInstance().getBlocksAndKeywords(); } preprocessedRep = GateDataExtractorSingle.createPreprocessRepositoryFromCSVFile( csv_data_source_file, ';', documents_dir, verbose, verbose_dir, split_by_keyword, blocks_and_keywords, middle_data_dir); } catch (Exception ex) { message.append("The format of '" + csv_data_source_file.getName() + "' does not seems be correct. Please check the headers of the csv file (read in the instructions which are optionals) and be sure that the field separators are ';'. Please read the intructions of the task. \r\nAlso check that you have uploaded all the documents referenced in the csv file (if you have upload all the documents compressed in " + input_data_documents_in_zip + " file, please, check that it has all the files referenced in the csv).<br>Message: " + ex.getMessage()); //FIXME ProjectLogger.LOGGER.error(message.toString(), ex); } if (preprocessedRep != null) { H2DBCredentials cred_resolver = GateDataExtractorService.getH2DBCredentials_Resolver(); H2DBCredentials cred_trad = GateDataExtractorService.getH2DBCredentials_Trad_Tables_Academic(); GateDataExtractorTaskInRest task = new GateDataExtractorTaskInRest(preprocessedRep, true, cred_trad, true, cred_resolver, user, pass, task_code, code_task_folder, email); try { GateDataExtractorService.getInstance() .addExecution((new CallbackableTaskExecutionWithResource(task))); success = true; message.write(TheResourceBundle.getString("Jsp Task Executed Msg")); } catch (Exception ex) { success = false; message.write(TheResourceBundle.getString("Jsp Task Executed Error Msg")); ProjectLogger.LOGGER.error(message.toString(), ex); validate = false; } } } return success; }
From source file:eu.alefzero.owncloud.authenticator.EasySSLSocketFactory.java
private static SSLContext createEasySSLContext() { try {// ww w .j a va2 s .c o m SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { new EasyX509TrustManager(null) }, null); return context; } catch (Exception er) { Log.e(TAG, er.getMessage() + ""); throw new HttpClientError(er.toString()); } }