List of usage examples for java.lang Exception getCause
public synchronized Throwable getCause()
From source file:com.flexive.shared.FxContext.java
/** * Performs a cleanup of the stored informations. *///from w w w . j a v a 2 s.c o m public static void cleanup() { try { // clean up cache invocation context (JBoss cache workaround) CacheAdmin.getInstance().cleanupAfterRequest(); } catch (Exception ex) { if (ex.getCause() instanceof InstanceNotFoundException) { // cache already removed, so no cleanup necessary/possible if (LOG.isDebugEnabled()) { LOG.debug("Failed to clean up cache context because cache was already removed", ex); } } else if (LOG.isWarnEnabled()) { LOG.warn("Failed to clean up cache context: " + ex.getMessage(), ex); } } // clear request-only XPath cache XPathElement.clearRequestCache(); // remove FxContext threadlocal if (info.get() != null) { info.get().clearCachedAttributes(); removeThreadLocal(); } }
From source file:de.betterform.agent.web.servlet.ErrorServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { WebUtil.nonCachingResponse(response); //pick up the exception details String xpath = "unknown"; String cause = ""; String msg = (String) getSessionAttribute(request, "betterform.exception.message"); if (msg != null) { int start = msg.indexOf("::"); if (start > 3) { xpath = msg.substring(start + 2); msg = msg.substring(0, start); }// w w w .j a v a2 s . c om //todo: don't we need an 'else' here? } Exception ex = (Exception) getSessionAttribute(request, "betterform.exception"); if (ex != null && ex.getCause() != null && ex.getCause().getMessage() != null) { cause = ex.getCause().getMessage(); } //create XML structure for exception details Element rootNode = DOMUtil.createRootElement("error"); DOMUtil.appendElement(rootNode, "context", request.getContextPath()); DOMUtil.appendElement(rootNode, "url", request.getSession().getAttribute("betterform.referer").toString()); DOMUtil.appendElement(rootNode, "xpath", xpath); DOMUtil.appendElement(rootNode, "message", msg); DOMUtil.appendElement(rootNode, "cause", cause); //transform is different depending on exception type if (ex instanceof XFormsErrorIndication) { Object o = ((XFormsErrorIndication) ex).getContextInfo(); if (o instanceof HashMap) { HashMap<String, Object> map = (HashMap) ((XFormsErrorIndication) ex).getContextInfo(); if (map.size() != 0) { Element contextinfo = rootNode.getOwnerDocument().createElement("contextInfo"); rootNode.appendChild(contextinfo); for (Map.Entry<String, Object> entry : map.entrySet()) { DOMUtil.appendElement(rootNode, entry.getKey(), entry.getValue().toString()); } } } //todo: check -> there are contextInfos containing a simple string but seems to be integrated within above error message already - skip for now /* else{ } */ Document hostDoc = (Document) getSessionAttribute(request, "betterform.hostDoc"); String serializedDoc = DOMUtil.serializeToString(hostDoc); //reparse try { byte bytes[] = serializedDoc.getBytes("UTF-8"); Document newDoc = PositionalXMLReader.readXML(new ByteArrayInputStream(bytes)); DOMUtil.prettyPrintDOM(newDoc); //eval xpath Node n = XPathUtil.evaluateAsSingleNode(newDoc, xpath); String linenumber = (String) n.getUserData("lineNumber"); DOMUtil.appendElement(rootNode, "lineNumber", linenumber); DOMUtil.prettyPrintDOM(rootNode); WebUtil.doTransform(getServletContext(), response, newDoc, "highlightError.xsl", rootNode); } catch (Exception e) { e.printStackTrace(); } } else { WebUtil.doTransform(getServletContext(), response, rootNode.getOwnerDocument(), "error.xsl", null); } }
From source file:com.nextdoor.bender.ipc.es.ElasticSearchTransporterTest.java
@Test(expected = TransportException.class) public void testGzipErrorsResponse() throws TransportException, IOException { byte[] respPayload = getResponse().getBytes(StandardCharsets.UTF_8); ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream os = new GZIPOutputStream(baos); os.write(respPayload);//from w ww.j a va 2 s.c om os.close(); byte[] compressedResponse = baos.toByteArray(); HttpClient client = getMockClientWithResponse(compressedResponse, ContentType.DEFAULT_BINARY, HttpStatus.SC_OK); ElasticSearchTransport transport = new ElasticSearchTransport(client, true); try { transport.sendBatch("foo".getBytes()); } catch (Exception e) { assertEquals("es call failed because expected failure", e.getCause().getMessage()); throw e; } }
From source file:com.konakart.actions.SubscribeNewsletterSubmitAction.java
public String execute() { HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); try {//from www. ja v a2 s.c o m int custId; KKAppEng kkAppEng = this.getKKAppEng(request, response); custId = this.loggedIn(request, response, kkAppEng, null); // Ensure we are using the correct protocol. Redirect if not. String redirForward = checkSSL(kkAppEng, request, custId, /* forceSSL */false); if (redirForward != null) { setupResponseForSSLRedirect(response, redirForward); return null; } EmailValidator validator = EmailValidator.getInstance(); if (!validator.isValid(emailAddr)) { msg = "Enter a valid email address"; error = true; return SUCCESS; } NotificationOptions options = new NotificationOptions(); options.setEmailAddr(emailAddr); options.setNewsletter(true); options.setAllProducts(false); options.setCustomerId(custId); if (custId > 0) { options.setSessionId(kkAppEng.getSessionId()); } try { kkAppEng.getEng().addCustomerNotifications(options); } catch (Exception e) { String userExists = "KKUserExistsException"; if ((e.getCause() != null && e.getCause().getClass().getName().indexOf(userExists) > -1) || (e.getMessage() != null && e.getMessage().indexOf(userExists) > -1)) { msg = "Sign in to register"; } error = true; return SUCCESS; } msg = "Registration was successful"; return SUCCESS; } catch (Exception e) { return super.handleException(request, e); } }
From source file:com.registryKit.user.userDAO.java
@SuppressWarnings("unchecked") public List<String> getUserRoles(User user) { try {/*w w w . j a v a 2s. c o m*/ String sql = ("select r.role as authority from users u inner join " + " user_roles r on u.roleId = r.id where u.status = 1 and u.email = :email"); Query query = sessionFactory.getCurrentSession().createSQLQuery(sql); query.setParameter("email", user.getEmail()); List<String> roles = query.list(); return roles; } catch (Exception ex) { System.err.println("getUserRoles " + ex.getCause()); ex.printStackTrace(); return null; } }
From source file:com.mac.holdempoker.socket.HoldemEndpoint.java
@Override public void onError(WebSocket ws, Exception excptn) { System.out.println("ERROR"); System.out.println(excptn);/*from w ww. java 2 s . co m*/ System.out.println(excptn.getLocalizedMessage()); System.out.println(excptn.getCause()); System.out.println(excptn.getMessage()); System.out.println(ws); }
From source file:com.infinities.skyport.async.impl.AsyncHandler.java
private Exception throwCause(Exception e, boolean combineStackTraces) throws Exception { Throwable cause = e.getCause(); if (cause == null) { throw e;// w w w.jav a 2 s .co m } if (combineStackTraces) { StackTraceElement[] combined = ObjectArrays.concat(cause.getStackTrace(), e.getStackTrace(), StackTraceElement.class); cause.setStackTrace(combined); } if (cause instanceof Exception) { throw (Exception) cause; } if (cause instanceof Error) { throw (Error) cause; } // The cause is a weird kind of Throwable, so throw the outer // exception. throw e; }
From source file:com.aliyun.odps.ship.download.DownloadTableTest.java
@Test public void testDownloadWrongTable_Sequential() throws Exception { ExecutionContext context = ExecutionContext.init(); String s = "tunnel d %s %s -cp=false"; DShipCommand cmd;// w ww . ja v a2 s .c o m try { cmd = DShipCommand.parse(String.format(s, "wrong_name", PATH), context); assertNotNull(cmd); cmd.run(); Assert.fail("table not found"); } catch (Exception e) { assertTrue("error message", e.getCause().getMessage().indexOf("Table not found") > 0); } }
From source file:com.tecapro.inventory.common.util.CSVReport.java
/** * Export CSV file// w w w.j a v a 2s .c om * * @param fileName * @param prefix * Prefix file * @param ext * Extension file * @param header * row header * @param dataLines * @return * CSV file name * @throws FileException */ private String exportCsv(String fileName, String prefix, String ext, String[] headers, List<String[]> dataLines) throws FileException { String reportFileName = StringUtils.EMPTY; String reportPathDest = StringUtils.EMPTY; // Get report file name reportFileName = String.format("%s_%s%s", fileName, prefix, ext); // Get path work folder reportPathDest = propUtil.getPathProperty(FILE_PATH_WORK_PROPERTY) + File.separator; try { FileOutputStream fos = new FileOutputStream(reportPathDest + reportFileName); OutputStreamWriter osw = new OutputStreamWriter(fos, commonUtil.getValue(CSV_ENCODE)); BufferedWriter bw = new BufferedWriter(osw); if (headers != null && headers.length > 0) { String header = createLineData(headers); bw.write(header); bw.write(WIN_NEW_LINE_CRLF); } Iterator<?> ite = dataLines.iterator(); String lineData; while (ite.hasNext()) { String[] nestList = (String[]) ite.next(); lineData = createLineData(nestList); bw.write(lineData); bw.write(WIN_NEW_LINE_CRLF); } bw.flush(); bw.close(); } catch (Exception e) { throw new FileException(e.getCause()); } return reportFileName; }
From source file:eu.domibus.ebms3.receiver.FaultInHandler.java
@Override /**//from ww w. j a v a 2 s .c o m * The {@code handleFault} method is responsible for handling and conversion of exceptions * thrown during the processing of incoming ebMS3 messages */ public boolean handleFault(SOAPMessageContext context) { Exception exception = (Exception) context.get(Exception.class.getName()); Throwable cause = exception.getCause(); EbMS3Exception ebMS3Exception = null; if (cause != null) { if (!(cause instanceof EbMS3Exception)) { //do Mapping of non ebms exceptions if (cause instanceof NoMatchingPModeFoundException) { ebMS3Exception = new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0010, cause.getMessage(), ((NoMatchingPModeFoundException) cause).getMessageId(), cause, MSHRole.RECEIVING); } else { if (cause instanceof WebServiceException) { if (cause.getCause() instanceof EbMS3Exception) { ebMS3Exception = (EbMS3Exception) cause.getCause(); } } else { ebMS3Exception = new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0004, "", cause, MSHRole.RECEIVING); } } } else { ebMS3Exception = (EbMS3Exception) cause; } this.processEbMSError(context, ebMS3Exception); } else { if (exception instanceof PolicyException) { //FIXME: use a consistent way of property exchange between JAXWS and CXF message model. This: PhaseInterceptorChain String messageId = (String) PhaseInterceptorChain.getCurrentMessage() .getContextualProperty("ebms.messageid"); ebMS3Exception = new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0103, exception.getMessage(), messageId, exception, MSHRole.RECEIVING); } else { ebMS3Exception = new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0004, "", cause, MSHRole.RECEIVING); } this.processEbMSError(context, ebMS3Exception); } return true; }