Search in sources :

Example 86 with UnavailableException

use of javax.servlet.UnavailableException in project winstone by jenkinsci.

the class UnavailableServlet method doGet.

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (!this.errorAtInit)
        throw new UnavailableException("Error thrown deliberately during get");
    Writer out = response.getWriter();
    out.write("This should not be shown, because we've thrown unavailable exceptions");
    out.close();
}
Also used : UnavailableException(javax.servlet.UnavailableException) Writer(java.io.Writer)

Example 87 with UnavailableException

use of javax.servlet.UnavailableException in project scout.rt by eclipse.

the class ServletExceptionTranslatorTest method before.

@Before
public void before() {
    m_servletException = new ServletException();
    m_unavailableException = new UnavailableException("");
    m_platformException = new ProcessingException();
    m_processingException = new ProcessingException();
    m_runtimeException = new RuntimeException();
    m_illegalArgumentException = new IllegalArgumentException();
    m_checkedException = new Exception();
    m_interruptedException = new InterruptedException();
    m_throwable = new Throwable();
    m_error = new Error();
}
Also used : ServletException(javax.servlet.ServletException) UnavailableException(javax.servlet.UnavailableException) ServletException(javax.servlet.ServletException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExecutionException(java.util.concurrent.ExecutionException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) UnavailableException(javax.servlet.UnavailableException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) Before(org.junit.Before)

Example 88 with UnavailableException

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

the class ActionServlet method splitAndResolvePaths.

/**
 * <p>Takes a comma-delimited string and splits it into paths, then
 * resolves those paths using the ServletContext and appropriate
 * ClassLoader.  When loading from the classloader, multiple resources per
 * path are supported to support, for example, multiple jars containing
 * the same named config file.</p>
 *
 * @param paths A comma-delimited string of paths
 * @return A list of resolved URL's for all found resources
 * @throws ServletException if a servlet exception is thrown
 */
protected List splitAndResolvePaths(String paths) throws ServletException {
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    if (loader == null) {
        loader = this.getClass().getClassLoader();
    }
    ArrayList resolvedUrls = new ArrayList();
    URL resource;
    String path = null;
    try {
        // Process each specified resource path
        while (paths.length() > 0) {
            resource = null;
            int comma = paths.indexOf(',');
            if (comma >= 0) {
                path = paths.substring(0, comma).trim();
                paths = paths.substring(comma + 1);
            } else {
                path = paths.trim();
                paths = "";
            }
            if (path.length() < 1) {
                break;
            }
            if (path.charAt(0) == '/') {
                resource = getServletContext().getResource(path);
            }
            if (resource == null) {
                if (log.isDebugEnabled()) {
                    log.debug("Unable to locate " + path + " in the servlet context, " + "trying classloader.");
                }
                Enumeration e = loader.getResources(path);
                if (!e.hasMoreElements()) {
                    String msg = internal.getMessage("configMissing", path);
                    log.error(msg);
                    throw new UnavailableException(msg);
                } else {
                    while (e.hasMoreElements()) {
                        resolvedUrls.add(e.nextElement());
                    }
                }
            } else {
                resolvedUrls.add(resource);
            }
        }
    } catch (MalformedURLException e) {
        handleConfigException(path, e);
    } catch (IOException e) {
        handleConfigException(path, e);
    }
    return resolvedUrls;
}
Also used : MalformedURLException(java.net.MalformedURLException) Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList) UnavailableException(javax.servlet.UnavailableException) IOException(java.io.IOException) URL(java.net.URL)

Example 89 with UnavailableException

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

the class ActionServlet method processActionConfigClass.

/**
 * <p>Checks if the current actionConfig is using the correct class based
 * on the class of its ancestor ActionConfig.</p>
 *
 * @param actionConfig The action config to check.
 * @param moduleConfig The config for the current module.
 * @return The config object using the correct class as determined by the
 *         config's ancestor and its own overridden value.
 * @throws ServletException if an instance of the action config class
 *                          cannot be created.
 */
protected ActionConfig processActionConfigClass(ActionConfig actionConfig, ModuleConfig moduleConfig) throws ServletException {
    String ancestor = actionConfig.getExtends();
    if (ancestor == null) {
        // Nothing to do, then
        return actionConfig;
    }
    // Make sure that this config is of the right class
    ActionConfig baseConfig = moduleConfig.findActionConfig(ancestor);
    if (baseConfig == null) {
        throw new UnavailableException("Unable to find " + "action config for '" + ancestor + "' to extend.");
    }
    // Was our actionConfig's class overridden already?
    if (actionConfig.getClass().equals(ActionMapping.class)) {
        // Ensure that our config is using the correct class
        if (!baseConfig.getClass().equals(actionConfig.getClass())) {
            // Replace the config with an instance of the correct class
            ActionConfig newActionConfig = null;
            String baseConfigClassName = baseConfig.getClass().getName();
            try {
                newActionConfig = (ActionConfig) RequestUtils.applicationInstance(baseConfigClassName);
                // copy the values
                BeanUtils.copyProperties(newActionConfig, actionConfig);
                // copy the forward and exception configs, too
                ForwardConfig[] forwards = actionConfig.findForwardConfigs();
                for (int i = 0; i < forwards.length; i++) {
                    newActionConfig.addForwardConfig(forwards[i]);
                }
                ExceptionConfig[] exceptions = actionConfig.findExceptionConfigs();
                for (int i = 0; i < exceptions.length; i++) {
                    newActionConfig.addExceptionConfig(exceptions[i]);
                }
            } catch (Exception e) {
                handleCreationException(baseConfigClassName, e);
            }
            // replace actionConfig with newActionConfig
            moduleConfig.removeActionConfig(actionConfig);
            moduleConfig.addActionConfig(newActionConfig);
            actionConfig = newActionConfig;
        }
    }
    return actionConfig;
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ExceptionConfig(org.apache.struts.config.ExceptionConfig) UnavailableException(javax.servlet.UnavailableException) ForwardConfig(org.apache.struts.config.ForwardConfig) ServletException(javax.servlet.ServletException) MissingResourceException(java.util.MissingResourceException) SAXException(org.xml.sax.SAXException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException)

Example 90 with UnavailableException

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

the class ActionServlet method parseModuleConfigFile.

/**
 * <p>Parses one module config file.</p>
 *
 * @param digester Digester instance that does the parsing
 * @param path     The path to the config file to parse.
 * @throws UnavailableException if file cannot be read or parsed
 * @since Struts 1.2
 * @deprecated use parseModuleConfigFile(Digester digester, URL url)
 *             instead
 */
protected void parseModuleConfigFile(Digester digester, String path) throws UnavailableException {
    try {
        List paths = splitAndResolvePaths(path);
        if (paths.size() > 0) {
            // Get first path as was the old behavior
            URL url = (URL) paths.get(0);
            parseModuleConfigFile(digester, url);
        } else {
            throw new UnavailableException("Cannot locate path " + path);
        }
    } catch (UnavailableException ex) {
        throw ex;
    } catch (ServletException ex) {
        handleConfigException(path, ex);
    }
}
Also used : ServletException(javax.servlet.ServletException) UnavailableException(javax.servlet.UnavailableException) List(java.util.List) ArrayList(java.util.ArrayList) URL(java.net.URL)

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