@Bean @Lazy public HandlerMappingIntrospector mvcHandlerMappingIntrospector() { return new HandlerMappingIntrospector(); }
private static List<HandlerMapping> initHandlerMappings(ApplicationContext applicationContext) { Map<String, HandlerMapping> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors( applicationContext, HandlerMapping.class, true, false); if (!beans.isEmpty()) { List<HandlerMapping> mappings = new ArrayList<>(beans.values()); AnnotationAwareOrderComparator.sort(mappings); return Collections.unmodifiableList(mappings); } return Collections.unmodifiableList(initFallback(applicationContext)); }
/** * Constructor that detects the configured {@code HandlerMapping}s in the * given {@code ApplicationContext} or falls back on * "DispatcherServlet.properties" like the {@code DispatcherServlet}. * @deprecated as of 4.3.12, in favor of {@link #setApplicationContext} */ @Deprecated public HandlerMappingIntrospector(ApplicationContext context) { this.handlerMappings = initHandlerMappings(context); }
private HandlerMappingIntrospector getIntrospector(WebApplicationContext cxt) { HandlerMappingIntrospector introspector = new HandlerMappingIntrospector(); introspector.setApplicationContext(cxt); introspector.afterPropertiesSet(); return introspector; }
@Test public void getMatchable() throws Exception { MutablePropertyValues pvs = new MutablePropertyValues( Collections.singletonMap("urlMap", Collections.singletonMap("/path", new Object()))); StaticWebApplicationContext cxt = new StaticWebApplicationContext(); cxt.registerSingleton("hm", SimpleUrlHandlerMapping.class, pvs); cxt.refresh(); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/path"); MatchableHandlerMapping hm = getIntrospector(cxt).getMatchableHandlerMapping(request); assertEquals(cxt.getBean("hm"), hm); assertNull("Attributes changes not ignored", request.getAttribute(BEST_MATCHING_PATTERN_ATTRIBUTE)); }
@Test(expected = IllegalStateException.class) public void getMatchableWhereHandlerMappingDoesNotImplementMatchableInterface() throws Exception { StaticWebApplicationContext cxt = new StaticWebApplicationContext(); cxt.registerSingleton("hm1", TestHandlerMapping.class); cxt.refresh(); MockHttpServletRequest request = new MockHttpServletRequest(); getIntrospector(cxt).getMatchableHandlerMapping(request); }
@Bean @Lazy public HandlerMappingIntrospector mvcHandlerMappingIntrospector() { return new HandlerMappingIntrospector(); }
@Override public void afterPropertiesSet() { if (this.handlerMappings == null) { Assert.notNull(this.applicationContext, "No ApplicationContext"); this.handlerMappings = initHandlerMappings(this.applicationContext); } }
private MatchableHandlerMapping getMapping(HttpServletRequest request) { try { return this.introspector.getMatchableHandlerMapping(request); } catch (Throwable t) { return null; } }
private static List<HandlerMapping> initHandlerMappings(ApplicationContext applicationContext) { Map<String, HandlerMapping> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors( applicationContext, HandlerMapping.class, true, false); if (!beans.isEmpty()) { List<HandlerMapping> mappings = new ArrayList<>(beans.values()); AnnotationAwareOrderComparator.sort(mappings); return Collections.unmodifiableList(mappings); } return Collections.unmodifiableList(initFallback(applicationContext)); }
/** * Allows configuring the {@link HttpSecurity} to only be invoked when matching the * provided Spring MVC pattern. If more advanced configuration is necessary, consider using * {@link #requestMatchers()} or {@link #requestMatcher(RequestMatcher)}. * * <p> * Invoking {@link #mvcMatcher(String)} will override previous invocations of {@link #mvcMatcher(String)}}, * {@link #requestMatchers()}, {@link #antMatcher(String)}, * {@link #regexMatcher(String)}, and {@link #requestMatcher(RequestMatcher)}. * </p> * * @param mvcPattern the Spring MVC Pattern to match on (i.e. "/admin/**") * @return the {@link HttpSecurity} for further customizations * @see MvcRequestMatcher */ public HttpSecurity mvcMatcher(String mvcPattern) { HandlerMappingIntrospector introspector = new HandlerMappingIntrospector(getContext()); return requestMatcher(new MvcRequestMatcher(introspector, mvcPattern)); }
/** * Constructor that detects the configured {@code HandlerMapping}s in the * given {@code ApplicationContext} or falls back on * "DispatcherServlet.properties" like the {@code DispatcherServlet}. * @deprecated as of 4.3.12, in favor of {@link #setApplicationContext} */ @Deprecated public HandlerMappingIntrospector(ApplicationContext context) { this.handlerMappings = initHandlerMappings(context); }
HandlerExecutionChain handler = null; try { MatchableHandlerMapping matchableHandlerMapping = mappingIntrospector.getMatchableHandlerMapping(request); if (matchableHandlerMapping != null) { handler = matchableHandlerMapping.getHandler(request);
private static List<HandlerMapping> initHandlerMappings(ApplicationContext applicationContext) { Map<String, HandlerMapping> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors( applicationContext, HandlerMapping.class, true, false); if (!beans.isEmpty()) { List<HandlerMapping> mappings = new ArrayList<HandlerMapping>(beans.values()); AnnotationAwareOrderComparator.sort(mappings); return Collections.unmodifiableList(mappings); } return Collections.unmodifiableList(initFallback(applicationContext)); }
/** * Allows configuring the {@link HttpSecurity} to only be invoked when matching the * provided Spring MVC pattern. If more advanced configuration is necessary, consider using * {@link #requestMatchers()} or {@link #requestMatcher(RequestMatcher)}. * * <p> * Invoking {@link #mvcMatcher(String)} will override previous invocations of {@link #mvcMatcher(String)}}, * {@link #requestMatchers()}, {@link #antMatcher(String)}, * {@link #regexMatcher(String)}, and {@link #requestMatcher(RequestMatcher)}. * </p> * * @param mvcPattern the Spring MVC Pattern to match on (i.e. "/admin/**") * @return the {@link HttpSecurity} for further customizations * @see MvcRequestMatcher */ public HttpSecurity mvcMatcher(String mvcPattern) { HandlerMappingIntrospector introspector = new HandlerMappingIntrospector(getContext()); return requestMatcher(new MvcRequestMatcher(introspector, mvcPattern)); }
@Override public void afterPropertiesSet() { if (this.handlerMappings == null) { Assert.notNull(this.applicationContext, "No ApplicationContext"); this.handlerMappings = initHandlerMappings(this.applicationContext); } }
@Bean @Lazy public HandlerMappingIntrospector mvcHandlerMappingIntrospector() { return new HandlerMappingIntrospector(); }
/** * Constructor that detects the configured {@code HandlerMapping}s in the * given {@code ApplicationContext} or falls back on * "DispatcherServlet.properties" like the {@code DispatcherServlet}. * @deprecated as of 4.3.12, in favor of {@link #setApplicationContext} */ @Deprecated public HandlerMappingIntrospector(ApplicationContext context) { this.handlerMappings = initHandlerMappings(context); }
@SuppressWarnings("deprecation") @Bean public WebMvcMetricsFilter webMetricsFilter(MeterRegistry registry, WebMvcTagsProvider tagsProvider, WebApplicationContext ctx) { return new WebMvcMetricsFilter(registry, tagsProvider, properties.getWeb().getServer().getRequestsMetricName(), properties.getWeb().getServer().isAutoTimeRequests(), new HandlerMappingIntrospector(ctx)); }
@Override public void afterPropertiesSet() { if (this.handlerMappings == null) { Assert.notNull(this.applicationContext, "No ApplicationContext"); this.handlerMappings = initHandlerMappings(this.applicationContext); } }