List of usage examples for java.lang Exception getLocalizedMessage
public String getLocalizedMessage()
From source file:net.bhira.sample.api.controller.CompanyController.java
/** * Fetch the instance of {@link net.bhira.sample.model.Company} represented by given companyId * and return it as JSON object./* w ww.j a v a 2 s . c om*/ * * @param companyId * the ID for {@link net.bhira.sample.model.Company}. * @param response * the http response to which the results will be written. * @return an instance of {@link net.bhira.sample.model.Company} as JSON. */ @RequestMapping(value = "/company/{companyId}", method = RequestMethod.GET) @ResponseBody public Callable<String> getCompany(@PathVariable long companyId, HttpServletResponse response) { return new Callable<String>() { public String call() throws Exception { String body = ""; try { LOG.debug("servicing GET company/{}", companyId); Company company = companyService.load(companyId); LOG.debug("GET company/{}, found = {}", companyId, company != null); if (company == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); } else { body = JsonUtil.createGson().toJson(company); } } catch (Exception ex) { response.setStatus(HttpServletResponse.SC_FORBIDDEN); body = ex.getLocalizedMessage(); LOG.warn("Error loading company/{}. {}", companyId, body); LOG.debug("Load error stacktrace: ", ex); } return body; } }; }
From source file:net.bhira.sample.api.controller.DepartmentController.java
/** * Delete the instance of {@link net.bhira.sample.model.Department} represented by given * departmentId. In case of an error return the error message. * //w ww . j a v a2 s . c om * @param departmentId * the ID for {@link net.bhira.sample.model.Department}. * @param response * the http response to which the results will be written. * @return the error message, if save was not successful. */ @RequestMapping(value = "/department/{departmentId}", method = RequestMethod.DELETE) @ResponseBody public Callable<String> deleteDepartment(@PathVariable long departmentId, HttpServletResponse response) { return new Callable<String>() { public String call() throws Exception { LOG.debug("servicing DELETE department/{}", departmentId); String body = ""; try { boolean success = departmentService.delete(departmentId); LOG.debug("DELETE department/{} status = {}", departmentId, success); if (!success) { response.setStatus(HttpServletResponse.SC_FORBIDDEN); } } catch (Exception ex) { response.setStatus(HttpServletResponse.SC_FORBIDDEN); body = ex.getLocalizedMessage(); LOG.warn("Error deleting department/{}. {}", departmentId, body); LOG.debug("Delete error stacktrace: ", ex); } return body; } }; }
From source file:com.amazonaws.mturk.cmd.AbstractCmd.java
public void run(String[] args) { try {// www . j ava 2 s.c o m BasicParser parser = new BasicParser(); CommandLine cmdLine = parser.parse(opt, args); if (cmdLine.hasOption(ARG_HELP) || cmdLine.hasOption(ARG_HELP_SHORT)) { printHelp(); System.exit(-1); } if (cmdLine.hasOption(ARG_SANDBOX) && !ClientConfig.SANDBOX_SERVICE_URL.equalsIgnoreCase(config.getServiceURL())) { log.info("Sandbox override"); setSandBoxMode(); } else { initService(); } log.debug(String.format("Running command against %s", config.getServiceURL())); runCommand(cmdLine); } catch (Exception e) { log.error("An error occurred: " + e.getLocalizedMessage(), e); System.exit(-1); } }
From source file:it.geosolutions.geobatch.migrationmonitor.statuschecker.CheckerAction.java
@Override public Queue<FileSystemEvent> execute(Queue<FileSystemEvent> arg0) throws ActionException { // return object final Queue<FileSystemEvent> outputEvents = new LinkedList<FileSystemEvent>(); try {/*from w w w.j a v a 2 s . c o m*/ //gather the input file in order to read the database table name File flowTempDirectory = new File(getTempDir().getParent()); File[] files = flowTempDirectory.listFiles(); File inputEventFile = null; if (files != null && files.length > 0) { for (File f : files) { if (f.isFile() && f.getName().endsWith(".xml")) { inputEventFile = f; } } } else { throw new Exception("One file, type xml, is expected in the root of the temp directory"); } // set as the action output event the flow input event FileSystemEvent fse = new FileSystemEvent(inputEventFile, FileSystemEventType.FILE_ADDED); outputEvents.add(fse); //parse the xml file and get the table name String tableName = ""; String host = ""; String db = ""; String schema = ""; try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder; dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(inputEventFile); doc.getDocumentElement().normalize(); NodeList nodes = doc.getElementsByTagName("typeName"); if (nodes == null || nodes.getLength() != 1) { throw new Exception( "more than one typeName has been found in the input event... this is not possible..."); } Node n = nodes.item(0); tableName = n.getTextContent(); NodeList entries = doc.getElementsByTagName("entry"); host = extractEntry("server", entries); if (host == null) { host = extractEntry("host", entries); } db = extractEntry("instance", entries); if (db == null) { db = extractEntry("database", entries); } schema = extractEntry("schema", entries); LOGGER.info("Changing state to MIGRATED for records with: server_ip:'" + host + "' db:'" + db + "' schema_nome:'" + schema + "' tabella:'" + tableName + "'"); } catch (Exception e) { LOGGER.error(e.getMessage(), e); throw new Exception("Error while parsing input file... exception message: " + e.getMessage()); } LOGGER.info("The table name is: " + tableName); //change the status in the strati_rif table MigrationMonitor mm = migrationMonitorDAO.findByTablename(host, db, schema, tableName); mm.setMigrationStatus(MigrationStatus.MIGRATED.toString().toUpperCase()); migrationMonitorDAO.merge(mm); } catch (Exception t) { final String message = "CheckerAction::execute(): " + t.getLocalizedMessage(); if (LOGGER.isErrorEnabled()) LOGGER.error(message, t); final ActionException exc = new ActionException(this, message, t); listenerForwarder.failed(exc); throw exc; } return outputEvents; }
From source file:com.aujur.ebookreader.catalog.LoadLocalOPDSTask.java
@Override protected Feed doInBackground(String... params) { String baseUrl = params[0];/*from w ww . ja va 2 s. co m*/ if (baseUrl == null || baseUrl.trim().length() == 0) { return null; } boolean isBaseFeed = baseUrl.equals(config.getBaseOPDSFeed()); baseUrl = baseUrl.trim(); try { AssetManager assetManager = context.getAssets(); InputStream stream = assetManager.open(baseUrl); Feed feed = Nucular.readAtomFeedFromStream(stream); feed.setURL(baseUrl); feed.setDetailFeed(asDetailsFeed); feed.setSearchFeed(asSearchFeed); for (Entry entry : feed.getEntries()) { entry.setBaseURL(baseUrl); } if (isBaseFeed) { addCustomSitesEntry(feed); } if (isCancelled()) { return null; } Link searchLink = feed.findByRel(AtomConstants.REL_SEARCH); if (searchLink != null) { URL mBaseUrl = new URL(baseUrl); URL mSearchUrl = new URL(mBaseUrl, searchLink.getHref()); searchLink.setHref(mSearchUrl.toString()); LOG.debug("Got searchLink of type " + searchLink.getType() + " with href=" + searchLink.getHref()); /* * Some sites report the search as OpenSearch, but still have * the searchTerms in the URL. If the URL already contains * searchTerms, we ignore the reported type and treat it as Atom */ if (searchLink.getHref().contains(AtomConstants.SEARCH_TERMS)) { searchLink.setType(AtomConstants.TYPE_ATOM); } if (AtomConstants.TYPE_OPENSEARCH.equals(searchLink.getType())) { String searchURL = searchLink.getHref(); LOG.debug("Attempting to download OpenSearch description from " + searchURL); // try { // currentRequest = new HttpGet(searchURL); // InputStream searchStream = httpClient // .execute(currentRequest).getEntity() // .getContent(); // // SearchDescription desc = Nucular // .readOpenSearchFromStream(searchStream); // // if (desc.getSearchLink() != null) { // searchLink.setHref(desc.getSearchLink().getHref()); // searchLink.setType(AtomConstants.TYPE_ATOM); // } // } catch (Exception searchIO) { // LOG.error("Could not get search info", searchIO); // } } LOG.debug("Using searchURL " + searchLink.getHref()); } return feed; } catch (Exception e) { this.errorMessage = e.getLocalizedMessage(); LOG.error("Download failed for url: " + baseUrl, e); return null; } }
From source file:es.urjc.mctwp.bbeans.research.image.DownloadBean.java
public String accDownloadImage() { if (imageId != null && !imageId.isEmpty()) { Trial trial = getSession().getTrial(); try {// w w w . j a va 2 s . com if (trial != null) { ZipOutputStream zos = prepareZOS(imageId); //Get Image LoadImage cmd = (LoadImage) getCommand(LoadImage.class); cmd.setCollection(trial.getCollection()); cmd.setImageId(imageId); cmd = (LoadImage) runCommand(cmd); Image img = cmd.getResult(); addImageToZos(zos, img, null); zos.close(); completeResponse(); } } catch (Exception e) { setErrorMessage(e.getLocalizedMessage()); e.printStackTrace(); } } return null; }
From source file:net.bhira.sample.api.controller.DepartmentController.java
/** * Fetch the instance of {@link net.bhira.sample.model.Department} represented by given * departmentId and return it as JSON object. * //from w w w . j a v a2 s . c om * @param departmentId * the ID for {@link net.bhira.sample.model.Department}. * @param response * the http response to which the results will be written. * @return an instance of {@link net.bhira.sample.model.Department} as JSON. */ @RequestMapping(value = "/department/{departmentId}", method = RequestMethod.GET) @ResponseBody public Callable<String> getDepartment(@PathVariable long departmentId, HttpServletResponse response) { return new Callable<String>() { public String call() throws Exception { String body = ""; try { LOG.debug("servicing GET department/{}", departmentId); Department department = departmentService.load(departmentId); LOG.debug("GET department/{}, found = {}", departmentId, department != null); if (department == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); } else { body = JsonUtil.createGson().toJson(department); } } catch (Exception ex) { response.setStatus(HttpServletResponse.SC_FORBIDDEN); body = ex.getLocalizedMessage(); LOG.warn("Error loading department/{}. {}", departmentId, body); LOG.debug("Load error stacktrace: ", ex); } return body; } }; }
From source file:com.adito.tunnels.TunnelPlugin.java
public void activatePlugin() throws ExtensionException { super.activatePlugin(); try {//from w w w . java 2s.co m initDatabase(); initPolicyFramework(); initTableItemActions(); initMainMenu(); initPageTasks(); initService(); CoreUtil.updateEventsTable(TunnelPlugin.MESSAGE_RESOURCES_KEY, TunnelsEventConstants.class); } catch (Exception e) { throw new ExtensionException(ExtensionException.INTERNAL_ERROR, e, e.getLocalizedMessage()); } }
From source file:com.willwinder.ugs.nbp.core.windows.StateTopComponent.java
private void executeNumber(char word, JTextField value) { if (!StringUtils.isNumeric(value.getText())) { value.setText("0"); GUIHelpers.displayErrorDialog("Provide numeric input."); return;/* ww w .j ava 2s . c o m*/ } if (backend.isIdle()) { try { backend.sendGcodeCommand(word + value.getText()); } catch (Exception ex) { GUIHelpers.displayErrorDialog(ex.getLocalizedMessage()); } } }
From source file:com.wonders.bud.freshmommy.web.asq.controller.AsqResultController.java
@RequestMapping(value = "/delete", method = RequestMethod.POST) @ResponseBody/*from w w w . j a v a 2 s . com*/ public RestMsg<Object> delete(HttpServletRequest request) { RestMsg<Object> rm = new RestMsg<Object>(); String sids = request.getParameter("sids"); try { if (StringUtils.isBlank(sids)) { rm.errorMsg("?"); return rm; } String[] ids = sids.split(","); asqResultService.delete(ids); ; rm.successMsg("??"); } catch (Exception e) { rm.errorMsg("?"); log.error(e.getLocalizedMessage()); } return rm; }