List of usage examples for javax.servlet ServletException getRootCause
public Throwable getRootCause()
From source file:org.openmrs.module.errorlogging.extension.html.ErrorHandlerExtension.java
private String createReportBtn(Exception exception, HttpServletRequest request) { UserContext userContext = (UserContext) request.getSession() .getAttribute(WebConstants.OPENMRS_USER_CONTEXT_HTTPSESSION_ATTR); if (userContext != null || userContext.getAuthenticatedUser() != null) { String reportBugUrl = Context.getAdministrationService() .getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_REPORT_BUG_URL); String openmrsVersion = OpenmrsConstants.OPENMRS_VERSION; String serverInfo = request.getSession().getServletContext().getServerInfo(); String username = Context.getAuthenticatedUser().getUsername(); if (StringUtils.isBlank(username)) { username = Context.getAuthenticatedUser().getSystemId(); }/*from w ww . ja v a2 s .co m*/ ImplementationId id = Context.getAdministrationService().getImplementationId(); String implementationId = ""; if (id != null) { implementationId = id.getImplementationId(); implementationId += " = " + id.getName(); } StringBuilder sb = new StringBuilder(); boolean isFirst = true; for (Module module : ModuleFactory.getStartedModules()) { if (isFirst) { sb.append(module.getModuleId()).append(" v").append(module.getVersion()); isFirst = false; } else sb.append(", ").append(module.getModuleId()).append(" v").append(module.getVersion()); } String startedModules = sb.toString(); String errorMessage = exception.toString(); StackTraceElement[] elements; if (exception instanceof ServletException) { // It's a ServletException: we should extract the root cause ServletException sEx = (ServletException) exception; Throwable rootCause = sEx.getRootCause(); if (rootCause == null) rootCause = sEx; elements = rootCause.getStackTrace(); } else { // It's not a ServletException, so we'll just show it elements = exception.getStackTrace(); } // Collect stack trace for reporting bug description StringBuilder description = new StringBuilder("Stack trace:\n"); for (StackTraceElement element : elements) { description.append(element).append("\n"); } String stackTrace = OpenmrsUtil.shortenedStackTrace(description.toString()); String reportBtn = "<form action=\"" + reportBugUrl + "\" target=\"_blank\" method=\"POST\">" + "<input type=\"hidden\" name=\"openmrs_version\" value=\"" + openmrsVersion + "\" />" + "<input type=\"hidden\" name=\"server_info\" value=\"" + serverInfo + "\" />" + "<input type=\"hidden\" name=\"username\" value=\"" + username + "\" />" + "<input type=\"hidden\" name=\"implementationId\" value=\"" + implementationId + "\" />" + "<input type=\"hidden\" name=\"startedModules\" value=\"" + startedModules + "\" />" + "<input type=\"hidden\" name=\"errorMessage\" value=\"" + errorMessage + "\" />" + "<input type=\"hidden\" name=\"stackTrace\" value=\"" + stackTrace + "\" />" + "<br/><input type=\"submit\" value=\"Report Problem\"></form>"; return reportBtn; } return ""; }
From source file:org.opennms.core.test.rest.AbstractSpringJerseyRestTestCase.java
@Before public void setUp() throws Throwable { beforeServletStart();//from w w w . j a v a2 s .co m setUser("admin", new String[] { "ROLE_ADMIN" }); DaoTestConfigBean bean = new DaoTestConfigBean(); bean.afterPropertiesSet(); MockDatabase db = new MockDatabase(true); DataSourceFactory.setInstance(db); XADataSourceFactory.setInstance(db); try { MockFilterConfig filterConfig = new MockFilterConfig(servletContext, "openSessionInViewFilter"); setFilter(new OpenSessionInViewFilter()); getFilter().init(filterConfig); // Jersey /* setServletConfig(new MockServletConfig(servletContext, "dispatcher")); getServletConfig().addInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig"); getServletConfig().addInitParameter("com.sun.jersey.config.property.packages", "org.codehaus.jackson.jaxrs;org.opennms.web.rest;org.opennms.web.rest.config"); getServletConfig().addInitParameter("com.sun.jersey.spi.container.ContainerRequestFilters", "com.sun.jersey.api.container.filter.GZIPContentEncodingFilter"); getServletConfig().addInitParameter("com.sun.jersey.spi.container.ContainerResponseFilters", "com.sun.jersey.api.container.filter.GZIPContentEncodingFilter"); setDispatcher(new SpringServlet()); getDispatcher().init(getServletConfig()); */ // Apache CXF setServletConfig(new MockServletConfig(servletContext, "dispatcher")); getServletConfig().addInitParameter("config-location", m_cxfContextPath); CXFServlet servlet = new CXFServlet(); setDispatcher(servlet); getDispatcher().init(getServletConfig()); } catch (ServletException se) { throw se.getRootCause(); } afterServletStart(); System.err.println("------------------------------------------------------------------------------"); }
From source file:org.opennms.web.rest.AbstractSpringJerseyRestTestCase.java
@Before public void setUp() throws Throwable { beforeServletStart();/* w w w . j a v a 2 s.com*/ DaoTestConfigBean bean = new DaoTestConfigBean(); bean.afterPropertiesSet(); MockDatabase db = new MockDatabase(true); DataSourceFactory.setInstance(db); setServletContext(new MockServletContext("file:src/main/webapp")); getServletContext().addInitParameter("contextConfigLocation", "classpath:/org/opennms/web/rest/applicationContext-test.xml " + "classpath:/META-INF/opennms/applicationContext-commonConfigs.xml " + "classpath:/META-INF/opennms/applicationContext-soa.xml " + "classpath*:/META-INF/opennms/component-service.xml " + "classpath*:/META-INF/opennms/component-dao.xml " + "classpath:/META-INF/opennms/applicationContext-reportingCore.xml " + "classpath:/META-INF/opennms/applicationContext-databasePopulator.xml " + "classpath:/org/opennms/web/svclayer/applicationContext-svclayer.xml " + "classpath:/META-INF/opennms/applicationContext-mockEventProxy.xml " + "classpath:/applicationContext-jersey-test.xml " + "classpath:/META-INF/opennms/applicationContext-reporting.xml " + "classpath:/META-INF/opennms/applicationContext-mock-usergroup.xml " + "classpath:/META-INF/opennms/applicationContext-minimal-conf.xml " + "/WEB-INF/applicationContext-spring-security.xml " + "/WEB-INF/applicationContext-jersey.xml"); getServletContext().addInitParameter("parentContextKey", "daoContext"); ServletContextEvent e = new ServletContextEvent(getServletContext()); setContextListener(new ContextLoaderListener()); getContextListener().contextInitialized(e); getServletContext().setContextPath(contextPath); setServletConfig(new MockServletConfig(getServletContext(), "dispatcher")); getServletConfig().addInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig"); getServletConfig().addInitParameter("com.sun.jersey.config.property.packages", "org.opennms.web.rest"); try { MockFilterConfig filterConfig = new MockFilterConfig(getServletContext(), "openSessionInViewFilter"); setFilter(new OpenSessionInViewFilter()); getFilter().init(filterConfig); setDispatcher(new SpringServlet()); getDispatcher().init(getServletConfig()); } catch (ServletException se) { throw se.getRootCause(); } setWebAppContext(WebApplicationContextUtils.getWebApplicationContext(getServletContext())); afterServletStart(); System.err.println("------------------------------------------------------------------------------"); }
From source file:org.romaframework.aspect.view.html.transformer.jsp.JspTemplateManager.java
public void execute(String templateName, HtmlViewRenderable renderable, String part, Writer writer) { ServletRequest request = HtmlViewAspectHelper.getServletRequest(); final String classJsp = getTemplatesPath() + templateName; final Object previousComponent = request.getAttribute(RequestConstants.CURRENT_COMPONENT_IN_TRANSFORMER); request.setAttribute(RequestConstants.CURRENT_COMPONENT_IN_TRANSFORMER, renderable); final Object previousPart = request.getAttribute(RequestConstants.CURRENT_COMPONENT_PART_IN_TRANSFORMER); request.setAttribute(RequestConstants.CURRENT_COMPONENT_PART_IN_TRANSFORMER, part); try {// ww w. j av a 2 s .c om HtmlViewAspectHelper.getHtmlFromJSP(request, classJsp, writer); } catch (ServletException e) { log.error("error in jsp transformer", e.getRootCause() == null ? e : e.getRootCause()); } catch (IOException e) { log.error("maybe wrong render defined", e); } request.setAttribute(RequestConstants.CURRENT_COMPONENT_IN_TRANSFORMER, previousComponent); request.setAttribute(RequestConstants.CURRENT_COMPONENT_PART_IN_TRANSFORMER, previousPart); }
From source file:org.springframework.security.oauth.consumer.OAuthConsumerProcessingFilter.java
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; Set<String> accessTokenDeps = getAccessTokenDependencies(request, response, chain); if (!accessTokenDeps.isEmpty()) { try {//from w ww . j a v a2 s .com Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (requireAuthenticated && !authentication.isAuthenticated()) { throw new InsufficientAuthenticationException("An authenticated principal must be present."); } OAuthConsumerTokenServices tokenServices = getTokenServicesFactory() .getTokenServices(authentication, request); List<OAuthConsumerToken> tokens = new ArrayList<OAuthConsumerToken>(); for (String dependency : accessTokenDeps) { OAuthConsumerToken token = tokenServices.getToken(dependency); if (token == null) { if (LOG.isDebugEnabled()) { LOG.debug("Obtaining request token for dependency: " + dependency); } //obtain authorization. String callbackURL = response.encodeRedirectURL(getCallbackURL(request)); OAuthConsumerToken requestToken = getConsumerSupport() .getUnauthorizedRequestToken(dependency, callbackURL); if (LOG.isDebugEnabled()) { LOG.debug("Request token obtained for dependency " + dependency + ": " + requestToken); } tokenServices.storeToken(dependency, requestToken); String redirect = getUserAuthorizationRedirectURL(requestToken, callbackURL); if (LOG.isDebugEnabled()) { LOG.debug("Redirecting request to " + redirect + " for user authorization of the request token for dependency " + dependency + "."); } response.sendRedirect(redirect); return; } else { if (!token.isAccessToken()) { if (LOG.isDebugEnabled()) { LOG.debug("Obtaining access token for dependency: " + dependency); } //authorize the request token and store it. try { token = getConsumerSupport().getAccessToken(token, request.getParameter(OAuthProviderParameter.oauth_verifier.toString())); } finally { //make sure any request tokens are removed. tokenServices.removeToken(dependency); } if (LOG.isDebugEnabled()) { LOG.debug("Access token " + token + " obtained for dependency " + dependency + ". Now storing and using."); } tokenServices.storeToken(dependency, token); } else if (LOG.isDebugEnabled()) { LOG.debug("Authorized access token " + token + " loaded for dependency " + dependency + "."); } //token already authorized. tokens.add(token); } } if (LOG.isDebugEnabled()) { LOG.debug("Storing access tokens in request attribute '" + getAccessTokensRequestAttribute() + "'."); } request.setAttribute(getAccessTokensRequestAttribute(), tokens); chain.doFilter(request, response); } catch (OAuthException ae) { fail(request, response, ae); } catch (ServletException e) { if (e.getRootCause() instanceof OAuthException) { fail(request, response, (OAuthException) e.getRootCause()); } else { throw e; } } } else { if (LOG.isDebugEnabled()) { LOG.debug("No access token dependencies for request."); } chain.doFilter(servletRequest, servletResponse); } }
From source file:org.springframework.security.oauth.provider.filter.OAuthProviderProcessingFilter.java
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; if (!skipProcessing(request)) { if (requiresAuthentication(request, response, chain)) { if (!allowMethod(request.getMethod().toUpperCase())) { if (log.isDebugEnabled()) { log.debug("Method " + request.getMethod() + " not supported."); }//from ww w .ja va2 s.com response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); return; } try { Map<String, String> oauthParams = getProviderSupport().parseParameters(request); if (parametersAreAdequate(oauthParams)) { if (log.isDebugEnabled()) { StringBuilder builder = new StringBuilder("OAuth parameters parsed: "); for (String param : oauthParams.keySet()) { builder.append(param).append('=').append(oauthParams.get(param)).append(' '); } log.debug(builder.toString()); } String consumerKey = oauthParams.get(OAuthConsumerParameter.oauth_consumer_key.toString()); if (consumerKey == null) { throw new InvalidOAuthParametersException(messages.getMessage( "OAuthProcessingFilter.missingConsumerKey", "Missing consumer key.")); } //load the consumer details. ConsumerDetails consumerDetails = getConsumerDetailsService() .loadConsumerByConsumerKey(consumerKey); if (log.isDebugEnabled()) { log.debug("Consumer details loaded for " + consumerKey + ": " + consumerDetails); } //validate the parameters for the consumer. validateOAuthParams(consumerDetails, oauthParams); if (log.isDebugEnabled()) { log.debug("Parameters validated."); } //extract the credentials. String token = oauthParams.get(OAuthConsumerParameter.oauth_token.toString()); String signatureMethod = oauthParams .get(OAuthConsumerParameter.oauth_signature_method.toString()); String signature = oauthParams.get(OAuthConsumerParameter.oauth_signature.toString()); String signatureBaseString = getProviderSupport().getSignatureBaseString(request); ConsumerCredentials credentials = new ConsumerCredentials(consumerKey, signature, signatureMethod, signatureBaseString, token); //create an authentication request. ConsumerAuthentication authentication = new ConsumerAuthentication(consumerDetails, credentials, oauthParams); authentication.setDetails(createDetails(request, consumerDetails)); Authentication previousAuthentication = SecurityContextHolder.getContext() .getAuthentication(); try { //set the authentication request (unauthenticated) into the context. SecurityContextHolder.getContext().setAuthentication(authentication); //validate the signature. validateSignature(authentication); //mark the authentication request as validated. authentication.setSignatureValidated(true); //mark that processing has been handled. request.setAttribute(OAUTH_PROCESSING_HANDLED, Boolean.TRUE); if (log.isDebugEnabled()) { log.debug("Signature validated."); } //go. onValidSignature(request, response, chain); } finally { //clear out the consumer authentication to make sure it doesn't get cached. resetPreviousAuthentication(previousAuthentication); } } else if (!isIgnoreInadequateCredentials()) { throw new InvalidOAuthParametersException( messages.getMessage("OAuthProcessingFilter.missingCredentials", "Inadequate OAuth consumer credentials.")); } else { if (log.isDebugEnabled()) { log.debug("Supplied OAuth parameters are inadequate. Ignoring."); } chain.doFilter(request, response); } } catch (AuthenticationException ae) { fail(request, response, ae); } catch (ServletException e) { if (e.getRootCause() instanceof AuthenticationException) { fail(request, response, (AuthenticationException) e.getRootCause()); } else { throw e; } } } else { if (log.isDebugEnabled()) { log.debug("Request does not require authentication. OAuth processing skipped."); } chain.doFilter(servletRequest, servletResponse); } } else { if (log.isDebugEnabled()) { log.debug("Processing explicitly skipped."); } chain.doFilter(servletRequest, servletResponse); } }
From source file:org.zilverline.core.TestIndexException.java
/** * This methods tests ServletException and 1.4 Throwable cause hierarchy. *///from w w w . j av a2 s .c om public void testExceptionHierarchy() { try { try { throw new Exception("Error"); } catch (Exception e) { try { throw new IndexException("Error in Index", e); } catch (IndexException ie) { throw new ServletException("Error in Servlet", ie); } } } catch (ServletException se) { Throwable rootCause = se.getRootCause(); Throwable seCause = se.getCause(); assertNotNull(rootCause); assertNull(seCause); assertEquals("Error in Index", rootCause.getMessage()); Throwable cause = rootCause.getCause(); assertNotNull(cause); assertEquals("Error", cause.getMessage()); assertEquals("Error in Servlet", se.getMessage()); } }
From source file:servletunit.frame2.MockFrame2TestCase.java
/** * Executes the Action instance to be tested. This method calls the * ActionServlet.doPost() method to execute the Action instance to be * tested, passing along any parameters set in the HttpServletRequest * object. It stores any results for further validation. * @exception AssertionFailedError if there are any execution errors while * calling Action.perform()/*from w w w .j a v a 2 s .c o m*/ */ public void doEvent() { confirmSetup(); try { this.servlet.doPost(this.request, this.response); } catch (ServletException se) { fail("Error running doEvent(): " + se.getRootCause().getClass() //$NON-NLS-1$ + " - " + se.getRootCause().getMessage()); //$NON-NLS-1$ } catch (Exception ex) { fail("Error running action.perform(): " + ex.getClass() + " - " //$NON-NLS-1$ //$NON-NLS-2$ + ex.getMessage()); } }