List of usage examples for java.lang Exception getCause
public synchronized Throwable getCause()
From source file:DDTTestRunner.java
public static void addVariable(String key, String value) { String result = ""; try {//from w w w . j a v a2s. c om if ((getVarsMap().get(key) != null)) getVarsMap().remove(key); // Consider the special case of date variables used for resetting date-specific system variables if (value.toString().toLowerCase().startsWith("%date") && (value.toString().toLowerCase().endsWith("%"))) { try { DDTDate referenceDate = new DDTDate(); referenceDate.resetDateProperties(value.toString(), getVarsMap()); if (referenceDate.hasException()) result = referenceDate.getException().getMessage().toString(); else result = referenceDate.getComments(); } catch (Exception e) { result = "Error encountered in setting date variables: " + e.getCause().toString(); } } else { getVarsMap().put(key.toLowerCase(), value); result = "Variable " + Util.sq(key.toLowerCase()) + " (re)set in the variables map to " + Util.sq((value instanceof String) ? value : value.toString()); } } catch (Exception e) { result = e.getCause().toString(); } finally { System.out.println(result); } }
From source file:com.microsoftopentechnologies.windowsazurestorage.WAStorageClient.java
/** * Downloads from Azure blob//from w ww . ja v a 2 s. c o m * * @param run environment of build * @param launcher env vars for remote builds * @param listener logging * @param strAcc storage account * @param includePattern pattern to download * @param excludePattern pattern to not download * @param downloadDirLoc dir to download to * @param flattenDirectories if directories are flattened * @param workspace workspace of build * @param containerName container with blobs * @return filesDownloaded number of files that are downloaded * @throws WAStorageException throws exception */ public static int download(Run<?, ?> run, Launcher launcher, TaskListener listener, StorageAccountInfo strAcc, String includePattern, String excludePattern, String downloadDirLoc, boolean flattenDirectories, FilePath workspace, String containerName) throws WAStorageException { int filesDownloaded = 0; try { FilePath workspacePath = new FilePath(launcher.getChannel(), workspace.getRemote()); FilePath downloadDir = getDownloadDir(workspacePath, downloadDirLoc); listener.getLogger().println(Messages.AzureStorageBuilder_downloading()); CloudBlobContainer container = WAStorageClient.getBlobContainerReference(strAcc, containerName, false, true, null); filesDownloaded = downloadBlobs(container, includePattern, excludePattern, downloadDir, flattenDirectories, listener); } catch (Exception e) { throw new WAStorageException(e.getMessage(), e.getCause()); } return filesDownloaded; }
From source file:com.microsoftopentechnologies.windowsazurestorage.WAStorageClient.java
/** * Blob download from storage//from w w w . j a va2 s.co m * * @param blob * @param downloadDir * @param listener * @throws URISyntaxException * @throws StorageException * @throws IOException * @throws InterruptedException */ private static void downloadBlob(CloudBlob blob, FilePath downloadDir, boolean flattenDirectories, TaskListener listener) throws WAStorageException { try { FilePath downloadFile = new FilePath(downloadDir, blob.getName()); // That filepath will contain all the directories and explicit virtual // paths, so if the user wanted it flattened, grab just the file name and // recreate the file path if (flattenDirectories) { downloadFile = new FilePath(downloadDir, downloadFile.getName()); } long startTime = System.currentTimeMillis(); try (OutputStream fos = downloadFile.write()) { blob.download(fos, null, getBlobRequestOptions(), Utils.updateUserAgent()); } long endTime = System.currentTimeMillis(); listener.getLogger().println("blob " + blob.getName() + " is downloaded to " + downloadDir + " in " + getTime(endTime - startTime)); } catch (Exception e) { throw new WAStorageException(e.getMessage(), e.getCause()); } }
From source file:com.enioka.jqm.tools.Helpers.java
static boolean testDbFailure(Exception e) { return (e instanceof LazyInitializationException) || (e instanceof JDBCConnectionException) || (e.getCause() instanceof JDBCConnectionException) || (e.getCause() != null && e.getCause().getCause() instanceof JDBCConnectionException) || (e.getCause() instanceof SQLTransientException) || (e.getCause() != null && e.getCause().getCause() instanceof SQLTransientException) || (e.getCause() != null && e.getCause().getCause() != null && e.getCause().getCause().getCause() instanceof SQLTransientException) || (e.getCause() != null && e.getCause().getCause() != null && e.getCause().getCause().getCause() != null && e.getCause().getCause().getCause().getCause() instanceof SQLTransientException); }
From source file:com.microsoftopentechnologies.windowsazurestorage.WAStorageClient.java
/** * Downloads from Azure blob/*from ww w. j a v a2 s. c o m*/ * * @param run environment of build * @param launcher env vars for remote builds * @param listener logging * @param strAcc storage account * @param blobs blobs from build * @param includePattern pattern to download * @param excludePattern pattern to not download * @param downloadDirLoc dir to download to * @param flattenDirectories if directories are flattened * @param workspace workspace of build * @return filesDownloaded number of files that are downloaded * @throws WAStorageException throws exception */ public static int download(Run<?, ?> run, Launcher launcher, TaskListener listener, StorageAccountInfo strAcc, List<AzureBlob> blobs, String includePattern, String excludePattern, String downloadDirLoc, boolean flattenDirectories, FilePath workspace) throws WAStorageException { int filesDownloaded = 0; for (AzureBlob blob : blobs) { try { FilePath workspacePath = new FilePath(launcher.getChannel(), workspace.getRemote()); FilePath downloadDir = getDownloadDir(workspacePath, downloadDirLoc); listener.getLogger().println(Messages.AzureStorageBuilder_downloading()); URL blobURL = new URL(blob.getBlobURL()); String filePath = blobURL.getFile(); CloudBlobContainer container = WAStorageClient.getBlobContainerReference(strAcc, filePath.split("/")[1], false, true, null); if (shouldDownload(includePattern, excludePattern, blob.getBlobName())) { filesDownloaded += downloadBlobs(container, blob, downloadDir, flattenDirectories, listener); } } catch (Exception e) { throw new WAStorageException(e.getMessage(), e.getCause()); } } return filesDownloaded; }
From source file:main.java.vasolsim.common.GenericUtils.java
/** * Tests if a given SMTP configuration is valid. It will validate addresses and the port. Then it will test * connectivity of the smtp address. Lastly, it will AUTH to smtp server and ensure the information is good. * * @param address the SMTP address/*from w ww .j av a2s .com*/ * @param port the SMTP port * @param email the email address * @param password the email address password * @param notify if popup dialogs will appear carrying the servers unsuccessful response message * * @return if the AUTH was successful */ public static boolean isValidSMTPConfiguration(String address, int port, String email, byte[] password, boolean notify) { if (!isValidAddress(address) || port <= 0 || !isValidEmail(email) || password.length == 0) return false; try { Properties smtpProperties = new Properties(); smtpProperties.put("mail.smtp.starttls.enable", "true"); smtpProperties.put("mail.smtp.auth", "true"); Session session = Session.getInstance(smtpProperties, null); Transport transport = session.getTransport("smtp"); transport.connect(address, port, email, new String(password)); transport.close(); return true; } catch (Exception e) { if (notify) { PopupManager.showMessage("Cause:\n" + e.getCause() + "\n\nMessage:\n" + e.getMessage(), "Bad SMTP"); System.out.println(e.getCause()); System.out.println(e.getMessage()); } return false; } }
From source file:edu.stanford.muse.email.MuseEmailFetcher.java
/** utility method for converting an exception encountered in this fetcher to something that can be shown to the user */ private static String getUserDisplayableMessageForException(EmailStore store, Exception e) { String failMessage;/* w w w . j a v a 2 s. c o m*/ if (e instanceof AuthenticationFailedException) { failMessage = "Invalid password for " + store.getDisplayName() + ". Please try again."; log.warn("Login failed, cause: " + failMessage + "\n" + Util.stackTrace(e)); } else if (e instanceof MessagingException) { Throwable cause = e.getCause(); if (cause != null && cause instanceof UnknownHostException) { if (store instanceof ImapPopEmailStore) { ImapPopEmailStore ipes = (ImapPopEmailStore) store; failMessage = "Unable to contact host: " + ipes.getServerHostname(); } else failMessage = "Unknown Host. Not expected with a " + store.getClass().getName() + ". Hmmm..."; } else { String server = ""; if (store instanceof ImapPopEmailStore) { ImapPopEmailStore ipes = (ImapPopEmailStore) store; server = "Unknown server: " + ipes.getServerHostname(); } failMessage = "Unable to communicate with server " + server + ": " + e.getMessage() + ". \n"; if (cause != null) failMessage += "Cause: " + cause + "\n"; } log.warn("Login failed, cause: " + failMessage + "\n" + Util.stackTrace(e)); } else { Throwable cause = e.getCause(); failMessage = "Internal error, " + cause; log.error("Exception trying to access folders: \n" + e + " : " + Util.stackTrace(e)); } return failMessage; }
From source file:cn.dockerfoundry.ide.eclipse.server.ui.internal.CloudUiUtil.java
public static IStatus runForked(final ICoreRunnable coreRunner, IWizard wizard) { try {//from w ww . j av a 2s . co m IRunnableWithProgress runner = new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { coreRunner.run(monitor); } catch (Exception e) { throw new InvocationTargetException(e); } finally { monitor.done(); } } }; wizard.getContainer().run(true, false, runner); } catch (InvocationTargetException e) { IStatus status; if (e.getCause() instanceof CoreException) { status = new Status(IStatus.ERROR, DockerFoundryServerUiPlugin.PLUGIN_ID, NLS.bind(Messages.CloudUiUtil_ERROR_FORK_OP_FAILED, e.getCause().getMessage()), e); } else { status = new Status(IStatus.ERROR, DockerFoundryServerUiPlugin.PLUGIN_ID, NLS.bind(Messages.CloudUiUtil_ERROR_FORK_UNEXPECTED, e.getMessage()), e); } DockerFoundryServerUiPlugin.getDefault().getLog().log(status); IWizardPage page = wizard.getContainer().getCurrentPage(); if (page instanceof DialogPage) { ((DialogPage) page).setErrorMessage(status.getMessage()); } return status; } catch (InterruptedException e) { return Status.CANCEL_STATUS; } return Status.OK_STATUS; }
From source file:fedora.utilities.install.Installer.java
/** * Print a message appropriate for the given exception in as human-readable * way as possible.//from ww w .j a v a 2s . c o m */ private static void printException(Exception e) { if (e instanceof InstallationCancelledException) { System.out.println("Installation cancelled."); return; } boolean recognized = false; String msg = "ERROR: "; if (e instanceof InstallationFailedException) { msg += "Installation failed: " + e.getMessage(); recognized = true; } else if (e instanceof OptionValidationException) { OptionValidationException ove = (OptionValidationException) e; msg += "Bad value for '" + ove.getOptionId() + "': " + e.getMessage(); recognized = true; } if (recognized) { System.err.println(msg); if (e.getCause() != null) { System.err.println("Caused by: "); e.getCause().printStackTrace(System.err); } } else { System.err.println(msg + "Unexpected error; installation aborted."); e.printStackTrace(); } }
From source file:com.seer.datacruncher.utils.generic.CommonUtils.java
public static String getExceptionMessage(Exception ex) { String msg = ex.getMessage(); if (msg != null) { return msg; } else {/*w w w . j a v a 2s .c o m*/ try { msg = ""; StackTraceElement[] trace = ex.getStackTrace(); Throwable e1 = ex.getCause(); if (e1 != null) { for (int i = 0; i < trace.length; i++) { if (e1 != null) { msg = e1.getMessage(); if (msg != null) { System.out.println(msg); break; } else { e1 = e1.getCause(); } } } } return msg; } catch (Exception e) { return msg; } } }