use of javax.servlet.UnavailableException in project tomcat70 by apache.
the class StandardWrapperValve method event.
/**
* Process a Comet event. The main differences here are to not use sendError
* (the response is committed), to avoid creating a new filter chain
* (which would work but be pointless), and a few very minor tweaks.
*
* @param request The servlet request to be processed
* @param response The servlet response to be created
*
* @exception IOException if an input/output error occurs, or is thrown
* by a subsequently invoked Valve, Filter, or Servlet
* @exception ServletException if a servlet error occurs, or is thrown
* by a subsequently invoked Valve, Filter, or Servlet
*/
@Override
public void event(Request request, Response response, CometEvent event) throws IOException, ServletException {
// Initialize local variables we may need
Throwable throwable = null;
// This should be a Request attribute...
long t1 = System.currentTimeMillis();
// FIXME: Add a flag to count the total amount of events processed ? requestCount++;
StandardWrapper wrapper = (StandardWrapper) getContainer();
if (wrapper == null) {
// Context has been shutdown. Nothing to do here.
return;
}
Servlet servlet = null;
Context context = (Context) wrapper.getParent();
// Check for the application being marked unavailable
boolean unavailable = !context.getState().isAvailable() || wrapper.isUnavailable();
// Allocate a servlet instance to process this request
try {
if (!unavailable) {
servlet = wrapper.allocate();
}
} catch (UnavailableException e) {
// The response is already committed, so it's not possible to do anything
} catch (ServletException e) {
container.getLogger().error(sm.getString("standardWrapper.allocateException", wrapper.getName()), StandardWrapper.getRootCause(e));
throwable = e;
exception(request, response, e);
} catch (Throwable e) {
ExceptionUtils.handleThrowable(e);
container.getLogger().error(sm.getString("standardWrapper.allocateException", wrapper.getName()), e);
throwable = e;
exception(request, response, e);
servlet = null;
}
MessageBytes requestPathMB = request.getRequestPathMB();
request.setAttribute(Globals.DISPATCHER_TYPE_ATTR, DispatcherType.REQUEST);
request.setAttribute(Globals.DISPATCHER_REQUEST_PATH_ATTR, requestPathMB);
// Get the current (unchanged) filter chain for this request
ApplicationFilterChain filterChain = (ApplicationFilterChain) request.getFilterChain();
// NOTE: This also calls the servlet's event() method
try {
if ((servlet != null) && (filterChain != null)) {
// Swallow output if needed
if (context.getSwallowOutput()) {
try {
SystemLogHandler.startCapture();
filterChain.doFilterEvent(request.getEvent());
} finally {
String log = SystemLogHandler.stopCapture();
if (log != null && log.length() > 0) {
context.getLogger().info(log);
}
}
} else {
filterChain.doFilterEvent(request.getEvent());
}
}
} catch (ClientAbortException e) {
throwable = e;
exception(request, response, e);
} catch (IOException e) {
container.getLogger().error(sm.getString("standardWrapper.serviceException", wrapper.getName(), context.getName()), e);
throwable = e;
exception(request, response, e);
} catch (UnavailableException e) {
container.getLogger().error(sm.getString("standardWrapper.serviceException", wrapper.getName(), context.getName()), e);
// Do not save exception in 'throwable', because we
// do not want to do exception(request, response, e) processing
} catch (ServletException e) {
Throwable rootCause = StandardWrapper.getRootCause(e);
if (!(rootCause instanceof ClientAbortException)) {
container.getLogger().error(sm.getString("standardWrapper.serviceExceptionRoot", wrapper.getName(), context.getName(), e.getMessage()), rootCause);
}
throwable = e;
exception(request, response, e);
} catch (Throwable e) {
ExceptionUtils.handleThrowable(e);
container.getLogger().error(sm.getString("standardWrapper.serviceException", wrapper.getName(), context.getName()), e);
throwable = e;
exception(request, response, e);
}
// Release the filter chain (if any) for this request
if (filterChain != null) {
filterChain.reuse();
}
// Deallocate the allocated servlet instance
try {
if (servlet != null) {
wrapper.deallocate(servlet);
}
} catch (Throwable e) {
ExceptionUtils.handleThrowable(e);
container.getLogger().error(sm.getString("standardWrapper.deallocateException", wrapper.getName()), e);
if (throwable == null) {
throwable = e;
exception(request, response, e);
}
}
// unload it and release this instance
try {
if ((servlet != null) && (wrapper.getAvailable() == Long.MAX_VALUE)) {
wrapper.unload();
}
} catch (Throwable e) {
ExceptionUtils.handleThrowable(e);
container.getLogger().error(sm.getString("standardWrapper.unloadException", wrapper.getName()), e);
if (throwable == null) {
throwable = e;
exception(request, response, e);
}
}
long t2 = System.currentTimeMillis();
long time = t2 - t1;
processingTime += time;
if (time > maxTime)
maxTime = time;
if (time < minTime)
minTime = time;
}
use of javax.servlet.UnavailableException in project tomcat70 by apache.
the class DefaultServlet method init.
/**
* Initialize this servlet.
*/
@Override
public void init() throws ServletException {
if (getServletConfig().getInitParameter("debug") != null)
debug = Integer.parseInt(getServletConfig().getInitParameter("debug"));
if (getServletConfig().getInitParameter("input") != null)
input = Integer.parseInt(getServletConfig().getInitParameter("input"));
if (getServletConfig().getInitParameter("output") != null)
output = Integer.parseInt(getServletConfig().getInitParameter("output"));
listings = Boolean.parseBoolean(getServletConfig().getInitParameter("listings"));
if (getServletConfig().getInitParameter("readonly") != null)
readOnly = Boolean.parseBoolean(getServletConfig().getInitParameter("readonly"));
if (getServletConfig().getInitParameter("sendfileSize") != null)
sendfileSize = Integer.parseInt(getServletConfig().getInitParameter("sendfileSize")) * 1024;
fileEncoding = getServletConfig().getInitParameter("fileEncoding");
globalXsltFile = getServletConfig().getInitParameter("globalXsltFile");
contextXsltFile = getServletConfig().getInitParameter("contextXsltFile");
localXsltFile = getServletConfig().getInitParameter("localXsltFile");
readmeFile = getServletConfig().getInitParameter("readmeFile");
if (getServletConfig().getInitParameter("useAcceptRanges") != null)
useAcceptRanges = Boolean.parseBoolean(getServletConfig().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) {
// Failed
throw new ServletException("No resources", e);
}
}
if (resources == null) {
throw new UnavailableException("No resources");
}
if (getServletConfig().getInitParameter("showServerInfo") != null) {
showServerInfo = Boolean.parseBoolean(getServletConfig().getInitParameter("showServerInfo"));
}
}
use of javax.servlet.UnavailableException in project tomee by apache.
the class DefaultServlet method init.
/**
* Initialize this servlet.
*/
@Override
public void init() throws ServletException {
if (getServletConfig().getInitParameter("debug") != null) {
debug = Integer.parseInt(getServletConfig().getInitParameter("debug"));
}
if (getServletConfig().getInitParameter("input") != null) {
input = Integer.parseInt(getServletConfig().getInitParameter("input"));
}
if (getServletConfig().getInitParameter("output") != null) {
output = Integer.parseInt(getServletConfig().getInitParameter("output"));
}
listings = Boolean.parseBoolean(getServletConfig().getInitParameter("listings"));
if (getServletConfig().getInitParameter("readonly") != null) {
readOnly = Boolean.parseBoolean(getServletConfig().getInitParameter("readonly"));
}
compressionFormats = parseCompressionFormats(getServletConfig().getInitParameter("precompressed"), getServletConfig().getInitParameter("gzip"));
if (getServletConfig().getInitParameter("sendfileSize") != null) {
sendfileSize = Integer.parseInt(getServletConfig().getInitParameter("sendfileSize")) * 1024;
}
fileEncoding = getServletConfig().getInitParameter("fileEncoding");
if (fileEncoding == null) {
fileEncodingCharset = Charset.defaultCharset();
fileEncoding = fileEncodingCharset.name();
} else {
try {
fileEncodingCharset = B2CConverter.getCharset(fileEncoding);
} catch (UnsupportedEncodingException e) {
throw new ServletException(e);
}
}
final String useBomIfPresentConfig = getServletConfig().getInitParameter("useBomIfPresent");
if (useBomIfPresentConfig != null) {
if (!Arrays.asList("true", "false", "pass-through").contains(useBomIfPresentConfig)) {
if (debug > 0) {
log("DefaultServlet.init: unsupported value " + useBomIfPresentConfig + " for useBomIfPresent." + " One of 'true', 'false', 'pass-through' is expected. Using 'true' by default.");
}
}
useBomIfPresent = useBomIfPresentConfig;
}
globalXsltFile = getServletConfig().getInitParameter("globalXsltFile");
contextXsltFile = getServletConfig().getInitParameter("contextXsltFile");
localXsltFile = getServletConfig().getInitParameter("localXsltFile");
readmeFile = getServletConfig().getInitParameter("readmeFile");
if (getServletConfig().getInitParameter("useAcceptRanges") != null) {
useAcceptRanges = Boolean.parseBoolean(getServletConfig().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 web resources
resources = (WebResourceRoot) getServletContext().getAttribute(Globals.RESOURCES_ATTR);
if (resources == null) {
throw new UnavailableException(sm.getString("defaultServlet.noResources"));
}
if (getServletConfig().getInitParameter("showServerInfo") != null) {
showServerInfo = Boolean.parseBoolean(getServletConfig().getInitParameter("showServerInfo"));
}
if (getServletConfig().getInitParameter("sortListings") != null) {
sortListings = Boolean.parseBoolean(getServletConfig().getInitParameter("sortListings"));
if (sortListings) {
boolean sortDirectoriesFirst;
if (getServletConfig().getInitParameter("sortDirectoriesFirst") != null) {
sortDirectoriesFirst = Boolean.parseBoolean(getServletConfig().getInitParameter("sortDirectoriesFirst"));
} else {
sortDirectoriesFirst = false;
}
sortManager = new SortManager(sortDirectoriesFirst);
}
}
if (getServletConfig().getInitParameter("allowPartialPut") != null) {
allowPartialPut = Boolean.parseBoolean(getServletConfig().getInitParameter("allowPartialPut"));
}
}
use of javax.servlet.UnavailableException in project zm-mailbox by Zimbra.
the class SoapServlet method init.
@Override
public void init() throws ServletException {
LogFactory.init();
String name = getServletName();
ZimbraLog.soap.info("Servlet " + name + " starting up");
super.init();
mEngine = new SoapEngine();
int i = 0;
String cname;
while ((cname = getInitParameter(PARAM_ENGINE_HANDLER + i)) != null) {
loadHandler(cname);
i++;
}
// See if any extra services were previously added by extensions
synchronized (sExtraServices) {
List<DocumentService> services = LoadingCacheUtil.get(sExtraServices, getServletName());
for (DocumentService service : services) {
addService(service);
i++;
}
}
mEngine.getDocumentDispatcher().clearSoapWhiteList();
if (i == 0)
throw new ServletException("Must specify at least one handler " + PARAM_ENGINE_HANDLER + i);
try {
Zimbra.startup();
} catch (OutOfMemoryError e) {
Zimbra.halt("out of memory", e);
} catch (Throwable t) {
ZimbraLog.soap.fatal("Unable to start servlet", t);
throw new UnavailableException(t.getMessage());
}
}
use of javax.servlet.UnavailableException in project jetty.project by eclipse.
the class Dump method init.
/* ------------------------------------------------------------ */
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
if (config.getInitParameter("unavailable") != null && !fixed) {
fixed = true;
throw new UnavailableException("Unavailable test", Integer.parseInt(config.getInitParameter("unavailable")));
}
_timer = new Timer(true);
}
Aggregations