List of usage examples for java.lang Exception getLocalizedMessage
public String getLocalizedMessage()
From source file:org.tangram.components.spring.SpringViewUtilities.java
public void render(Writer writer, Map<String, Object> model, String view) throws IOException { ServletRequest request = (ServletRequest) model.get(Constants.ATTRIBUTE_REQUEST); ServletResponse response = (ServletResponse) model.get(Constants.ATTRIBUTE_RESPONSE); ViewContext vc = viewContextFactory.createViewContext(model, view); ModelAndView mav = SpringViewUtilities.createModelAndView(vc); View effectiveView = mav.getView(); LOG.debug("render() effectiveView={}", effectiveView); try {/*w w w . j a v a2 s. com*/ if (effectiveView == null) { String viewName = mav.getViewName(); if (viewName == null) { viewName = Constants.DEFAULT_VIEW; } // if effectiveView = viewHandler.resolveView(viewName, mav.getModel(), Locale.getDefault(), request); } // if if (writer != null) { writer.flush(); } // if LOG.debug("render() model={}", mav.getModel()); LOG.debug("render({}) effectiveView={}", mav.getViewName(), effectiveView); effectiveView.render(mav.getModel(), (HttpServletRequest) request, (HttpServletResponse) response); } catch (Exception e) { LOG.error("render() #" + view, e); if (writer != null) { writer.write(e.getLocalizedMessage()); } // if } // try/catch }
From source file:com.amazonaws.mturk.cmd.ReviewResults.java
public void reviewAssignments(String fileName) throws IOException { if (fileName == null) { throw new IllegalArgumentException("File name is null."); }//from w ww . j a v a 2 s. co m // all assignment IDs String[] assignmentIds = super.getFieldValuesFromFile(fileName, ASSIGNMENT_COLUMN); // all reject flags String[] rejectFlags = super.getFieldValuesFromFile(fileName, REJECT_COLUMN); boolean approveAll = false; if (assignmentIds == null) { throw new IllegalArgumentException( "Could not find any assignmentIds. Does " + ASSIGNMENT_COLUMN + " column exist?"); } else if (rejectFlags == null) { // If the reject column doesn't exist, // approve all assignments upon confirmation checkIsUserCertain("You are about to approve ALL assignments."); approveAll = true; } else if (rejectFlags.length != assignmentIds.length) { throw new IllegalArgumentException(); } for (int i = 0; i < assignmentIds.length; i++) { String assignmentId = assignmentIds[i]; if (assignmentId.equals("")) continue; // no submitted assignment try { String opStr; String rejectFlag = rejectFlags != null ? rejectFlags[i] : HITResults.EMPTY; if (approveAll || rejectFlag.equals(HITResults.EMPTY)) { // For each assignment that doesn't have the reject column marked, // the system will approve the assignment. service.approveAssignment(assignmentId, DEFAULT_COMMENT); approvedCount++; opStr = "approved"; } else { // For each assignment that has the reject column marked, // the system will reject the assignment. service.rejectAssignment(assignmentId, DEFAULT_COMMENT); rejectedCount++; opStr = "rejected"; } log.info("[" + assignmentId + "] Assignment successfully " + opStr); } catch (Exception e) { errorCount++; log.error("Could not process assignment [" + assignmentId + "], " + e.getLocalizedMessage(), e); } runningCount++; } log.info(""); log.info(String.format("Assignments approved: %d/%d (%d%%)", approvedCount, runningCount, approvedCount * 100 / runningCount)); log.info(String.format("Assignments rejected: %d/%d (%d%%)", rejectedCount, runningCount, rejectedCount * 100 / runningCount)); log.info(String.format("Errors occurred: %d", errorCount)); }
From source file:com.epam.dlab.backendapi.service.impl.GitCredentialServiceImpl.java
@Override public void updateGitCredentials(UserInfo userInfo, ExploratoryGitCredsDTO formDTO) { log.debug("Updating GIT creds for user {} to {}", userInfo.getName(), formDTO); try {/*from www . ja va 2 s. co m*/ gitCredsDAO.updateGitCreds(userInfo.getName(), formDTO); final String failedNotebooks = exploratoryDAO.fetchRunningExploratoryFields(userInfo.getName()).stream() .filter(ui -> !updateNotebookGitCredentials(userInfo, formDTO, ui)) .map(UserInstanceDTO::getExploratoryName).collect(Collectors.joining(",")); if (StringUtils.isNotEmpty(failedNotebooks)) { throw new DlabException("Requests for notebooks failed: " + failedNotebooks); } } catch (Exception t) { log.error("Cannot update the GIT creds for user {}", userInfo.getName(), t); throw new DlabException("Cannot update the GIT credentials: " + t.getLocalizedMessage(), t); } }
From source file:com.ibm.mobilefirstplatform.clientsdk.android.core.internal.ResponseImpl.java
public ResponseImpl(com.squareup.okhttp.Response response) { okHttpResponse = response;/*w ww . ja v a 2s . co m*/ if (okHttpResponse != null) { headers = okHttpResponse.headers(); try { bodyBytes = okHttpResponse.body().bytes(); } catch (Exception e) { logger.error("Response body bytes can't be read: " + e.getLocalizedMessage()); bodyBytes = null; } contentType = okHttpResponse.body().contentType(); } }
From source file:br.com.elotech.sits.config.form.ConfigForm.java
private void save() { Properties config = new Properties(loadConfigFile()); config.setProperty("ISS.serviceType", "elotech"); try {/*w w w . j av a 2 s . co m*/ saveFields(config); saveKeyAlias(config); config.store(new FileOutputStream(new File(CONFIG_FILE)), "Arquivo gerado pelo configurador"); close(); } catch (Exception e) { LogFactory.getLog(getClass()).error(e.getLocalizedMessage(), e); JOptionPane.showMessageDialog(getFrame(), e.getLocalizedMessage(), "Erro durante gravao", JOptionPane.CLOSED_OPTION + JOptionPane.ERROR_MESSAGE); } }
From source file:com.ibm.rpe.web.service.docgen.servlet.XmlToXsd.java
@GET @Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN }) public Response convertXmlToJson(@Context HttpServletRequest request, @QueryParam("url") String xmlUrl) throws Exception { String xsd = null;/*from ww w . ja va 2s . co m*/ try { Client client = new Client(); WebResource service = client.resource(UriBuilder.fromUri(xmlUrl).build()); ClientResponse clientResponse = service.accept(MediaType.APPLICATION_XML).get(ClientResponse.class); if (Response.Status.OK.getStatusCode() != clientResponse.getStatus()) { return Response.serverError().status(Status.BAD_REQUEST) .entity(clientResponse.getEntity(String.class)).build(); } InputStream xmlStream = clientResponse.getEntityInputStream(); String xmlAsString = IOUtils.toString(xmlStream, "UTF-8"); String workingDirectory = System.getProperty("java.io.tmpdir") + "schema_" //$NON-NLS-1$//$NON-NLS-2$ + UUID.randomUUID().toString() + File.separator; String xsdFilePath = workingDirectory + "xsd_" + UUID.randomUUID().toString() + ".xsd"; //$NON-NLS-1$ //$NON-NLS-2$ FileUtils.createFileParent(xsdFilePath); String xmlFilePath = workingDirectory + "xsd_" + UUID.randomUUID().toString() + ".xml"; //$NON-NLS-1$ //$NON-NLS-2$ FileWriter fileWritter = new FileWriter(xmlFilePath); BufferedWriter bufferWritter = new BufferedWriter(fileWritter); String s = new String(xmlAsString.getBytes(), "UTF-8"); //$NON-NLS-1$ try { bufferWritter.write(s); } finally { bufferWritter.close(); } try { XsdGeneration.generateXSD(xmlFilePath, xsdFilePath); } catch (Exception e2) { e2.printStackTrace(); } // return Response.ok().build(); xsd = IOUtils.toString(new FileInputStream(xsdFilePath), "UTF-8"); // TODO Delete workingDirectory directory return Response.ok().entity(xsd).build(); } catch (Exception e) { e.printStackTrace(); return Response.serverError().status(Status.BAD_REQUEST) .entity(JSONUtils.writeValue(e.getLocalizedMessage())).build(); } }
From source file:cn.vlabs.umt.ui.actions.EditTemplateAction.java
public ActionForward saveTemplate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {//from w ww .j a v a2 s. c om EditTemplateForm etForm = (EditTemplateForm) form; StringBuffer sb = new StringBuffer(); sb.append(EmailTemplate.SIGN_TITLE).append(etForm.getTitle()); sb.append(EmailTemplate.SIGN_CONTENT).append(etForm.getContent()); String templateFileDir = request.getSession().getServletContext().getRealPath("/"); boolean succ = true; try { String path = getConfig().getStringProp(EmailTemplate.TEMPLATE_DIR, "WEB-INF/message/"); String localeddir = path + "/" + Locale.getDefault().toString(); File f = new File(templateFileDir + localeddir); if (!f.exists()) { localeddir = path + "/zh_CN"; } templateFileDir += localeddir + "/" + etForm.getTarget(); Writer writer = new OutputStreamWriter(new FileOutputStream(templateFileDir), "UTF-8"); writer.write(sb.toString()); writer.flush(); writer.close(); } catch (Exception e) { succ = false; log.error(e.getLocalizedMessage()); } EmailTemplate email = getEmailTemplate(request, etForm.getTarget()); request.setAttribute("template", email); if (succ) { request.setAttribute("succ", "emailtempt.update.success"); } else { request.setAttribute("succ", "emailtempt.update.error"); } request.setAttribute("act", request.getParameter("reAct")); return mapping.getInputForward(); }
From source file:com.amazonaws.mturk.cmd.RejectWork.java
private void rejectAssignments(String[] assignments, String[] comments) { // If we're not given anything, just no-op if (assignments == null) { return;// w w w . j a v a 2s.co m } checkIsUserCertain("You are about to reject " + assignments.length + " assignment(s)."); String comment = null; if (comments == null) { comment = getComment(); } for (int i = 0; assignments != null && i < assignments.length; i++) { runningCount++; try { if (comments != null) comment = comments[i]; service.rejectAssignment(assignments[i], comment); successCount++; log.info("[" + assignments[i] + "] Assignment successfully rejected " + (comment != null ? " with comment (" + comment + ")" : "")); } catch (Exception e) { failedCount++; log.error("Error rejecting assignment " + assignments[i] + " with comment [" + comment + "]: " + e.getLocalizedMessage(), e); } } }
From source file:FileSplitter.java
public boolean split(long size) { if (size <= 0) return false; try {/*from w ww . j av a2 s. c om*/ int parts = ((int) (f.length() / size)); long flength = 0; if (f.length() % size > 0) parts++; File[] fparts = new File[parts]; FileInputStream fis = new FileInputStream(f); FileOutputStream fos = null; for (int i = 0; i < fparts.length; i++) { fparts[i] = new File(f.getPath() + ".part." + i); fos = new FileOutputStream(fparts[i]); int read = 0; long total = 0; byte[] buff = new byte[1024]; int origbuff = buff.length; while (total < size) { read = fis.read(buff); if (read != -1) { buff = FileEncoder.invertBuffer(buff, 0, read); total += read; flength += read; fos.write(buff, 0, read); } if (i == fparts.length - 1 && read < origbuff) break; } fos.flush(); fos.close(); fos = null; } fis.close(); // f.delete(); f = fparts[0]; System.out.println("Length Readed (KB): " + flength / 1024.0); return true; } catch (Exception ex) { System.out.println(ex); System.out.println(ex.getLocalizedMessage()); System.out.println(ex.getStackTrace()[0].getLineNumber()); ex.printStackTrace(); return false; } }
From source file:com.amazonaws.mturk.cmd.ApproveWork.java
public void approveHitsInFile(String fileName) throws IOException { if (fileName == null) { throw new IllegalArgumentException("fileName must not be null"); }// w ww. ja v a 2 s . c o m String[] hits = super.getFieldValuesFromFile(fileName, HIT_TO_APPROVE_COLUMN); resultTemplate = RESULT_TEMPLATE_HIT; resultMap = new HashMap<String, String>(); List<String> assignmentIds = new ArrayList<String>(); for (int i = 0; i < hits.length; i++) { try { Assignment[] assignments = service.getAllSubmittedAssignmentsForHIT(hits[i]); if (assignments != null && assignments.length > 0) { for (Assignment a : assignments) { assignmentIds.add(a.getAssignmentId()); resultMap.put(a.getAssignmentId(), a.getHITId()); submitAssignmentsFromHitIfNecessary(assignmentIds, WorkQueue.getNumberOfThreads()); // batch up assignments } } } catch (Exception ex) { log.error("ERROR submitting assignments for HIT " + hits[i] + ": " + ex.getLocalizedMessage(), ex); } } submitAssignmentsFromHitIfNecessary(assignmentIds, 0); // submit remaining assignments }