List of usage examples for org.apache.commons.lang.exception ExceptionUtils getRootCauseStackTrace
public static String[] getRootCauseStackTrace(Throwable throwable)
Creates a compact stack trace for the root cause of the supplied Throwable
.
The output of this method is consistent across JDK versions.
From source file:com.eucalyptus.system.log.EucaThrowableRenderer.java
@Override public String[] doRender(final Throwable t) { return ExceptionUtils.getRootCauseStackTrace(t); }
From source file:ddf.catalog.impl.operations.MetacardFactory.java
Metacard generateMetacard(String mimeTypeRaw, String id, String fileName, Path tmpContentPath) throws MetacardCreationException, MimeTypeParseException { Metacard generatedMetacard = null;//from w ww .j a v a2s . c o m MimeType mimeType = new MimeType(mimeTypeRaw); List<InputTransformer> listOfCandidates = mimeTypeToTransformerMapper.findMatches(InputTransformer.class, mimeType); List<String> stackTraceList = new ArrayList<>(); LOGGER.debug("List of matches for mimeType [{}]: {}", mimeType, listOfCandidates); for (InputTransformer candidate : listOfCandidates) { try (InputStream transformerStream = com.google.common.io.Files.asByteSource(tmpContentPath.toFile()) .openStream()) { generatedMetacard = candidate.transform(transformerStream); } catch (CatalogTransformerException | IOException e) { List<String> stackTraces = Arrays.asList(ExceptionUtils.getRootCauseStackTrace(e)); stackTraceList.add(String.format("Transformer [%s] could not create metacard.", candidate)); stackTraceList.addAll(stackTraces); LOGGER.debug("Transformer [{}] could not create metacard.", candidate, e); } if (generatedMetacard != null) { break; } } if (generatedMetacard == null) { throw new MetacardCreationException(String.format("Could not create metacard with mimeType %s : %s", mimeTypeRaw, StringUtils.join(stackTraceList, "\n"))); } if (id != null) { generatedMetacard.setAttribute(new AttributeImpl(Metacard.ID, id)); } else { generatedMetacard.setAttribute(new AttributeImpl(Metacard.ID, uuidGenerator.generateUuid())); } if (StringUtils.isBlank(generatedMetacard.getTitle())) { generatedMetacard.setAttribute(new AttributeImpl(Metacard.TITLE, fileName)); } return generatedMetacard; }
From source file:com.openmeap.admin.web.backing.AddModifyApplicationBacking.java
/** * With the first of the bean name matching "addModifyApp", there are * three ways to access this:// w ww. ja v a 2 s .c om * - request has applicationId and processTarget - modifying an application * - request has applicationId only - pulling up an application to modify * - request has processTarget only - submitting a brand new application * * See the WEB-INF/ftl/form-application-addmodify.ftl for input/output parameters. * * @param context Not referenced at all, may be null * @param templateVariables Variables output to for the view * @param parameterMap Parameters passed in to drive processing * @return on errors, returns an array of error processingevents * @see TemplatedSectionBacking::process() */ public Collection<ProcessingEvent> process(ProcessingContext context, Map<Object, Object> templateVariables, Map<Object, Object> parameterMap) { List<ProcessingEvent> events = new ArrayList<ProcessingEvent>(); templateVariables.put(FormConstants.PROCESS_TARGET, PROCESS_TARGET); Application app = new Application(); if (ParameterMapUtils.notEmpty(FormConstants.APP_ID, parameterMap)) { app = modelManager.getModelService().findByPrimaryKey(Application.class, Long.valueOf(ParameterMapUtils.firstValue(FormConstants.APP_ID, parameterMap))); } Boolean mayCreate = modelManager.getAuthorizer().may(Authorizer.Action.CREATE, new Application()); Boolean mayModify = modelManager.getAuthorizer().may(Authorizer.Action.MODIFY, app); Boolean willProcess = mayCreate || mayModify; if (!willProcess) { events.add(new MessagesEvent("Current user does not have permissions to make changes here")); } templateVariables.put("willProcess", willProcess); // if the request is targeting this section or the primary page of this section // the user is submitting the form for either an add or modify if (ParameterMapUtils.notEmpty(FormConstants.PROCESS_TARGET, parameterMap) && PROCESS_TARGET.equals(((String[]) parameterMap.get(FormConstants.PROCESS_TARGET))[0]) && willProcess) { app = createApplicationFromParameters(app, parameterMap, events); if (ParameterMapUtils.firstValue("submit", parameterMap).equals("true")) { if (events.size() == 0) { try { app.setLastModifier(firstValue("userPrincipalName", parameterMap)); modelManager.begin(); app = modelManager.addModify(app, events); modelManager.commit(events); events.add(new MessagesEvent("Application successfully created/modified!")); } catch (InvalidPropertiesException e) { events.add(new MessagesEvent(String.format("Application add/modify failed: %s %s", ExceptionUtils.getRootCauseMessage(e), ExceptionUtils.getRootCauseStackTrace(e)[0]))); logger.error("Add/Modify application with id " + app.getId() + " failed", e); modelManager.rollback(); } catch (PersistenceException e) { events.add(new MessagesEvent(String.format("Application add/modify failed: %s %s", ExceptionUtils.getRootCauseMessage(e), ExceptionUtils.getRootCauseStackTrace(e)[0]))); logger.error("Add/Modify application with id " + app.getId() + " failed", e); modelManager.rollback(); } } if (app == null && ParameterMapUtils.notEmpty(FormConstants.APP_ID, parameterMap)) app = modelManager.getModelService().findByPrimaryKey(Application.class, Long.valueOf(ParameterMapUtils.firstValue(FormConstants.APP_ID, parameterMap))); } if (ParameterMapUtils.notEmpty("delete", parameterMap) && ParameterMapUtils.firstValue("delete", parameterMap).equals("true")) { if (!ParameterMapUtils.empty("deleteConfirm", parameterMap) && ParameterMapUtils .firstValue("deleteConfirm", parameterMap).equals(FormConstants.APP_DELETE_CONFIRM_TEXT)) { try { modelManager.begin(); modelManager.delete(app, events); modelManager.commit(events); events.add(new MessagesEvent("Application successfully deleted!")); app = null; // we remove the applicationId parameter, so that the form can populate empty parameterMap.remove(FormConstants.APP_ID); } catch (Exception e) { events.add(new MessagesEvent(String.format("Application delete failed: %s %s", ExceptionUtils.getRootCauseMessage(e), ExceptionUtils.getRootCauseStackTrace(e)[0]))); logger.error("Deleting application with id " + app.getId() + " failed", e); modelManager.rollback(); } } else { events.add(new MessagesEvent( "You must confirm your desire to delete by typing in the delete confirmation message.")); } } } // the user is visiting the page to view or modify an application else if (ParameterMapUtils.notEmpty(FormConstants.APP_ID, parameterMap)) { app = modelManager.getModelService().findByPrimaryKey(Application.class, Long.valueOf(ParameterMapUtils.firstValue(FormConstants.APP_ID, parameterMap))); } if (app == null && ParameterMapUtils.notEmpty(FormConstants.APP_ID, parameterMap)) { events.add(new MessagesEvent("Application with id " + ParameterMapUtils.firstValue(FormConstants.APP_ID, parameterMap) + " not found")); } else if (app != null && app.getId() != null) { // in order to create the ApplicationVersion testVer = new ApplicationVersion(); testVer.setApplication(app); Boolean mayCreateVersions = modelManager.getAuthorizer().may(Authorizer.Action.CREATE, testVer); if (mayCreateVersions) { events.add(new AddSubNavAnchorEvent( new Anchor("?bean=addModifyAppVersionPage&applicationId=" + app.getId(), "Create new version", "Create new version"))); } events.add( new AddSubNavAnchorEvent(new Anchor("?bean=appVersionListingsPage&applicationId=" + app.getId(), "Version Listings", "Version Listings"))); events.add( new AddSubNavAnchorEvent(new Anchor("?bean=deploymentListingsPage&applicationId=" + app.getId(), "Deployment History", "Deployment History"))); } fillInVariablesFromApplication(templateVariables, app); return events; }
From source file:org.codice.ddf.rest.impl.CatalogServiceImpl.java
private Metacard generateMetacard(MimeType mimeType, String id, InputStream message, String transformerId) throws MetacardCreationException { Metacard generatedMetacard = null;// w ww . ja v a 2 s . co m List<InputTransformer> listOfCandidates = mimeTypeToTransformerMapper.findMatches(InputTransformer.class, mimeType); List<String> stackTraceList = new ArrayList<>(); LOGGER.trace("Entering generateMetacard."); LOGGER.debug("List of matches for mimeType [{}]: {}", mimeType, listOfCandidates); try (TemporaryFileBackedOutputStream fileBackedOutputStream = new TemporaryFileBackedOutputStream()) { try { if (null != message) { IOUtils.copy(message, fileBackedOutputStream); } else { throw new MetacardCreationException( "Could not copy bytes of content message. Message was NULL."); } } catch (IOException e) { throw new MetacardCreationException("Could not copy bytes of content message.", e); } Iterator<InputTransformer> it = listOfCandidates.iterator(); if (StringUtils.isNotEmpty(transformerId)) { BundleContext bundleContext = getBundleContext(); Collection<ServiceReference<InputTransformer>> serviceReferences = bundleContext .getServiceReferences(InputTransformer.class, "(id=" + transformerId + ")"); it = serviceReferences.stream().map(bundleContext::getService).iterator(); } while (it.hasNext()) { InputTransformer transformer = it.next(); try (InputStream inputStreamMessageCopy = fileBackedOutputStream.asByteSource().openStream()) { generatedMetacard = transformer.transform(inputStreamMessageCopy); } catch (CatalogTransformerException | IOException e) { List<String> stackTraces = Arrays.asList(ExceptionUtils.getRootCauseStackTrace(e)); stackTraceList.add(String.format("Transformer [%s] could not create metacard.", transformer)); stackTraceList.addAll(stackTraces); LOGGER.debug("Transformer [{}] could not create metacard.", transformer, e); } if (generatedMetacard != null) { break; } } if (generatedMetacard == null) { throw new MetacardCreationException(String.format("Could not create metacard with mimeType %s : %s", mimeType, StringUtils.join(stackTraceList, "\n"))); } if (id != null) { generatedMetacard.setAttribute(new AttributeImpl(Metacard.ID, id)); } LOGGER.debug("Metacard id is {}", generatedMetacard.getId()); } catch (IOException e) { throw new MetacardCreationException("Could not create metacard.", e); } catch (InvalidSyntaxException e) { throw new MetacardCreationException("Could not determine transformer", e); } return generatedMetacard; }
From source file:org.parosproxy.paros.core.proxy.ProxyThread.java
private static void setErrorResponse(HttpMessage msg, String responseStatus, Exception cause, String errorType) throws HttpMalformedHeaderException { msg.setResponseHeader("HTTP/1.1 " + responseStatus); StringBuilder strBuilder = new StringBuilder(); strBuilder.append(errorType).append(" [").append(cause.getClass().getName()).append("]: ") .append(cause.getLocalizedMessage()).append("\n\nStack Trace:\n"); for (String stackTraceFrame : ExceptionUtils.getRootCauseStackTrace(cause)) { strBuilder.append(stackTraceFrame).append('\n'); }//from w ww . ja v a 2 s. co m if (!HttpRequestHeader.HEAD.equals(msg.getRequestHeader().getMethod())) { msg.setResponseBody(strBuilder.toString()); } msg.getResponseHeader().addHeader(HttpHeader.CONTENT_LENGTH, Integer.toString(strBuilder.length())); msg.getResponseHeader().addHeader(HttpHeader.CONTENT_TYPE, "text/plain; charset=UTF-8"); }