Search in sources :

Example 41 with UnavailableException

use of javax.servlet.UnavailableException in project sonar-java 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 42 with UnavailableException

use of javax.servlet.UnavailableException in project i2p.i2p by i2p.

the class I2PDefaultServlet method init.

/**
 * Overridden to save local copies of dirAllowed, locale, resourceBase, and stylesheet.
 * Calls super.
 */
@Override
public void init() throws UnavailableException {
    super.init();
    _dirAllowed = getInitBoolean("dirAllowed", _dirAllowed);
    String rb = getInitParameter("resourceBase");
    if (rb != null) {
        try {
            _resourceBase = _contextHandler.newResource(rb);
        } catch (Exception e) {
            throw new UnavailableException(e.toString());
        }
    }
    String css = getInitParameter("stylesheet");
    try {
        if (css != null) {
            _stylesheet = Resource.newResource(css);
            if (!_stylesheet.exists()) {
                _stylesheet = null;
            }
        }
        if (_stylesheet == null) {
            _stylesheet = Resource.newResource(this.getClass().getResource("/jetty-dir.css"));
        }
    } catch (Exception e) {
    }
}
Also used : UnavailableException(javax.servlet.UnavailableException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException)

Example 43 with UnavailableException

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

the class IafServletFilter method init.

@Override
public void init(final FilterConfig filterConfig) throws ServletException {
    String config = filterConfig.getInitParameter("config");
    if (config == null) {
        config = "/WEB-INF/iaf-config.xml";
    }
    final ServletContext servletContext = filterConfig.getServletContext();
    WebUiContext.setServletContext(servletContext);
    final WebApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
    try {
        final URL configResource = servletContext.getResource(config);
        final XmlConfigLoader configLoader = new XmlConfigLoader(configResource, servletContext);
        this.rsWebUiConfig = configLoader.loadConfig();
        servletContext.setAttribute("rsWebUiConfig", this.rsWebUiConfig);
    } catch (final InvalidConfigException e) {
        log.error(e.getErrors(), e);
        throw new UnavailableException("Cannot load a rsWebUiConfig resource from '" + config + "' due to " + e.getErrors());
    } catch (final Exception e) {
        log.error(e.getMessage(), e);
        throw new UnavailableException("Cannot load a rsWebUiConfig resource from '" + config + "' due to " + e.getMessage());
    }
}
Also used : XmlConfigLoader(com.revolsys.ui.web.config.XmlConfigLoader) UnavailableException(javax.servlet.UnavailableException) ServletContext(javax.servlet.ServletContext) InvalidConfigException(com.revolsys.ui.web.config.InvalidConfigException) URL(java.net.URL) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException) InvalidConfigException(com.revolsys.ui.web.config.InvalidConfigException) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 44 with UnavailableException

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

the class WebUiFilter method loadIafConfig.

private void loadIafConfig(final String config, final FilterConfig filterConfig) throws UnavailableException {
    final ServletContext servletContext = filterConfig.getServletContext();
    WebUiContext.setServletContext(servletContext);
    this.applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
    try {
        final URL configResource = servletContext.getResource(config);
        final XmlConfigLoader configLoader = new XmlConfigLoader(configResource, servletContext);
        this.rsWebUiConfig = configLoader.loadConfig();
        servletContext.setAttribute("rsWebUiConfig", this.rsWebUiConfig);
    } catch (final InvalidConfigException e) {
        LOG.error(e.getErrors(), e);
        throw new UnavailableException("Cannot load a rsWebUiConfig resource from '" + config + "' due to " + e.getErrors());
    } catch (final Exception e) {
        LOG.error(e.getMessage(), e);
        throw new UnavailableException("Cannot load a rsWebUiConfig resource from '" + config + "' due to " + e.getMessage());
    }
}
Also used : XmlConfigLoader(com.revolsys.ui.web.config.XmlConfigLoader) UnavailableException(javax.servlet.UnavailableException) ServletContext(javax.servlet.ServletContext) InvalidConfigException(com.revolsys.ui.web.config.InvalidConfigException) URL(java.net.URL) ServletException(javax.servlet.ServletException) InvalidConfigException(com.revolsys.ui.web.config.InvalidConfigException) PageNotFoundException(com.revolsys.ui.web.exception.PageNotFoundException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException)

Example 45 with UnavailableException

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

the class SecurityUtil method execute.

/**
 * Perform work as a particular </code>Subject</code>. Here the work
 * will be granted to a <code>null</code> subject.
 *
 * @param method the method to apply the security restriction
 * @param targetObject the <code>Servlet</code> on which the method will
 * be called.
 * @param targetArguments <code>Object</code> array contains the
 * runtime parameters instance.
 * @param principal the <code>Principal</code> to which the security
 * privilege applies
 */
private static void execute(final Method method, final Object targetObject, final Object[] targetArguments, Principal principal) throws java.lang.Exception {
    try {
        Subject subject = null;
        PrivilegedExceptionAction<Void> pea = new PrivilegedExceptionAction<Void>() {

            @Override
            public Void run() throws Exception {
                method.invoke(targetObject, targetArguments);
                return null;
            }
        };
        // The first argument is always the request object
        if (targetArguments != null && targetArguments[0] instanceof HttpServletRequest) {
            HttpServletRequest request = (HttpServletRequest) targetArguments[0];
            boolean hasSubject = false;
            HttpSession session = request.getSession(false);
            if (session != null) {
                subject = (Subject) session.getAttribute(Globals.SUBJECT_ATTR);
                hasSubject = (subject != null);
            }
            if (subject == null) {
                subject = new Subject();
                if (principal != null) {
                    subject.getPrincipals().add(principal);
                }
            }
            if (session != null && !hasSubject) {
                session.setAttribute(Globals.SUBJECT_ATTR, subject);
            }
        }
        Subject.doAsPrivileged(subject, pea, null);
    } catch (PrivilegedActionException pe) {
        Throwable e;
        if (pe.getException() instanceof InvocationTargetException) {
            e = pe.getException().getCause();
            ExceptionUtils.handleThrowable(e);
        } else {
            e = pe;
        }
        if (log.isDebugEnabled()) {
            log.debug(sm.getString("SecurityUtil.doAsPrivilege"), e);
        }
        if (e instanceof UnavailableException)
            throw (UnavailableException) e;
        else if (e instanceof ServletException)
            throw (ServletException) e;
        else if (e instanceof IOException)
            throw (IOException) e;
        else if (e instanceof RuntimeException)
            throw (RuntimeException) e;
        else
            throw new ServletException(e.getMessage(), e);
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) HttpSession(javax.servlet.http.HttpSession) UnavailableException(javax.servlet.UnavailableException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) IOException(java.io.IOException) Subject(javax.security.auth.Subject) InvocationTargetException(java.lang.reflect.InvocationTargetException) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException)

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