Search in sources :

Example 66 with UnavailableException

use of javax.servlet.UnavailableException in project lucene-solr by apache.

the class SolrDispatchFilter method doFilter.

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain, boolean retry) throws IOException, ServletException {
    if (!(request instanceof HttpServletRequest))
        return;
    try {
        if (cores == null || cores.isShutDown()) {
            try {
                init.await();
            } catch (InterruptedException e) {
            //well, no wait then
            }
            final String msg = "Error processing the request. CoreContainer is either not initialized or shutting down.";
            if (cores == null || cores.isShutDown()) {
                log.error(msg);
                throw new UnavailableException(msg);
            }
        }
        AtomicReference<ServletRequest> wrappedRequest = new AtomicReference<>();
        if (!authenticateRequest(request, response, wrappedRequest)) {
            // sent
            return;
        }
        if (wrappedRequest.get() != null) {
            request = wrappedRequest.get();
        }
        request = closeShield(request, retry);
        response = closeShield(response, retry);
        if (cores.getAuthenticationPlugin() != null) {
            log.debug("User principal: {}", ((HttpServletRequest) request).getUserPrincipal());
        }
        // No need to even create the HttpSolrCall object if this path is excluded.
        if (excludePatterns != null) {
            String requestPath = ((HttpServletRequest) request).getServletPath();
            String extraPath = ((HttpServletRequest) request).getPathInfo();
            if (extraPath != null) {
                // In embedded mode, servlet path is empty - include all post-context path here for
                // testing
                requestPath += extraPath;
            }
            for (Pattern p : excludePatterns) {
                Matcher matcher = p.matcher(requestPath);
                if (matcher.lookingAt()) {
                    chain.doFilter(request, response);
                    return;
                }
            }
        }
        HttpSolrCall call = getHttpSolrCall((HttpServletRequest) request, (HttpServletResponse) response, retry);
        ExecutorUtil.setServerThreadFlag(Boolean.TRUE);
        try {
            Action result = call.call();
            switch(result) {
                case PASSTHROUGH:
                    chain.doFilter(request, response);
                    break;
                case RETRY:
                    doFilter(request, response, chain, true);
                    break;
                case FORWARD:
                    request.getRequestDispatcher(call.getPath()).forward(request, response);
                    break;
            }
        } finally {
            call.destroy();
            ExecutorUtil.setServerThreadFlag(null);
        }
    } finally {
        consumeInputFully((HttpServletRequest) request);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) UnavailableException(javax.servlet.UnavailableException) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 67 with UnavailableException

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

the class ServletWrapper method service.

/**
     * Call the servlet.
     * @param request The current request.
     * @param response The current response.
     * @throws Exception
     */
public void service(HttpServletRequest request, HttpServletResponse response) throws Exception {
    try {
        if ((available > 0L) && (available < Long.MAX_VALUE)) {
            if (available > System.currentTimeMillis()) {
                response.setDateHeader("Retry-After", available);
                response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Servlet unavailable.");
                logger.error("Java servlet {} is unavailable.", this.sourcePath);
                return;
            }
            // Wait period has expired. Reset.
            available = 0;
        }
        final Servlet servlet = this.getServlet();
        // invoke the servlet
        if (servlet instanceof SingleThreadModel) {
            // of the page is determined right before servicing
            synchronized (this) {
                servlet.service(request, response);
            }
        } else {
            servlet.service(request, response);
        }
    } catch (final UnavailableException ex) {
        int unavailableSeconds = ex.getUnavailableSeconds();
        if (unavailableSeconds <= 0) {
            // Arbitrary default
            unavailableSeconds = 60;
        }
        available = System.currentTimeMillis() + (unavailableSeconds * 1000L);
        response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, ex.getMessage());
        logger.error("Java servlet {} is unavailable.", this.sourcePath);
    }
}
Also used : UnavailableException(javax.servlet.UnavailableException) Servlet(javax.servlet.Servlet) SingleThreadModel(javax.servlet.SingleThreadModel)

Example 68 with UnavailableException

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

the class DefaultServlet method init.

/**
 * Initialize this servlet.
 */
public void init() throws ServletException {
    ServletConfig sc = getServletConfig();
    if (sc.getInitParameter("debug") != null)
        debug = Integer.parseInt(sc.getInitParameter("debug"));
    if (sc.getInitParameter("input") != null)
        input = Integer.parseInt(sc.getInitParameter("input"));
    if (sc.getInitParameter("output") != null)
        output = Integer.parseInt(sc.getInitParameter("output"));
    listings = Boolean.parseBoolean(sc.getInitParameter("listings"));
    String sortedByInitParam = sc.getInitParameter("sortedBy");
    if (sortedByInitParam != null) {
        sortedBy = Enum.valueOf(SortedBy.class, sortedByInitParam);
    }
    if (sc.getInitParameter("readonly") != null)
        readOnly = Boolean.parseBoolean(sc.getInitParameter("readonly"));
    if (sc.getInitParameter("sendfileSize") != null)
        sendfileSize = Integer.parseInt(sc.getInitParameter("sendfileSize")) * 1024;
    if (sc.getInitParameter("maxHeaderRangeItems") != null) {
        maxHeaderRangeItems = Integer.parseInt(sc.getInitParameter("maxHeaderRangeItems"));
    }
    fileEncoding = sc.getInitParameter("fileEncoding");
    globalXsltFile = sc.getInitParameter("globalXsltFile");
    contextXsltFile = sc.getInitParameter("contextXsltFile");
    localXsltFile = sc.getInitParameter("localXsltFile");
    readmeFile = sc.getInitParameter("readmeFile");
    if (sc.getInitParameter("useAcceptRanges") != null)
        useAcceptRanges = Boolean.parseBoolean(sc.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) {
            throw new ServletException("No resources", e);
        } catch (ClassCastException e) {
        // Failed : Not the right type
        }
    }
    if (resources == null) {
        throw new UnavailableException("No resources");
    }
    try {
        alternateDocBases = getAlternateDocBases();
    } catch (ClassCastException e) {
    // Failed : Not the right type
    }
}
Also used : ServletException(javax.servlet.ServletException) ServletConfig(javax.servlet.ServletConfig) UnavailableException(javax.servlet.UnavailableException) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext)

Example 69 with UnavailableException

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

the class InvokerServlet method init.

/**
 * Initialize this servlet.
 */
public synchronized void init() throws ServletException {
    // Ensure that our ContainerServlet properties have been set
    if ((wrapper == null) || (context == null))
        throw new UnavailableException(rb.getString(LogFacade.SET_WRAPPER_NOT_CALLED_EXCEPTION));
    // Set our properties from the initialization parameters
    String value = null;
    try {
        value = getServletConfig().getInitParameter("debug");
        debug = Integer.parseInt(value);
    } catch (Throwable t) {
        ;
    }
    if (debug >= 1)
        log("init: Associated with Context '" + context.getPath() + "'");
}
Also used : UnavailableException(javax.servlet.UnavailableException)

Example 70 with UnavailableException

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

the class StandardWrapper method initServlet.

private synchronized void initServlet(Servlet servlet) throws ServletException {
    if (instanceInitialized && !singleThreadModel)
        return;
    // Call the initialization method of this servlet
    try {
        instanceSupport.fireInstanceEvent(InstanceEvent.BEFORE_INIT_EVENT, servlet);
        if (Globals.IS_SECURITY_ENABLED) {
            boolean success = false;
            try {
                Object[] args = new Object[] { facade };
                SecurityUtil.doAsPrivilege("init", servlet, classType, args);
                success = true;
            } finally {
                if (!success) {
                    // destroy() will not be called, thus clear the reference now
                    SecurityUtil.remove(servlet);
                }
            }
        } else {
            servlet.init(facade);
        }
        instanceInitialized = true;
        instanceSupport.fireInstanceEvent(InstanceEvent.AFTER_INIT_EVENT, servlet);
    } catch (UnavailableException f) {
        instanceSupport.fireInstanceEvent(InstanceEvent.AFTER_INIT_EVENT, servlet, f);
        unavailable(f);
        throw f;
    } catch (ServletException f) {
        instanceSupport.fireInstanceEvent(InstanceEvent.AFTER_INIT_EVENT, servlet, f);
        // said so, so do not call unavailable(null).
        throw f;
    } catch (Throwable f) {
        ExceptionUtils.handleThrowable(f);
        getServletContext().log("StandardWrapper.Throwable", f);
        instanceSupport.fireInstanceEvent(InstanceEvent.AFTER_INIT_EVENT, servlet, f);
        // said so, so do not call unavailable(null).
        throw new ServletException(sm.getString("standardWrapper.initException", 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