private static void addErrorPages(Context context) { for (int errorCode : ERROR_PAGE_STATUSES) { ErrorPage errorPage = new ErrorPage(); errorPage.setErrorCode(errorCode); errorPage.setLocation("/error"); context.addErrorPage(errorPage); } ErrorPage errorPage = new ErrorPage(); errorPage.setExceptionType(Throwable.class.getName()); errorPage.setLocation("/error"); context.addErrorPage(errorPage); }
public void addToContext(Context context) { Assert.state(this.nativePage != null, "No Tomcat 8 detected so no native error page exists"); if (ClassUtils.isPresent(ERROR_PAGE_CLASS, null)) { org.apache.tomcat.util.descriptor.web.ErrorPage errorPage = (org.apache.tomcat.util.descriptor.web.ErrorPage) this.nativePage; errorPage.setLocation(this.location); errorPage.setErrorCode(this.errorCode); errorPage.setExceptionType(this.exceptionType); context.addErrorPage(errorPage); } else { callMethod(this.nativePage, "setLocation", this.location, String.class); callMethod(this.nativePage, "setErrorCode", this.errorCode, int.class); callMethod(this.nativePage, "setExceptionType", this.exceptionType, String.class); callMethod(context, "addErrorPage", this.nativePage, this.nativePage.getClass()); } }
public void remove(ErrorPage errorPage) { String exceptionType = errorPage.getExceptionType(); if (exceptionType == null) { statusPages.remove(Integer.valueOf(errorPage.getErrorCode()), errorPage); } else { exceptionPages.remove(exceptionType, errorPage); } }
if (errorPage.getExceptionType() == null) { appendElement(sb, INDENT4, "error-code", Integer.toString(errorPage.getErrorCode())); } else { appendElement(sb, INDENT4, "exception-type", errorPage.getExceptionType()); appendElement(sb, INDENT4, "location", errorPage.getLocation()); sb.append(" </error-page>\n");
throw new IllegalArgumentException (sm.getString("standardContext.errorPage.required")); String location = errorPage.getLocation(); if ((location != null) && !location.startsWith("/")) { if (isServlet22()) { log.debug(sm.getString("standardContext.errorPage.warning", location)); errorPage.setLocation("/" + location); } else { throw new IllegalArgumentException String exceptionType = errorPage.getExceptionType(); if (exceptionType != null) { synchronized (exceptionPages) { statusPages.put(Integer.valueOf(errorPage.getErrorCode()), errorPage);
/** * Return the context-relative URI of the error page for the specified * HTTP status code, if any; otherwise return <code>null</code>. * * @param status HTTP status code to look up */ @Override public String findStatusPage(int status) { ErrorPage errorPage = statusPages.get(Integer.valueOf(status)); if (errorPage!=null) { return errorPage.getLocation(); } return null; }
/** * Add an error page for the specified error or Java exception. * * @param errorPage The error page definition to be added */ @Override public void addErrorPage(ErrorPage errorPage) { // Validate the input parameters if (errorPage == null) throw new IllegalArgumentException (sm.getString("standardContext.errorPage.required")); String location = errorPage.getLocation(); if ((location != null) && !location.startsWith("/")) { if (isServlet22()) { if(log.isDebugEnabled()) log.debug(sm.getString("standardContext.errorPage.warning", location)); errorPage.setLocation("/" + location); } else { throw new IllegalArgumentException (sm.getString("standardContext.errorPage.error", location)); } } errorPageSupport.add(errorPage); fireContainerEvent("addErrorPage", errorPage); }
/** * Return the error page entry for the specified Java exception type, * if any; otherwise return <code>null</code>. * * @param exceptionType Exception type to look up * @return a string representation of the error page * @throws MBeanException propagated from the managed resource access * @deprecated Unused. Will be removed in Tomcat 10. * Use {@link #findErrorPage(Throwable)} instead. */ @Deprecated public String findErrorPage(String exceptionType) throws MBeanException { Context context = doGetManagedResource(); return context.findErrorPage(exceptionType).toString(); }
public void addErrorPage(ErrorPage errorPage) { errorPages.put(errorPage.getName(), errorPage); } public Map<String,ErrorPage> getErrorPages() { return errorPages; }
public void add(ErrorPage errorPage) { String exceptionType = errorPage.getExceptionType(); if (exceptionType == null) { statusPages.put(Integer.valueOf(errorPage.getErrorCode()), errorPage); } else { exceptionPages.put(exceptionType, errorPage); } }
String exceptionType = errorPage.getExceptionType(); int errorCode = errorPage.getErrorCode(); if (errorPage.getExceptionType() != null) { appendElement(sb, INDENT4, "exception-type", exceptionType); } else if (errorPage.getErrorCode() > 0) { appendElement(sb, INDENT4, "error-code", Integer.toString(errorCode)); appendElement(sb, INDENT4, "location", errorPage.getLocation()); sb.append(" </error-page>\n");
@Override @Deprecated public String findStatusPage(int status) { ErrorPage errorPage = findErrorPage(status); if (errorPage != null) { return errorPage.getLocation(); } return null; }
/** * Add an error page for the specified error or Java exception. * * @param errorPage The error page definition to be added */ @Override public void addErrorPage(ErrorPage errorPage) { // Validate the input parameters if (errorPage == null) throw new IllegalArgumentException (sm.getString("standardContext.errorPage.required")); String location = errorPage.getLocation(); if ((location != null) && !location.startsWith("/")) { if (isServlet22()) { if(log.isDebugEnabled()) log.debug(sm.getString("standardContext.errorPage.warning", location)); errorPage.setLocation("/" + location); } else { throw new IllegalArgumentException (sm.getString("standardContext.errorPage.error", location)); } } errorPageSupport.add(errorPage); fireContainerEvent("addErrorPage", errorPage); }
/** * Return the error page entry for the specified HTTP error code, * if any; otherwise return <code>null</code>. * * @param errorCode Error code to look up * @return a string representation of the error page * @throws MBeanException propagated from the managed resource access */ public String findErrorPage(int errorCode) throws MBeanException { Context context = doGetManagedResource(); return context.findErrorPage(errorCode).toString(); }
public void addErrorPage(ErrorPage errorPage) { errorPages.put(errorPage.getName(), errorPage); } public Map<String,ErrorPage> getErrorPages() { return errorPages; }
public boolean setProperty(String name, String value) { if (name.startsWith("errorCode.")) { int code = Integer.parseInt(name.substring(10)); ErrorPage ep = new ErrorPage(); ep.setErrorCode(code); ep.setLocation(value); errorPageSupport.add(ep); return true; } else if (name.startsWith("exceptionType.")) { String className = name.substring(14); ErrorPage ep = new ErrorPage(); ep.setExceptionType(className); ep.setLocation(value); errorPageSupport.add(ep); return true; } return false; }
public void remove(ErrorPage errorPage) { String exceptionType = errorPage.getExceptionType(); if (exceptionType == null) { statusPages.remove(Integer.valueOf(errorPage.getErrorCode()), errorPage); } else { exceptionPages.remove(exceptionType, errorPage); } }
String exceptionType = errorPage.getExceptionType(); int errorCode = errorPage.getErrorCode(); if (errorPage.getExceptionType() != null) { appendElement(sb, INDENT4, "exception-type", exceptionType); } else if (errorPage.getErrorCode() > 0) { appendElement(sb, INDENT4, "error-code", Integer.toString(errorCode)); appendElement(sb, INDENT4, "location", errorPage.getLocation()); sb.append(" </error-page>\n");
@Override @Deprecated public String findStatusPage(int status) { ErrorPage errorPage = findErrorPage(status); if (errorPage != null) { return errorPage.getLocation(); } return null; }
/** * Return the error page entry for the specified Java exception type, * if any; otherwise return <code>null</code>. * * @param exceptionType Exception type to look up * @return a string representation of the error page * @throws MBeanException propagated from the managed resource access */ public String findErrorPage(Throwable exceptionType) throws MBeanException { Context context = doGetManagedResource(); return context.findErrorPage(exceptionType).toString(); }