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;
}
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);
}
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);
}
}
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);
}
}
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);
}
}
Aggregations