Search in sources :

Example 1 with UnavailableException

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

the class BalancerServlet method getBalancerNames.

private Set<String> getBalancerNames() throws ServletException {
    Set<String> names = new HashSet<>();
    for (String initParameterName : Collections.list(getServletConfig().getInitParameterNames())) {
        if (!initParameterName.startsWith(BALANCER_MEMBER_PREFIX))
            continue;
        int endOfNameIndex = initParameterName.lastIndexOf(".");
        if (endOfNameIndex <= BALANCER_MEMBER_PREFIX.length())
            throw new UnavailableException(initParameterName + " parameter does not provide a balancer member name");
        names.add(initParameterName.substring(BALANCER_MEMBER_PREFIX.length(), endOfNameIndex));
    }
    return names;
}
Also used : UnavailableException(javax.servlet.UnavailableException) HashSet(java.util.HashSet)

Example 2 with UnavailableException

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

the class DefaultServlet method init.

/* ------------------------------------------------------------ */
@Override
public void init() throws UnavailableException {
    _servletContext = getServletContext();
    _contextHandler = initContextHandler(_servletContext);
    _mimeTypes = _contextHandler.getMimeTypes();
    _welcomes = _contextHandler.getWelcomeFiles();
    if (_welcomes == null)
        _welcomes = new String[] { "index.html", "index.jsp" };
    _resourceService.setAcceptRanges(getInitBoolean("acceptRanges", _resourceService.isAcceptRanges()));
    _resourceService.setDirAllowed(getInitBoolean("dirAllowed", _resourceService.isDirAllowed()));
    _resourceService.setRedirectWelcome(getInitBoolean("redirectWelcome", _resourceService.isRedirectWelcome()));
    _resourceService.setPrecompressedFormats(parsePrecompressedFormats(getInitParameter("precompressed"), getInitBoolean("gzip", false)));
    _resourceService.setPathInfoOnly(getInitBoolean("pathInfoOnly", _resourceService.isPathInfoOnly()));
    _resourceService.setEtags(getInitBoolean("etags", _resourceService.isEtags()));
    if ("exact".equals(getInitParameter("welcomeServlets"))) {
        _welcomeExactServlets = true;
        _welcomeServlets = false;
    } else
        _welcomeServlets = getInitBoolean("welcomeServlets", _welcomeServlets);
    _useFileMappedBuffer = getInitBoolean("useFileMappedBuffer", _useFileMappedBuffer);
    _relativeResourceBase = getInitParameter("relativeResourceBase");
    String rb = getInitParameter("resourceBase");
    if (rb != null) {
        if (_relativeResourceBase != null)
            throw new UnavailableException("resourceBase & relativeResourceBase");
        try {
            _resourceBase = _contextHandler.newResource(rb);
        } catch (Exception e) {
            LOG.warn(Log.EXCEPTION, e);
            throw new UnavailableException(e.toString());
        }
    }
    String css = getInitParameter("stylesheet");
    try {
        if (css != null) {
            _stylesheet = Resource.newResource(css);
            if (!_stylesheet.exists()) {
                LOG.warn("!" + css);
                _stylesheet = null;
            }
        }
        if (_stylesheet == null) {
            _stylesheet = Resource.newResource(this.getClass().getResource("/jetty-dir.css"));
        }
    } catch (Exception e) {
        LOG.warn(e.toString());
        LOG.debug(e);
    }
    int encodingHeaderCacheSize = getInitInt("encodingHeaderCacheSize", -1);
    if (encodingHeaderCacheSize >= 0)
        _resourceService.setEncodingCacheSize(encodingHeaderCacheSize);
    String cc = getInitParameter("cacheControl");
    if (cc != null)
        _resourceService.setCacheControl(new PreEncodedHttpField(HttpHeader.CACHE_CONTROL, cc));
    String resourceCache = getInitParameter("resourceCache");
    int max_cache_size = getInitInt("maxCacheSize", -2);
    int max_cached_file_size = getInitInt("maxCachedFileSize", -2);
    int max_cached_files = getInitInt("maxCachedFiles", -2);
    if (resourceCache != null) {
        if (max_cache_size != -1 || max_cached_file_size != -2 || max_cached_files != -2)
            LOG.debug("ignoring resource cache configuration, using resourceCache attribute");
        if (_relativeResourceBase != null || _resourceBase != null)
            throw new UnavailableException("resourceCache specified with resource bases");
        _cache = (CachedContentFactory) _servletContext.getAttribute(resourceCache);
    }
    try {
        if (_cache == null && (max_cached_files != -2 || max_cache_size != -2 || max_cached_file_size != -2)) {
            _cache = new CachedContentFactory(null, this, _mimeTypes, _useFileMappedBuffer, _resourceService.isEtags(), _resourceService.getPrecompressedFormats());
            if (max_cache_size >= 0)
                _cache.setMaxCacheSize(max_cache_size);
            if (max_cached_file_size >= -1)
                _cache.setMaxCachedFileSize(max_cached_file_size);
            if (max_cached_files >= -1)
                _cache.setMaxCachedFiles(max_cached_files);
            _servletContext.setAttribute(resourceCache == null ? "resourceCache" : resourceCache, _cache);
        }
    } catch (Exception e) {
        LOG.warn(Log.EXCEPTION, e);
        throw new UnavailableException(e.toString());
    }
    HttpContent.ContentFactory contentFactory = _cache;
    if (contentFactory == null) {
        contentFactory = new ResourceContentFactory(this, _mimeTypes, _resourceService.getPrecompressedFormats());
        if (resourceCache != null)
            _servletContext.setAttribute(resourceCache, contentFactory);
    }
    _resourceService.setContentFactory(contentFactory);
    _resourceService.setWelcomeFactory(this);
    List<String> gzip_equivalent_file_extensions = new ArrayList<String>();
    String otherGzipExtensions = getInitParameter("otherGzipFileExtensions");
    if (otherGzipExtensions != null) {
        //comma separated list
        StringTokenizer tok = new StringTokenizer(otherGzipExtensions, ",", false);
        while (tok.hasMoreTokens()) {
            String s = tok.nextToken().trim();
            gzip_equivalent_file_extensions.add((s.charAt(0) == '.' ? s : "." + s));
        }
    } else {
        //.svgz files are gzipped svg files and must be served with Content-Encoding:gzip
        gzip_equivalent_file_extensions.add(".svgz");
    }
    _resourceService.setGzipEquivalentFileExtensions(gzip_equivalent_file_extensions);
    _servletHandler = _contextHandler.getChildHandlerByClass(ServletHandler.class);
    for (ServletHolder h : _servletHandler.getServlets()) if (h.getServletInstance() == this)
        _defaultHolder = h;
    if (LOG.isDebugEnabled())
        LOG.debug("resource base = " + _resourceBase);
}
Also used : CachedContentFactory(org.eclipse.jetty.server.CachedContentFactory) UnavailableException(javax.servlet.UnavailableException) ArrayList(java.util.ArrayList) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException) StringTokenizer(java.util.StringTokenizer) ResourceContentFactory(org.eclipse.jetty.server.ResourceContentFactory) PreEncodedHttpField(org.eclipse.jetty.http.PreEncodedHttpField) HttpContent(org.eclipse.jetty.http.HttpContent)

Example 3 with UnavailableException

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

the class ServletHolder method initServlet.

/* ------------------------------------------------------------ */
private void initServlet() throws ServletException {
    Object old_run_as = null;
    try {
        if (_servlet == null)
            _servlet = newInstance();
        if (_config == null)
            _config = new Config();
        // Handle run as
        if (_identityService != null) {
            old_run_as = _identityService.setRunAs(_identityService.getSystemUserIdentity(), _runAsToken);
        }
        // Handle configuring servlets that implement org.apache.jasper.servlet.JspServlet
        if (isJspServlet()) {
            initJspServlet();
            detectJspContainer();
        } else if (_forcedPath != null)
            detectJspContainer();
        initMultiPart();
        if (LOG.isDebugEnabled())
            LOG.debug("Servlet.init {} for {}", _servlet, getName());
        _servlet.init(_config);
    } catch (UnavailableException e) {
        makeUnavailable(e);
        _servlet = null;
        _config = null;
        throw e;
    } catch (ServletException e) {
        makeUnavailable(e.getCause() == null ? e : e.getCause());
        _servlet = null;
        _config = null;
        throw e;
    } catch (Exception e) {
        makeUnavailable(e);
        _servlet = null;
        _config = null;
        throw new ServletException(this.toString(), e);
    } finally {
        // pop run-as role
        if (_identityService != null)
            _identityService.unsetRunAs(old_run_as);
    }
}
Also used : ServletException(javax.servlet.ServletException) ServletConfig(javax.servlet.ServletConfig) UnavailableException(javax.servlet.UnavailableException) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException)

Example 4 with UnavailableException

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

the class ServletHolder method handle.

/* ------------------------------------------------------------ */
/**
     * Service a request with this servlet.
     *
     * @param baseRequest the base request
     * @param request the request
     * @param response the response
     * @throws ServletException if unable to process the servlet
     * @throws UnavailableException if servlet is unavailable
     * @throws IOException if unable to process the request or response
     */
public void handle(Request baseRequest, ServletRequest request, ServletResponse response) throws ServletException, UnavailableException, IOException {
    if (_class == null)
        throw new UnavailableException("Servlet Not Initialized");
    Servlet servlet = ensureInstance();
    // Service the request
    Object old_run_as = null;
    boolean suspendable = baseRequest.isAsyncSupported();
    try {
        // Handle aliased path
        if (_forcedPath != null)
            adaptForcedPathToJspContainer(request);
        // Handle run as
        if (_identityService != null)
            old_run_as = _identityService.setRunAs(baseRequest.getResolvedUserIdentity(), _runAsToken);
        if (baseRequest.isAsyncSupported() && !isAsyncSupported()) {
            try {
                baseRequest.setAsyncSupported(false, this.toString());
                servlet.service(request, response);
            } finally {
                baseRequest.setAsyncSupported(true, null);
            }
        } else
            servlet.service(request, response);
    } catch (UnavailableException e) {
        makeUnavailable(e);
        throw _unavailableEx;
    } finally {
        // Pop run-as role.
        if (_identityService != null)
            _identityService.unsetRunAs(old_run_as);
    }
}
Also used : UnavailableException(javax.servlet.UnavailableException) Servlet(javax.servlet.Servlet) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject)

Example 5 with UnavailableException

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

the class PutFilter method init.

/* ------------------------------------------------------------ */
public void init(FilterConfig config) throws ServletException {
    _context = config.getServletContext();
    _tmpdir = (File) _context.getAttribute("javax.servlet.context.tempdir");
    if (_context.getRealPath("/") == null)
        throw new UnavailableException("Packed war");
    String b = config.getInitParameter("baseURI");
    if (b != null) {
        _baseURI = b;
    } else {
        File base = new File(_context.getRealPath("/"));
        _baseURI = base.toURI().toString();
    }
    _delAllowed = getInitBoolean(config, "delAllowed");
    _putAtomic = getInitBoolean(config, "putAtomic");
    _operations.add(__OPTIONS);
    _operations.add(__PUT);
    if (_delAllowed) {
        _operations.add(__DELETE);
        _operations.add(__MOVE);
    }
}
Also used : UnavailableException(javax.servlet.UnavailableException) File(java.io.File)

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