List of usage examples for java.lang Throwable getCause
public synchronized Throwable getCause()
From source file:fr.certu.chouette.command.ExchangeCommand.java
/** * @param manager/*from ww w . j a v a2s.co m*/ * @param parameters * @return */ @SuppressWarnings("incomplete-switch") public List<NeptuneIdentifiedObject> executeImport(INeptuneManager<NeptuneIdentifiedObject> manager, Map<String, List<String>> parameters) { String reportFileName = getSimpleString(parameters, "reportfile", ""); String reportFormat = getSimpleString(parameters, "reportformat", "txt"); boolean append = getBoolean(parameters, "append"); String format = getSimpleString(parameters, "format"); PrintStream stream = System.out; String encoding = Charset.defaultCharset().toString(); if (!reportFileName.isEmpty()) { try { if (reportFormat.equals("json")) { encoding = "UTF-8"; } stream = new PrintStream(new FileOutputStream(new File(reportFileName), append), true, encoding); } catch (IOException e) { System.err.println("cannot open file :" + reportFileName + " " + e.getMessage()); reportFileName = ""; } } try { List<FormatDescription> formats = manager.getImportFormats(null); FormatDescription description = null; for (FormatDescription formatDescription : formats) { if (formatDescription.getName().equalsIgnoreCase(format)) { description = formatDescription; break; } } if (description == null) { throw new IllegalArgumentException( "format " + format + " unavailable, check command getImportFormats for list "); } List<ParameterValue> values = new ArrayList<ParameterValue>(); for (ParameterDescription desc : description.getParameterDescriptions()) { String name = desc.getName(); String key = name.toLowerCase(); List<String> vals = parameters.get(key); if (vals == null) { if (desc.isMandatory()) { throw new IllegalArgumentException( "parameter -" + name + " is required, check command getImportFormats for list "); } } else { if (desc.isCollection()) { ListParameterValue val = new ListParameterValue(name); switch (desc.getType()) { case FILEPATH: val.setFilepathList(vals); break; case STRING: val.setStringList(vals); break; case FILENAME: val.setFilenameList(vals); break; default: throw new IllegalArgumentException( "parameter -" + name + " invalid, check command getImportFormats for list "); } values.add(val); } else { if (vals.size() != 1) { throw new IllegalArgumentException("parameter -" + name + " must be unique, check command getImportFormats for list "); } String simpleval = vals.get(0); SimpleParameterValue val = new SimpleParameterValue(name); switch (desc.getType()) { case FILEPATH: val.setFilepathValue(simpleval); break; case STRING: val.setStringValue(simpleval); break; case FILENAME: val.setFilenameValue(simpleval); break; case BOOLEAN: val.setBooleanValue(Boolean.parseBoolean(simpleval)); break; case INTEGER: val.setIntegerValue(Long.parseLong(simpleval)); break; case DATE: val.setDateValue(toCalendar(simpleval)); break; } values.add(val); } } } ReportHolder ireport = new ReportHolder(); ReportHolder vreport = new ReportHolder(); List<NeptuneIdentifiedObject> beans = manager.doImport(null, format, values, ireport, vreport); if (ireport.getReport() != null) { Report r = ireport.getReport(); if (reportFormat.equals("json")) { stream.println(r.toJSON()); } else { stream.println(r.getLocalizedMessage()); printItems(stream, "", r.getItems()); } } if (vreport.getReport() != null) { Report r = vreport.getReport(); if (reportFormat.equals("json")) { stream.println(r.toJSON()); } else { stream.println(r.getLocalizedMessage()); printItems(stream, "", r.getItems()); } } if (beans == null || beans.isEmpty()) { System.out.println("import failed"); } else { System.out.println("beans count = " + beans.size()); } return beans; } catch (ChouetteException e) { log.error(e.getMessage()); Throwable caused = e.getCause(); while (caused != null) { log.error("caused by " + caused.getMessage()); caused = caused.getCause(); } throw new RuntimeException("import failed , see log for details"); } finally { if (!reportFileName.isEmpty()) { stream.close(); } } }
From source file:com.google.ratel.service.error.ErrorReport.java
protected Throwable getRootCause(Throwable error) { Throwable root = error; while (root.getCause() != null) { root = root.getCause();/*from w w w.ja v a 2s .c om*/ } return root; }
From source file:fr.paris.lutece.portal.web.PortalJspBean.java
/** * Returns the 500 Error page//from ww w . ja v a2 s. c om * @param request The HTTP request * @param exception The Exception * @return The page */ public String getError500Page(HttpServletRequest request, Throwable exception) { AppLogService.error("Error 500 : " + exception.getMessage(), exception); String strCause = null; if (AppPropertiesService.getProperty(PROPERTY_DEBUG, PROPERTY_DEBUG_DEFAULT).equalsIgnoreCase("true")) { strCause = exception.getMessage(); if (exception.getCause() != null) { strCause += exception.getCause().getMessage(); } } return getError500Page(request, strCause); }
From source file:org.ng200.openolympus.controller.OlympusErrorController.java
@Override public Map<String, Object> extract(final RequestAttributes attributes, final boolean b1, final boolean b2) { final Map<String, Object> map = new LinkedHashMap<String, Object>(); map.put("timestamp", new Date()); try {//from w w w. ja v a 2 s. c o m Throwable error = (Throwable) attributes.getAttribute("javax.servlet.error.exception", RequestAttributes.SCOPE_REQUEST); final Object obj = attributes.getAttribute("javax.servlet.error.status_code", RequestAttributes.SCOPE_REQUEST); int status = 999; if (obj != null) { status = (Integer) obj; } else { } map.put("status", status); map.put("statusPhrase", HttpStatus.valueOf(status).getReasonPhrase()); final List<Throwable> exceptions = new ArrayList<Throwable>(); while (error != null) { exceptions.add(error); error = error.getCause(); } map.put("exceptions", exceptions); return map; } catch (final Exception ex) { map.put("status", HttpStatus.INTERNAL_SERVER_ERROR.value()); map.put("statusPhrase", HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()); map.put("exceptions", Lists.from(ex)); return map; } }
From source file:com.emc.vipr.sync.ViPRSync.java
protected Throwable getCause(Throwable t) { Throwable cause = t; while (cause.getCause() != null) cause = cause.getCause();//from w w w. j a v a2 s.co m return cause; }
From source file:com.microsoft.intellij.helpers.IDEHelperImpl.java
@NotNull @Override/*from w w w . ja v a2s . c o m*/ public ListenableFuture<String> buildArtifact(@NotNull ProjectDescriptor projectDescriptor, @NotNull ArtifactDescriptor artifactDescriptor) { try { Project project = findOpenProject(projectDescriptor); final Artifact artifact = findProjectArtifact(project, artifactDescriptor); final SettableFuture<String> future = SettableFuture.create(); Futures.addCallback(buildArtifact(project, artifact, false), new FutureCallback<Boolean>() { @Override public void onSuccess(@Nullable Boolean succeded) { if (succeded != null && succeded) { future.set(artifact.getOutputFilePath()); } else { future.setException(new AzureCmdException("An error occurred while building the artifact")); } } @Override public void onFailure(Throwable throwable) { if (throwable instanceof ExecutionException) { future.setException(new AzureCmdException("An error occurred while building the artifact", throwable.getCause())); } else { future.setException( new AzureCmdException("An error occurred while building the artifact", throwable)); } } }); return future; } catch (AzureCmdException e) { return Futures.immediateFailedFuture(e); } }
From source file:com.google.ratel.service.error.ErrorReport.java
protected Throwable getTemplateException(Throwable error) { if (error instanceof TemplateException) { return error; }//from www. j a v a2s. c o m Throwable root = error; while (root.getCause() != null) { root = root.getCause(); if (root instanceof TemplateException) { return root; } } return root; }
From source file:de.tudarmstadt.lt.ltbot.postprocessor.DecesiveValueProducerPerplexity.java
double getPerplexity(CrawlURI uri) { assert _lmprvdr != null : "String provider service must not be null here. This should have been checked before."; String cleaned_plaintext = _textExtractorInstance.getCleanedUtf8PlainText(uri).trim(); String cleaned_plaintext_abbr = MULTIPLE_SPACES_PATTERN .matcher(StringUtils.abbreviate(cleaned_plaintext, 50)).replaceAll(" "); addExtraInfo(uri, EXTRA_INFO_PLAINTEXT_ABBREVIATED, cleaned_plaintext_abbr); if (cleaned_plaintext.isEmpty()) return Double.POSITIVE_INFINITY; double perplexity = Double.POSITIVE_INFINITY; try {/*from www . jav a2 s . c o m*/ String docid = "#" + Integer.toHexString(cleaned_plaintext.hashCode()); LOG.finest(String.format("Sending text with id '%s' to StringProvider: '%s' (length %d).", docid, cleaned_plaintext_abbr, cleaned_plaintext.length())); perplexity = computePerplexity(cleaned_plaintext); // if (Double.isNaN(perplexity)) { // double perplexity_new = -1d; // LOG.log(Level.WARNING, String.format("[%s '%s'] failed to get meaningful perplexity: %g. Setting perplexity to %g.", uri.toString(), cleaned_plaintext_abbr, perplexity, perplexity_new)); // perplexity = perplexity_new; // } LOG.finest(String.format("[%s, '%s'] perplexity: %g.", uri.toString(), cleaned_plaintext_abbr, perplexity)); } catch (Throwable t) { for (int i = 1; t != null && i < 10; i++) { LOG.log(Level.SEVERE, String.format("Could not compute perplexity for URI '%s' and text: '%s'. (%d %s:%s)", uri.toString(), cleaned_plaintext_abbr, i, t.getClass().getSimpleName(), t.getMessage()), t); t = t.getCause(); LOG.log(Level.SEVERE, "Requesting to pause crawl."); getCrawlController().requestCrawlPause(); _paused_due_to_error = true; } } if (!Double.isFinite(perplexity) || perplexity <= 1) { LOG.log(Level.FINE, String.format( "[%s '%s'] resetting infinite perplexity to predefined maximum perplexity value (-1).", uri.toString(), cleaned_plaintext_abbr)); perplexity = -1; } return perplexity; }