List of usage examples for java.lang Exception getCause
public synchronized Throwable getCause()
From source file:com.nextdoor.bender.ipc.http.HttpTransportTest.java
@Test(expected = TransportException.class) public void testErrorsResponse() throws TransportException, IOException { byte[] respPayload = "resp".getBytes(StandardCharsets.UTF_8); HttpClient client = getMockClientWithResponse(respPayload, ContentType.APPLICATION_JSON, HttpStatus.SC_INTERNAL_SERVER_ERROR, false); HttpTransport transport = new HttpTransport(client, "", false, 1, 1); try {/*ww w . j a va 2s. co m*/ transport.sendBatch("foo".getBytes()); } catch (Exception e) { assertEquals("http transport call failed because \"expected failure\" payload response \"resp\"", e.getCause().getMessage()); throw e; } }
From source file:com.nextdoor.bender.ipc.http.HttpTransportTest.java
@Test(expected = TransportException.class) public void testRetries() throws Exception { byte[] respPayload = "resp".getBytes(StandardCharsets.UTF_8); HttpClient client = getMockClientWithResponse(respPayload, ContentType.APPLICATION_JSON, HttpStatus.SC_INTERNAL_SERVER_ERROR, false); HttpTransport transport = new HttpTransport(client, "", false, 3, 10); try {/* w ww.j a v a2 s . co m*/ transport.sendBatch("foo".getBytes()); } catch (Exception e) { assertEquals("http transport call failed because \"expected failure\" payload response \"resp\"", e.getCause().getMessage()); throw e; } }
From source file:net.padaf.xmpbox.parser.XMLPropertiesDescriptionManager.java
/** * Load Properties Description from XML Stream * /*from w w w. ja va 2 s . c o m*/ * @param is * Stream where read data * @throws BuildPDFAExtensionSchemaDescriptionException * When problems to get or treat data in XML description file */ public void loadListFromXML(InputStream is) throws BuildPDFAExtensionSchemaDescriptionException { try { Object o = xstream.fromXML(is); if (o instanceof List<?>) { if (((List<?>) o).get(0) != null) { if (((List<?>) o).get(0) instanceof PropertyDescription) { propDescs = (List<PropertyDescription>) o; } else { throw new BuildPDFAExtensionSchemaDescriptionException( "Failed to get correct properties descriptions from specified XML stream"); } } else { throw new BuildPDFAExtensionSchemaDescriptionException( "Failed to find a properties description into the specified XML stream"); } } } catch (Exception e) { e.printStackTrace(); throw new BuildPDFAExtensionSchemaDescriptionException( "Failed to get correct properties descriptions from specified XML stream", e.getCause()); } finally { IOUtils.closeQuietly(is); } }
From source file:com.sisrni.managedbean.RolesMB.java
public void cancelar() throws Exception { try {/* ww w. j a va 2 s. c o m*/ this.ssRoles = null; setActualizar(false); RequestContext.getCurrentInstance().update("formAdmin"); RequestContext.getCurrentInstance().update("formRol"); } catch (Exception e) { e.printStackTrace(); throw new Exception("Error class RoleMB - Editar()\n" + e.getMessage(), e.getCause()); } finally { this.ssRoles = new SsRoles(); } }
From source file:org.synyx.hades.dao.config.TypeFilterParser.java
private void parseTypeFilters(Element element, ClassPathScanningCandidateComponentProvider scanner, Type type) { NodeList nodeList = element.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); Element childElement = type.getElement(node); if (childElement != null) { try { type.addFilter(createTypeFilter((Element) node, classLoader), scanner); } catch (Exception e) { readerContext.error(e.getMessage(), readerContext.extractSource(element), e.getCause()); }/* w w w.jav a2 s . c om*/ } } }
From source file:com.nextdoor.bender.ipc.http.HttpTransportTest.java
@Test(expected = TransportException.class) public void testGzipErrorsResponse() throws TransportException, IOException { byte[] respPayload = "gzip resp".getBytes(StandardCharsets.UTF_8); ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream os = new GZIPOutputStream(baos); os.write(respPayload);/* w ww. ja v a 2s .c o m*/ os.close(); byte[] compressedResponse = baos.toByteArray(); HttpClient client = getMockClientWithResponse(compressedResponse, ContentType.DEFAULT_BINARY, HttpStatus.SC_INTERNAL_SERVER_ERROR, true); HttpTransport transport = new HttpTransport(client, "", true, 1, 1); try { transport.sendBatch("foo".getBytes()); } catch (Exception e) { assertEquals("http transport call failed because \"expected failure\" payload response \"gzip resp\"", e.getCause().getMessage()); throw e; } }
From source file:org.pentaho.di.ui.spoon.SpoonSlaveTest.java
@Test public void setErrorTextWithCauseMessageException() { ClientProtocolException cpe = new ClientProtocolException("causeMessage"); Exception e = new KettleException("kettleMessage", cpe); SpoonSlave spoonSlave = mock(SpoonSlave.class); doCallRealMethod().when(spoonSlave).setExceptionMessage(any(Exception.class)); String message = spoonSlave.setExceptionMessage(e); Throwable cause = e.getCause(); assertEquals(message, cause.getMessage().toString()); }
From source file:com.thoughtworks.go.plugin.infra.FelixGoPluginOSGiFrameworkIntegrationTest.java
@Test public void shouldHandleErrorGeneratedByAValidGoPluginOSGiBundleAtUsageTime() { Bundle bundle = pluginOSGiFramework.loadPlugin( new GoPluginDescriptor(PLUGIN_ID, null, null, null, errorGeneratingDescriptorBundleDir, true)); assertThat(bundle.getState(), is(Bundle.ACTIVE)); ActionWithReturn<GoPlugin, Object> action = new ActionWithReturn<GoPlugin, Object>() { @Override/*from ww w . ja va 2 s . c o m*/ public Object execute(GoPlugin goPlugin, GoPluginDescriptor goPluginDescriptor) { goPlugin.pluginIdentifier(); return null; } }; try { pluginOSGiFramework.doOn(GoPlugin.class, "testplugin.descriptorValidator", "CANNOT_FIND_EXTENSION_TYPE", action); fail("Should Throw An Exception"); } catch (Exception ex) { assertThat(ex.getCause() instanceof AbstractMethodError, is(true)); } }
From source file:de.betterform.agent.web.servlet.XFormsErrorServlet.java
private String getHTML(HttpServletRequest request) { StringBuffer html = new StringBuffer(); String msg = (String) request.getSession().getAttribute("betterform.exception.message"); String xpath = "unknown"; String cause = " "; if (msg != null) { int start = msg.indexOf("::"); if (start > 3) { xpath = msg.substring(start + 2); msg = msg.substring(0, start); }/*from w w w .j a v a2s.c o m*/ } Exception ex = (Exception) request.getSession().getAttribute("betterform.exception"); if (ex != null && ex.getCause() != null && ex.getCause().getMessage() != null) { cause = ex.getCause().getMessage(); } request.getSession().removeAttribute("betterform.exception"); request.getSession().removeAttribute("betterform.exception.message"); html.append("<div class=\"message2\" id=\"msg\">"); html.append(msg); html.append("</div>"); html.append("<div class=\"message3\"><strong>URL:</strong><br/>"); html.append(request.getSession().getAttribute("betterform.referer")); html.append("</div>"); html.append("<div class=\"message3\"><strong>Element causing Exception:</strong><br/>"); html.append(xpath); html.append("</div>"); if (ex.getCause() != null) { html.append("<div class=\"message3\"><strong>Caused by:</strong><br/>"); html.append(cause); html.append("</div>"); } 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) { html.append("<table>"); html.append("<caption>Context Information:</caption>"); for (Map.Entry<String, Object> entry : map.entrySet()) { html.append("<tr><td>"); html.append(entry.getKey()); html.append("</td>"); html.append("<td>"); html.append(entry.getValue().toString()); html.append("</td></tr>"); } html.append("</table>"); } } //todo: check -> there are contextInfos containing a simple string but seems to be integrated within above error message already - skip for now /* else{ html.append("<div>"); html.append(o.toString()); html.append("</div>"); } */ } html.append("<form><input type=\"button\" value=\"Back\" onClick=\"history.back()\"/></form>"); try { String mail = Config.getInstance().getProperty("admin.mail"); StringBuffer mailbody = new StringBuffer(); html.append("<div class=\"message3\">"); html.append("<a href=\"mailto:"); html.append(mail); mailbody.append("?subject=XForms Problem at "); mailbody.append(request.getSession().getAttribute("betterform.referer")); mailbody.append("&Body=Message:\n"); mailbody.append(msg); mailbody.append("%0D%0A%0D%0AElement causing Exception:"); mailbody.append(xpath); mailbody.append("%0D%0A%0D%0ACaused by:\n"); mailbody.append(URLEncoder.encode(cause, "UTF-8")); html.append(mailbody.toString()); html.append("\">"); html.append("Report this problem...</a>"); html.append("</div>"); } catch (Exception e) { LOGGER.debug(e); } LOGGER.error(html.toString()); return html.toString(); }
From source file:com.app.inventario.controlador.Controlador.java
@RequestMapping(value = "/agregar-usuario", method = RequestMethod.POST) public @ResponseBody Map agregarUsuario(@ModelAttribute("usuario") Usuario usuario, HttpServletRequest request, HttpServletResponse response) {//from ww w .j ava2 s . com Map map = new HashMap(); try { this.usuarioServicio.guardar(usuario); response.setStatus(HttpServletResponse.SC_OK); map.put("Status", "OK"); map.put("Message", "Agregado Correctamente"); } catch (Exception ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); map.put("Status", "FAIL"); map.put("Message", ex.getCause().getCause().getCause().getMessage()); } return map; }