List of usage examples for org.apache.commons.lang.exception ExceptionUtils getMessage
public static String getMessage(Throwable th)
From source file:ch.unibas.fittingwizard.presentation.base.CatchedRunnable.java
private void showError(Exception e) { String details = ExceptionUtils.getMessage(e); OverlayDialog.showError("An unhandeled erro occured", "The error contained the following message:\n" + details); }
From source file:com.github.dbourdette.glass.log.joblog.JobLog.java
public static JobLog exception(JobExecution execution, JobLogLevel level, String message, Throwable e) { JobLog jobLog = message(execution, level, message); jobLog.stackTrace = ExceptionUtils.getFullStackTrace(e); jobLog.rootCause = ExceptionUtils.getMessage(ExceptionUtils.getRootCause(e)); if (StringUtils.isEmpty(jobLog.rootCause)) { jobLog.rootCause = ExceptionUtils.getMessage(e); }// ww w .ja va2s. c om if (StringUtils.isEmpty(jobLog.rootCause)) { jobLog.rootCause = "no message"; } return jobLog; }
From source file:fusejext2.JextThreadFactory.java
@Override public synchronized Thread newThread(Runnable r) { final String name = new StringBuilder().append(threadPrefix).append("[").append(count.getAndIncrement()) .append("]").toString(); Thread t = new Thread(r); t.setName(name);//from w w w . j a v a 2 s . c o m t.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { logger.severe(new StringBuffer().append("Uncaught Exception in thread ").append(name).append("\n") .append(ExceptionUtils.getMessage(e)).append(", ") .append(ExceptionUtils.getRootCauseMessage(e)).append("\n") .append(ExceptionUtils.getFullStackTrace(e)).toString()); logger.severe("Shutting down due to unexpected exception.."); System.exit(23); } }); logger.info("Created new Thread: " + name); return t; }
From source file:com.haulmont.cuba.web.exception.DefaultExceptionHandler.java
@Override public boolean handle(ErrorEvent event, App app) { // Copied from com.vaadin.server.DefaultErrorHandler.doDefault() //noinspection ThrowableResultOfMethodCallIgnored Throwable t = event.getThrowable(); //noinspection ThrowableResultOfMethodCallIgnored if (t instanceof SocketException || ExceptionUtils.getRootCause(t) instanceof SocketException) { // Most likely client browser closed socket return true; }//from www . j a va2s. co m // Support Tomcat 8 ClientAbortException if (StringUtils.contains(ExceptionUtils.getMessage(t), "ClientAbortException")) { // Most likely client browser closed socket return true; } AppUI ui = AppUI.getCurrent(); if (ui == null) { // there is no UI, just add error to log return true; } if (t != null) { if (app.getConnection().getSession() != null) { showDialog(app, t); } else { showNotification(app, t); } } return true; }
From source file:com.baasbox.controllers.Link.java
@With({ UserCredentialWrapFilter.class, ConnectToDBFilter.class, ExtractQueryParameters.class }) public static Result getLinks() throws IOException { Context ctx = Http.Context.current.get(); QueryParams criteria = (QueryParams) ctx.args.get(IQueryParametersKeys.QUERY_PARAMETERS); List<ODocument> listOfLinks; try {// www . j ava 2 s . c o m listOfLinks = LinkService.getLink(criteria); } catch (InvalidCriteriaException e) { return badRequest(ExceptionUtils.getMessage(e)); } catch (SqlInjectionException e) { return badRequest( "The parameters you passed are incorrect. HINT: check if the querystring is correctly encoded"); } return ok(JSONFormats.prepareResponseToJson(listOfLinks, Formats.LINK)); }
From source file:com.baasbox.commands.ScriptsResource.java
private static JsonNode wsCall(JsonNode command, JsonCallback callback) throws CommandException { try {/*from w ww. j a v a2 s . c o m*/ return ScriptingService.callJsonSync(command.get(ScriptCommand.PARAMS)); } catch (Exception e) { throw new CommandExecutionException(command, ExceptionUtils.getMessage(e), e); } }
From source file:com.baasbox.controllers.actions.filters.BasicAuthAccess.java
@Override public boolean setCredential(Context ctx) { if (BaasBoxLogger.isTraceEnabled()) BaasBoxLogger.trace("Method Start"); if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("BasicAuthHeader for resource " + Http.Context.current().request()); //retrieve AppCode String appcode = RequestHeaderHelper.getAppCode(ctx); if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug(SessionKeys.APP_CODE + ": " + appcode); ctx.args.put("appcode", appcode); String username = ""; String password = ""; //getting the credential from the request header: http://digitalsanctum.com/2012/06/07/basic-authentication-in-the-play-framework-using-custom-action-annotation/ //-------------------------------------------------------------- String authHeader = ctx.request().getHeader(AUTHORIZATION); if (authHeader == null) { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug(AUTHORIZATION + " header is null or missing"); return false; }//from www .j a va 2s . c om byte[] decodedAuth; try { String auth = authHeader.substring(6); if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug(AUTHORIZATION + ": " + auth); decodedAuth = Base64.decodeBase64(auth);// new sun.misc.BASE64Decoder().decodeBuffer(auth); } catch (Exception e) { BaasBoxLogger.error("Cannot decode " + AUTHORIZATION + " header. " + ExceptionUtils.getMessage(e)); return false; } // } catch (IOException e1) { // Logger.error("Cannot decode " + AUTHORIZATION + " header. " + e1.getMessage()); // return false; // } catch (StringIndexOutOfBoundsException e){ // Logger.error("Cannot decode " + AUTHORIZATION + " header. " + ExceptionUtils.getMessage(e)); // return false; // } if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("Decoded header: " + decodedAuth); String[] credString; try { credString = new String(decodedAuth, "UTF-8").split(":"); } catch (UnsupportedEncodingException e) { BaasBoxLogger.error("UTF-8 encoding not supported, really???", e); throw new RuntimeException("UTF-8 encoding not supported, really???", e); } if (credString == null || credString.length != 2) { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug(AUTHORIZATION + " header is not valid (has not user:password pair)"); return false; } username = credString[0]; password = credString[1]; if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("username: " + username); if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("password: <hidden>"); ctx.args.put("username", username); ctx.args.put("password", password); if (BaasBoxLogger.isTraceEnabled()) BaasBoxLogger.trace("Method End"); return true; }
From source file:com.baasbox.configuration.IosCertificateHandler.java
@Override public void change(Object iCurrentValue, Object iNewValue) { if (iNewValue == null) { return;/*w ww .j a va 2s. c o m*/ } String folder = BBConfiguration.getPushCertificateFolder(); File f = new File(folder); if (!f.exists()) { f.mkdirs(); } ConfigurationFileContainer newValue = null; ConfigurationFileContainer currentValue = null; if (iNewValue != null && iNewValue instanceof ConfigurationFileContainer) { newValue = (ConfigurationFileContainer) iNewValue; } if (iCurrentValue != null) { if (iCurrentValue instanceof String) { try { currentValue = new ObjectMapper().readValue(iCurrentValue.toString(), ConfigurationFileContainer.class); } catch (Exception e) { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("unable to convert value to ConfigurationFileContainer"); } } else if (iCurrentValue instanceof ConfigurationFileContainer) { currentValue = (ConfigurationFileContainer) iCurrentValue; } } if (currentValue != null) { File oldFile = new File(folder + sep + currentValue.getName()); if (oldFile.exists()) { try { FileUtils.forceDelete(oldFile); } catch (Exception e) { BaasBoxLogger.error(ExceptionUtils.getMessage(e)); } } } if (newValue != null) { File newFile = new File(folder + sep + newValue.getName()); try { if (!newFile.exists()) { newFile.createNewFile(); } } catch (IOException ioe) { throw new RuntimeException("unable to create file:" + ExceptionUtils.getMessage(ioe)); } ByteArrayInputStream bais = new ByteArrayInputStream(newValue.getContent()); try { FileUtils.copyInputStreamToFile(bais, newFile); bais.close(); } catch (IOException ioe) { //TODO:more specific exception throw new RuntimeException(ExceptionUtils.getMessage(ioe)); } } else { BaasBoxLogger.warn("Ios Certificate Handler invoked with wrong parameters"); //TODO:throw an exception? } }
From source file:ch.unibas.fittingwizard.presentation.base.progress.ProgressPage.java
@Override public void initializeData() { if (task == null) { task = new Task<Boolean>() { @Override/* w w w . j a v a 2 s . co m*/ protected Boolean call() throws Exception { return ProgressPage.this.run(ProgressPage.this); } }; task.setOnCancelled(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent event) { logger.info("Task canceled."); goBack(); } }); task.setOnSucceeded(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent event) { logger.info("Task succeeded."); final boolean result = task.getValue(); Platform.runLater(new CatchedRunnable() { @Override public void safelyRun() { handleFinishedRun(result); } }); task = null; } }); task.setOnFailed(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent event) { logger.info("Task failed."); String error = "No exception details available."; if (task.getException() != null) { error = ExceptionUtils.getMessage(task.getException()); logger.error("Task failed with exception.", task.getException()); } OverlayDialog.showError("Error in the task execution", "There was an error in the task execution.\n\n" + error); goBack(); } }); } logger.info("Starting task"); new Thread(task).start(); logger.info("Task started."); }
From source file:com.baasbox.controllers.actions.filters.ConnectToDBFilter.java
@Override public F.Promise<SimpleResult> call(Context ctx) throws Throwable { if (BaasBoxLogger.isTraceEnabled()) BaasBoxLogger.trace("Method Start"); //set the current Context in the local thread to be used in the views: https://groups.google.com/d/msg/play-framework/QD3czEomKIs/LKLX24dOFKMJ Http.Context.current.set(ctx); //fixme should happen as early as possible in the action chain RouteTagger.attachAnnotations(ctx);// www .j av a 2s . c o m if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("ConnectToDB for resource " + Http.Context.current().request()); String username = (String) Http.Context.current().args.get("username"); String password = (String) Http.Context.current().args.get("password"); String appcode = (String) Http.Context.current().args.get("appcode"); ODatabaseRecordTx database = null; F.Promise<SimpleResult> result = null; try { //close an eventually 'ghost' connection left open in this thread //(this may happen in case of Promise usage) DbHelper.close(DbHelper.getConnection()); try { database = DbHelper.open(appcode, username, password); if (!Tags.verifyAccess(ctx)) { return F.Promise.<SimpleResult>pure(forbidden("Endpoint has been disabled")); } } catch (OSecurityAccessException e) { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug(ExceptionUtils.getMessage(e)); return F.Promise.<SimpleResult>pure(unauthorized( "User " + Http.Context.current().args.get("username") + " is not authorized to access")); } catch (ShuttingDownDBException sde) { String message = ExceptionUtils.getMessage(sde); BaasBoxLogger.info(message); return F.Promise.<SimpleResult>pure(status(503, message)); } result = delegate.call(ctx); if (DbHelper.getConnection() != null && DbHelper.isInTransaction()) throw new TransactionIsStillOpenException( "Controller left an open transaction. Database will be rollbacked"); } catch (OSecurityAccessException e) { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug( "ConnectToDB: user authenticated but a security exception against the resource has been detected: " + ExceptionUtils.getMessage(e)); result = F.Promise.<SimpleResult>pure(forbidden(ExceptionUtils.getMessage(e))); } catch (InvalidAppCodeException e) { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("ConnectToDB: Invalid App Code " + ExceptionUtils.getMessage(e)); result = F.Promise.<SimpleResult>pure(unauthorized(ExceptionUtils.getMessage(e))); } catch (Throwable e) { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug( "ConnectToDB: an expected error has been detected: " + ExceptionUtils.getFullStackTrace(e)); result = F.Promise.<SimpleResult>pure(internalServerError(ExceptionUtils.getFullStackTrace(e))); } finally { Http.Context.current.set(ctx); if (DbHelper.getConnection() != null && DbHelper.isInTransaction()) DbHelper.rollbackTransaction(); DbHelper.close(database); } if (BaasBoxLogger.isTraceEnabled()) BaasBoxLogger.trace("Method End"); return result; }