use of org.springframework.boot.web.server.ErrorPage in project spring-boot by spring-projects.
the class TomcatServletWebServerFactory method configureContext.
/**
* Configure the Tomcat {@link Context}.
* @param context the Tomcat context
* @param initializers initializers to apply
*/
protected void configureContext(Context context, ServletContextInitializer[] initializers) {
TomcatStarter starter = new TomcatStarter(initializers);
if (context instanceof TomcatEmbeddedContext) {
TomcatEmbeddedContext embeddedContext = (TomcatEmbeddedContext) context;
embeddedContext.setStarter(starter);
embeddedContext.setFailCtxIfServletStartFails(true);
}
context.addServletContainerInitializer(starter, NO_CLASSES);
for (LifecycleListener lifecycleListener : this.contextLifecycleListeners) {
context.addLifecycleListener(lifecycleListener);
}
for (Valve valve : this.contextValves) {
context.getPipeline().addValve(valve);
}
for (ErrorPage errorPage : getErrorPages()) {
org.apache.tomcat.util.descriptor.web.ErrorPage tomcatErrorPage = new org.apache.tomcat.util.descriptor.web.ErrorPage();
tomcatErrorPage.setLocation(errorPage.getPath());
tomcatErrorPage.setErrorCode(errorPage.getStatusCode());
tomcatErrorPage.setExceptionType(errorPage.getExceptionName());
context.addErrorPage(tomcatErrorPage);
}
for (MimeMappings.Mapping mapping : getMimeMappings()) {
context.addMimeMapping(mapping.getExtension(), mapping.getMimeType());
}
configureSession(context);
configureCookieProcessor(context);
new DisableReferenceClearingContextCustomizer().customize(context);
for (String webListenerClassName : getWebListenerClassNames()) {
context.addApplicationListener(webListenerClassName);
}
for (TomcatContextCustomizer customizer : this.tomcatContextCustomizers) {
customizer.customize(context);
}
}
use of org.springframework.boot.web.server.ErrorPage in project scoold by Erudika.
the class ScooldServer method errorPageRegistrar.
/**
* @return Error page registry bean
*/
@Bean
public ErrorPageRegistrar errorPageRegistrar() {
return new ErrorPageRegistrar() {
@Override
public void registerErrorPages(ErrorPageRegistry epr) {
epr.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/not-found"));
epr.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, "/error/403"));
epr.addErrorPages(new ErrorPage(HttpStatus.UNAUTHORIZED, "/error/401"));
epr.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500"));
epr.addErrorPages(new ErrorPage(HttpStatus.SERVICE_UNAVAILABLE, "/error/503"));
epr.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/error/400"));
epr.addErrorPages(new ErrorPage(HttpStatus.METHOD_NOT_ALLOWED, "/error/405"));
epr.addErrorPages(new ErrorPage(Exception.class, "/error/500"));
}
};
}
use of org.springframework.boot.web.server.ErrorPage in project spring-boot by spring-projects.
the class ErrorPageFilterTests method errorMessageForRequestWithoutPathInfo.
@Test
public void errorMessageForRequestWithoutPathInfo() throws IOException, ServletException {
this.request.setServletPath("/test");
this.filter.addErrorPages(new ErrorPage("/error"));
this.chain = new MockFilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
super.doFilter(request, response);
throw new RuntimeException();
}
};
this.filter.doFilter(this.request, this.response, this.chain);
assertThat(this.output.toString()).contains("request [/test]");
}
use of org.springframework.boot.web.server.ErrorPage in project spring-boot by spring-projects.
the class AbstractServletWebServerFactoryTests method errorPageFromPutRequest.
@Test
void errorPageFromPutRequest() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/hello"));
this.webServer = factory.getWebServer(exampleServletRegistration(), errorServletRegistration());
this.webServer.start();
assertThat(getResponse(getLocalUrl("/hello"), HttpMethod.PUT)).isEqualTo("Hello World");
assertThat(getResponse(getLocalUrl("/bang"), HttpMethod.PUT)).isEqualTo("Hello World");
}
use of org.springframework.boot.web.server.ErrorPage in project spring-boot by spring-projects.
the class ErrorPageFilterTests method responseIsCommittedWhenRequestIsAsyncAndStatusIs400Plus.
@Test
void responseIsCommittedWhenRequestIsAsyncAndStatusIs400Plus() throws Exception {
this.filter.addErrorPages(new ErrorPage("/error"));
this.request.setAsyncStarted(true);
this.chain = new TestFilterChain((request, response, chain) -> {
chain.call();
response.sendError(400, "BAD");
});
this.filter.doFilter(this.request, this.response, this.chain);
assertThat(this.chain.getRequest()).isEqualTo(this.request);
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getResponse()).isEqualTo(this.response);
assertThat(this.response.isCommitted()).isTrue();
}
Aggregations