Java Code Examples for org.springframework.web.servlet.HandlerExecutionChain#getHandler()
The following examples show how to use
org.springframework.web.servlet.HandlerExecutionChain#getHandler() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HandlerMappingIntrospector.java From spring-analysis-note with MIT License | 5 votes |
@Override @Nullable public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { Assert.notNull(this.handlerMappings, "Handler mappings not initialized"); HttpServletRequest wrapper = new RequestAttributeChangeIgnoringWrapper(request); for (HandlerMapping handlerMapping : this.handlerMappings) { HandlerExecutionChain handler = null; try { handler = handlerMapping.getHandler(wrapper); } catch (Exception ex) { // Ignore } if (handler == null) { continue; } if (handler.getInterceptors() != null) { for (HandlerInterceptor interceptor : handler.getInterceptors()) { if (interceptor instanceof CorsConfigurationSource) { return ((CorsConfigurationSource) interceptor).getCorsConfiguration(wrapper); } } } if (handler.getHandler() instanceof CorsConfigurationSource) { return ((CorsConfigurationSource) handler.getHandler()).getCorsConfiguration(wrapper); } } return null; }
Example 2
Source File: WebMvcConfigurationSupportExtensionTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void contentNegotiation() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.json"); NativeWebRequest webRequest = new ServletWebRequest(request); RequestMappingHandlerMapping mapping = this.config.requestMappingHandlerMapping( this.config.mvcContentNegotiationManager(), this.config.mvcConversionService(), this.config.mvcResourceUrlProvider()); ContentNegotiationManager manager = mapping.getContentNegotiationManager(); assertEquals(Collections.singletonList(APPLICATION_JSON), manager.resolveMediaTypes(webRequest)); request.setRequestURI("/foo.xml"); assertEquals(Collections.singletonList(APPLICATION_XML), manager.resolveMediaTypes(webRequest)); request.setRequestURI("/foo.rss"); assertEquals(Collections.singletonList(MediaType.valueOf("application/rss+xml")), manager.resolveMediaTypes(webRequest)); request.setRequestURI("/foo.atom"); assertEquals(Collections.singletonList(APPLICATION_ATOM_XML), manager.resolveMediaTypes(webRequest)); request.setRequestURI("/foo"); request.setParameter("f", "json"); assertEquals(Collections.singletonList(APPLICATION_JSON), manager.resolveMediaTypes(webRequest)); request.setRequestURI("/resources/foo.gif"); SimpleUrlHandlerMapping handlerMapping = (SimpleUrlHandlerMapping) this.config.resourceHandlerMapping( this.config.mvcUrlPathHelper(), this.config.mvcPathMatcher(), this.config.mvcContentNegotiationManager(), this.config.mvcConversionService(), this.config.mvcResourceUrlProvider()); handlerMapping.setApplicationContext(this.context); HandlerExecutionChain chain = handlerMapping.getHandler(request); assertNotNull(chain); ResourceHttpRequestHandler handler = (ResourceHttpRequestHandler) chain.getHandler(); assertNotNull(handler); assertSame(manager, handler.getContentNegotiationManager()); }
Example 3
Source File: HandlerMappingIntrospector.java From java-technology-stack with MIT License | 5 votes |
@Override @Nullable public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { Assert.notNull(this.handlerMappings, "Handler mappings not initialized"); HttpServletRequest wrapper = new RequestAttributeChangeIgnoringWrapper(request); for (HandlerMapping handlerMapping : this.handlerMappings) { HandlerExecutionChain handler = null; try { handler = handlerMapping.getHandler(wrapper); } catch (Exception ex) { // Ignore } if (handler == null) { continue; } if (handler.getInterceptors() != null) { for (HandlerInterceptor interceptor : handler.getInterceptors()) { if (interceptor instanceof CorsConfigurationSource) { return ((CorsConfigurationSource) interceptor).getCorsConfiguration(wrapper); } } } if (handler.getHandler() instanceof CorsConfigurationSource) { return ((CorsConfigurationSource) handler.getHandler()).getCorsConfiguration(wrapper); } } return null; }
Example 4
Source File: WebMvcConfigurationSupportExtensionTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void contentNegotiation() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.json"); NativeWebRequest webRequest = new ServletWebRequest(request); RequestMappingHandlerMapping mapping = this.config.requestMappingHandlerMapping(); ContentNegotiationManager manager = mapping.getContentNegotiationManager(); assertEquals(Collections.singletonList(APPLICATION_JSON), manager.resolveMediaTypes(webRequest)); request.setRequestURI("/foo.xml"); assertEquals(Collections.singletonList(APPLICATION_XML), manager.resolveMediaTypes(webRequest)); request.setRequestURI("/foo.rss"); assertEquals(Collections.singletonList(MediaType.valueOf("application/rss+xml")), manager.resolveMediaTypes(webRequest)); request.setRequestURI("/foo.atom"); assertEquals(Collections.singletonList(APPLICATION_ATOM_XML), manager.resolveMediaTypes(webRequest)); request.setRequestURI("/foo"); request.setParameter("f", "json"); assertEquals(Collections.singletonList(APPLICATION_JSON), manager.resolveMediaTypes(webRequest)); request.setRequestURI("/resources/foo.gif"); SimpleUrlHandlerMapping handlerMapping = (SimpleUrlHandlerMapping) this.config.resourceHandlerMapping(); handlerMapping.setApplicationContext(this.context); HandlerExecutionChain chain = handlerMapping.getHandler(request); assertNotNull(chain); ResourceHttpRequestHandler handler = (ResourceHttpRequestHandler) chain.getHandler(); assertNotNull(handler); assertSame(manager, handler.getContentNegotiationManager()); }
Example 5
Source File: HandlerMappingIntrospector.java From foremast with Apache License 2.0 | 5 votes |
@Override public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { Assert.notNull(this.handlerMappings, "Handler mappings not initialized"); HttpServletRequest wrapper = new RequestAttributeChangeIgnoringWrapper(request); for (HandlerMapping handlerMapping : this.handlerMappings) { HandlerExecutionChain handler = null; try { handler = handlerMapping.getHandler(wrapper); } catch (Exception ex) { // Ignore } if (handler == null) { continue; } if (handler.getInterceptors() != null) { for (HandlerInterceptor interceptor : handler.getInterceptors()) { if (interceptor instanceof CorsConfigurationSource) { return ((CorsConfigurationSource) interceptor).getCorsConfiguration(wrapper); } } } if (handler.getHandler() instanceof CorsConfigurationSource) { return ((CorsConfigurationSource) handler.getHandler()).getCorsConfiguration(wrapper); } } return null; }
Example 6
Source File: HandlerMappingIntrospector.java From foremast with Apache License 2.0 | 5 votes |
@Override public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { Assert.notNull(this.handlerMappings, "Handler mappings not initialized"); HttpServletRequest wrapper = new RequestAttributeChangeIgnoringWrapper(request); for (HandlerMapping handlerMapping : this.handlerMappings) { HandlerExecutionChain handler = null; try { handler = handlerMapping.getHandler(wrapper); } catch (Exception ex) { // Ignore } if (handler == null) { continue; } if (handler.getInterceptors() != null) { for (HandlerInterceptor interceptor : handler.getInterceptors()) { if (interceptor instanceof CorsConfigurationSource) { return ((CorsConfigurationSource) interceptor).getCorsConfiguration(wrapper); } } } if (handler.getHandler() instanceof CorsConfigurationSource) { return ((CorsConfigurationSource) handler.getHandler()).getCorsConfiguration(wrapper); } } return null; }
Example 7
Source File: HandlerMappingIntrospector.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { Assert.notNull(this.handlerMappings, "Handler mappings not initialized"); HttpServletRequest wrapper = new RequestAttributeChangeIgnoringWrapper(request); for (HandlerMapping handlerMapping : this.handlerMappings) { HandlerExecutionChain handler = null; try { handler = handlerMapping.getHandler(wrapper); } catch (Exception ex) { // Ignore } if (handler == null) { continue; } if (handler.getInterceptors() != null) { for (HandlerInterceptor interceptor : handler.getInterceptors()) { if (interceptor instanceof CorsConfigurationSource) { return ((CorsConfigurationSource) interceptor).getCorsConfiguration(wrapper); } } } if (handler.getHandler() instanceof CorsConfigurationSource) { return ((CorsConfigurationSource) handler.getHandler()).getCorsConfiguration(wrapper); } } return null; }
Example 8
Source File: InterceptorInjector.java From gocd with Apache License 2.0 | 5 votes |
public HandlerExecutionChain mergeInterceptorsToTabs(ProceedingJoinPoint pjp) throws Throwable { HandlerExecutionChain handlerExecutionChain = (HandlerExecutionChain) pjp.proceed(); if (handlerExecutionChain == null) { return null; } return new HandlerExecutionChain(handlerExecutionChain.getHandler(), mergeInterceptors(handlerExecutionChain)); }
Example 9
Source File: RequestMappingInfoHandlerMappingTests.java From spring-analysis-note with MIT License | 4 votes |
private HandlerMethod getHandler(MockHttpServletRequest request) throws Exception { HandlerExecutionChain chain = this.handlerMapping.getHandler(request); assertNotNull(chain); return (HandlerMethod) chain.getHandler(); }
Example 10
Source File: RequestMappingInfoHandlerMappingTests.java From java-technology-stack with MIT License | 4 votes |
private HandlerMethod getHandler(MockHttpServletRequest request) throws Exception { HandlerExecutionChain chain = this.handlerMapping.getHandler(request); assertNotNull(chain); return (HandlerMethod) chain.getHandler(); }