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()); } }
TomcatErrorPage(ErrorPage errorPage) { this.location = errorPage.getPath(); this.exceptionType = errorPage.getExceptionName(); this.errorCode = errorPage.getStatusCode(); this.nativePage = createNativePage(); }
new TomcatErrorPage(errorPage).addToContext(context);