Search in sources :

Example 46 with UnavailableException

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

the class StandardWrapperValve method event.

/**
 * Process a Comet event. The main differences here are to not use sendError
 * (the response is committed), to avoid creating a new filter chain
 * (which would work but be pointless), and a few very minor tweaks.
 *
 * @param request The servlet request to be processed
 * @param response The servlet response to be created
 *
 * @exception IOException if an input/output error occurs, or is thrown
 *  by a subsequently invoked Valve, Filter, or Servlet
 * @exception ServletException if a servlet error occurs, or is thrown
 *  by a subsequently invoked Valve, Filter, or Servlet
 */
@Override
public void event(Request request, Response response, CometEvent event) throws IOException, ServletException {
    // Initialize local variables we may need
    Throwable throwable = null;
    // This should be a Request attribute...
    long t1 = System.currentTimeMillis();
    // FIXME: Add a flag to count the total amount of events processed ? requestCount++;
    StandardWrapper wrapper = (StandardWrapper) getContainer();
    if (wrapper == null) {
        // Context has been shutdown. Nothing to do here.
        return;
    }
    Servlet servlet = null;
    Context context = (Context) wrapper.getParent();
    // Check for the application being marked unavailable
    boolean unavailable = !context.getState().isAvailable() || wrapper.isUnavailable();
    // Allocate a servlet instance to process this request
    try {
        if (!unavailable) {
            servlet = wrapper.allocate();
        }
    } catch (UnavailableException e) {
    // The response is already committed, so it's not possible to do anything
    } catch (ServletException e) {
        container.getLogger().error(sm.getString("standardWrapper.allocateException", wrapper.getName()), StandardWrapper.getRootCause(e));
        throwable = e;
        exception(request, response, e);
    } catch (Throwable e) {
        ExceptionUtils.handleThrowable(e);
        container.getLogger().error(sm.getString("standardWrapper.allocateException", wrapper.getName()), e);
        throwable = e;
        exception(request, response, e);
        servlet = null;
    }
    MessageBytes requestPathMB = request.getRequestPathMB();
    request.setAttribute(Globals.DISPATCHER_TYPE_ATTR, DispatcherType.REQUEST);
    request.setAttribute(Globals.DISPATCHER_REQUEST_PATH_ATTR, requestPathMB);
    // Get the current (unchanged) filter chain for this request
    ApplicationFilterChain filterChain = (ApplicationFilterChain) request.getFilterChain();
    // NOTE: This also calls the servlet's event() method
    try {
        if ((servlet != null) && (filterChain != null)) {
            // Swallow output if needed
            if (context.getSwallowOutput()) {
                try {
                    SystemLogHandler.startCapture();
                    filterChain.doFilterEvent(request.getEvent());
                } finally {
                    String log = SystemLogHandler.stopCapture();
                    if (log != null && log.length() > 0) {
                        context.getLogger().info(log);
                    }
                }
            } else {
                filterChain.doFilterEvent(request.getEvent());
            }
        }
    } catch (ClientAbortException e) {
        throwable = e;
        exception(request, response, e);
    } catch (IOException e) {
        container.getLogger().error(sm.getString("standardWrapper.serviceException", wrapper.getName(), context.getName()), e);
        throwable = e;
        exception(request, response, e);
    } catch (UnavailableException e) {
        container.getLogger().error(sm.getString("standardWrapper.serviceException", wrapper.getName(), context.getName()), e);
    // Do not save exception in 'throwable', because we
    // do not want to do exception(request, response, e) processing
    } catch (ServletException e) {
        Throwable rootCause = StandardWrapper.getRootCause(e);
        if (!(rootCause instanceof ClientAbortException)) {
            container.getLogger().error(sm.getString("standardWrapper.serviceExceptionRoot", wrapper.getName(), context.getName(), e.getMessage()), rootCause);
        }
        throwable = e;
        exception(request, response, e);
    } catch (Throwable e) {
        ExceptionUtils.handleThrowable(e);
        container.getLogger().error(sm.getString("standardWrapper.serviceException", wrapper.getName(), context.getName()), e);
        throwable = e;
        exception(request, response, e);
    }
    // Release the filter chain (if any) for this request
    if (filterChain != null) {
        filterChain.reuse();
    }
    // Deallocate the allocated servlet instance
    try {
        if (servlet != null) {
            wrapper.deallocate(servlet);
        }
    } catch (Throwable e) {
        ExceptionUtils.handleThrowable(e);
        container.getLogger().error(sm.getString("standardWrapper.deallocateException", wrapper.getName()), e);
        if (throwable == null) {
            throwable = e;
            exception(request, response, e);
        }
    }
    // unload it and release this instance
    try {
        if ((servlet != null) && (wrapper.getAvailable() == Long.MAX_VALUE)) {
            wrapper.unload();
        }
    } catch (Throwable e) {
        ExceptionUtils.handleThrowable(e);
        container.getLogger().error(sm.getString("standardWrapper.unloadException", wrapper.getName()), e);
        if (throwable == null) {
            throwable = e;
            exception(request, response, e);
        }
    }
    long t2 = System.currentTimeMillis();
    long time = t2 - t1;
    processingTime += time;
    if (time > maxTime)
        maxTime = time;
    if (time < minTime)
        minTime = time;
}
Also used : Context(org.apache.catalina.Context) UnavailableException(javax.servlet.UnavailableException) MessageBytes(org.apache.tomcat.util.buf.MessageBytes) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) Servlet(javax.servlet.Servlet) ClientAbortException(org.apache.catalina.connector.ClientAbortException)

Example 47 with UnavailableException

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

the class DefaultServlet method init.

/**
 * Initialize this servlet.
 */
@Override
public void init() throws ServletException {
    if (getServletConfig().getInitParameter("debug") != null)
        debug = Integer.parseInt(getServletConfig().getInitParameter("debug"));
    if (getServletConfig().getInitParameter("input") != null)
        input = Integer.parseInt(getServletConfig().getInitParameter("input"));
    if (getServletConfig().getInitParameter("output") != null)
        output = Integer.parseInt(getServletConfig().getInitParameter("output"));
    listings = Boolean.parseBoolean(getServletConfig().getInitParameter("listings"));
    if (getServletConfig().getInitParameter("readonly") != null)
        readOnly = Boolean.parseBoolean(getServletConfig().getInitParameter("readonly"));
    if (getServletConfig().getInitParameter("sendfileSize") != null)
        sendfileSize = Integer.parseInt(getServletConfig().getInitParameter("sendfileSize")) * 1024;
    fileEncoding = getServletConfig().getInitParameter("fileEncoding");
    globalXsltFile = getServletConfig().getInitParameter("globalXsltFile");
    contextXsltFile = getServletConfig().getInitParameter("contextXsltFile");
    localXsltFile = getServletConfig().getInitParameter("localXsltFile");
    readmeFile = getServletConfig().getInitParameter("readmeFile");
    if (getServletConfig().getInitParameter("useAcceptRanges") != null)
        useAcceptRanges = Boolean.parseBoolean(getServletConfig().getInitParameter("useAcceptRanges"));
    // Sanity check on the specified buffer sizes
    if (input < 256)
        input = 256;
    if (output < 256)
        output = 256;
    if (debug > 0) {
        log("DefaultServlet.init:  input buffer size=" + input + ", output buffer size=" + output);
    }
    // Load the proxy dir context.
    resources = (ProxyDirContext) getServletContext().getAttribute(Globals.RESOURCES_ATTR);
    if (resources == null) {
        try {
            resources = (ProxyDirContext) new InitialContext().lookup(RESOURCES_JNDI_NAME);
        } catch (NamingException e) {
            // Failed
            throw new ServletException("No resources", e);
        }
    }
    if (resources == null) {
        throw new UnavailableException("No resources");
    }
    if (getServletConfig().getInitParameter("showServerInfo") != null) {
        showServerInfo = Boolean.parseBoolean(getServletConfig().getInitParameter("showServerInfo"));
    }
}
Also used : ServletException(javax.servlet.ServletException) UnavailableException(javax.servlet.UnavailableException) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext)

Example 48 with UnavailableException

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

the class DefaultServlet method init.

/**
 * Initialize this servlet.
 */
@Override
public void init() throws ServletException {
    if (getServletConfig().getInitParameter("debug") != null) {
        debug = Integer.parseInt(getServletConfig().getInitParameter("debug"));
    }
    if (getServletConfig().getInitParameter("input") != null) {
        input = Integer.parseInt(getServletConfig().getInitParameter("input"));
    }
    if (getServletConfig().getInitParameter("output") != null) {
        output = Integer.parseInt(getServletConfig().getInitParameter("output"));
    }
    listings = Boolean.parseBoolean(getServletConfig().getInitParameter("listings"));
    if (getServletConfig().getInitParameter("readonly") != null) {
        readOnly = Boolean.parseBoolean(getServletConfig().getInitParameter("readonly"));
    }
    compressionFormats = parseCompressionFormats(getServletConfig().getInitParameter("precompressed"), getServletConfig().getInitParameter("gzip"));
    if (getServletConfig().getInitParameter("sendfileSize") != null) {
        sendfileSize = Integer.parseInt(getServletConfig().getInitParameter("sendfileSize")) * 1024;
    }
    fileEncoding = getServletConfig().getInitParameter("fileEncoding");
    if (fileEncoding == null) {
        fileEncodingCharset = Charset.defaultCharset();
        fileEncoding = fileEncodingCharset.name();
    } else {
        try {
            fileEncodingCharset = B2CConverter.getCharset(fileEncoding);
        } catch (UnsupportedEncodingException e) {
            throw new ServletException(e);
        }
    }
    final String useBomIfPresentConfig = getServletConfig().getInitParameter("useBomIfPresent");
    if (useBomIfPresentConfig != null) {
        if (!Arrays.asList("true", "false", "pass-through").contains(useBomIfPresentConfig)) {
            if (debug > 0) {
                log("DefaultServlet.init:  unsupported value " + useBomIfPresentConfig + " for useBomIfPresent." + " One of 'true', 'false', 'pass-through' is expected. Using 'true' by default.");
            }
        }
        useBomIfPresent = useBomIfPresentConfig;
    }
    globalXsltFile = getServletConfig().getInitParameter("globalXsltFile");
    contextXsltFile = getServletConfig().getInitParameter("contextXsltFile");
    localXsltFile = getServletConfig().getInitParameter("localXsltFile");
    readmeFile = getServletConfig().getInitParameter("readmeFile");
    if (getServletConfig().getInitParameter("useAcceptRanges") != null) {
        useAcceptRanges = Boolean.parseBoolean(getServletConfig().getInitParameter("useAcceptRanges"));
    }
    // Sanity check on the specified buffer sizes
    if (input < 256) {
        input = 256;
    }
    if (output < 256) {
        output = 256;
    }
    if (debug > 0) {
        log("DefaultServlet.init:  input buffer size=" + input + ", output buffer size=" + output);
    }
    // Load the web resources
    resources = (WebResourceRoot) getServletContext().getAttribute(Globals.RESOURCES_ATTR);
    if (resources == null) {
        throw new UnavailableException(sm.getString("defaultServlet.noResources"));
    }
    if (getServletConfig().getInitParameter("showServerInfo") != null) {
        showServerInfo = Boolean.parseBoolean(getServletConfig().getInitParameter("showServerInfo"));
    }
    if (getServletConfig().getInitParameter("sortListings") != null) {
        sortListings = Boolean.parseBoolean(getServletConfig().getInitParameter("sortListings"));
        if (sortListings) {
            boolean sortDirectoriesFirst;
            if (getServletConfig().getInitParameter("sortDirectoriesFirst") != null) {
                sortDirectoriesFirst = Boolean.parseBoolean(getServletConfig().getInitParameter("sortDirectoriesFirst"));
            } else {
                sortDirectoriesFirst = false;
            }
            sortManager = new SortManager(sortDirectoriesFirst);
        }
    }
    if (getServletConfig().getInitParameter("allowPartialPut") != null) {
        allowPartialPut = Boolean.parseBoolean(getServletConfig().getInitParameter("allowPartialPut"));
    }
}
Also used : ServletException(javax.servlet.ServletException) UnavailableException(javax.servlet.UnavailableException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 49 with UnavailableException

use of javax.servlet.UnavailableException in project zm-mailbox by Zimbra.

the class SoapServlet method init.

@Override
public void init() throws ServletException {
    LogFactory.init();
    String name = getServletName();
    ZimbraLog.soap.info("Servlet " + name + " starting up");
    super.init();
    mEngine = new SoapEngine();
    int i = 0;
    String cname;
    while ((cname = getInitParameter(PARAM_ENGINE_HANDLER + i)) != null) {
        loadHandler(cname);
        i++;
    }
    // See if any extra services were previously added by extensions
    synchronized (sExtraServices) {
        List<DocumentService> services = LoadingCacheUtil.get(sExtraServices, getServletName());
        for (DocumentService service : services) {
            addService(service);
            i++;
        }
    }
    mEngine.getDocumentDispatcher().clearSoapWhiteList();
    if (i == 0)
        throw new ServletException("Must specify at least one handler " + PARAM_ENGINE_HANDLER + i);
    try {
        Zimbra.startup();
    } catch (OutOfMemoryError e) {
        Zimbra.halt("out of memory", e);
    } catch (Throwable t) {
        ZimbraLog.soap.fatal("Unable to start servlet", t);
        throw new UnavailableException(t.getMessage());
    }
}
Also used : ServletException(javax.servlet.ServletException) UnavailableException(javax.servlet.UnavailableException)

Example 50 with UnavailableException

use of javax.servlet.UnavailableException in project jetty.project by eclipse.

the class Dump method init.

/* ------------------------------------------------------------ */
@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    if (config.getInitParameter("unavailable") != null && !fixed) {
        fixed = true;
        throw new UnavailableException("Unavailable test", Integer.parseInt(config.getInitParameter("unavailable")));
    }
    _timer = new Timer(true);
}
Also used : Timer(java.util.Timer) 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