List of usage examples for java.lang Throwable getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:de.tudarmstadt.lt.ltbot.text.JSoupTextExtractor.java
@Override public String getPlaintext(final String htmltext) { try {/*from w w w .j av a 2 s.c o m*/ // preserve newlines // html = html.replaceAll("(?i)<br[^>]*>", "br2nl"); // <br>s are often just inserted for style String hhtmltext = _end_prgrph_ptrn.matcher(htmltext).replaceAll("</p>br2nl"); hhtmltext = _nwln_ptrn.matcher(hhtmltext).replaceAll("br2nl"); Document soup = Jsoup.parse(hhtmltext); String plaintext = soup.text(); plaintext = _tmp_nwln_ptrn.matcher(plaintext).replaceAll("\n"); plaintext = _emptln_ptrn.matcher(plaintext.trim()).replaceAll(""); return plaintext; } catch (Throwable t) { for (int i = 1; t != null && i < 10; i++) { LOG.log(Level.SEVERE, String.format("Failed to get plaintext from while '%s' (%d %s:%s).", StringUtils.abbreviate(htmltext, 100), i, t.getClass().getName(), t.getMessage()), t); t = t.getCause(); } return "Failed to get plaintext content \n" + htmltext; } }
From source file:de.decoit.visa.http.ajax.handlers.IOToolResetHandler.java
@Override public void handle(HttpExchange he) throws IOException { log.info(he.getRequestURI().toString()); // Create String for the response String response = null;//from w w w . ja v a 2s. co m // Any exception thrown during object creation will // cause failure of the AJAX request try { // Execute the request to the IO-Tool IOToolRequestStatus status = TEBackend.getIOConnector().resetIOTool(); JSONObject rv = new JSONObject(); if (status == IOToolRequestStatus.SUCCESS) { rv.put("status", AJAXServer.AJAX_SUCCESS); } else if (status == IOToolRequestStatus.WAIT) { rv.put("status", AJAXServer.AJAX_IOTOOL_WAIT); } else if (status == IOToolRequestStatus.IOTOOL_BUSY) { rv.put("status", AJAXServer.AJAX_ERROR_IOTOOL_BUSY); } else { rv.put("status", AJAXServer.AJAX_ERROR_GENERAL); } rv.put("returncode", TEBackend.getIOConnector().getLastReturnCode()); rv.put("message", TEBackend.getIOConnector().getLastReturnMsg()); response = rv.toString(); } catch (Throwable ex) { TEBackend.logException(ex, log); JSONObject rv = new JSONObject(); try { rv.put("status", AJAXServer.AJAX_ERROR_EXCEPTION); rv.put("type", ex.getClass().getSimpleName()); rv.put("message", ex.getMessage()); } catch (JSONException exc) { /* Ignore */ } response = rv.toString(); } // Send the response sendResponse(he, response); }
From source file:gov.nih.nci.firebird.proxy.PoolingHandler.java
private boolean isValidException(Throwable t) { for (Class<? extends Throwable> validExceptionType : getValidExceptions()) { if (validExceptionType.isAssignableFrom(t.getClass())) { return true; }// w w w. j a v a2 s . com } return false; }
From source file:com.ryantenney.metrics.spring.ExceptionMeteredMethodInterceptor.java
@Override public Object invoke(MethodInvocation invocation) throws Throwable { try {/*from w w w . jav a 2 s .c o m*/ return invocation.proceed(); } catch (Throwable t) { final MethodKey key = MethodKey.forMethod(invocation.getMethod()); final ExceptionMeter exceptionMeter = meters.get(key); if (exceptionMeter != null && exceptionMeter.getCause().isAssignableFrom(t.getClass())) { exceptionMeter.getMeter().mark(); } throw t; } }
From source file:org.openregistry.core.service.DefaultIdentifierNotificationServiceIntegrationTests.java
private Person constructPersonWithNetId(final String firstName, final String lastName, final String emailAddress, final String netId) { final ReconciliationCriteria reconciliationCriteria = new JpaReconciliationCriteriaImpl(); final JpaSorPersonImpl sorPerson = (JpaSorPersonImpl) reconciliationCriteria.getSorPerson(); sorPerson.setDateOfBirth(new Date(0)); sorPerson.setGender("M"); sorPerson.setSourceSor("TEST_SOR"); final SorName name = sorPerson .addName(this.referenceRepository.findType(Type.DataTypes.NAME, Type.NameTypes.FORMAL)); name.setFamily(lastName);/* www .jav a 2s.c om*/ name.setGiven(firstName); Person person = null; try { person = this.personService.addPerson(reconciliationCriteria).getTargetObject(); // add a Net ID person.addIdentifier(netIdIdentifierType, netId); // set preferred email address person.getPreferredContactEmailAddress().setAddress(emailAddress); // add role JpaSorRoleImpl sorRole = new JpaSorRoleImpl(this.referenceRepository.getTypeById(new Long(6)), sorPerson); sorRole.setOrganizationalUnit(this.referenceRepository.getOrganizationalUnitById(new Long(1))); sorRole.setSystemOfRecord(this.referenceRepository.findSystemOfRecord("test")); sorRole.setTitle("FOO"); sorRole.setStart(new Date(0)); sorRole.setPersonStatus(this.referenceRepository.getTypeById(new Long(998))); sorRole.setSponsorType(this.referenceRepository.getTypeById(new Long(5))); // see AbstractIntegrationTests.java sorRole.setSponsorId(new Long(0)); sorRole.addOrUpdateEmail(emailAddress, homeEmailType); person.addRole(sorRole); } catch (Throwable e) { e.printStackTrace(); fail("No exception should be thrown, caught " + e.getClass().getName() + " with message: " + e.getMessage()); } return person; }
From source file:de.decoit.visa.http.ajax.handlers.IOToolCleanupHandler.java
@Override public void handle(HttpExchange he) throws IOException { log.info(he.getRequestURI().toString()); // Create String for the response String response = null;//from w w w . jav a2 s. c o m // Any exception thrown during object creation will // cause failure of the AJAX request try { // Execute the request to the IO-Tool IOToolRequestStatus status = TEBackend.getIOConnector().cleanUpIOTool(); JSONObject rv = new JSONObject(); if (status == IOToolRequestStatus.SUCCESS) { rv.put("status", AJAXServer.AJAX_SUCCESS); } else if (status == IOToolRequestStatus.WAIT) { rv.put("status", AJAXServer.AJAX_IOTOOL_WAIT); } else if (status == IOToolRequestStatus.IOTOOL_BUSY) { rv.put("status", AJAXServer.AJAX_ERROR_IOTOOL_BUSY); } else { rv.put("status", AJAXServer.AJAX_ERROR_GENERAL); } rv.put("returncode", TEBackend.getIOConnector().getLastReturnCode()); rv.put("message", TEBackend.getIOConnector().getLastReturnMsg()); response = rv.toString(); } catch (Throwable ex) { TEBackend.logException(ex, log); JSONObject rv = new JSONObject(); try { rv.put("status", AJAXServer.AJAX_ERROR_EXCEPTION); rv.put("type", ex.getClass().getSimpleName()); rv.put("message", ex.getMessage()); } catch (JSONException exc) { /* Ignore */ } response = rv.toString(); } // Send the response sendResponse(he, response); }
From source file:de.metas.ui.web.config.WebuiExceptionHandler.java
private final boolean isExcludeFromLogging(final Throwable ex) { for (final Class<?> exceptionClass : EXCEPTIONS_ExcludeFromLogging) { if (exceptionClass.isAssignableFrom(ex.getClass())) { return true; }//from w ww . ja v a 2s. c o m } return false; }
From source file:org.toobsframework.pres.chart.controller.ChartHandler.java
/** * /* ww w . j av a 2 s . co m*/ * Retrieves the URL path to use for lookup and delegates to * <code>getViewNameForUrlPath</code>. * * @throws Exception Exception fetching or rendering component. * @see #getViewNameForUrlPath * */ @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response, UrlDispatchInfo dispatchInfo) throws Exception { String chartId = dispatchInfo.getResourceId(); if (log.isDebugEnabled()) { log.debug("Rendering chart '" + chartId + "' for lookup path: " + dispatchInfo.getOriginalPath()); } IRequest componentRequest = this.setupComponentRequest(dispatchInfo, request, response, true); Date startTime = null; if (log.isDebugEnabled()) { startTime = new Date(); } JFreeChart chart = null; int height = 400; int width = 600; ChartDefinition chartDef = null; if (null != chartId && !chartId.equals("")) { try { request.setAttribute("chartId", chartId); chartDef = this.chartManager.getChartDefinition(chartId); } catch (ChartNotFoundException cnfe) { log.warn("Chart " + chartId + " not found."); throw cnfe; } try { chart = chartBuilder.build(chartDef, componentRequest); width = chartDef.getChartWidth(); height = chartDef.getChartHeight(); } catch (ChartException e) { Throwable t = e.rootCause(); log.info("Root cause " + t.getClass().getName() + " " + t.getMessage()); throw e; } catch (Exception e) { throw e; } finally { this.componentRequestManager.unset(); } } else { throw new Exception("No chartId specified"); } //Write out to the response. response.setHeader("Pragma", "no-cache"); // HTTP 1.0 response.setHeader("Cache-Control", "max-age=0, must-revalidate"); // HTTP 1.1 ChartRenderingInfo chartRenderingInfo = new ChartRenderingInfo(); if (chartDef.doImageWithMap()) { response.setContentType("text/html; charset=UTF-8"); String genFileName = chartDef.getId() + "-" + new Date().getTime() + ".png"; String imageOutputFileName = configuration.getUploadDir() + genFileName; File imageOutputFile = new File(imageOutputFileName); OutputStream os = null; try { os = new FileOutputStream(imageOutputFile); ChartUtilities.writeChartAsPNG(os, chart, width, height, chartRenderingInfo); } finally { if (os != null) { os.close(); } } PrintWriter writer = response.getWriter(); StringBuffer sb = new StringBuffer(); // TODO BUGBUG Chart location needs to fixed sb.append("<img id=\"chart-").append(chartDef.getId()).append("\" src=\"") .append(/*Configuration.getInstance().getMainContext() +*/ "/upload/" + genFileName) .append("\" ismap=\"ismap\" usemap=\"#").append(chartDef.getId()).append("Map\" />"); URLTagFragmentGenerator urlGenerator; if (chartDef.getUrlFragmentBean() != null) { urlGenerator = (URLTagFragmentGenerator) beanFactory.getBean(chartDef.getUrlFragmentBean()); } else { urlGenerator = new StandardURLTagFragmentGenerator(); } sb.append(ImageMapUtilities.getImageMap(chartDef.getId() + "Map", chartRenderingInfo, null, urlGenerator)); writer.print(sb.toString()); writer.flush(); } else { response.setContentType("image/png"); ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, width, height, chartRenderingInfo); } if (log.isDebugEnabled()) { Date endTime = new Date(); log.debug("Time [" + chartId + "] - " + (endTime.getTime() - startTime.getTime())); } return null; }
From source file:co.runrightfast.vertx.core.eventbus.MessageConsumerConfig.java
public Failure toFailure(@NonNull final Throwable t) { final Class<? extends Throwable> clazz = t.getClass(); final Failure failure = exceptionFailureMap.get(clazz); if (failure != null) { return new Failure(failure, t); }// w w w . j a va2 s .c o m return new Failure( exceptionFailureMap.entrySet().stream().filter(entry -> entry.getClass().isAssignableFrom(clazz)) .map(Map.Entry::getValue).findFirst().orElse(INTERNAL_SERVER_ERROR), t); }
From source file:edu.ucsd.xmlrpc.xmlrpc.server.XmlRpcStreamServer.java
protected void logError(Throwable t) { final String msg = t.getMessage() == null ? t.getClass().getName() : t.getMessage(); errorLogger.log(msg, t);//from w ww.j a v a 2 s . co m }