List of usage examples for java.lang Exception getCause
public synchronized Throwable getCause()
From source file:com.nextdoor.bender.ipc.es.ElasticSearchTransporterTest.java
@Test(expected = TransportException.class) public void testErrorsResponse() throws TransportException, IOException { byte[] respPayload = getResponse().getBytes(StandardCharsets.UTF_8); HttpClient client = getMockClientWithResponse(respPayload, ContentType.APPLICATION_JSON, HttpStatus.SC_OK); ElasticSearchTransport transport = new ElasticSearchTransport(client, false); try {/*w w w. j ava 2 s . c o m*/ transport.sendBatch("foo".getBytes()); } catch (Exception e) { assertEquals("es index failure count is 1", e.getCause().getMessage()); throw e; } }
From source file:com.nextdoor.bender.ipc.es.ElasticSearchTransporterTest.java
@Test(expected = TransportException.class) public void testRetries() throws Exception { byte[] respPayload = getResponse().getBytes(StandardCharsets.UTF_8); HttpClient client = getMockClientWithResponse(respPayload, ContentType.APPLICATION_JSON, HttpStatus.SC_OK); ElasticSearchTransport transport = new ElasticSearchTransport(client, "", false, 3, 10); try {/*from w w w . j av a2 s .com*/ transport.sendBatch("foo".getBytes()); } catch (Exception e) { assertEquals("es index failure count is 1", e.getCause().getMessage()); throw e; } }
From source file:eu.europa.ec.markt.dss.signature.token.Pkcs12SignatureToken.java
@Override public List<DSSPrivateKeyEntry> getKeys() throws KeyStoreException { List<DSSPrivateKeyEntry> list = new ArrayList<DSSPrivateKeyEntry>(); InputStream input = null;/*from w ww . ja va 2 s . co m*/ try { KeyStore keyStore = KeyStore.getInstance("PKCS12"); if (pkcs12Data != null) { input = new ByteArrayInputStream(pkcs12Data); } else { input = new FileInputStream(pkcs12File); } keyStore.load(input, password); PasswordProtection pp = new KeyStore.PasswordProtection(password); Enumeration<String> aliases = keyStore.aliases(); while (aliases.hasMoreElements()) { String alias = aliases.nextElement(); if (keyStore.isKeyEntry(alias)) { PrivateKeyEntry entry = (PrivateKeyEntry) keyStore.getEntry(alias, pp); list.add(new KSPrivateKeyEntry(entry)); } } } catch (Exception e) { if (e.getCause() instanceof BadPaddingException) { throw new BadPasswordException(MSG.PKCS12_BAD_PASSWORD); } throw new KeyStoreException( "Can't initialize Sun PKCS#12 security provider. Reason: " + getCauseMessage(e), e); } finally { DSSUtils.closeQuietly(input); } return list; }
From source file:eu.liveGov.libraries.livegovtoolkit.helper.UserInformationHelper.java
@Override public void webcallReady(HttpResponse response) { if (response != null && response.getStatusLine().getStatusCode() == 200) { try {//from w w w .j a va 2s.c om Gson gson = new Gson(); InputStream is = response.getEntity().getContent(); JsonReader jr = new JsonReader(new InputStreamReader(is)); UserInformation result = gson.fromJson(jr, UserInformation.class); saveAnonymousUserId(_context, result.getAnonymousUserId()); UserInformation currentUI = loadUserInformartion(_context, false); currentUI.setAnonymousUserId(result.getAnonymousUserId()); } catch (Exception e) { logger.error("webcallReady; Exception: {}", e.getCause()); } getUserInfoQuestionaire(_context); } else { if (response == null) { logger.error("webcallReady; No internet"); } else { logger.error("webcallReady; http statuscode: {}", response.getStatusLine().getStatusCode()); } } sendAnonymousUpdated(); }
From source file:org.jfrog.teamcity.server.global.ArtifactoryGlobalServerConfigController.java
private void handleConnectionException(ActionErrors errors, String url, Exception e) { Throwable throwable = e.getCause(); String errorMessage; if (throwable != null) { errorMessage = e.getMessage() + " (" + throwable.getClass().getCanonicalName() + ")"; } else {/* w w w. j av a2 s. c o m*/ errorMessage = e.getClass().getCanonicalName() + ": " + e.getMessage(); } errors.addError("errorConnection", errorMessage); Loggers.SERVER.error("Error while testing the connection to Artifactory server " + url, e); }
From source file:com.sourceallies.beanoh.configuration.CorruptConfigurationTest.java
@Test public void testCorruptConfiguration_preserveStackTrace() { try {/*from www . ja v a2s . com*/ assertContextLoading(); fail(); } catch (Exception e) { String contextName = new DefaultContextLocationBuilder().build(getClass()); assertEquals("Unable to locate " + contextName + ".", e.getMessage()); assertTrue(e.getCause() instanceof BeanDefinitionStoreException); assertEquals( "Line 36 in XML document from class path resource [com/sourceallies/beanoh/configuration/CorruptConfigurationTest-BeanohContext.xml] is invalid;" + " nested exception is org.xml.sax.SAXParseException: The end-tag for element type \"bean\" must end with a '>' delimiter.", e.getCause().getMessage()); assertTrue(e.getCause().getCause() instanceof org.xml.sax.SAXParseException); assertEquals("The end-tag for element type \"bean\" must end with a '>' delimiter.", e.getCause().getCause().getMessage()); } }
From source file:Controller.ProsesRegis.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try {//from w ww . ja va 2 s . c o m /* TODO output your page here. You may use following sample code. */ boolean isMultiPart = ServletFileUpload.isMultipartContent(request); if (isMultiPart) { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List items = upload.parseRequest(request); Iterator<FileItem> iter = items.iterator(); while (iter.hasNext()) { FileItem fileItem = iter.next(); if (fileItem.isFormField()) { processFormField(fileItem); } else { flItem = fileItem; } } try { Photo = flItem.getName(); File savedFile = new File( "D:\\Latihan Java\\web\\AplikasiPMB\\web\\backend\\images_student\\" + Photo); flItem.write(savedFile); } catch (Exception e) { out.println(e); System.out.println(e.getMessage()); } KoneksiDatabase obj_con = new KoneksiDatabase(); Code b = new Code(); b.setIdStudent(IdStudent); b.setFullname(Fullname); b.setIdMajor(IdMajor); b.setGender(Gender); b.setBirth(Birth); b.setSchool(School); b.setmajor(Major); b.setAddress(Address); b.setPhone(Phone); b.setEmail(Email); b.setGraduation(Grayear); b.setPhoto(Photo); int i = b.Registration(); int g = b.doUpdate(IdMajor); if (i > 0) { RequestDispatcher rd = request.getRequestDispatcher("frontend/index.jsp"); request.setAttribute("return", "Regristration Successfully!"); rd.forward(request, response); //response.sendRedirect("frontend/index.jsp"); } else { RequestDispatcher rd = request.getRequestDispatcher("frontend/index.jsp"); request.setAttribute("return", "Registration Failed!"); rd.forward(request, response); } } } catch (Exception ex) { out.println(ex.getCause()); System.out.println(ex.getMessage()); } /* TODO output your page here. You may use following sample code. */ }
From source file:org.openmrs.web.controller.report.ReportSchemaXmlFormController.java
/** * @see org.springframework.validation.Validator#validate(java.lang.Object, * org.springframework.validation.Errors) *///from www. j a v a 2s . c o m public void validate(Object commandObject, Errors errors) { ValidationUtils.rejectIfEmpty(errors, "xml", "Paste XML for report before saving"); ReportSchemaXml rsx = (ReportSchemaXml) commandObject; try { ReportService reportService = (ReportService) Context.getService(ReportService.class); ReportSchema schema = reportService.getReportSchema(rsx); if (schema == null) throw new NullPointerException(); } catch (Exception ex) { log.warn("Exception building ReportSchema from XML", ex); if (ex.getCause() != null) { Throwable temp = ex.getCause(); while (temp.getCause() != null) { temp = temp.getCause(); } errors.rejectValue("xml", temp.getMessage()); } else { StringBuilder sb = new StringBuilder(); sb.append("Invalid XML content<br/>"); sb.append(ex).append("<br/>"); for (StackTraceElement e : ex.getStackTrace()) sb.append(e.toString()).append("<br/>"); errors.rejectValue("xml", sb.toString()); } } }
From source file:com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptorBuilder.java
public GoPluginDescriptor build(File pluginJarFile, boolean isBundledPlugin) { if (!pluginJarFile.exists()) { throw new RuntimeException( String.format("Plugin jar does not exist: %s", pluginJarFile.getAbsoluteFile())); }/*www . j a va 2 s . co m*/ InputStream pluginXMLStream = null; JarFile jarFile = null; try { jarFile = new JarFile(pluginJarFile); ZipEntry entry = jarFile.getEntry(PLUGIN_XML); if (entry == null) { return GoPluginDescriptor.usingId(pluginJarFile.getName(), pluginJarFile.getAbsolutePath(), getBundleLocation(bundlePathLocation, pluginJarFile.getName()), isBundledPlugin); } pluginXMLStream = jarFile.getInputStream(entry); return GoPluginDescriptorParser.parseXML(pluginXMLStream, pluginJarFile.getAbsolutePath(), getBundleLocation(bundlePathLocation, pluginJarFile.getName()), isBundledPlugin); } catch (Exception e) { LOGGER.warn("Could not load plugin with jar filename:" + pluginJarFile.getName(), e); String cause = e.getCause() != null ? String.format("%s. Cause: %s", e.getMessage(), e.getCause().getMessage()) : e.getMessage(); return GoPluginDescriptor .usingId(pluginJarFile.getName(), pluginJarFile.getAbsolutePath(), getBundleLocation(bundlePathLocation, pluginJarFile.getName()), isBundledPlugin) .markAsInvalid(Arrays.asList( String.format("Plugin with ID (%s) is not valid: %s", pluginJarFile.getName(), cause)), e); } finally { IOUtils.closeQuietly(pluginXMLStream); closeQuietly(jarFile); } }
From source file:com.ttolley.pongbot.opencv.CvWorker.java
public CvWorker() { yPos = new DescriptiveStatistics(); xPos = new DescriptiveStatistics(); xPos.setWindowSize(10);/* www . j a va2s . co m*/ yPos.setWindowSize(10); try { // Load the native library. System.loadLibrary(Core.NATIVE_LIBRARY_NAME); capture = new VideoCapture(1); } catch (Exception ex) { System.out.println(ex.getCause().getMessage()); } }