本文整理汇总了Java中org.springframework.web.servlet.handler.MappedInterceptor类的典型用法代码示例。如果您正苦于以下问题:Java MappedInterceptor类的具体用法?Java MappedInterceptor怎么用?Java MappedInterceptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MappedInterceptor类属于org.springframework.web.servlet.handler包,在下文中一共展示了MappedInterceptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInterceptor
import org.springframework.web.servlet.handler.MappedInterceptor; //导入依赖的package包/类
/**
* Returns the underlying interceptor. If URL patterns are provided the returned type is
* {@link MappedInterceptor}; otherwise {@link HandlerInterceptor}.
*/
protected Object getInterceptor() {
if (this.includePatterns.isEmpty() && this.excludePatterns.isEmpty()) {
return this.interceptor;
}
String[] include = toArray(this.includePatterns);
String[] exclude = toArray(this.excludePatterns);
MappedInterceptor mappedInterceptor = new MappedInterceptor(include, exclude, this.interceptor);
if (this.pathMatcher != null) {
mappedInterceptor.setPathMatcher(this.pathMatcher);
}
return mappedInterceptor;
}
示例2: registerUrlProvider
import org.springframework.web.servlet.handler.MappedInterceptor; //导入依赖的package包/类
private void registerUrlProvider(ParserContext parserContext, Object source) {
if (!parserContext.getRegistry().containsBeanDefinition(RESOURCE_URL_PROVIDER)) {
RootBeanDefinition urlProvider = new RootBeanDefinition(ResourceUrlProvider.class);
urlProvider.setSource(source);
urlProvider.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
parserContext.getRegistry().registerBeanDefinition(RESOURCE_URL_PROVIDER, urlProvider);
parserContext.registerComponent(new BeanComponentDefinition(urlProvider, RESOURCE_URL_PROVIDER));
RootBeanDefinition interceptor = new RootBeanDefinition(ResourceUrlProviderExposingInterceptor.class);
interceptor.setSource(source);
interceptor.getConstructorArgumentValues().addIndexedArgumentValue(0, urlProvider);
RootBeanDefinition mappedInterceptor = new RootBeanDefinition(MappedInterceptor.class);
mappedInterceptor.setSource(source);
mappedInterceptor.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
mappedInterceptor.getConstructorArgumentValues().addIndexedArgumentValue(0, (Object) null);
mappedInterceptor.getConstructorArgumentValues().addIndexedArgumentValue(1, interceptor);
String mappedInterceptorName = parserContext.getReaderContext().registerWithGeneratedName(mappedInterceptor);
parserContext.registerComponent(new BeanComponentDefinition(mappedInterceptor, mappedInterceptorName));
}
}
示例3: mappedInterceptors
import org.springframework.web.servlet.handler.MappedInterceptor; //导入依赖的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);
}
示例4: getInterceptorsForPath
import org.springframework.web.servlet.handler.MappedInterceptor; //导入依赖的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;
}
示例5: getInterceptorsForPath
import org.springframework.web.servlet.handler.MappedInterceptor; //导入依赖的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;
}
示例6: testResources
import org.springframework.web.servlet.handler.MappedInterceptor; //导入依赖的package包/类
@Test
public void testResources() throws Exception {
loadBeanDefinitions("mvc-config-resources.xml", 10);
HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class);
assertNotNull(adapter);
ResourceHttpRequestHandler handler = appContext.getBean(ResourceHttpRequestHandler.class);
assertNotNull(handler);
SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class);
assertNotNull(mapping);
assertEquals(Ordered.LOWEST_PRECEDENCE - 1, mapping.getOrder());
BeanNameUrlHandlerMapping beanNameMapping = appContext.getBean(BeanNameUrlHandlerMapping.class);
assertNotNull(beanNameMapping);
assertEquals(2, beanNameMapping.getOrder());
ResourceUrlProvider urlProvider = appContext.getBean(ResourceUrlProvider.class);
assertNotNull(urlProvider);
MappedInterceptor mappedInterceptor = appContext.getBean(MappedInterceptor.class);
assertNotNull(urlProvider);
assertEquals(ResourceUrlProviderExposingInterceptor.class, mappedInterceptor.getInterceptor().getClass());
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("/resources/foo.css");
request.setMethod("GET");
HandlerExecutionChain chain = mapping.getHandler(request);
assertTrue(chain.getHandler() instanceof ResourceHttpRequestHandler);
MockHttpServletResponse response = new MockHttpServletResponse();
for (HandlerInterceptor interceptor : chain.getInterceptors()) {
interceptor.preHandle(request, response, chain.getHandler());
}
ModelAndView mv = adapter.handle(request, response, chain.getHandler());
assertNull(mv);
}
示例7: addInterceptorsWithCustomPathMatcher
import org.springframework.web.servlet.handler.MappedInterceptor; //导入依赖的package包/类
@Test
public void addInterceptorsWithCustomPathMatcher() {
PathMatcher pathMatcher = Mockito.mock(PathMatcher.class);
this.registry.addInterceptor(interceptor1).addPathPatterns("/path1/**").pathMatcher(pathMatcher);
MappedInterceptor mappedInterceptor = (MappedInterceptor) this.registry.getInterceptors().get(0);
assertSame(pathMatcher, mappedInterceptor.getPathMatcher());
}
示例8: addMappedInterceptors
import org.springframework.web.servlet.handler.MappedInterceptor; //导入依赖的package包/类
/**
* Add interceptors mapped to a set of path patterns.
*/
public StandaloneMockMvcBuilder addMappedInterceptors(String[] pathPatterns, HandlerInterceptor... interceptors) {
for (HandlerInterceptor interceptor : interceptors) {
this.mappedInterceptors.add(new MappedInterceptor(pathPatterns, interceptor));
}
return this;
}
示例9: addInterceptors
import org.springframework.web.servlet.handler.MappedInterceptor; //导入依赖的package包/类
@Override
protected void addInterceptors(InterceptorRegistry registry) {
for (MappedInterceptor interceptor : mappedInterceptors) {
InterceptorRegistration registration = registry.addInterceptor(interceptor.getInterceptor());
if (interceptor.getPathPatterns() != null) {
registration.addPathPatterns(interceptor.getPathPatterns());
}
}
}
示例10: build
import org.springframework.web.servlet.handler.MappedInterceptor; //导入依赖的package包/类
@Override
public Map<String, Object> build(String beanName,MappedInterceptor mappedInterceptor){
HandlerInterceptor handlerInterceptor = mappedInterceptor.getInterceptor();
String[] pathPatterns = mappedInterceptor.getPathPatterns();
Object readField = getExcludePatterns(mappedInterceptor);
//---------------------------------------------------------------
Map<String, Object> map = newLinkedHashMap();
map.put("handlerInterceptor", handlerInterceptor.getClass().getName());
map.put("includePatterns", pathPatterns);
map.put("excludePatterns", readField);
map.put("beanName", beanName);
return map;
}
示例11: getExcludePatterns
import org.springframework.web.servlet.handler.MappedInterceptor; //导入依赖的package包/类
/**
* Gets the exclude patterns.
*
* @param mappedInterceptor
* the mapped interceptor
* @return the exclude patterns
*/
private Object getExcludePatterns(MappedInterceptor mappedInterceptor){
try{
return FieldUtils.readField(mappedInterceptor, "excludePatterns", true);
}catch (IllegalAccessException e){
LOGGER.error("", e);
}
return null;
}
示例12: getInterceptor
import org.springframework.web.servlet.handler.MappedInterceptor; //导入依赖的package包/类
/**
* Returns the underlying interceptor. If URL patterns are provided the returned type is
* {@link MappedInterceptor}; otherwise {@link HandlerInterceptor}.
*/
protected Object getInterceptor() {
if (this.includePatterns.isEmpty()) {
return this.interceptor;
}
return new MappedInterceptor(toArray(this.includePatterns), toArray(this.excludePatterns), interceptor);
}
示例13: parse
import org.springframework.web.servlet.handler.MappedInterceptor; //导入依赖的package包/类
public BeanDefinition parse(Element element, ParserContext parserContext) {
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element));
parserContext.pushContainingComponent(compDefinition);
List<Element> interceptors = DomUtils.getChildElementsByTagName(element, "bean", "ref", "interceptor");
for (Element interceptor : interceptors) {
RootBeanDefinition mappedInterceptorDef = new RootBeanDefinition(MappedInterceptor.class);
mappedInterceptorDef.setSource(parserContext.extractSource(interceptor));
mappedInterceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
ManagedList<String> includePatterns = null;
ManagedList<String> excludePatterns = null;
Object interceptorBean;
if ("interceptor".equals(interceptor.getLocalName())) {
includePatterns = getIncludePatterns(interceptor, "mapping");
excludePatterns = getIncludePatterns(interceptor, "exclude-mapping");
Element beanElem = DomUtils.getChildElementsByTagName(interceptor, "bean", "ref").get(0);
interceptorBean = parserContext.getDelegate().parsePropertySubElement(beanElem, null);
}
else {
interceptorBean = parserContext.getDelegate().parsePropertySubElement(interceptor, null);
}
mappedInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, includePatterns);
mappedInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(1, excludePatterns);
mappedInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(2, interceptorBean);
String beanName = parserContext.getReaderContext().registerWithGeneratedName(mappedInterceptorDef);
parserContext.registerComponent(new BeanComponentDefinition(mappedInterceptorDef, beanName));
}
parserContext.popAndRegisterContainingComponent();
return null;
}
示例14: mappedCorsInterceptor
import org.springframework.web.servlet.handler.MappedInterceptor; //导入依赖的package包/类
@Bean
public MappedInterceptor mappedCorsInterceptor()
{
/*
* This way, the cors interceptor is added to the resource handlers as well, if the patterns overlap.
*
* See https://jira.spring.io/browse/SPR-10655
*/
return new MappedInterceptor(new String[] { "/api/**", "/fdp/**" }, corsInterceptor());
}
示例15: deprecatedApi
import org.springframework.web.servlet.handler.MappedInterceptor; //导入依赖的package包/类
@Bean
public MappedInterceptor deprecatedApi() {
return new MappedInterceptor(null, new DeprecatedApiInterceptor());
}