List of usage examples for java.lang Throwable getCause
public synchronized Throwable getCause()
From source file:org.apache.hive.jdbc.TestSSL.java
/*** * Tests to ensure SSLv2 and SSLv3 are disabled */// w w w.jav a2 s. c o m @Test public void testSSLVersion() throws Exception { Assume.assumeTrue(execCommand("which openssl") == 0); // we need openssl Assume.assumeTrue(System.getProperty("os.name").toLowerCase().contains("linux")); // we depend on linux openssl exit codes setSslConfOverlay(confOverlay); // Test in binary mode setBinaryConfOverlay(confOverlay); // Start HS2 with SSL miniHS2.start(confOverlay); // make SSL connection hs2Conn = DriverManager .getConnection( miniHS2.getJdbcURL() + ";ssl=true;sslTrustStore=" + dataFileDir + File.separator + TRUST_STORE_NAME + ";trustStorePassword=" + KEY_STORE_PASSWORD, System.getProperty("user.name"), "bar"); hs2Conn.close(); Assert.assertEquals("Expected exit code of 1", 1, execCommand("openssl s_client -connect " + miniHS2.getHost() + ":" + miniHS2.getBinaryPort() + " -ssl2 < /dev/null")); Assert.assertEquals("Expected exit code of 1", 1, execCommand("openssl s_client -connect " + miniHS2.getHost() + ":" + miniHS2.getBinaryPort() + " -ssl3 < /dev/null")); miniHS2.stop(); // Test in http mode setHttpConfOverlay(confOverlay); miniHS2.start(confOverlay); // make SSL connection try { hs2Conn = DriverManager.getConnection(miniHS2.getJdbcURL() + ";ssl=true;sslTrustStore=" + dataFileDir + File.separator + TRUST_STORE_NAME + ";trustStorePassword=" + KEY_STORE_PASSWORD + "?hive.server2.transport.mode=" + HS2_HTTP_MODE + ";hive.server2.thrift.http.path=" + HS2_HTTP_ENDPOINT, System.getProperty("user.name"), "bar"); Assert.fail("Expected SQLException during connect"); } catch (SQLException e) { LOG.info("Expected exception: " + e, e); Assert.assertEquals("08S01", e.getSQLState().trim()); Throwable cause = e.getCause(); Assert.assertNotNull(cause); while (cause.getCause() != null) { cause = cause.getCause(); } Assert.assertEquals("org.apache.http.NoHttpResponseException", cause.getClass().getName()); Assert.assertTrue(cause.getMessage().contains("failed to respond")); } miniHS2.stop(); }
From source file:com.alibaba.napoli.gecko.service.impl.GeckoHandler.java
public void onExceptionCaught(final Session session, final Throwable throwable) { if (throwable.getCause() != null) { ExceptionMonitor.getInstance().exceptionCaught(throwable.getCause()); } else {//from w w w.j ava2 s . c om ExceptionMonitor.getInstance().exceptionCaught(throwable); } }
From source file:com.mgmtp.jfunk.unit.UnitSupport.java
void afterScript(final String methodName, final boolean success, final Throwable throwable) { try {/* w w w. java2 s .co m*/ if (throwable != null) { // Look up the cause hierarchy if we find a ModuleExecutionException. // We only need to log exceptions other than ModuleExecutionException because they // have already been logged and we don't want to pollute the log file any further. Throwable th = throwable; while (!(th instanceof ModuleExecutionException)) { if (th == null) { // log original throwable which was passed in!!! LOGGER.error("Error executing method: " + methodName, throwable); break; } th = th.getCause(); } } ScriptMetaData scriptMetaData = scriptMetaDataProvider.get(); scriptMetaData.setEndDate(new Date()); scriptMetaData.setThrowable(throwable); eventBus.post(new AfterScriptEvent(methodName, success)); } finally { scriptScope.exitScope(); } }
From source file:com.netflix.niws.client.http.SecureAcceptAllGetTest.java
@Test public void testNegativeAcceptAllSSLSocketFactory() throws Exception { // test exception is thrown connecting to a random SSL endpoint without explicitly setting factory to allow all String name = "GetPostSecureTest" + ".testNegativeAcceptAllSSLSocketFactory"; // don't set any interesting properties -- really we're just setting the defaults RestClient rc = (RestClient) ClientFactory.getNamedClient(name); TEST_SERVER.accept();//from w ww .j a v a2 s . c om URI getUri = new URI(TEST_SERVICE_URI + "test/"); HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build(); boolean foundCause = false; try { rc.execute(request); } catch (Throwable t) { while (t != null && !foundCause) { if (t instanceof SSLPeerUnverifiedException && t.getMessage().startsWith("peer not authenticated")) { foundCause = true; break; } t = t.getCause(); } } assertTrue(foundCause); }
From source file:ddf.catalog.impl.operations.OperationsCrudSupport.java
private Metacard generateMetacard(String mimeTypeRaw, String id, String fileName, Subject subject, Path tmpContentPath) throws MetacardCreationException, MimeTypeParseException { Metacard generatedMetacard = null;//from w ww .j a v a2 s . co m InputTransformer transformer = null; StringBuilder causeMessage = new StringBuilder("Could not create metacard with mimeType "); try { MimeType mimeType = new MimeType(mimeTypeRaw); List<InputTransformer> listOfCandidates = frameworkProperties.getMimeTypeToTransformerMapper() .findMatches(InputTransformer.class, mimeType); LOGGER.debug("List of matches for mimeType [{}]: {}", mimeType, listOfCandidates); for (InputTransformer candidate : listOfCandidates) { transformer = candidate; try (InputStream transformerStream = com.google.common.io.Files .asByteSource(tmpContentPath.toFile()).openStream()) { generatedMetacard = transformer.transform(transformerStream); } if (generatedMetacard != null) { break; } } } catch (CatalogTransformerException | IOException e) { causeMessage.append(mimeTypeRaw).append(". Reason: ").append(System.lineSeparator()) .append(e.getMessage()); // The caught exception more than likely does not have the root cause message // that is needed to inform the caller as to why things have failed. Therefore // we need to iterate through the chain of cause exceptions and gather up // all of their message details. Throwable cause = e.getCause(); while (cause != null && cause != cause.getCause()) { causeMessage.append(System.lineSeparator()).append(cause.getMessage()); cause = cause.getCause(); } LOGGER.debug("Transformer [{}] could not create metacard.", transformer, e); } if (generatedMetacard == null) { throw new MetacardCreationException(causeMessage.toString()); } if (id != null) { generatedMetacard.setAttribute(new AttributeImpl(Metacard.ID, id)); } else { generatedMetacard .setAttribute(new AttributeImpl(Metacard.ID, UUID.randomUUID().toString().replaceAll("-", ""))); } if (StringUtils.isBlank(generatedMetacard.getTitle())) { generatedMetacard.setAttribute(new AttributeImpl(Metacard.TITLE, fileName)); } String name = Optional.ofNullable(SubjectUtils.getName(subject)).orElse(""); generatedMetacard.setAttribute(new AttributeImpl(Metacard.POINT_OF_CONTACT, name)); return generatedMetacard; }
From source file:de.tudarmstadt.lt.ltbot.postprocessor.DecesiveValueLogger2.java
@Override protected void innerProcess(CrawlURI uri) throws InterruptedException { LOG.finest(String.format("[%s (%s): %s via %s]: %s; %s;", getBeanName(), getExtraInfoValueFieldName(), uri, uri.getVia(), uri.getExtraInfo(), uri.getFullVia() != null ? uri.getFullVia().getExtraInfo() : "{}")); JSONObject info = uri.getExtraInfo(); try {/*from w w w . j av a 2 s. c om*/ synchronized (_w) { if (!(info.has(EXTRA_INFO_PLAINTEXT_ABBREVIATED) || uri.getVia() != null)) return;/* DO NOT WRITE ANYTHING */ if (info.has(EXTRA_INFO_PLAINTEXT_ABBREVIATED)) /* decision value was computed on the current document */ writeInformationFromCurrentURI(uri, info); else /* decision value was computed on the preceding document */ writeInformationFromPrecedingURI(uri); _w.flush(); } } catch (Throwable t) { for (int i = 1; t != null && i < 10; i++) { LOG.log(Level.WARNING, String.format("Failed to write decesive value from extra info to file (%d-%s:%s).", i, t.getClass().getName(), t.getMessage()), t); t = t.getCause(); } } }
From source file:org.LexGrid.LexBIG.caCore.web.util.LexEVSHTTPQuery.java
/** * Generates an HTML Error message based upon a given Exception * @param Exception The exception that should be used to generate an HTML error message * @return A string-based HTML error message containing the Exception message. */// www . j a va 2s .c o m private String getHTMLErrorMsg(Exception ex) { StringBuilder sb = new StringBuilder(); sb.append("<html>\n").append("<head>\n").append("<title>caCORE HTTP Servlet Error</title>\n") .append("</head>\n").append("<body>\n") .append("<table height=\"100%\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" >\n") .append("<tr valign=\"top\" align=\"left\">\n").append("<td valign=\"top\" align=\"left\">\n") .append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" >\n") .append("<tr valign=\"top\" align=\"left\">\n").append("<td valign=\"top\" align=\"left\">\n") .append("<tr>\n").append("<td valign=\"top\" align=\"left\">\n") .append("<b><font size=6>caCORE HTTP Servlet Error:</font></b>\n").append("</td>\n") .append("</tr>\n").append("<tr>\n").append("<td valign=\"top\" align=\"left\">\n") .append("<b><hr></b>\n").append("</td>\n").append("</tr>\n").append("<tr>\n") .append("<td valign=\"top\" align=\"left\">\n").append("<pre class=\"autoOverflow\">\n") .append("<font size=4 color=red><b><br><br>\n"); String msg = ex.getMessage(); msg = org.apache.commons.lang.StringEscapeUtils.escapeHtml(msg); Throwable tempEx = ex.getCause(); while (tempEx != null) { msg += "<br><br>Caused by: " + tempEx.getMessage(); tempEx = tempEx.getCause(); } sb.append(msg); sb.append("</b></font>\n").append("</pre>\n").append("</td>\n").append("</tr>\n").append("</td>\n") .append("</tr>\n").append("</table>\n"); return sb.toString(); }
From source file:com.googlecode.android_scripting.rpc.MethodDescriptor.java
/** * Invokes the call that belongs to this object with the given parameters. Wraps the response * (possibly an exception) in a JSONObject. * // w w w . j a va2s.com * @param parameters * {@code JSONArray} containing the parameters * @return result * @throws Throwable */ public Object invoke(RpcReceiverManager manager, final JSONArray parameters) throws Throwable { // Issue track call first in case of failure. Analytics.track("api", getName()); final Type[] parameterTypes = getGenericParameterTypes(); final Object[] args = new Object[parameterTypes.length]; final Annotation annotations[][] = getParameterAnnotations(); if (parameters.length() > args.length) { throw new RpcError("Too many parameters specified."); } for (int i = 0; i < args.length; i++) { final Type parameterType = parameterTypes[i]; if (i < parameters.length()) { args[i] = convertParameter(parameters, i, parameterType); } else if (MethodDescriptor.hasDefaultValue(annotations[i])) { args[i] = MethodDescriptor.getDefaultValue(parameterType, annotations[i]); } else { throw new RpcError("Argument " + (i + 1) + " is not present"); } } Object result = null; try { result = manager.invoke(mClass, mMethod, args); } catch (Throwable t) { throw t.getCause(); } return result; }
From source file:gov.nih.nci.system.web.HTTPQuery.java
/** * Generates an HTML Error message based upon a given Exception * @param Exception The exception that should be used to generate an HTML error message * @return A string-based HTML error message containing the Exception message. *//*from w w w . jav a2 s . co m*/ private String getXMLErrorMsg(Exception ex, String query) { StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") .append("<xlink:httpQuery xmlns:xlink=\"http://www.w3.org/1999/xlink\">").append("<queryRequest>") .append("<query>").append("<queryString>" + query + "</queryString>").append("<class></class>") .append("</query>").append("<criteria></criteria>").append("</queryRequest>") .append("<queryResponse>"); String msg = ex.getMessage(); msg = org.apache.commons.lang.StringEscapeUtils.escapeXml(msg); Throwable tempEx = ex.getCause(); while (tempEx != null) { msg += "\n\nCaused by: " + tempEx.getMessage(); tempEx = tempEx.getCause(); } sb.append(msg); sb.append("<error>" + msg + "</error>").append("</queryReponse>").append("</xlink:httpQuery>"); return sb.toString(); }
From source file:com.chiorichan.configuration.serialization.ConfigurationSerialization.java
protected ConfigurationSerializable deserializeViaCtor(Constructor<? extends ConfigurationSerializable> ctor, Map<String, Object> args) { try {// w ww . ja v a 2 s.co m return ctor.newInstance(args); } catch (Throwable ex) { Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE, "Could not call constructor '" + ctor.toString() + "' of " + clazz + " for deserialization", ex instanceof InvocationTargetException ? ex.getCause() : ex); } return null; }