当前位置: 首页>>代码示例>>Java>>正文


Java ErrorPage类代码示例

本文整理汇总了Java中org.springframework.boot.web.servlet.ErrorPage的典型用法代码示例。如果您正苦于以下问题:Java ErrorPage类的具体用法?Java ErrorPage怎么用?Java ErrorPage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ErrorPage类属于org.springframework.boot.web.servlet包,在下文中一共展示了ErrorPage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: errorPageRegistrar

import org.springframework.boot.web.servlet.ErrorPage; //导入依赖的package包/类
/**
 * @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/403"));
			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"));
		}
	};
}
 
开发者ID:Erudika,项目名称:scoold,代码行数:20,代码来源:ScooldServer.java

示例2: customize

import org.springframework.boot.web.servlet.ErrorPage; //导入依赖的package包/类
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
	if (this.managementServerProperties == null) {
		this.managementServerProperties = BeanFactoryUtils
				.beanOfTypeIncludingAncestors(this.beanFactory,
						ManagementServerProperties.class);
		this.server = BeanFactoryUtils.beanOfTypeIncludingAncestors(
				this.beanFactory, ServerProperties.class);
	}
	// Customize as per the parent context first (so e.g. the access logs go to
	// the same place)
	this.server.customize(container);
	// Then reset the error pages
	container.setErrorPages(Collections.<ErrorPage>emptySet());
	// and the context path
	container.setContextPath("");
	// and add the management-specific bits
	container.setPort(this.managementServerProperties.getPort());
	if (this.managementServerProperties.getSsl() != null) {
		container.setSsl(this.managementServerProperties.getSsl());
	}
	container.setServerHeader(this.server.getServerHeader());
	container.setAddress(this.managementServerProperties.getAddress());
	container.addErrorPages(new ErrorPage(this.server.getError().getPath()));
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:26,代码来源:EndpointWebMvcChildContextConfiguration.java

示例3: containerCustomizer

import org.springframework.boot.web.servlet.ErrorPage; //导入依赖的package包/类
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {

    return (container -> {
        ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, "/401.html");
        ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/404.html");
        ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500.html");

        container.addErrorPages(error401Page, error404Page, error500Page);
    });
}
 
开发者ID:ChinaLHR,项目名称:JavaQuarkBBS,代码行数:12,代码来源:AdminApplication.java

示例4: registerErrorPages

import org.springframework.boot.web.servlet.ErrorPage; //导入依赖的package包/类
@Override
public void registerErrorPages(@NonNull ErrorPageRegistry registry) {
  for (HttpStatus httpStatus : HttpStatus.values()) {
    registry.addErrorPages(new ErrorPage(httpStatus,
        String.format("/%s/%d", ErrorModule.SERVLET_ERROR_PATH_PREFIX, httpStatus.value())));
  }
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:8,代码来源:ServletErrorPageRegistrar.java

示例5: addToContext

import org.springframework.boot.web.servlet.ErrorPage; //导入依赖的package包/类
public void addToContext(Context context) {
	Assert.state(this.nativePage != null,
			"Neither Tomcat 7 nor 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());
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:TomcatErrorPage.java

示例6: configureContext

import org.springframework.boot.web.servlet.ErrorPage; //导入依赖的package包/类
/**
 * 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) {
		// Should be true
		((TomcatEmbeddedContext) context).setStarter(starter);
	}
	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()) {
		new TomcatErrorPage(errorPage).addToContext(context);
	}
	for (MimeMappings.Mapping mapping : getMimeMappings()) {
		context.addMimeMapping(mapping.getExtension(), mapping.getMimeType());
	}
	configureSession(context);
	for (TomcatContextCustomizer customizer : this.tomcatContextCustomizers) {
		customizer.customize(context);
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:31,代码来源:TomcatEmbeddedServletContainerFactory.java

示例7: addJettyErrorPages

import org.springframework.boot.web.servlet.ErrorPage; //导入依赖的package包/类
private void addJettyErrorPages(ErrorHandler errorHandler,
		Collection<ErrorPage> errorPages) {
	if (errorHandler instanceof ErrorPageErrorHandler) {
		ErrorPageErrorHandler handler = (ErrorPageErrorHandler) errorHandler;
		for (ErrorPage errorPage : errorPages) {
			if (errorPage.isGlobal()) {
				handler.addErrorPage(ErrorPageErrorHandler.GLOBAL_ERROR_PAGE,
						errorPage.getPath());
			}
			else {
				if (errorPage.getExceptionName() != null) {
					handler.addErrorPage(errorPage.getExceptionName(),
							errorPage.getPath());
				}
				else {
					handler.addErrorPage(errorPage.getStatusCode(),
							errorPage.getPath());
				}
			}
		}
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:23,代码来源:JettyEmbeddedServletContainerFactory.java

示例8: unauthorizedWithErrorPath

import org.springframework.boot.web.servlet.ErrorPage; //导入依赖的package包/类
@Test
public void unauthorizedWithErrorPath() throws Exception {
	this.filter.addErrorPages(new ErrorPage("/error"));
	this.chain = new MockFilterChain() {
		@Override
		public void doFilter(ServletRequest request, ServletResponse response)
				throws IOException, ServletException {
			((HttpServletResponse) response).sendError(401, "UNAUTHORIZED");
			super.doFilter(request, response);
		}
	};
	this.filter.doFilter(this.request, this.response, this.chain);
	assertThat(this.chain.getRequest()).isEqualTo(this.request);
	HttpServletResponseWrapper wrapper = (HttpServletResponseWrapper) this.chain
			.getResponse();
	assertThat(wrapper.getResponse()).isEqualTo(this.response);
	assertThat(this.response.isCommitted()).isTrue();
	assertThat(wrapper.getStatus()).isEqualTo(401);
	// The real response has to be 401 as well...
	assertThat(this.response.getStatus()).isEqualTo(401);
	assertThat(this.response.getForwardedUrl()).isEqualTo("/error");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:23,代码来源:ErrorPageFilterTests.java

示例9: globalError

import org.springframework.boot.web.servlet.ErrorPage; //导入依赖的package包/类
@Test
public void globalError() throws Exception {
	this.filter.addErrorPages(new ErrorPage("/error"));
	this.chain = new MockFilterChain() {
		@Override
		public void doFilter(ServletRequest request, ServletResponse response)
				throws IOException, ServletException {
			((HttpServletResponse) response).sendError(400, "BAD");
			super.doFilter(request, response);
		}
	};
	this.filter.doFilter(this.request, this.response, this.chain);
	assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
			.isEqualTo(400);
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE))
			.isEqualTo(400);
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_MESSAGE))
			.isEqualTo("BAD");
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI))
			.isEqualTo("/test/path");
	assertThat(this.response.isCommitted()).isTrue();
	assertThat(this.response.getForwardedUrl()).isEqualTo("/error");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:24,代码来源:ErrorPageFilterTests.java

示例10: statusError

import org.springframework.boot.web.servlet.ErrorPage; //导入依赖的package包/类
@Test
public void statusError() throws Exception {
	this.filter.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400"));
	this.chain = new MockFilterChain() {
		@Override
		public void doFilter(ServletRequest request, ServletResponse response)
				throws IOException, ServletException {
			((HttpServletResponse) response).sendError(400, "BAD");
			super.doFilter(request, response);
		}
	};
	this.filter.doFilter(this.request, this.response, this.chain);
	assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
			.isEqualTo(400);
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE))
			.isEqualTo(400);
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_MESSAGE))
			.isEqualTo("BAD");
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI))
			.isEqualTo("/test/path");
	assertThat(this.response.isCommitted()).isTrue();
	assertThat(this.response.getForwardedUrl()).isEqualTo("/400");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:24,代码来源:ErrorPageFilterTests.java

示例11: statusErrorWithCommittedResponse

import org.springframework.boot.web.servlet.ErrorPage; //导入依赖的package包/类
@Test
public void statusErrorWithCommittedResponse() throws Exception {
	this.filter.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400"));
	this.chain = new MockFilterChain() {
		@Override
		public void doFilter(ServletRequest request, ServletResponse response)
				throws IOException, ServletException {
			((HttpServletResponse) response).sendError(400, "BAD");
			response.flushBuffer();
			super.doFilter(request, response);
		}
	};
	this.filter.doFilter(this.request, this.response, this.chain);
	assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
			.isEqualTo(400);
	assertThat(this.response.isCommitted()).isTrue();
	assertThat(this.response.getForwardedUrl()).isNull();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:19,代码来源:ErrorPageFilterTests.java

示例12: exceptionError

import org.springframework.boot.web.servlet.ErrorPage; //导入依赖的package包/类
@Test
public void exceptionError() throws Exception {
	this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500"));
	this.chain = new MockFilterChain() {
		@Override
		public void doFilter(ServletRequest request, ServletResponse response)
				throws IOException, ServletException {
			super.doFilter(request, response);
			throw new RuntimeException("BAD");
		}
	};
	this.filter.doFilter(this.request, this.response, this.chain);
	assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
			.isEqualTo(500);
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE))
			.isEqualTo(500);
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_MESSAGE))
			.isEqualTo("BAD");
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE))
			.isEqualTo(RuntimeException.class.getName());
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI))
			.isEqualTo("/test/path");
	assertThat(this.response.isCommitted()).isTrue();
	assertThat(this.response.getForwardedUrl()).isEqualTo("/500");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:26,代码来源:ErrorPageFilterTests.java

示例13: subClassExceptionError

import org.springframework.boot.web.servlet.ErrorPage; //导入依赖的package包/类
@Test
public void subClassExceptionError() throws Exception {
	this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500"));
	this.chain = new MockFilterChain() {
		@Override
		public void doFilter(ServletRequest request, ServletResponse response)
				throws IOException, ServletException {
			super.doFilter(request, response);
			throw new IllegalStateException("BAD");
		}
	};
	this.filter.doFilter(this.request, this.response, this.chain);
	assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
			.isEqualTo(500);
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE))
			.isEqualTo(500);
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_MESSAGE))
			.isEqualTo("BAD");
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE))
			.isEqualTo(IllegalStateException.class.getName());
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI))
			.isEqualTo("/test/path");
	assertThat(this.response.isCommitted()).isTrue();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:25,代码来源:ErrorPageFilterTests.java

示例14: responseIsCommittedWhenExceptionIsThrownDuringAsyncDispatch

import org.springframework.boot.web.servlet.ErrorPage; //导入依赖的package包/类
@Test
public void responseIsCommittedWhenExceptionIsThrownDuringAsyncDispatch()
		throws Exception {
	this.filter.addErrorPages(new ErrorPage("/error"));
	setUpAsyncDispatch();
	this.chain = new MockFilterChain() {
		@Override
		public void doFilter(ServletRequest request, ServletResponse response)
				throws IOException, ServletException {
			super.doFilter(request, response);
			throw new RuntimeException("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();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:ErrorPageFilterTests.java

示例15: responseIsCommittedWhenStatusIs400PlusDuringAsyncDispatch

import org.springframework.boot.web.servlet.ErrorPage; //导入依赖的package包/类
@Test
public void responseIsCommittedWhenStatusIs400PlusDuringAsyncDispatch()
		throws Exception {
	this.filter.addErrorPages(new ErrorPage("/error"));
	setUpAsyncDispatch();
	this.chain = new MockFilterChain() {
		@Override
		public void doFilter(ServletRequest request, ServletResponse response)
				throws IOException, ServletException {
			super.doFilter(request, response);
			((HttpServletResponse) 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();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:ErrorPageFilterTests.java


注:本文中的org.springframework.boot.web.servlet.ErrorPage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。