List of usage examples for javax.servlet UnavailableException getUnavailableSeconds
public int getUnavailableSeconds()
From source file:org.apache.catalina.core.StandardWrapper.java
/** * Process an UnavailableException, marking this servlet as unavailable * for the specified amount of time./*from w w w . ja v a 2 s . com*/ * * @param unavailable The exception that occurred, or <code>null</code> * to mark this servlet as permanently unavailable */ public void unavailable(UnavailableException unavailable) { getServletContext().log(sm.getString("standardWrapper.unavailable", getName())); if (unavailable == null) setAvailable(Long.MAX_VALUE); else if (unavailable.isPermanent()) setAvailable(Long.MAX_VALUE); else { int unavailableSeconds = unavailable.getUnavailableSeconds(); if (unavailableSeconds <= 0) unavailableSeconds = 60; // Arbitrary default setAvailable(System.currentTimeMillis() + (unavailableSeconds * 1000L)); } }
From source file:org.apache.jasper.servlet.JspServletWrapper.java
public void service(HttpServletRequest request, HttpServletResponse response, boolean precompile) throws ServletException, IOException, FileNotFoundException { try {//www . ja v a2 s. com if (ctxt.isRemoved()) { throw new FileNotFoundException(jspUri); } if ((available > 0L) && (available < Long.MAX_VALUE)) { response.setDateHeader("Retry-After", available); response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, Localizer.getMessage("jsp.error.unavailable")); } if (options.getDevelopment() || firstTime) { synchronized (this) { ctxt.compile(); } } if (reload) { getServlet(); } // If a page is to only to be precompiled return. if (precompile) { return; } if (theServlet instanceof SingleThreadModel) { // sync on the wrapper so that the freshness // of the page is determined right before servicing synchronized (this) { theServlet.service(request, response); } } else { theServlet.service(request, response); } } catch (UnavailableException ex) { String includeRequestUri = (String) request.getAttribute("javax.servlet.include.request_uri"); if (includeRequestUri != null) { // This file was included. Throw an exception as // a response.sendError() will be ignored by the // servlet engine. throw ex; } else { int unavailableSeconds = ex.getUnavailableSeconds(); if (unavailableSeconds <= 0) { unavailableSeconds = 60; // Arbitrary default } available = System.currentTimeMillis() + (unavailableSeconds * 1000L); response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, ex.getMessage()); } } catch (FileNotFoundException ex) { String includeRequestUri = (String) request.getAttribute("javax.servlet.include.request_uri"); if (includeRequestUri != null) { // This file was included. Throw an exception as // a response.sendError() will be ignored by the // servlet engine. throw new ServletException(ex); } else { try { response.sendError(HttpServletResponse.SC_NOT_FOUND, ex.getMessage()); } catch (IllegalStateException ise) { log.error(Localizer.getMessage("jsp.error.file.not.found", ex.getMessage()), ex); } } } catch (ServletException ex) { throw ex; } catch (IOException ex) { throw ex; } catch (IllegalStateException ex) { throw ex; } catch (Exception ex) { throw new JasperException(ex); } }
From source file:org.ireland.jnetty.webapp.ErrorPageManager.java
public void sendServletErrorImpl(Throwable e, ServletRequest req, ServletResponse res) throws IOException { HttpServletResponse response = (HttpServletResponse) res; HttpServletRequest request = (HttpServletRequest) req; Throwable rootExn = e;/*from w w w . ja v a 2s. c o m*/ Throwable errorPageExn = null; LineMap lineMap = null; try { response.reset(); } catch (IllegalStateException e1) { } if (req.isAsyncStarted()) { AsyncContext async = req.getAsyncContext(); if (async != null) async.complete(); } if (response instanceof HttpServletResponseImpl) { HttpServletResponseImpl resFacade = (HttpServletResponseImpl) response; resFacade.killCache(); resFacade.setNoCache(true); } if (rootExn instanceof ClientDisconnectException) throw (ClientDisconnectException) rootExn; String location = null; String title = "500 Servlet Exception"; boolean isBadRequest = false; boolean doStackTrace = true; boolean isCompileException = false; boolean isServletException = false; Throwable compileException = null; String lineMessage = null; boolean lookupErrorPage = true; while (true) { if (rootExn instanceof LineMapException) lineMap = ((LineMapException) rootExn).getLineMap(); if (lookupErrorPage) { errorPageExn = rootExn; } if (rootExn instanceof DisplayableException) { doStackTrace = false; isCompileException = true; if (compileException == null) compileException = rootExn; } else if (rootExn instanceof CompileException) { doStackTrace = false; isCompileException = true; if (compileException == null) // ! isLineCompileException) compileException = rootExn; } else if (rootExn instanceof LineException) { if (lineMessage == null) lineMessage = rootExn.getMessage(); } if (rootExn instanceof BadRequestException) { isBadRequest = true; } if (rootExn instanceof OutOfMemoryError) { String msg = "TcpSocketLink OutOfMemory"; ShutdownSystem.shutdownOutOfMemory(msg); } if (location != null || !lookupErrorPage) { } else if (rootExn instanceof LineMapException && rootExn instanceof ServletException && !(rootExn instanceof LineCompileException) && rootExn.getCause() != null) { // hack to deal with JSP wrapping } else if (!isServletException) { // SRV.9.9.2 Servlet 2.4 // location = getErrorPage(rootExn, ServletException.class); location = getErrorPage(rootExn); isServletException = true; } else { location = getErrorPage(rootExn); lookupErrorPage = false; } if (location != null) lookupErrorPage = false; if (isBadRequest) break; Throwable cause = null; if (rootExn instanceof ServletException && !(rootExn instanceof LineCompileException)) cause = ((ServletException) rootExn).getRootCause(); else { lookupErrorPage = false; cause = rootExn.getCause(); } if (cause != null) rootExn = cause; else { break; } } if (location == null && lookupErrorPage) { location = getErrorPage(rootExn); } if (location == null) location = getErrorPage(500); if (isBadRequest) { // server/05a0, server/0532 if (rootExn instanceof CompileException) title = rootExn.getMessage(); else title = String.valueOf(rootExn); doStackTrace = false; isBadRequest = true; if (request instanceof CauchoRequest) ((CauchoRequest) request).killKeepalive("bad request: " + rootExn); response.resetBuffer(); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); /* * if (location == null) log.warn(e.toString()); */ } else if (rootExn instanceof UnavailableException) { UnavailableException unAvail = (UnavailableException) rootExn; if (unAvail.isPermanent()) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); title = "404 Not Found"; if (location == null) location = getErrorPage(HttpServletResponse.SC_NOT_FOUND); } else { response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); title = "503 Unavailable"; if (unAvail.getUnavailableSeconds() > 0) response.setIntHeader("Retry-After", unAvail.getUnavailableSeconds()); if (location == null) location = getErrorPage(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } } else { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } if (location == null) location = _defaultLocation; if (log.isTraceEnabled()) log.trace(e.toString(), e); else if (isCompileException) { if (isBadRequest) log.trace(BadRequestException.class.getSimpleName() + ": " + compileException.getMessage()); else log.trace(compileException.getMessage()); } else if (!doStackTrace) log.trace(rootExn.toString()); else log.trace(e.toString(), e); if (location != null) { if (errorPageExn == null) errorPageExn = rootExn; request.setAttribute(JSP_EXCEPTION, errorPageExn); request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, errorPageExn); request.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE, errorPageExn.getClass()); if (request instanceof HttpServletRequest) request.setAttribute(RequestDispatcher.ERROR_REQUEST_URI, ((HttpServletRequest) request).getRequestURI()); String servletName = getServletName(request); if (servletName != null) request.setAttribute(RequestDispatcher.ERROR_SERVLET_NAME, servletName); request.setAttribute(RequestDispatcher.ERROR_STATUS_CODE, new Integer(500)); request.setAttribute(RequestDispatcher.ERROR_MESSAGE, errorPageExn.getMessage()); try { RequestDispatcher disp = null; // can't use filters because of error pages due to filters // or security. WebApp webApp = getWebApp(); if (webApp != null) disp = webApp.getRequestDispatcher(location); else if (_host != null) disp = _host.getWebAppContainer().getRequestDispatcher(location); if (disp != null) { ((RequestDispatcherImpl) disp).error(request, response); return; } } catch (Throwable e1) { log.info(e1.toString(), e1); rootExn = e1; } } response.setContentType("text/html"); String encoding = CharacterEncoding.getLocalEncoding(); if (encoding != null) response.setCharacterEncoding(encoding); else { Locale locale = Locale.getDefault(); if (!"ISO-8859-1".equals(Encoding.getMimeName(locale))) response.setLocale(Locale.getDefault()); else response.setCharacterEncoding("utf-8"); } PrintWriter out; try { out = response.getWriter(); } catch (IllegalStateException e1) { log.trace(e1.toString(), e1); out = new PrintWriter(new OutputStreamWriter(response.getOutputStream())); } if (isDevelopmentModeErrorPage()) { out.println("<html>"); if (!response.isCommitted()) out.println("<head><title>" + escapeHtml(title) + "</title></head>"); out.println("<body>"); out.println("<h1>" + escapeHtml(title) + "</h1>"); out.println("<code><pre>"); if (debug && !CurrentTime.isTest()) doStackTrace = true; if (doStackTrace) { out.println("<script language='javascript' type='text/javascript'>"); out.println("function show() { document.getElementById('trace').style.display = ''; }"); out.println("</script>"); out.print("<a style=\"text-decoration\" href=\"javascript:show();\">[show]</a> "); } if (compileException instanceof DisplayableException) { // ioc/0000 // XXX: dispExn.print doesn't normalize user.name // dispExn.print(out); out.println(escapeHtml(compileException.getMessage())); } else if (compileException != null) out.println(escapeHtml(compileException.getMessage())); else out.println(escapeHtml(rootExn.toString())); if (doStackTrace) { out.println("<span id=\"trace\" style=\"display:none\">"); printStackTrace(out, lineMessage, e, rootExn, lineMap); out.println("</span>"); } /* * if (doStackTrace || debug) { printStackTrace(out, lineMessage, e, rootExn, lineMap); } */ out.println("</pre></code>"); printVersion(out); out.println("</body></html>"); } else { // non-development mode out.println("<html>"); out.println("<title>Server Error</title>"); out.println("<body>"); out.println("<h1>Server Error</h1>"); out.println("<p>The server is temporarily unavailable due to an"); out.println("internal error. Please notify the system administrator"); out.println("of this problem.</p>"); out.println("<pre><code>"); out.println("Date: " + QDate.formatISO8601(CurrentTime.getCurrentTime())); out.println("</code></pre>"); printVersion(out); out.println("</body></html>"); } String userAgent = request.getHeader("User-Agent"); if (userAgent != null && userAgent.indexOf("MSIE") >= 0) { out.print(MSIE_PADDING); } out.close(); }
From source file:org.tinygroup.jspengine.servlet.JspServletWrapper.java
public void service(HttpServletRequest request, HttpServletResponse response, boolean precompile) throws ServletException, IOException { try {/*from w w w . j a v a 2 s . com*/ if (ctxt.isRemoved()) { jspFileNotFound(request, response); return; } if ((available > 0L) && (available < Long.MAX_VALUE)) { response.setDateHeader("Retry-After", available); response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, Localizer.getMessage("jsp.error.unavailable")); } /* * (1) Compile */ // BEGIN S1AS 6181923 // if (options.getDevelopment() || firstTime) { // END S1AS 6181923 // BEGIN S1AS 6181923 if (!options.getUsePrecompiled() && (options.getDevelopment() || firstTime)) { // END S1AS 6181923 synchronized (this) { firstTime = false; // The following sets reload to true, if necessary ctxt.compile(); } } else { if (compileException != null) { // Throw cached compilation exception throw compileException; } } /* * (2) (Re)load servlet class file */ getServlet(); // If a page is to be precompiled only, return. if (precompile) { return; } /* * (3) Service request */ if (theServlet instanceof SingleThreadModel) { // sync on the wrapper so that the freshness // of the page is determined right before servicing synchronized (this) { theServlet.service(request, response); } } else { theServlet.service(request, response); } } catch (UnavailableException ex) { String includeRequestUri = (String) request.getAttribute("javax.servlet.include.request_uri"); if (includeRequestUri != null) { // This file was included. Throw an exception as // a response.sendError() will be ignored by the // servlet engine. throw ex; } else { int unavailableSeconds = ex.getUnavailableSeconds(); if (unavailableSeconds <= 0) { unavailableSeconds = 60; // Arbitrary default } available = System.currentTimeMillis() + (unavailableSeconds * 1000L); response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, ex.getMessage()); } } catch (ServletException ex) { throw ex; } catch (IOException ex) { throw ex; } catch (IllegalStateException ex) { throw ex; } catch (Exception ex) { throw new JasperException(ex); } }