List of usage examples for java.lang Throwable getCause
public synchronized Throwable getCause()
From source file:com.izforge.izpack.event.AntAction.java
/** * Wraps a Ant {@link BuildException} to an {@link InstallerException}. * This is mainly done for the purpose of cutting of the location from the build failure message. * Locations should appear just in logs, not to the user. * * @param e the {@link IzPackException} with the nested {@link BuildException} * @throws InstallerException//from w ww. j a va2 s. c o m */ public void throwBuildException(IzPackException e) throws InstallerException { String message; Throwable cause = e.getCause(), nested = e; IzPackException ize = e; while (cause != null) { nested = cause; cause = cause.getCause(); } if (nested instanceof BuildException) { // Workaround for BuildException.toString(): // Filter off the location, just leave the clean failure message Location location = ((BuildException) nested).getLocation(); message = nested.toString().substring(location.toString().length()); ize = new IzPackException(message, e, severity); } throw new InstallerException(ize); }
From source file:de.tudarmstadt.lt.ltbot.postprocessor.DecesiveValueProducerPerplexity.java
private boolean testStringProviderService() { try {//w w w.jav a 2 s . co m computePerplexity("Hello Test Run run run run."); } catch (Throwable t) { for (int i = 1; t != null && i < 10; i++) { LOG.log(Level.SEVERE, String.format("Initialization test failed. (%d %s:%s)", i, t.getClass().getSimpleName(), t.getMessage()), t); t = t.getCause(); } return false; } LOG.info("Initialization test succeeded."); return true; }
From source file:dk.netarkivet.common.utils.JMXUtils.java
/** Get a JMXConnector to a given host and port, using login and password. * * @param hostName The host to attempt to connect to. * @param jmxPort The port on the host to connect to * (a non-negative number)./* w ww. ja v a2 s . co m*/ * @param login The login name to authenticate as (typically "controlRole" * or "monitorRole". * @param password The password for JMX access. * @return A JMX connector to the given host and port, using default RMI. * @throws IOFailure if connecting to JMX fails. */ public static JMXConnector getJMXConnector(String hostName, int jmxPort, final String login, final String password) { ArgumentNotValid.checkNotNullOrEmpty(hostName, "String hostName"); ArgumentNotValid.checkNotNegative(jmxPort, "int jmxPort"); ArgumentNotValid.checkNotNullOrEmpty(login, "String login"); ArgumentNotValid.checkNotNullOrEmpty(password, "String password"); JMXServiceURL rmiurl = getUrl(hostName, jmxPort, -1); Map<String, ?> environment = packageCredentials(login, password); Throwable lastException; int retries = 0; final int maxJmxRetries = getMaxTries(); do { try { return JMXConnectorFactory.connect(rmiurl, environment); } catch (IOException e) { lastException = e; if (retries < maxJmxRetries && e.getCause() != null && (e.getCause() instanceof ServiceUnavailableException || e.getCause() instanceof SocketTimeoutException)) { // Sleep a bit before trying again TimeUtils.exponentialBackoffSleep(retries); /* called exponentialBackoffSleep(retries) which used Calendar.MILLISECOND as time unit, which means we only wait an exponential number of milliseconds. */ continue; } break; } } while (retries++ < maxJmxRetries); throw new IOFailure( "Failed to connect to URL " + rmiurl + " after " + retries + " of " + maxJmxRetries + " attempts.\nException type: " + lastException.getCause().getClass().getName(), lastException); }
From source file:net.solarnetwork.node.control.demandbalancer.DemandBalancer.java
/** * Get a message for an exception. This will try to return the root cause's * message. If that is not available the name of the root cause's class will * be returned./*from w w w . j a va 2 s. co m*/ * * @param t * the exception * @return message */ private String messageForException(Throwable t) { Throwable root = t; while (root.getCause() != null) { root = root.getCause(); } String msg = root.getMessage(); if (msg == null || msg.length() < 1) { msg = t.getMessage(); if (msg == null || msg.length() < 1) { msg = root.getClass().getName(); } } return msg; }
From source file:it.geosolutions.geobatch.destination.common.InputObject.java
/** * @param e//from ww w. jav a 2 s.c o m * @return */ protected String getError(Exception e) { // TODO: human readble error Throwable t = e; while (t.getCause() != null) { t = t.getCause(); } return t.getMessage().substring(0, Math.min(t.getMessage().length(), 1000)); }
From source file:hudson.model.Fingerprint.java
private static String messageOfParseException(Throwable t) { if (t instanceof XmlPullParserException || t instanceof EOFException) { return t.getMessage(); }//www. ja va2 s . co m Throwable t2 = t.getCause(); if (t2 != null) { return messageOfParseException(t2); } else { return null; } }
From source file:py.una.pol.karaku.exception.KarakuJSFExceptionHandler.java
@Override public void handle() { if (this.isDevelop()) { this.wrapped.handle(); return;//from w w w. j a v a2s . c o m } // itera sobre todas las excepciones no controladas Iterator<ExceptionQueuedEvent> iterator = this.getUnhandledExceptionQueuedEvents().iterator(); while (iterator.hasNext()) { ExceptionQueuedEvent event = iterator.next(); ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource(); // obtiene un throwable object Throwable t = context.getException(); try { // iteramos para encontrar todas las causas del error while (t != null) { // manegamos la excepcion if (t instanceof org.springframework.security.access.AccessDeniedException) { // redirigimos al error view etc.... this.accessDenied(t); return; } t = t.getCause(); } // no se ha tratado aun ningun error this.error(context.getException()); } catch (Exception e) { LOG.error("Se ha producido un error al manejar el error", e); } finally { // despues que la excepcion es controlada, la removemos de la // cola iterator.remove(); } } // no dejamos al parent handler manejar el resto debido a que no // visualizara la pgina de error para hacer esto invocar // getWrapped()#handle }
From source file:connectivity.ClarolineService.java
/** * Verify that the passed host is a valid Claroline platform. * /*w ww. j a v a2s . c o m*/ * @param hostURL * the requested url * @param handler * the handler to execute after the request */ public void checkHostValidity(final String hostURL, final AsyncHttpResponseHandler handler) { mClient.get(hostURL.replace(' ', '\0'), new AsyncHttpResponseHandler() { @Override public void onFailure(final Throwable error, final String content) { if (error.getCause() instanceof SSLException && App.getPrefs().getBoolean(App.SETTINGS_HTTP_NO_SSL, false)) { checkHostValidity(hostURL.replace("https://", "http://"), handler); } else { handler.onFailure(error, content); } } @Override public void onFinish() { handler.onFinish(); } @Override public void onSuccess(final String content) { handler.onSuccess(String.valueOf( content.contains("<!-- - - - - - - - - - - Claroline " + "Body - - - - - - - - - -->")) + "#" + hostURL); } }); }
From source file:net.ripe.rpki.commons.provisioning.cms.ProvisioningCmsObjectParser.java
private String extractMessages(CMSException e) { Throwable t = e; final List<String> messages = new ArrayList<String>(); while (t != null && !messages.contains(t.getMessage())) { messages.add(t.getMessage());/*from ww w. ja v a 2 s . c o m*/ t = t.getCause(); } return StringUtils.join(messages, ", reason: "); }
From source file:fxts.stations.transport.tradingapi.TradingServerSession.java
/** * log into the trade server/*from w w w.j av a 2s .c o m*/ * * @param aUsername user * @param aPassword pass * @param aTerminal terminal * @param aUrl url * * @throws Exception aex */ public void login(String aUsername, String aPassword, String aTerminal, String aUrl, String aCfgFile) throws Exception { mLogout = false; mUsername = aUsername; mPassword = aPassword; mTerminal = aTerminal; mHostUrl = aUrl; UserPreferences preferences = UserPreferences.getUserPreferences(TradeDesk.getInst().getUserName()); GATEWAY.logout(); GATEWAY.registerGenericMessageListener(this); GATEWAY.registerStatusMessageListener(this); if (aCfgFile == null) { mCfgFile = mApplication.getServerConfigFile(mUsername); } else { mCfgFile = aCfgFile; } try { FXCMLoginProperties props = new FXCMLoginProperties(mUsername, mPassword, mTerminal, mHostUrl, "".equals(mCfgFile) ? null : mCfgFile); //props.addProperty(IConnectionManager.HTTP_IMPLEMENTATION, "apache"); //props.addProperty(IConnectionManager.MSG_FLAGS, String.valueOf(IFixDefs.CHANNEL_MARKET_DATA)); //props.addProperty(IConnectionManager.RELOGIN_TIMEOUT, "0"); String value = preferences.getString("Server.secure." + mTerminal); if (value != null) { props.addProperty(IConnectionManager.SECURE_PREF, value); } props.addProperty(IConnectionManager.APP_INFO, "JTS"); if (preferences.getBoolean("Proxy.use")) { props.addProperty(IConnectionManager.PROXY_SERVER, preferences.getString("Proxy.host")); props.addProperty(IConnectionManager.PROXY_PORT, preferences.getString("Proxy.port")); props.addProperty(IConnectionManager.PROXY_UID, preferences.getString("Proxy.user")); props.addProperty(IConnectionManager.PROXY_PWD, preferences.getString("Proxy.password")); } TradingSessionDesc[] tradingSessions = GATEWAY.getTradingSessions(props); MainFrame mainFrame = TradeApp.getInst().getMainFrame(); TradingSessionDesc selectedSession; if (tradingSessions.length > 1) { TradingSessionDialog tsd = new TradingSessionDialog(mainFrame, tradingSessions); int selection = tsd.showModal(); selectedSession = tradingSessions[selection]; mLogger.debug("selection = " + selectedSession); } else { selectedSession = tradingSessions[0]; } String pinRequired = selectedSession.getProperty("PIN_REQUIRED"); if (pinRequired != null && "Y".equalsIgnoreCase(pinRequired)) { PINDialog pinDialog = new PINDialog(mainFrame); pinDialog.setVisible(true); Properties properties = new Properties(); properties.setProperty(IUserSession.PIN, pinDialog.getPIN()); GATEWAY.openSession(selectedSession, properties); } else { GATEWAY.openSession(selectedSession); } } catch (Exception e) { //loop through all nested causes looking for authentication exception Throwable cause = e; while (cause.getCause() != null && !(cause instanceof AuthenticationException)) { cause = cause.getCause(); } String error = OraCodeFactory.toMessage(cause.getMessage()); if (error != null && error.length() > 0) { throw new LoginException(cause, error); } else if (e instanceof AuthenticationException || cause instanceof AuthenticationException) { String value = "Login failed: Incorrect user name or password."; throw new LoginException(cause, value); } else { String value = "Login failed. Server does not return session id."; throw new LoginException(cause, value); } } getUserObjects(); FXCMConnection cx = FXCMConnectionsManager.getConnection(mTerminal); cx.setUsername(mUsername); FXCMConnectionsManager.updateAddConnection(mTerminal, cx); preferences.set("Server.last.connected.terminal", mTerminal); }