Search in sources :

Example 81 with UnavailableException

use of javax.servlet.UnavailableException in project sonar-java by SonarSource.

the class TestActionServlet method testInitModuleExceptionConfigsNullFormType.

/**
 * Test that initModuleExceptionConfigs throws an exception when a handler
 * with a null key is present.
 */
public void testInitModuleExceptionConfigsNullFormType() throws ServletException {
    ExceptionConfig handler = new ExceptionConfig();
    handler.setType("java.lang.NullPointerException");
    moduleConfig.addExceptionConfig(handler);
    try {
        actionServlet.initModuleExceptionConfigs(moduleConfig);
        fail("An exception should've been thrown here.");
    } catch (UnavailableException e) {
    // success
    } catch (Exception e) {
        fail("Unrecognized exception thrown: " + e);
    }
}
Also used : ExceptionConfig(org.apache.struts.config.ExceptionConfig) UnavailableException(javax.servlet.UnavailableException) ServletException(javax.servlet.ServletException) UnavailableException(javax.servlet.UnavailableException)

Example 82 with UnavailableException

use of javax.servlet.UnavailableException in project sonar-java by SonarSource.

the class TestActionServlet method testProcessExceptionConfigClassNoExtends.

/**
 * Make sure processExceptionConfigClass() returns what it was given if
 * the handler passed to it doesn't extend anything.
 */
public void testProcessExceptionConfigClassNoExtends() throws Exception {
    moduleConfig.addExceptionConfig(baseException);
    ExceptionConfig result = null;
    try {
        result = actionServlet.processExceptionConfigClass(baseException, moduleConfig, null);
    } 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.", baseException, result);
}
Also used : ExceptionConfig(org.apache.struts.config.ExceptionConfig) UnavailableException(javax.servlet.UnavailableException)

Example 83 with UnavailableException

use of javax.servlet.UnavailableException in project sonar-java by SonarSource.

the class ValidatorPlugIn method init.

/**
 * Initialize and load our resources.
 *
 * @param servlet The ActionServlet for our application
 * @param config  The ModuleConfig for our owning module
 * @throws ServletException if we cannot configure ourselves correctly
 */
public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {
    // Remember our associated configuration and servlet
    this.config = config;
    this.servlet = servlet;
    // Load our database from persistent storage
    try {
        this.initResources();
        servlet.getServletContext().setAttribute(VALIDATOR_KEY + config.getPrefix(), resources);
        servlet.getServletContext().setAttribute(STOP_ON_ERROR_KEY + '.' + config.getPrefix(), (this.stopOnFirstError ? Boolean.TRUE : Boolean.FALSE));
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new UnavailableException("Cannot load a validator resource from '" + pathnames + "'");
    }
}
Also used : UnavailableException(javax.servlet.UnavailableException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException) SAXException(org.xml.sax.SAXException)

Example 84 with UnavailableException

use of javax.servlet.UnavailableException in project com.revolsys.open by revolsys.

the class IafServlet method init.

/**
 * Initialise the servlet. Loads the configuration from the
 * /WEB-INF/nice-config.xml file.
 *
 * @param config The servlet configuration parameters
 * @exception ServletException if there was a problem initialising the servlet
 */
@Override
public void init(final ServletConfig config) throws ServletException {
    super.init(config);
    try {
        this.servletContext = config.getServletContext();
        final URL configResource = this.servletContext.getResource("/WEB-INF/iaf-config.xml");
        WebUiContext.setServletContext(this.servletContext);
        final XmlConfigLoader configLoader = new XmlConfigLoader(configResource, this.servletContext);
        this.applicationConfig = configLoader.loadConfig();
        this.servletContext.setAttribute("rsWebUiConfig", this.applicationConfig);
    } catch (final InvalidConfigException ice) {
        ice.printStackTrace();
        log.fatal(ice.getErrors());
        throw new UnavailableException(ice.getMessage() + ":" + ice.getErrors());
    } catch (final MalformedURLException mue) {
        log.fatal(mue.getMessage(), mue);
        throw new UnavailableException("Failed to initialise Servlet");
    } catch (final Throwable t) {
        t.printStackTrace();
        log.error(t.getMessage(), t);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) XmlConfigLoader(com.revolsys.ui.web.config.XmlConfigLoader) UnavailableException(javax.servlet.UnavailableException) InvalidConfigException(com.revolsys.ui.web.config.InvalidConfigException) URL(java.net.URL)

Example 85 with UnavailableException

use of javax.servlet.UnavailableException in project Payara by payara.

the class StandardWrapper method initServlet.

/**
 * Initializes the given servlet instance, by calling its init method.
 */
private void initServlet(Servlet servlet) throws ServletException {
    if (instanceInitialized && !singleThreadModel) {
        // Servlet has already been initialized
        return;
    }
    try {
        instanceSupport.fireInstanceEvent(BEFORE_INIT_EVENT, servlet);
        // START SJS WS 7.0 6236329
        if (executeUnderSubjectDoAs()) {
            // END OF SJS WS 7.0 6236329
            Object[] initType = { facade };
            doAsPrivilege("init", servlet, classType, initType);
            initType = null;
        } else {
            servlet.init(facade);
        }
        instanceInitialized = true;
        // Invoke jspInit on JSP pages
        if (loadOnStartup >= 0 && jspFile != null) {
            // Invoking jspInit
            DummyRequest req = new DummyRequest();
            req.setServletPath(jspFile);
            req.setQueryString("jsp_precompile=true");
            // START PWC 4707989
            String allowedMethods = parameters.get("httpMethods");
            if (allowedMethods != null && allowedMethods.length() > 0) {
                String[] allowedMethod = allowedMethods.split(",");
                if (allowedMethod.length > 0) {
                    req.setMethod(allowedMethod[0].trim());
                }
            }
            // END PWC 4707989
            DummyResponse res = new DummyResponse();
            // START SJS WS 7.0 6236329
            if (executeUnderSubjectDoAs()) {
                // END OF SJS WS 7.0 6236329
                Object[] serviceType = { req, res };
                doAsPrivilege("service", servlet, classTypeUsedInService, serviceType);
            } else {
                servlet.service(req, res);
            }
        }
        instanceSupport.fireInstanceEvent(AFTER_INIT_EVENT, servlet);
    } catch (UnavailableException f) {
        instanceSupport.fireInstanceEvent(AFTER_INIT_EVENT, servlet, f);
        unavailable(f);
        throw f;
    } catch (ServletException f) {
        instanceSupport.fireInstanceEvent(AFTER_INIT_EVENT, servlet, f);
        // said so, so do not call unavailable(null).
        throw f;
    } catch (Throwable f) {
        getServletContext().log("StandardWrapper.Throwable", f);
        instanceSupport.fireInstanceEvent(AFTER_INIT_EVENT, servlet, f);
        // said so, so do not call unavailable(null).
        throw new ServletException(format(rb.getString(SERVLET_INIT_EXCEPTION), getName()), f);
    }
}
Also used : ServletException(javax.servlet.ServletException) UnavailableException(javax.servlet.UnavailableException)

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