Search in sources :

Example 21 with UnavailableException

use of javax.servlet.UnavailableException in project sonarqube by SonarSource.

the class TestActionServlet method testInitModuleFormBeansNullFormType.

/**
     * Test that initModuleFormBeans throws an exception when a form with a
     * null type is present.
     */
public void testInitModuleFormBeansNullFormType() throws ServletException {
    FormBeanConfig formBean = new FormBeanConfig();
    formBean.setName("noTypeForm");
    moduleConfig.addFormBeanConfig(formBean);
    try {
        actionServlet.initModuleFormBeans(moduleConfig);
        fail("An exception should've been thrown here.");
    } catch (UnavailableException e) {
    // success
    } catch (Exception e) {
        fail("Unrecognized exception thrown: " + e);
    }
}
Also used : FormBeanConfig(org.apache.struts.config.FormBeanConfig) UnavailableException(javax.servlet.UnavailableException) ServletException(javax.servlet.ServletException) UnavailableException(javax.servlet.UnavailableException)

Example 22 with UnavailableException

use of javax.servlet.UnavailableException in project sonarqube by SonarSource.

the class TestActionServlet method testProcessActionConfigClassNoExtends.

/**
     * Make sure processActionConfigClass() returns what it was given if the
     * action passed to it doesn't extend anything.
     */
public void testProcessActionConfigClassNoExtends() throws Exception {
    moduleConfig.addActionConfig(baseAction);
    ActionConfig result = null;
    try {
        result = actionServlet.processActionConfigClass(baseAction, moduleConfig);
    } catch (UnavailableException e) {
        fail("An exception should not be thrown here");
    }
    assertSame("Result should be the same as the input.", baseAction, result);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) UnavailableException(javax.servlet.UnavailableException)

Example 23 with UnavailableException

use of javax.servlet.UnavailableException in project sonarqube by SonarSource.

the class TestActionServlet method testProcessFormBeanConfigClassNoExtends.

/**
     * Make sure processFormBeanConfigClass() returns what it was given if the
     * form passed to it doesn't extend anything.
     */
public void testProcessFormBeanConfigClassNoExtends() throws Exception {
    moduleConfig.addFormBeanConfig(baseFormBean);
    FormBeanConfig result = null;
    try {
        result = actionServlet.processFormBeanConfigClass(baseFormBean, moduleConfig);
    } catch (UnavailableException e) {
        fail("An exception should not be thrown when there's nothing to do");
    }
    assertSame("Result should be the same as the input.", baseFormBean, result);
}
Also used : FormBeanConfig(org.apache.struts.config.FormBeanConfig) UnavailableException(javax.servlet.UnavailableException)

Example 24 with UnavailableException

use of javax.servlet.UnavailableException in project sonarqube by SonarSource.

the class TestActionServlet method notestProcessActionConfigClassError.

/**
     * Make sure the code throws the correct exception when it can't create an
     * instance of the base config's custom class.
     */
public void notestProcessActionConfigClassError() throws Exception {
    ActionConfig customBase = new CustomActionConfigArg("/index");
    moduleConfig.addActionConfig(customBase);
    ActionConfig customSub = new ActionMapping();
    customSub.setPath("/sub");
    customSub.setExtends("/index");
    moduleConfig.addActionConfig(customSub);
    try {
        actionServlet.processActionConfigClass(customSub, moduleConfig);
        fail("Exception should be thrown");
    } catch (UnavailableException e) {
    // success
    } catch (Exception e) {
        fail("Unexpected exception thrown.");
    }
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) UnavailableException(javax.servlet.UnavailableException) ServletException(javax.servlet.ServletException) UnavailableException(javax.servlet.UnavailableException)

Example 25 with UnavailableException

use of javax.servlet.UnavailableException in project sling by apache.

the class SlingRequestProcessorImpl method doProcessRequest.

/**
     * This method is directly called by the Sling main servlet.
     */
public void doProcessRequest(final HttpServletRequest servletRequest, final HttpServletResponse servletResponse, final ResourceResolver resourceResolver) throws IOException {
    // setting the Sling request and response
    final RequestData requestData = new RequestData(this, servletRequest, servletResponse);
    final SlingHttpServletRequest request = requestData.getSlingRequest();
    final SlingHttpServletResponse response = requestData.getSlingResponse();
    // record the request for the web console display
    RequestHistoryConsolePlugin.recordRequest(request);
    try {
        final ServletResolver sr = this.servletResolver;
        // check that we have all required services
        if (resourceResolver == null) {
            throw new UnavailableException("ResourceResolver");
        } else if (sr == null) {
            throw new UnavailableException("ServletResolver");
        }
        // initialize the request data - resolve resource and servlet
        Resource resource = requestData.initResource(resourceResolver);
        requestData.initServlet(resource, sr);
        FilterHandle[] filters = filterManager.getFilters(FilterChainType.REQUEST);
        if (filters != null) {
            FilterChain processor = new RequestSlingFilterChain(this, filters);
            request.getRequestProgressTracker().log("Applying " + FilterChainType.REQUEST + "filters");
            processor.doFilter(request, response);
        } else {
            // no filters, directly call resource level filters and servlet
            processComponent(request, response, FilterChainType.COMPONENT);
        }
    } catch (final SlingHttpServletResponseImpl.WriterAlreadyClosedException wace) {
        log.error("Writer has already been closed.", wace);
    } catch (ResourceNotFoundException rnfe) {
        // send this exception as a 404 status
        log.info("service: Resource {} not found", rnfe.getResource());
        handleError(HttpServletResponse.SC_NOT_FOUND, rnfe.getMessage(), request, response);
    } catch (final SlingException se) {
        // we assume, that this is the name of the causing servlet
        if (requestData.getActiveServletName() != null) {
            request.setAttribute(ERROR_SERVLET_NAME, requestData.getActiveServletName());
        }
        // send this exception as is (albeit unwrapping and wrapped
        // exception.
        Throwable t = se;
        while (t instanceof SlingException && t.getCause() != null) {
            t = t.getCause();
        }
        log.error("service: Uncaught SlingException", t);
        handleError(t, request, response);
    } catch (AccessControlException ace) {
        // SLING-319 if anything goes wrong, send 403/FORBIDDEN
        log.info("service: Authenticated user {} does not have enough rights to executed requested action", request.getRemoteUser());
        handleError(HttpServletResponse.SC_FORBIDDEN, null, request, response);
    } catch (UnavailableException ue) {
        // exception is thrown before the SlingHttpServletRequest/Response
        // is properly set up due to missing dependencies. In this case
        // we must not use the Sling error handling infrastructure but
        // just return a 503 status response handled by the servlet
        // container environment
        final int status = HttpServletResponse.SC_SERVICE_UNAVAILABLE;
        final String errorMessage = ue.getMessage() + " service missing, cannot service requests";
        log.error("{} , sending status {}", errorMessage, status);
        servletResponse.sendError(status, errorMessage);
    } catch (IOException ioe) {
        // forward IOException up the call chain to properly handle it
        throw ioe;
    } catch (Throwable t) {
        // we assume, that this is the name of the causing servlet
        if (requestData.getActiveServletName() != null) {
            request.setAttribute(ERROR_SERVLET_NAME, requestData.getActiveServletName());
        }
        log.error("service: Uncaught Throwable", t);
        handleError(t, request, response);
    } finally {
        if (mbean != null) {
            mbean.addRequestData(requestData);
        }
    }
}
Also used : SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) FilterHandle(org.apache.sling.engine.impl.filter.FilterHandle) RequestSlingFilterChain(org.apache.sling.engine.impl.filter.RequestSlingFilterChain) SlingComponentFilterChain(org.apache.sling.engine.impl.filter.SlingComponentFilterChain) FilterChain(javax.servlet.FilterChain) AbstractSlingFilterChain(org.apache.sling.engine.impl.filter.AbstractSlingFilterChain) UnavailableException(javax.servlet.UnavailableException) Resource(org.apache.sling.api.resource.Resource) AccessControlException(java.security.AccessControlException) IOException(java.io.IOException) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) RequestSlingFilterChain(org.apache.sling.engine.impl.filter.RequestSlingFilterChain) ServletResolver(org.apache.sling.api.servlets.ServletResolver) RequestData(org.apache.sling.engine.impl.request.RequestData) SlingException(org.apache.sling.api.SlingException) ResourceNotFoundException(org.apache.sling.api.resource.ResourceNotFoundException)

Aggregations

UnavailableException (javax.servlet.UnavailableException)95 ServletException (javax.servlet.ServletException)54 IOException (java.io.IOException)33 MalformedURLException (java.net.MalformedURLException)15 SAXException (org.xml.sax.SAXException)14 MissingResourceException (java.util.MissingResourceException)12 ExceptionConfig (org.apache.struts.config.ExceptionConfig)10 URL (java.net.URL)8 Servlet (javax.servlet.Servlet)8 FormBeanConfig (org.apache.struts.config.FormBeanConfig)8 ForwardConfig (org.apache.struts.config.ForwardConfig)8 ServletContext (javax.servlet.ServletContext)6 ActionConfig (org.apache.struts.config.ActionConfig)6 ArrayList (java.util.ArrayList)5 ServletConfig (javax.servlet.ServletConfig)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 ClientAbortException (org.apache.catalina.connector.ClientAbortException)4 InvalidConfigException (com.revolsys.ui.web.config.InvalidConfigException)3 XmlConfigLoader (com.revolsys.ui.web.config.XmlConfigLoader)3 BufferedImage (java.awt.image.BufferedImage)3