Search in sources :

Example 51 with UnavailableException

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

the class BalancerServlet method initBalancers.

private void initBalancers() throws ServletException {
    Set<BalancerMember> members = new HashSet<>();
    for (String balancerName : getBalancerNames()) {
        String memberProxyToParam = BALANCER_MEMBER_PREFIX + balancerName + ".proxyTo";
        String proxyTo = getServletConfig().getInitParameter(memberProxyToParam);
        if (proxyTo == null || proxyTo.trim().length() == 0)
            throw new UnavailableException(memberProxyToParam + " parameter is empty.");
        members.add(new BalancerMember(balancerName, proxyTo));
    }
    _balancerMembers.addAll(members);
}
Also used : UnavailableException(javax.servlet.UnavailableException) HashSet(java.util.HashSet)

Example 52 with UnavailableException

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

the class ServletHolder method doStart.

/* ------------------------------------------------------------ */
public void doStart() throws Exception {
    _unavailable = 0;
    if (!_enabled)
        return;
    // Handle JSP file forced paths
    if (_forcedPath != null) {
        // Look for a precompiled JSP Servlet
        String precompiled = getClassNameForJsp(_forcedPath);
        if (!StringUtil.isBlank(precompiled)) {
            if (LOG.isDebugEnabled())
                LOG.debug("Checking for precompiled servlet {} for jsp {}", precompiled, _forcedPath);
            ServletHolder jsp = getServletHandler().getServlet(precompiled);
            if (jsp != null && jsp.getClassName() != null) {
                if (LOG.isDebugEnabled())
                    LOG.debug("JSP file {} for {} mapped to Servlet {}", _forcedPath, getName(), jsp.getClassName());
                // set the className for this servlet to the precompiled one
                setClassName(jsp.getClassName());
            } else {
                // Look for normal JSP servlet
                jsp = getServletHandler().getServlet("jsp");
                if (jsp != null) {
                    if (LOG.isDebugEnabled())
                        LOG.debug("JSP file {} for {} mapped to JspServlet class {}", _forcedPath, getName(), jsp.getClassName());
                    setClassName(jsp.getClassName());
                    //copy jsp init params that don't exist for this servlet
                    for (Map.Entry<String, String> entry : jsp.getInitParameters().entrySet()) {
                        if (!_initParams.containsKey(entry.getKey()))
                            setInitParameter(entry.getKey(), entry.getValue());
                    }
                    //jsp specific: set up the jsp-file on the JspServlet. If load-on-startup is >=0 and the jsp container supports
                    //precompilation, the jsp will be compiled when this holder is initialized. If not load on startup, or the
                    //container does not support startup precompilation, it will be compiled at runtime when handling a request for this jsp.
                    //See also adaptForcedPathToJspContainer
                    setInitParameter("jspFile", _forcedPath);
                }
            }
        } else
            LOG.warn("Bad jsp-file {} conversion to classname in holder {}", _forcedPath, getName());
    }
    //check servlet has a class (ie is not a preliminary registration). If preliminary, fail startup.
    try {
        super.doStart();
    } catch (UnavailableException ue) {
        makeUnavailable(ue);
        if (_servletHandler.isStartWithUnavailable()) {
            LOG.ignore(ue);
            return;
        } else
            throw ue;
    }
    //servlet is not an instance of javax.servlet.Servlet
    try {
        checkServletType();
    } catch (UnavailableException ue) {
        makeUnavailable(ue);
        if (_servletHandler.isStartWithUnavailable()) {
            LOG.ignore(ue);
            return;
        } else
            throw ue;
    }
    //check if we need to forcibly set load-on-startup
    checkInitOnStartup();
    _identityService = _servletHandler.getIdentityService();
    if (_identityService != null && _runAsRole != null)
        _runAsToken = _identityService.newRunAsToken(_runAsRole);
    _config = new Config();
    if (_class != null && javax.servlet.SingleThreadModel.class.isAssignableFrom(_class))
        _servlet = new SingleThreadedWrapper();
}
Also used : ServletConfig(javax.servlet.ServletConfig) UnavailableException(javax.servlet.UnavailableException) HashMap(java.util.HashMap) Map(java.util.Map) SingleThreadModel(javax.servlet.SingleThreadModel)

Example 53 with UnavailableException

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

the class ServletHolder method makeUnavailable.

/* ------------------------------------------------------------ */
private void makeUnavailable(final Throwable e) {
    if (e instanceof UnavailableException)
        makeUnavailable((UnavailableException) e);
    else {
        ServletContext ctx = _servletHandler.getServletContext();
        if (ctx == null)
            LOG.info("unavailable", e);
        else
            ctx.log("unavailable", e);
        _unavailableEx = new UnavailableException(String.valueOf(e), -1) {

            {
                initCause(e);
            }
        };
        _unavailable = -1;
    }
}
Also used : UnavailableException(javax.servlet.UnavailableException) ServletContext(javax.servlet.ServletContext)

Example 54 with UnavailableException

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

the class Invoker method service.

/* ------------------------------------------------------------ */
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // Get the requested path and info
    boolean included = false;
    String servlet_path = (String) request.getAttribute(Dispatcher.INCLUDE_SERVLET_PATH);
    if (servlet_path == null)
        servlet_path = request.getServletPath();
    else
        included = true;
    String path_info = (String) request.getAttribute(Dispatcher.INCLUDE_PATH_INFO);
    if (path_info == null)
        path_info = request.getPathInfo();
    // Get the servlet class
    String servlet = path_info;
    if (servlet == null || servlet.length() <= 1) {
        response.sendError(404);
        return;
    }
    int i0 = servlet.charAt(0) == '/' ? 1 : 0;
    int i1 = servlet.indexOf('/', i0);
    servlet = i1 < 0 ? servlet.substring(i0) : servlet.substring(i0, i1);
    // look for a named holder
    ServletHolder[] holders = _servletHandler.getServlets();
    ServletHolder holder = getHolder(holders, servlet);
    if (holder != null) {
        // now we add a mapping for it
        if (LOG.isDebugEnabled())
            LOG.debug("Adding servlet mapping for named servlet:" + servlet + ":" + URIUtil.addPaths(servlet_path, servlet) + "/*");
        ServletMapping mapping = new ServletMapping();
        mapping.setServletName(servlet);
        mapping.setPathSpec(URIUtil.addPaths(servlet_path, servlet) + "/*");
        _servletHandler.setServletMappings(ArrayUtil.addToArray(_servletHandler.getServletMappings(), mapping, ServletMapping.class));
    } else {
        // look for a class mapping
        if (servlet.endsWith(".class"))
            servlet = servlet.substring(0, servlet.length() - 6);
        if (servlet == null || servlet.length() == 0) {
            response.sendError(404);
            return;
        }
        synchronized (_servletHandler) {
            // find the entry for the invoker (me)
            _invokerEntry = _servletHandler.getHolderEntry(servlet_path);
            // Check for existing mapping (avoid threaded race).
            String path = URIUtil.addPaths(servlet_path, servlet);
            MappedResource<ServletHolder> entry = _servletHandler.getHolderEntry(path);
            if (entry != null && !entry.equals(_invokerEntry)) {
                // Use the holder
                holder = (ServletHolder) entry.getResource();
            } else {
                // Make a holder
                if (LOG.isDebugEnabled())
                    LOG.debug("Making new servlet=" + servlet + " with path=" + path + "/*");
                holder = _servletHandler.addServletWithMapping(servlet, path + "/*");
                if (_parameters != null)
                    holder.setInitParameters(_parameters);
                try {
                    holder.start();
                } catch (Exception e) {
                    LOG.debug(e);
                    throw new UnavailableException(e.toString());
                }
                // Check it is from an allowable classloader
                if (!_nonContextServlets) {
                    Object s = holder.getServlet();
                    if (_contextHandler.getClassLoader() != s.getClass().getClassLoader()) {
                        try {
                            holder.stop();
                        } catch (Exception e) {
                            LOG.ignore(e);
                        }
                        LOG.warn("Dynamic servlet " + s + " not loaded from context " + request.getContextPath());
                        throw new UnavailableException("Not in context");
                    }
                }
                if (_verbose && LOG.isDebugEnabled())
                    LOG.debug("Dynamic load '" + servlet + "' at " + path);
            }
        }
    }
    if (holder != null) {
        final Request baseRequest = Request.getBaseRequest(request);
        holder.handle(baseRequest, new InvokedRequest(request, included, servlet, servlet_path, path_info), response);
    } else {
        LOG.info("Can't find holder for servlet: " + servlet);
        response.sendError(404);
    }
}
Also used : UnavailableException(javax.servlet.UnavailableException) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException)

Example 55 with UnavailableException

use of javax.servlet.UnavailableException in project sonarqube by SonarSource.

the class ActionServlet method initModulePlugIns.

/**
     * <p>Initialize the plug ins for the specified module.</p>
     *
     * @param config ModuleConfig information for this module
     * @throws ServletException if initialization cannot be performed
     * @since Struts 1.1
     */
protected void initModulePlugIns(ModuleConfig config) throws ServletException {
    if (log.isDebugEnabled()) {
        log.debug("Initializing module path '" + config.getPrefix() + "' plug ins");
    }
    PlugInConfig[] plugInConfigs = config.findPlugInConfigs();
    PlugIn[] plugIns = new PlugIn[plugInConfigs.length];
    getServletContext().setAttribute(Globals.PLUG_INS_KEY + config.getPrefix(), plugIns);
    for (int i = 0; i < plugIns.length; i++) {
        try {
            plugIns[i] = (PlugIn) RequestUtils.applicationInstance(plugInConfigs[i].getClassName());
            BeanUtils.populate(plugIns[i], plugInConfigs[i].getProperties());
            // This plugin config object is needed by Tiles
            try {
                PropertyUtils.setProperty(plugIns[i], "currentPlugInConfigObject", plugInConfigs[i]);
            } catch (Exception e) {
                ;
            // FIXME Whenever we fail silently, we must document a valid
            // reason for doing so.  Why should we fail silently if a
            // property can't be set on the plugin?
            /**
                     * Between version 1.138-1.140 cedric made these changes.
                     * The exceptions are caught to deal with containers
                     * applying strict security. This was in response to bug
                     * #15736
                     *
                     * Recommend that we make the currentPlugInConfigObject part
                     * of the PlugIn Interface if we can, Rob
                     */
            }
            plugIns[i].init(this, config);
        } catch (ServletException e) {
            throw e;
        } catch (Exception e) {
            String errMsg = internal.getMessage("plugIn.init", plugInConfigs[i].getClassName());
            log(errMsg, e);
            throw new UnavailableException(errMsg);
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) PlugInConfig(org.apache.struts.config.PlugInConfig) UnavailableException(javax.servlet.UnavailableException) 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)

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