List of usage examples for java.lang Throwable getMessage
public String getMessage()
From source file:com.nextep.designer.vcs.ui.impl.ExceptionHandler.java
/** * Handles exception within the neXtep designer environment. This method returns a boolean * indicating whether the exception handling should go on with Eclipse exception handling or if * it has been absorbed by neXtep.//from w w w .j a va 2 s . co m * * @param t the exception to handle * @return <code>true</code> when the exception has been completely handled and should not be * raised, else <code>false</code>. */ public static boolean handle(Throwable t) { if (t instanceof OutOfDateObjectException) { VersionUIHelper.promptObjectSynched(((OutOfDateObjectException) t).getStaleObject()); } else if (t instanceof CancelException) { log.info(t.getMessage()); } else if (t instanceof ErrorException) { if (t.getCause() instanceof InvocationTargetException) { t = t.getCause().getCause(); return handle(t); } log.error(t.getMessage(), t); MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error when performing user action", t.getMessage()); // if("true".equals(Designer.getInstance().getProperty("nextep.designer.debug"))) { // log.error(t); // } } else if (t instanceof ExitDesignerException) { log.info(t.getMessage()); } else if (t instanceof JDBCConnectionException) { if (!Designer.getTerminationSignal()) { Designer.setTerminationSignal(true); try { // Ensuring a UI Thread Display.getDefault().syncExec(new Runnable() { @Override public void run() { // We are in a situation where we've lost our connection to the // repository MessageDialog.openError(null, UIMessages.getString("exceptionHandler.repositoryConnectionLost.title"), //$NON-NLS-1$ UIMessages.getString("exceptionHandler.repositoryConnectionLost.message")); //$NON-NLS-1$ // Closing perpective IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getActivePage(); page.closeAllPerspectives(true, true); // Closing and reopening session HibernateUtil.getInstance().reconnectAll(); // Changing view final IWorkspaceUIService viewUiService = VCSUIPlugin .getService(IWorkspaceUIService.class); final IWorkspaceService viewService = VCSPlugin.getService(IWorkspaceService.class); viewUiService.changeWorkspace(viewService.getCurrentWorkspace().getUID()); } }); } finally { Designer.setTerminationSignal(false); } } else { log.error("Error thrown while reinitializing repository connection: " + t.getMessage(), t); } return true; } else { log.error("An error has been raised: " + t.getMessage(), t); //$NON-NLS-1$ if (t instanceof HibernateException && PlatformUI.getWorkbench() != null && PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) { MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), UIMessages.getString("systemInstableTitle"), UIMessages //$NON-NLS-1$ .getString("systemInstable")); //$NON-NLS-1$ } } if (Designer.isDebugging()) { t.printStackTrace(); } // By default we consider that we haven't handled completely the problem return false; }
From source file:com.espertech.esper.event.bean.PropertyHelper.java
/** * Return getter for the given method and CGLIB FastClass. * @param method to return getter for// w w w .jav a2 s . c o m * @param fastClass is the CGLIB fast classs to make FastMethod for * @param eventAdapterService factory for event beans and event types * @return property getter */ public static EventPropertyGetter getGetter(Method method, FastClass fastClass, EventAdapterService eventAdapterService) { // Get CGLib fast method handle FastMethod fastMethod = null; try { if (fastClass != null) { fastMethod = fastClass.getMethod(method); } } catch (Throwable ex) { log.warn(".getAccessors Unable to obtain CGLib fast method implementation, msg=" + ex.getMessage()); } // Construct the appropriate property getter CGLib or reflect EventPropertyGetter getter; if (fastMethod != null) { getter = new CGLibPropertyGetter(method, fastMethod, eventAdapterService); } else { getter = new ReflectionPropMethodGetter(method, eventAdapterService); } return getter; }
From source file:com.hihframework.osplugins.json.JsonUtil.java
/** * ejson/*from w ww. j a v a2 s . c o m*/ * * @param e * @return */ public synchronized static String toString(Throwable e) { Throwable now = e; Throwable next = now.getCause(); while (next != null) { now = next; next = now.getCause(); } Map<String, String> map = new HashMap<String, String>(); map.put("error", now.toString()); map.put("message", now.getMessage() == null ? "" : now.getMessage()); return JSONObject.fromObject(map).toString(); }
From source file:com.predic8.membrane.core.config.spring.TrackingFileSystemXmlApplicationContext.java
public static void handleXmlBeanDefinitionStoreException(XmlBeanDefinitionStoreException e) throws InvalidConfigurationException { Throwable cause = e.getCause(); if (cause != null) { if (cause instanceof SAXParseException) { int line = ((SAXParseException) cause).getLineNumber(); throw new InvalidConfigurationException("line " + line + ": " + cause.getMessage()); }/*from w w w . j a v a2s .c o m*/ } throw e; }
From source file:org.sakuli.exceptions.SakuliExceptionHandler.java
public static String getAllExceptionMessages(Throwable e, boolean flatFormatted) { if (e != null) { String msg = format(e.getMessage()); //add suppressed exceptions for (Throwable ee : e.getSuppressed()) { if (flatFormatted) { msg += " -- Suppressed EXCEPTION: " + format(ee.getMessage()); } else { msg += "\n\t\t Suppressed EXCEPTION: " + format(ee.getMessage()); }/*from w ww . j a v a 2 s. c o m*/ } if (flatFormatted) { msg = StringUtils.replace(msg, "\n", " "); msg = StringUtils.replace(msg, "\t", " "); return msg; } return msg; } else { return null; } }
From source file:com.shareplaylearn.utilities.OauthPasswordFlow.java
public static LoginInfo googleLogin(String username, String password, String clientId, String callbackUri) throws URISyntaxException, IOException, AuthorizationException, UnauthorizedException { CloseableHttpClient httpClient = HttpClients.custom().build(); String oAuthQuery = "client_id=" + clientId + "&"; oAuthQuery += "response_type=code&"; oAuthQuery += "scope=openid email&"; oAuthQuery += "redirect_uri=" + callbackUri; URI oAuthUrl = new URI("https", null, "accounts.google.com", 443, "/o/oauth2/auth", oAuthQuery, null); Connection oauthGetCoonnection = Jsoup.connect(oAuthUrl.toString()); Connection.Response oauthResponse = oauthGetCoonnection.method(Connection.Method.GET).execute(); if (oauthResponse.statusCode() != 200) { String errorMessage = "Error contacting Google's oauth endpoint: " + oauthResponse.statusCode() + " / " + oauthResponse.statusMessage(); if (oauthResponse.body() != null) { errorMessage += oauthResponse.body(); }/* w ww .j av a2s .c om*/ throw new AuthorizationException(errorMessage); } Map<String, String> oauthCookies = oauthResponse.cookies(); Document oauthPage = oauthResponse.parse(); Element oauthForm = oauthPage.getElementById("gaia_loginform"); System.out.println(oauthForm.toString()); Connection oauthPostConnection = Jsoup.connect("https://accounts.google.com/ServiceLoginAuth"); HashMap<String, String> formParams = new HashMap<>(); for (Element child : oauthForm.children()) { if (child.tagName().equals("input") && child.hasAttr("name")) { String keyName = child.attr("name"); String keyValue = null; if (keyName.equals("Email")) { keyValue = username; } else if (keyName.equals("Passwd")) { keyValue = password; } else if (child.hasAttr("value")) { keyValue = child.attr("value"); } if (keyValue != null) { oauthPostConnection.data(keyName, keyValue); formParams.put(keyName, keyValue); } } } oauthPostConnection.cookies(oauthCookies); //oauthPostConnection.followRedirects(false); System.out.println("form post params were: "); for (Map.Entry<String, String> kvp : formParams.entrySet()) { //DO NOT let passwords end up in the logs ;) if (kvp.getKey().equals("Passwd")) { continue; } System.out.println(kvp.getKey() + "," + kvp.getValue()); } System.out.println("form cookies were: "); for (Map.Entry<String, String> cookie : oauthCookies.entrySet()) { System.out.println(cookie.getKey() + "," + cookie.getValue()); } Connection.Response postResponse = null; try { postResponse = oauthPostConnection.method(Connection.Method.POST).timeout(5000).execute(); } catch (Throwable t) { System.out.println("Failed to post login information to googles endpoint :/ " + t.getMessage()); System.out.println("This usually means the connection is bad, shareplaylearn.com is down, or " + " google is being a punk - login manually and check."); assertTrue(false); } if (postResponse.statusCode() != 200) { String errorMessage = "Failed to validate credentials: " + oauthResponse.statusCode() + " / " + oauthResponse.statusMessage(); if (oauthResponse.body() != null) { errorMessage += oauthResponse.body(); } throw new UnauthorizedException(errorMessage); } System.out.println("Response headers (after post to google form & following redirect):"); for (Map.Entry<String, String> header : postResponse.headers().entrySet()) { System.out.println(header.getKey() + "," + header.getValue()); } System.out.println("Final response url was: " + postResponse.url().toString()); String[] args = postResponse.url().toString().split("&"); LoginInfo loginInfo = new LoginInfo(); for (String arg : args) { if (arg.startsWith("access_token")) { loginInfo.accessToken = arg.split("=")[1].trim(); } else if (arg.startsWith("id_token")) { loginInfo.idToken = arg.split("=")[1].trim(); } else if (arg.startsWith("expires_in")) { loginInfo.expiry = arg.split("=")[1].trim(); } } //Google doesn't actually throw a 401 or anything - it just doesn't redirect //and sends you back to it's login page to try again. //So this is what happens with an invalid password. if (loginInfo.accessToken == null || loginInfo.idToken == null) { //Document oauthPostResponse = postResponse.parse(); //System.out.println("*** Oauth response from google *** "); //System.out.println(oauthPostResponse.toString()); throw new UnauthorizedException( "Error retrieving authorization: did you use the correct username/password?"); } String[] idTokenFields = loginInfo.idToken.split("\\."); if (idTokenFields.length < 3) { throw new AuthorizationException("Error parsing id token " + loginInfo.idToken + "\n" + "it only had " + idTokenFields.length + " field!"); } String jwtBody = new String(Base64.decodeBase64(idTokenFields[1]), StandardCharsets.UTF_8); loginInfo.idTokenBody = new Gson().fromJson(jwtBody, OauthJwt.class); loginInfo.id = loginInfo.idTokenBody.sub; return loginInfo; }
From source file:cc.sion.core.utils.Exceptions.java
/** * ??????, ?/* w w w . ja va2s. c o m*/ */ public static String getErrorMessageWithNestedException(Throwable ex) { Throwable nestedException = ex.getCause(); return new StringBuilder().append(ex.getMessage()).append(" nested exception is ") .append(nestedException.getClass().getName()).append(":").append(nestedException.getMessage()) .toString(); }
From source file:org.apache.asterix.api.http.server.ResultUtil.java
public static String buildParseExceptionMessage(Throwable e, String query) { StringBuilder errorMessage = new StringBuilder(); String message = e.getMessage(); message = message.replace("<", "<"); message = message.replace(">", ">"); errorMessage.append("Error: " + message + "\n"); int pos = message.indexOf("line"); if (pos > 0) { Pattern p = Pattern.compile("\\d+"); Matcher m = p.matcher(message); if (m.find(pos)) { int lineNo = Integer.parseInt(message.substring(m.start(), m.end())); String[] lines = query.split("\n"); if (lineNo > lines.length) { errorMessage.append("===> <BLANK LINE> \n"); } else { String line = lines[lineNo - 1]; errorMessage.append("==> " + line); }/*from www .j a v a 2 s. c o m*/ } } return errorMessage.toString(); }
From source file:com.maverick.http.SocketWithLayeredTransport.java
public static String getExceptionMessageChain(Throwable t) { StringBuffer buf = new StringBuffer(); while (t != null) { if (buf.length() > 0 && !buf.toString().endsWith(".")) { //$NON-NLS-1$ buf.append(". "); //$NON-NLS-1$ }/*from w w w . j av a2s . c o m*/ if (t.getMessage() != null) { buf.append(t.getMessage().trim()); } try { Method m = t.getClass().getMethod("getCause", (Class[]) null); //$NON-NLS-1$ t = (Throwable) m.invoke(t, (Object[]) null); } catch (Throwable ex) { } } return buf.toString(); }
From source file:com.bluemarsh.jswat.console.Main.java
/** * Interprets the given command via the command parser. * * @param output where to write error messages. * @param parser the command interpreter. * @param input the input command./* ww w . j av a 2 s . c o m*/ */ private static void performCommand(PrintWriter output, CommandParser parser, String input) { // Send the input to the command parser, which will run the // command and send output to the writer it was assigned earlier. try { parser.parseInput(input); } catch (MissingArgumentsException mae) { output.println(mae.getMessage()); output.println(NbBundle.getMessage(Main.class, "ERR_Main_HelpCommand")); } catch (CommandException ce) { // Print the message which should explain everything. // If there is a root cause, show that, too. output.println(ce.getMessage()); Throwable cause = ce.getCause(); if (cause != null) { String cmsg = cause.getMessage(); if (cmsg != null) { output.println(cmsg); } } } }