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);
}
}
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);
}
}
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
}
}
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() + "'");
}
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);
}
}
Aggregations