List of usage examples for java.lang Throwable getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.jeeframework.util.resource.ResolverUtil.java
/** * Add the class designated by the fully qualified class name provided to the set of * resolved classes if and only if it is approved by the Test supplied. * * @param test the test used to determine if the class matches * @param fqn the fully qualified name of a class *///from ww w.j a v a 2s . c o m protected void addIfMatching(Test test, String fqn) { try { String externalName = fqn.substring(0, fqn.indexOf('.')).replace('/', '.'); ClassLoader loader = getClassLoader(); if (log.isDebugEnabled()) { log.debug("Checking to see if class " + externalName + " matches criteria [" + test + "]"); } Class type = loader.loadClass(externalName); if (test.matches(type)) { matches.add((Class<T>) type); } } catch (Throwable t) { log.warn("Could not examine class '" + fqn + "' due to a " + t.getClass().getName() + " with message: " + t.getMessage()); } }
From source file:com.bstek.dorado.web.resolver.ErrorPageResolver.java
private void doExcecute(HttpServletRequest request, HttpServletResponse response) throws Exception, IOException { response.setContentType(HttpConstants.CONTENT_TYPE_HTML); response.setCharacterEncoding(Constants.DEFAULT_CHARSET); Context velocityContext = new VelocityContext(); Exception e = (Exception) request.getAttribute(EXCEPTION_ATTRIBUTE); if (e != null) { logger.error(e, e);//w w w . j a v a 2s .c o m if (e instanceof PageNotFoundException) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); } else if (e instanceof PageAccessDeniedException) { response.setStatus(HttpServletResponse.SC_FORBIDDEN); } Throwable throwable = e; while (throwable.getCause() != null) { throwable = throwable.getCause(); } String message = null; if (throwable != null) { message = throwable.getMessage(); } message = StringUtils.defaultString(message, throwable.getClass().getName()); velocityContext.put("message", message); velocityContext.put(EXCEPTION_ATTRIBUTE, throwable); } else { velocityContext.put("message", "Can not gain exception information!"); } velocityContext.put("esc", stringEscapeHelper); Template template = getVelocityEngine().getTemplate("com/bstek/dorado/web/resolver/ErrorPage.html"); PrintWriter writer = getWriter(request, response); try { template.merge(velocityContext, writer); } finally { writer.flush(); writer.close(); } }
From source file:de.decoit.visa.http.ajax.handlers.IOToolCollectHandler.java
@Override public void handle(HttpExchange he) throws IOException { log.info(he.getRequestURI().toString()); // Get the URI of the request and extract the query string from it QueryString queryParameters = new QueryString(he.getRequestURI()); // Create String for the response String response = null;/*from w w w . j a va 2 s . c o m*/ // Check if the query parameters are valid for this handler if (this.checkQueryParameters(queryParameters)) { // 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() .collectTopology(queryParameters.get("id").get()); JSONObject rv = new JSONObject(); if (status == IOToolRequestStatus.SUCCESS) { // If the collect operation was successful reload the // topology from the IO-Tool to have the most recent version // in storage. This is necessary because the IO-Tool may // change URIs of resources which may cause problems. // Execute the request to the IO-Tool status = TEBackend.getIOConnector().requestTopology(queryParameters.get("id").get()); if (status == IOToolRequestStatus.SUCCESS) { Map<String, String> data = TEBackend.getIOConnector().getLastReturnData(); // Wrap the RDF/XML information into an InputStream ByteArrayInputStream bais = new ByteArrayInputStream( data.get(queryParameters.get("id").get()).getBytes()); // Read that InputStream into the RDFManager TEBackend.RDF_MANAGER.loadRDF(bais, true, queryParameters.get("id").get()); TEBackend.TOPOLOGY_STORAGE.setTopologyID(queryParameters.get("id").get()); rv.put("status", AJAXServer.AJAX_SUCCESS); } else { rv.put("status", AJAXServer.AJAX_ERROR_GENERAL); } } 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("topology", TEBackend.TOPOLOGY_STORAGE.genTopologyJSON()); 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(); } } else { JSONObject rv = new JSONObject(); try { // Missing or malformed query string, set response to error code rv.put("status", AJAXServer.AJAX_ERROR_MISSING_ARGS); } catch (JSONException exc) { /* Ignore */ } response = rv.toString(); } // Send the response sendResponse(he, response); }
From source file:org.sakuli.exceptions.SakuliExceptionHandler.java
/** * handleException methode for Eception, where no testcase could be identified; The default value for non {@link * SakuliException} is there that the Execution of the tescase will stop! * * @param e any Throwable/*from w w w. ja va2 s. c o m*/ */ public void handleException(Throwable e) { //avoid nullpointer for missing messages if (e.getMessage() == null) { e = new SakuliException(e, e.getClass().getSimpleName()); } //e.g. Proxy Exception should only be handled if no other exceptions have been added if (!(e instanceof SakuliInitException) || (!containsException(loader.getTestSuite()))) { //if the exception have been already processed do no exception handling! if (isAlreadyProcessed(e)) { logger.debug("ALREADY PROCESSED: " + e.getMessage(), e); } else { processException(e); } } }
From source file:de.decoit.visa.http.ajax.handlers.IOToolWriteTopoHandler.java
@Override public void handle(HttpExchange he) throws IOException { log.info(he.getRequestURI().toString()); // Get the URI of the request and extract the query string from it QueryString queryParameters = new QueryString(he.getRequestURI()); // Create String for the response String response = null;// w ww.j av a2 s . co m // Check if the query parameters are valid for this handler if (this.checkQueryParameters(queryParameters)) { // Any exception thrown during object creation will // cause failure of the AJAX request try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); TEBackend.RDF_MANAGER.writeRDF(baos); // Execute the request to the IO-Tool IOToolRequestStatus status = TEBackend.getIOConnector().writeTopology( queryParameters.get("id").get(), new String(baos.toByteArray()), TEBackend.RDF_MANAGER.getRootNodeName()); JSONObject rv = new JSONObject(); if (status == IOToolRequestStatus.SUCCESS) { // If the write operation was successful reload the topology // from the IO-Tool to have the most recent version in // storage. This is neccessary because the IO-Tool may // change URIs of resources which may cause problems. // Execute the request to the IO-Tool status = TEBackend.getIOConnector().requestTopology(queryParameters.get("id").get()); if (status == IOToolRequestStatus.SUCCESS) { Map<String, String> data = TEBackend.getIOConnector().getLastReturnData(); // Wrap the RDF/XML information into an InputStream ByteArrayInputStream bais = new ByteArrayInputStream( data.get(queryParameters.get("id").get()).getBytes()); // Read that InputStream into the RDFManager TEBackend.RDF_MANAGER.loadRDF(bais, true, queryParameters.get("id").get()); TEBackend.TOPOLOGY_STORAGE.setTopologyID(queryParameters.get("id").get()); rv.put("status", AJAXServer.AJAX_SUCCESS); } else { rv.put("status", AJAXServer.AJAX_ERROR_GENERAL); } } else if (status == IOToolRequestStatus.IOTOOL_BUSY) { rv.put("status", AJAXServer.AJAX_ERROR_IOTOOL_BUSY); } else { rv.put("status", AJAXServer.AJAX_ERROR_GENERAL); } rv.put("topology", TEBackend.TOPOLOGY_STORAGE.genTopologyJSON()); 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(); } } else { JSONObject rv = new JSONObject(); try { // Missing or malformed query string, set response to error code rv.put("status", AJAXServer.AJAX_ERROR_MISSING_ARGS); } catch (JSONException exc) { /* Ignore */ } response = rv.toString(); } // Send the response sendResponse(he, response); }
From source file:com.stevesouza.spring.contrib.JamonPerformanceMonitorInterceptor.java
/** * Count the thrown exception and also put the stack trace in the details portion of the key. * This will allow the stack trace to be viewed in the JAMon web application. * @since 4.1/*from w w w .ja va 2 s . c om*/ */ private void trackException(MonKeyImp key, Throwable exception) { String stackTrace = new StringBuilder().append("stackTrace=").append(Misc.getExceptionTrace(exception)) .toString(); key.setDetails(stackTrace); // Specific exception counter. Example: java.lang.RuntimeException MonitorFactory.add(new MonKeyImp(exception.getClass().getName(), stackTrace, EXCEPTION), 1); // General exception counter which is a total for all exceptions thrown MonitorFactory.add(new MonKeyImp(MonitorFactory.EXCEPTIONS_LABEL, stackTrace, EXCEPTION), 1); }
From source file:com.qmetry.qaf.automation.step.StringTestStep.java
@Override public Object execute() { if (DryRunAnalyzer.isDryRun(this)) { return null; }//from w ww . j a va2s . c o m initStep(); if (null != step) { Object retVal = null; try { retVal = step.execute(); if (isNotBlank(resultParameterName)) { if (resultParameterName.indexOf("${") == 0) { getBundle().setProperty(resultParameterName, retVal); } else { getBundle().setProperty("${" + resultParameterName + "}", retVal); } } } catch (Error ae) { StepInvocationException se = new StepInvocationException(this, ae); ae.setStackTrace(se.getStackTrace()); throw ae; } catch (Throwable e) { StepInvocationException se = new StepInvocationException(this, e); RuntimeException re = (RuntimeException.class.isAssignableFrom(e.getClass()) ? (RuntimeException) e : new RuntimeException(e)); re.setStackTrace(se.getStackTrace()); throw re; } return retVal; } throw new StepNotFoundException(this); }
From source file:com.hrhih.dispatcher.HrhihJakartaMultiPartRequest.java
protected String buildErrorMessage(Throwable e, Object[] args) { String errorKey = "struts.messages.upload.error." + e.getClass().getSimpleName(); if (LOG.isDebugEnabled()) { LOG.debug("Preparing error message for key: [#0]", errorKey); }/*from ww w . j av a2s . c o m*/ return LocalizedTextUtil.findText(this.getClass(), errorKey, defaultLocale, e.getMessage(), args); }
From source file:net.nicholaswilliams.java.licensing.encryption.TestKeyFileUtilities.java
@Test public void testConstructionForbidden() throws IllegalAccessException, InstantiationException, NoSuchMethodException { Constructor<KeyFileUtilities> constructor = KeyFileUtilities.class.getDeclaredConstructor(); constructor.setAccessible(true);/*from w ww. ja va2s.co m*/ try { constructor.newInstance(); fail("Expected exception java.lang.reflect.InvocationTargetException, but got no exception."); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); assertNotNull("Expected cause for InvocationTargetException, but got no cause.", cause); assertSame("Expected exception java.lang.RuntimeException, but got " + cause.getClass(), RuntimeException.class, cause.getClass()); assertEquals("The message was incorrect.", "This class cannot be instantiated.", cause.getMessage()); } }
From source file:com.utest.webservice.interceptors.UtestRestFaultOutInterceptor.java
private String translateError(Throwable error, final String message) { if (error instanceof DomainException) { return ((DomainException) error).getErrorMessageKey(); }/*from w ww. j a va 2 s . com*/ if (message == null) { if (error != null) { return error.getClass().getSimpleName(); } else { return null; } } else { return message; } }