List of usage examples for java.lang Throwable getCause
public synchronized Throwable getCause()
From source file:net.solarnetwork.node.setup.impl.DefaultKeystoreService.java
@Override public X509Certificate generateNodeSelfSignedCertificate(String dn) throws CertificateException { KeyStore keyStore = null;/* ww w .jav a 2 s.co m*/ try { keyStore = loadKeyStore(); } catch (CertificateException e) { Throwable root = e; while (root.getCause() != null) { root = root.getCause(); } if (root instanceof UnrecoverableKeyException) { // bad password... we shall assume here that a new node association is underway, // so delete the existing key store and re-create File ksFile = new File(getKeyStorePath()); if (ksFile.isFile()) { log.info("Deleting existing certificate store due to invalid password, will create new store"); if (ksFile.delete()) { // clear out old key store password, so we generate a new one setupIdentityDao.saveSetupIdentityInfo( setupIdentityDao.getSetupIdentityInfo().withKeyStorePassword(null)); keyStore = loadKeyStore(); } } } if (keyStore == null) { // re-throw, we didn't handle it throw e; } } return createSelfSignedCertificate(keyStore, dn, nodeAlias); }
From source file:io.pravega.segmentstore.server.host.handler.AppendProcessor.java
private void handleException(UUID writerId, long requestId, String segment, String doingWhat, Throwable u) { if (u == null) { IllegalStateException exception = new IllegalStateException("No exception to handle."); log.error("Append processor: Error {} onsegment = '{}'", doingWhat, segment, exception); throw exception; }//from w w w . j av a 2 s . c o m if (u instanceof CompletionException) { u = u.getCause(); } log.error("Error (Segment = '{}', Operation = 'append')", segment, u); if (u instanceof StreamSegmentExistsException) { connection.send(new SegmentAlreadyExists(requestId, segment)); } else if (u instanceof StreamSegmentNotExistsException) { connection.send(new NoSuchSegment(requestId, segment)); } else if (u instanceof StreamSegmentSealedException) { connection.send(new SegmentIsSealed(requestId, segment)); } else if (u instanceof WrongHostException) { WrongHostException wrongHost = (WrongHostException) u; connection.send(new WrongHost(requestId, wrongHost.getStreamSegmentName(), wrongHost.getCorrectHost())); } else if (u instanceof BadAttributeUpdateException) { connection.send(new InvalidEventNumber(writerId, requestId)); connection.close(); } else { // TODO: don't know what to do here... connection.close(); } }
From source file:com.mirth.connect.client.ui.LibraryResourcesPanel.java
public void initialize() { final String workingId = PlatformUI.MIRTH_FRAME.startWorking("Loading library resources..."); SwingWorker<List<LibraryProperties>, Void> worker = new SwingWorker<List<LibraryProperties>, Void>() { @Override/*from www . j a va 2s.c o m*/ public List<LibraryProperties> doInBackground() throws ClientException { List<ResourceProperties> resourceProperties = PlatformUI.MIRTH_FRAME.mirthClient.getResources(); List<LibraryProperties> libraryProperties = new ArrayList<LibraryProperties>(); for (ResourceProperties resource : resourceProperties) { if (resource instanceof LibraryProperties) { libraryProperties.add((LibraryProperties) resource); } } return libraryProperties; } @Override public void done() { try { List<LibraryProperties> resources = get(); if (resources == null) { resources = new ArrayList<LibraryProperties>(); } Object[][] data = new Object[resources.size()][3]; int i = 0; for (LibraryProperties properties : resources) { data[i][SELECTED_COLUMN] = null; data[i][PROPERTIES_COLUMN] = properties; data[i][TYPE_COLUMN] = properties.getType(); i++; for (Map<String, String> resourceIds : selectedResourceIds.values()) { if (resourceIds.containsKey(properties.getId())) { resourceIds.put(properties.getId(), properties.getName()); } } } ((RefreshTableModel) resourceTable.getModel()).refreshDataVector(data); treeTable.getSelectionModel().setSelectionInterval(0, 0); treeTable.getTreeSelectionModel().setSelectionPath(treeTable.getPathForRow(0)); parent.resourcesReady(); } catch (Throwable t) { if (t instanceof ExecutionException) { t = t.getCause(); } PlatformUI.MIRTH_FRAME.alertThrowable(PlatformUI.MIRTH_FRAME, t, "Error loading library resources: " + t.toString()); } finally { PlatformUI.MIRTH_FRAME.stopWorking(workingId); } } }; worker.execute(); }
From source file:com.chaosinmotion.securechat.server.json.ReturnResult.java
/** * Generate an error result. This is used to aid in debugging on the * client side. This also initializes an array to help diagnose the * problem client-side.//w w w. j a v a 2s. co m * * Normally this should never be called. * * @param exception */ public ReturnResult(Throwable th) { success = false; errorCode = Errors.ERROR_EXCEPTION; errorMessage = "Internal exception: " + th.getMessage(); exception = new ArrayList<String>(); boolean cflag = false; do { if (cflag) { exception.add("Caused by " + th.getMessage()); } else { cflag = true; } StackTraceElement[] e = th.getStackTrace(); int maxlen = e.length; th = th.getCause(); if (th != null) { // If there is a cause, we trim the items we show for this // exception by removing the tail of the stack trace that // is in common. This helps with reading the stack frame. StackTraceElement[] n = th.getStackTrace(); int nlen = n.length; while ((maxlen > 0) && (nlen > 0)) { StackTraceElement el = e[maxlen - 1]; StackTraceElement nl = n[nlen - 1]; if (el.equals(nl)) { --maxlen; --nlen; } else { break; } } // Make sure we show at least one item, unless we don't have // a stack frame (which can happen sometimes) if (maxlen == 0) { maxlen++; if (maxlen > e.length) maxlen = e.length; } } // Now add the stack frame for (int i = 0; i < maxlen; ++i) { exception.add(" " + e[i].toString()); } } while (th != null); }
From source file:org.sonar.runner.Main.java
public void showError(String message, Throwable e, boolean showStackTrace) { if (showStackTrace) { Logs.error(message, e);//from w ww .j a v a 2 s.co m if (!cli.isDebugMode()) { Logs.error(""); suggestDebugMode(); } } else { Logs.error(message); if (e != null) { Logs.error(e.getMessage()); String previousMsg = ""; for (Throwable cause = e.getCause(); cause != null && cause.getMessage() != null && !cause.getMessage().equals(previousMsg); cause = cause.getCause()) { Logs.error("Caused by: " + cause.getMessage()); previousMsg = cause.getMessage(); } } Logs.error(""); Logs.error("To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch."); if (!cli.isDebugMode()) { suggestDebugMode(); } } }
From source file:com.cerema.cloud2.lib.common.network.AdvancedSslSocketFactory.java
/** * Verifies the identity of the server. * /* ww w . j a v a 2 s .c o m*/ * The server certificate is verified first. * * Then, the host name is compared with the content of the server certificate using the current host name verifier, * if any. * @param socket */ private void verifyPeerIdentity(String host, int port, Socket socket) throws IOException { try { CertificateCombinedException failInHandshake = null; /// 1. VERIFY THE SERVER CERTIFICATE through the registered TrustManager /// (that should be an instance of AdvancedX509TrustManager) try { SSLSocket sock = (SSLSocket) socket; // a new SSLSession instance is created as a "side effect" sock.startHandshake(); } catch (RuntimeException e) { if (e instanceof CertificateCombinedException) { failInHandshake = (CertificateCombinedException) e; } else { Throwable cause = e.getCause(); Throwable previousCause = null; while (cause != null && cause != previousCause && !(cause instanceof CertificateCombinedException)) { previousCause = cause; cause = cause.getCause(); } if (cause != null && cause instanceof CertificateCombinedException) { failInHandshake = (CertificateCombinedException) cause; } } if (failInHandshake == null) { throw e; } failInHandshake.setHostInUrl(host); } /// 2. VERIFY HOSTNAME SSLSession newSession = null; boolean verifiedHostname = true; if (mHostnameVerifier != null) { if (failInHandshake != null) { /// 2.1 : a new SSLSession instance was NOT created in the handshake X509Certificate serverCert = failInHandshake.getServerCertificate(); try { mHostnameVerifier.verify(host, serverCert); } catch (SSLException e) { verifiedHostname = false; } } else { /// 2.2 : a new SSLSession instance was created in the handshake newSession = ((SSLSocket) socket).getSession(); if (!mTrustManager.isKnownServer((X509Certificate) (newSession.getPeerCertificates()[0]))) { verifiedHostname = mHostnameVerifier.verify(host, newSession); } } } /// 3. Combine the exceptions to throw, if any if (!verifiedHostname) { SSLPeerUnverifiedException pue = new SSLPeerUnverifiedException( "Names in the server certificate do not match to " + host + " in the URL"); if (failInHandshake == null) { failInHandshake = new CertificateCombinedException( (X509Certificate) newSession.getPeerCertificates()[0]); failInHandshake.setHostInUrl(host); } failInHandshake.setSslPeerUnverifiedException(pue); pue.initCause(failInHandshake); throw pue; } else if (failInHandshake != null) { SSLHandshakeException hse = new SSLHandshakeException("Server certificate could not be verified"); hse.initCause(failInHandshake); throw hse; } } catch (IOException io) { try { socket.close(); } catch (Exception x) { // NOTHING - irrelevant exception for the caller } throw io; } }
From source file:com.rightscale.app.dashboard.ShowServerMonitoring.java
public void consumeContentError(Throwable t, String tag) { Spinner spinner = (Spinner) findViewById(R.id.show_server_monitoring_spinner); spinner.setEnabled(false);//from w ww . j av a2 s . c o m consumeImage(null, null); //We get RestException (422) when there is no monitoring for a server, and for some reason we see it //as RestAuthException here. In this particular view, rather than displaying an error dialog, we //just swallow the error (but hide the throbber). if (t.getCause() instanceof RestException) { _helper.hideThrobber(true); } else { _helper.onConsumeContentError(t); } }
From source file:com.mirth.connect.server.controllers.DefaultCodeTemplateController.java
private Throwable convertUpdateCause(Throwable t) { if (t instanceof ControllerException) { if (t.getCause() != null) { t = t.getCause();//from w ww . j a va 2s . c o m } else { StackTraceElement[] stackTrace = t.getStackTrace(); t = new Exception(t.getMessage()); t.setStackTrace(stackTrace); } } return t; }
From source file:com.hangum.tadpole.rdb.core.editors.main.composite.MessageComposite.java
/** * new error message//from www .j a v a 2 s. co m * * @param userDBDAO * @param requestQuery * @param tadpoleMessageDAO */ public void addErrorAfterRefresh(UserDBDAO userDBDAO, RequestQuery requestQuery, TadpoleMessageDAO tadpoleMessageDAO) { String strNewMessage = " "; //$NON-NLS-1$ String strSearchError = userDBDAO.getDbms_type() + " "; //$NON-NLS-1$ Throwable throwable = tadpoleMessageDAO.getThrowable(); if (throwable == null) { strNewMessage = Messages.get().SystemMessage; strNewMessage += tadpoleMessageDAO.getStrMessage(); strSearchError = tadpoleMessageDAO.getStrMessage(); textMessage.setBackground(SWTResourceManager.getColor(248, 248, 255)); } else { strNewMessage = Messages.get().ErrorMessage; Throwable cause = throwable.getCause(); if (throwable instanceof SQLException) { strNewMessage += sqlExceptionToMsg((SQLException) throwable, tadpoleMessageDAO); strSearchError += sqlExceptionToSearchMsg((SQLException) throwable, tadpoleMessageDAO); } else if (cause instanceof SQLException) { strNewMessage += sqlExceptionToMsg((SQLException) cause, tadpoleMessageDAO); strSearchError += sqlExceptionToSearchMsg((SQLException) cause, tadpoleMessageDAO); } else { strNewMessage += tadpoleMessageDAO.getStrMessage(); strSearchError += tadpoleMessageDAO.getStrMessage(); } // sqlite ?,? .--;; if (userDBDAO.getDBDefine() == DBDefine.SQLite_DEFAULT) { strSearchError = throwable.getMessage(); } textMessage.setBackground(SWTResourceManager.getColor(255, 228, 225)); } // // first show last error message // final String strOldText = textMessage.getText(); // if ("".equals(strOldText)) { //$NON-NLS-1$ textMessage.setText(strNewMessage); try { String strDeleteWhiteSpace = StringUtils.replace(strSearchError, "\"", "'"); lblGoogleSearch.setText("<a href=\"http://www.google.com/search?q=" + strDeleteWhiteSpace + "\" target='_blank'>" + strDeleteWhiteSpace + "</a>"); lblGoogleSearch.getParent().layout(); } catch (Exception e) { logger.error("===" + strSearchError + "===="); logger.error("parse", e); } // } else { // textMessage.setText(strNewMessage + PublicTadpoleDefine.LINE_SEPARATOR + PublicTadpoleDefine.LINE_SEPARATOR + strOldText); // } // textMessage.setSelection(0, strNewMessage.length()); // textMessage.setFocus(); }
From source file:edu.harvard.iq.dataverse.HandlenetServiceBean.java
public Throwable registerNewHandle(Dataset dataset) { logger.log(Level.FINE, "registerNewHandle"); String handlePrefix = dataset.getAuthority(); String handle = getDatasetHandle(dataset); String datasetUrl = getRegistrationUrl(dataset); logger.info("Creating NEW handle " + handle); String authHandle = getHandleAuthority(dataset); PublicKeyAuthenticationInfo auth = getAuthInfo(handlePrefix); HandleResolver resolver = new HandleResolver(); try {//from w ww .j ava 2 s .c o m AdminRecord admin = new AdminRecord(authHandle.getBytes("UTF8"), 300, true, true, true, true, true, true, true, true, true, true, true, true); int timestamp = (int) (System.currentTimeMillis() / 1000); HandleValue[] val = { new HandleValue(100, "HS_ADMIN".getBytes("UTF8"), Encoder.encodeAdminRecord(admin), HandleValue.TTL_TYPE_RELATIVE, 86400, timestamp, null, true, true, true, false), new HandleValue(1, "URL".getBytes("UTF8"), datasetUrl.getBytes(), HandleValue.TTL_TYPE_RELATIVE, 86400, timestamp, null, true, true, true, false) }; CreateHandleRequest req = new CreateHandleRequest(handle.getBytes("UTF8"), val, auth); resolver.traceMessages = true; AbstractResponse response = resolver.processRequest(req); if (response.responseCode == AbstractMessage.RC_SUCCESS) { logger.info("Success! Response: \n" + response); return null; } else { logger.log(Level.WARNING, "registerNewHandle failed"); logger.warning("Error response: \n" + response); return new Exception("registerNewHandle failed: " + response); } } catch (Throwable t) { logger.log(Level.WARNING, "registerNewHandle failed"); logger.log(Level.WARNING, "String {0}", t.toString()); logger.log(Level.WARNING, "localized message {0}", t.getLocalizedMessage()); logger.log(Level.WARNING, "cause", t.getCause()); logger.log(Level.WARNING, "message {0}", t.getMessage()); return t; } }