本文整理匯總了Java中org.springframework.web.servlet.HandlerInterceptor類的典型用法代碼示例。如果您正苦於以下問題:Java HandlerInterceptor類的具體用法?Java HandlerInterceptor怎麽用?Java HandlerInterceptor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HandlerInterceptor類屬於org.springframework.web.servlet包,在下文中一共展示了HandlerInterceptor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: restAuthenticationThrottle
import org.springframework.web.servlet.HandlerInterceptor; //導入依賴的package包/類
@ConditionalOnMissingBean(name = "restAuthenticationThrottle")
@Bean
public HandlerInterceptor restAuthenticationThrottle() {
final String throttler = casProperties.getRest().getThrottler();
if (StringUtils.isNotBlank(throttler) && this.applicationContext.containsBean(throttler)) {
return this.applicationContext.getBean(throttler, HandlerInterceptor.class);
}
return new HandlerInterceptorAdapter() {
@Override
public boolean preHandle(final HttpServletRequest request,
final HttpServletResponse response,
final Object handler) {
return true;
}
};
}
示例2: registerTenantInterceptorWithIgnorePathPattern
import org.springframework.web.servlet.HandlerInterceptor; //導入依賴的package包/類
/**
* Registered interceptor to all request except passed urls.
* @param registry helps with configuring a list of mapped interceptors.
* @param interceptor the interceptor
*/
protected void registerTenantInterceptorWithIgnorePathPattern(
InterceptorRegistry registry, HandlerInterceptor interceptor) {
InterceptorRegistration tenantInterceptorRegistration = registry.addInterceptor(interceptor);
tenantInterceptorRegistration.addPathPatterns("/**");
List<String> tenantIgnorePathPatterns = getTenantIgnorePathPatterns();
Objects.requireNonNull(tenantIgnorePathPatterns, "tenantIgnorePathPatterns can't be null");
for (String pattern : tenantIgnorePathPatterns) {
tenantInterceptorRegistration.excludePathPatterns(pattern);
}
LOGGER.info("Added handler interceptor '{}' to all urls, exclude {}", interceptor.getClass()
.getSimpleName(), tenantIgnorePathPatterns);
}
示例3: resourceHandlerMapping
import org.springframework.web.servlet.HandlerInterceptor; //導入依賴的package包/類
/**
* Return a handler mapping ordered at Integer.MAX_VALUE-1 with mapped
* resource handlers. To configure resource handling, override
* {@link #addResourceHandlers}.
*/
@Bean
public HandlerMapping resourceHandlerMapping() {
ResourceHandlerRegistry registry = new ResourceHandlerRegistry(this.applicationContext, this.servletContext);
addResourceHandlers(registry);
AbstractHandlerMapping handlerMapping = registry.getHandlerMapping();
if (handlerMapping != null) {
handlerMapping.setPathMatcher(mvcPathMatcher());
handlerMapping.setUrlPathHelper(mvcUrlPathHelper());
handlerMapping.setInterceptors(new HandlerInterceptor[] {
new ResourceUrlProviderExposingInterceptor(mvcResourceUrlProvider())});
handlerMapping.setCorsConfigurations(getCorsConfigurations());
}
else {
handlerMapping = new EmptyHandlerMapping();
}
return handlerMapping;
}
示例4: mappedInterceptors
import org.springframework.web.servlet.HandlerInterceptor; //導入依賴的package包/類
@Test
public void mappedInterceptors() throws Exception {
String path = "/foo";
HandlerInterceptor interceptor = new HandlerInterceptorAdapter() {};
MappedInterceptor mappedInterceptor = new MappedInterceptor(new String[] {path}, interceptor);
TestRequestMappingInfoHandlerMapping hm = new TestRequestMappingInfoHandlerMapping();
hm.registerHandler(new TestController());
hm.setInterceptors(new Object[] { mappedInterceptor });
hm.setApplicationContext(new StaticWebApplicationContext());
HandlerExecutionChain chain = hm.getHandler(new MockHttpServletRequest("GET", path));
assertNotNull(chain);
assertNotNull(chain.getInterceptors());
assertSame(interceptor, chain.getInterceptors()[0]);
chain = hm.getHandler(new MockHttpServletRequest("GET", "/invalid"));
assertNull(chain);
}
示例5: getInterceptorsForPath
import org.springframework.web.servlet.HandlerInterceptor; //導入依賴的package包/類
private List<HandlerInterceptor> getInterceptorsForPath(String lookupPath) {
PathMatcher pathMatcher = new AntPathMatcher();
List<HandlerInterceptor> result = new ArrayList<HandlerInterceptor>();
for (Object interceptor : this.registry.getInterceptors()) {
if (interceptor instanceof MappedInterceptor) {
MappedInterceptor mappedInterceptor = (MappedInterceptor) interceptor;
if (mappedInterceptor.matches(lookupPath, pathMatcher)) {
result.add(mappedInterceptor.getInterceptor());
}
}
else if (interceptor instanceof HandlerInterceptor) {
result.add((HandlerInterceptor) interceptor);
}
else {
fail("Unexpected interceptor type: " + interceptor.getClass().getName());
}
}
return result;
}
示例6: printHandler
import org.springframework.web.servlet.HandlerInterceptor; //導入依賴的package包/類
/**
* Print the handler.
*/
protected void printHandler(Object handler, HandlerInterceptor[] interceptors) throws Exception {
if (handler == null) {
this.printer.printValue("Type", null);
}
else {
if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
this.printer.printValue("Type", handlerMethod.getBeanType().getName());
this.printer.printValue("Method", handlerMethod);
}
else {
this.printer.printValue("Type", handler.getClass().getName());
}
}
}
示例7: sitePreferenceHandlerInterceptorRegistered
import org.springframework.web.servlet.HandlerInterceptor; //導入依賴的package包/類
@Test
public void sitePreferenceHandlerInterceptorRegistered() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(Config.class, WebMvcAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
SitePreferenceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
RequestMappingHandlerMapping mapping = this.context
.getBean(RequestMappingHandlerMapping.class);
HandlerInterceptor[] interceptors = mapping
.getHandler(new MockHttpServletRequest()).getInterceptors();
assertThat(interceptors)
.hasAtLeastOneElementOfType(SitePreferenceHandlerInterceptor.class);
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:17,代碼來源:SitePreferenceAutoConfigurationTests.java
示例8: sitePreferenceHandlerInterceptorRegistered
import org.springframework.web.servlet.HandlerInterceptor; //導入依賴的package包/類
@Test
public void sitePreferenceHandlerInterceptorRegistered() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(Config.class, WebMvcAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
SitePreferenceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
RequestMappingHandlerMapping mapping = this.context
.getBean(RequestMappingHandlerMapping.class);
HandlerInterceptor[] interceptors = mapping
.getHandler(new MockHttpServletRequest()).getInterceptors();
assertThat(interceptors,
hasItemInArray(instanceOf(SitePreferenceHandlerInterceptor.class)));
}
示例9: deviceResolverHandlerInterceptorRegistered
import org.springframework.web.servlet.HandlerInterceptor; //導入依賴的package包/類
@Test
public void deviceResolverHandlerInterceptorRegistered() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(Config.class, WebMvcAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
DeviceResolverAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
RequestMappingHandlerMapping mapping = this.context
.getBean(RequestMappingHandlerMapping.class);
HandlerInterceptor[] interceptors = mapping
.getHandler(new MockHttpServletRequest()).getInterceptors();
assertThat(interceptors,
hasItemInArray(instanceOf(DeviceResolverHandlerInterceptor.class)));
}
示例10: addInterceptors
import org.springframework.web.servlet.HandlerInterceptor; //導入依賴的package包/類
@Override
public void addInterceptors(InterceptorRegistry registry) {
/*Optional.ofNullable(interceptorList).ifPresent(list->{
list.stream().forEach(inter->registry.addInterceptor(inter));
});*/
if(LangUtils.isEmpty(interceptorList)){
return ;
}
for(HandlerInterceptor inter : interceptorList){
InterceptorRegistration reg = registry.addInterceptor(inter);
if(inter instanceof WebInterceptorAdapter){
WebInterceptorAdapter webinter = (WebInterceptorAdapter) inter;
if(LangUtils.isEmpty(webinter.getPathPatterns())){
continue;
}
reg.addPathPatterns(webinter.getPathPatterns());
}
}
// registry.addInterceptor(new BootFirstInterceptor());
}
示例11: getHandlerInterceptors
import org.springframework.web.servlet.HandlerInterceptor; //導入依賴的package包/類
@SuppressWarnings({ "unchecked", "rawtypes" })
private List<HandlerInterceptor> getHandlerInterceptors(Class<? extends Object> clazz,
Interceptors interceptorAnnotation) {
List<HandlerInterceptor> interceptors = new ArrayList<HandlerInterceptor>();
if (interceptorAnnotation != null) {
Class[] interceptorClasses = interceptorAnnotation.value();
if (interceptorClasses != null) {
for (Class interceptorClass : interceptorClasses) {
if (!HandlerInterceptor.class.isAssignableFrom(interceptorClass)) {
raiseIllegalInterceptorValue(clazz, interceptorClass);
}
interceptors.add((HandlerInterceptor) getApplicationContext().getBean(interceptorClass));
}
}
}
return interceptors;
}
示例12: printHandler
import org.springframework.web.servlet.HandlerInterceptor; //導入依賴的package包/類
/** Print the handler */
protected void printHandler(Object handler, HandlerInterceptor[] interceptors) throws Exception {
if (handler == null) {
this.printer.printValue("Type", null);
}
else {
if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
this.printer.printValue("Type", handlerMethod.getBeanType().getName());
this.printer.printValue("Method", handlerMethod);
}
else {
this.printer.printValue("Type", handler.getClass().getName());
}
}
}
示例13: getInterceptorsForPath
import org.springframework.web.servlet.HandlerInterceptor; //導入依賴的package包/類
private List<HandlerInterceptor> getInterceptorsForPath(String lookupPath) {
PathMatcher pathMatcher = new AntPathMatcher();
List<HandlerInterceptor> result = new ArrayList<HandlerInterceptor>();
for (Object i : registry.getInterceptors()) {
if (i instanceof MappedInterceptor) {
MappedInterceptor mappedInterceptor = (MappedInterceptor) i;
if (mappedInterceptor.matches(lookupPath, pathMatcher)) {
result.add(mappedInterceptor.getInterceptor());
}
}
else if (i instanceof HandlerInterceptor){
result.add((HandlerInterceptor) i);
}
else {
fail("Unexpected interceptor type: " + i.getClass().getName());
}
}
return result;
}
示例14: testShouldMergeInterceptors
import org.springframework.web.servlet.HandlerInterceptor; //導入依賴的package包/類
public void testShouldMergeInterceptors() throws Throwable {
HandlerInterceptor interceptorOfFramework = new HandlerInterceptorSub();
HandlerInterceptor interceptorOfTab = new HandlerInterceptorSub();
HandlerInterceptor[] interceptorsOfFramework = new HandlerInterceptor[] {interceptorOfFramework};
HandlerInterceptor[] interceptorsOfTab = new HandlerInterceptor[] {interceptorOfTab};
Mock proceedingJoinPoint = mock(ProceedingJoinPoint.class);
proceedingJoinPoint.expects(once()).method("proceed").will(
returnValue(new HandlerExecutionChain(null, interceptorsOfTab)));
InterceptorInjector injector = new InterceptorInjector();
injector.setInterceptors(interceptorsOfFramework);
HandlerExecutionChain handlers =
injector.mergeInterceptorsToTabs((ProceedingJoinPoint) proceedingJoinPoint.proxy());
assertEquals(2, handlers.getInterceptors().length);
assertSame(interceptorOfFramework, handlers.getInterceptors()[0]);
assertSame(interceptorOfTab, handlers.getInterceptors()[1]);
}
示例15: testShouldJustReturnInterceptorsOfFrameworkIfNoTabInterceptors
import org.springframework.web.servlet.HandlerInterceptor; //導入依賴的package包/類
public void testShouldJustReturnInterceptorsOfFrameworkIfNoTabInterceptors() throws Throwable {
HandlerInterceptor interceptorOfFramework = new HandlerInterceptorSub();
HandlerInterceptor[] interceptorsOfFramework = new HandlerInterceptor[] {interceptorOfFramework};
Mock proceedingJoinPoint = mock(ProceedingJoinPoint.class);
proceedingJoinPoint.expects(once()).method("proceed").will(
returnValue(new HandlerExecutionChain(null, null)));
InterceptorInjector injector = new InterceptorInjector();
injector.setInterceptors(interceptorsOfFramework);
HandlerExecutionChain handlers =
injector.mergeInterceptorsToTabs((ProceedingJoinPoint) proceedingJoinPoint.proxy());
assertEquals(1, handlers.getInterceptors().length);
assertSame(interceptorOfFramework, handlers.getInterceptors()[0]);
}