org.springframework.web.servlet.handler.SimpleUrlHandlerMapping Java Examples
The following examples show how to use
org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.
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: MvcNamespaceTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testViewControllersDefaultConfig() { loadBeanDefinitions("mvc-config-view-controllers-minimal.xml", 7); SimpleUrlHandlerMapping hm = this.appContext.getBean(SimpleUrlHandlerMapping.class); assertNotNull(hm); ParameterizableViewController viewController = (ParameterizableViewController) hm.getUrlMap().get("/path"); assertNotNull(viewController); assertEquals("home", viewController.getViewName()); ParameterizableViewController redirectViewController = (ParameterizableViewController) hm.getUrlMap().get("/old"); assertNotNull(redirectViewController); assertThat(redirectViewController.getView(), Matchers.instanceOf(RedirectView.class)); ParameterizableViewController statusViewController = (ParameterizableViewController) hm.getUrlMap().get("/bad"); assertNotNull(statusViewController); assertEquals(404, statusViewController.getStatusCode().value()); BeanNameUrlHandlerMapping beanNameMapping = this.appContext.getBean(BeanNameUrlHandlerMapping.class); assertNotNull(beanNameMapping); assertEquals(2, beanNameMapping.getOrder()); }
Example #2
Source File: MvcNamespaceTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testDefaultServletHandler() throws Exception { loadBeanDefinitions("mvc-config-default-servlet.xml"); HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class); assertNotNull(adapter); DefaultServletHttpRequestHandler handler = appContext.getBean(DefaultServletHttpRequestHandler.class); assertNotNull(handler); SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class); assertNotNull(mapping); assertEquals(Ordered.LOWEST_PRECEDENCE, mapping.getOrder()); MockHttpServletRequest request = new MockHttpServletRequest(); request.setRequestURI("/foo.css"); request.setMethod("GET"); HandlerExecutionChain chain = mapping.getHandler(request); assertTrue(chain.getHandler() instanceof DefaultServletHttpRequestHandler); MockHttpServletResponse response = new MockHttpServletResponse(); ModelAndView mv = adapter.handle(request, response, chain.getHandler()); assertNull(mv); }
Example #3
Source File: MvcNamespaceTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testDefaultServletHandlerWithOptionalAttributes() throws Exception { loadBeanDefinitions("mvc-config-default-servlet-optional-attrs.xml"); HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class); assertNotNull(adapter); DefaultServletHttpRequestHandler handler = appContext.getBean(DefaultServletHttpRequestHandler.class); assertNotNull(handler); SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class); assertNotNull(mapping); assertEquals(Ordered.LOWEST_PRECEDENCE, mapping.getOrder()); MockHttpServletRequest request = new MockHttpServletRequest(); request.setRequestURI("/foo.css"); request.setMethod("GET"); HandlerExecutionChain chain = mapping.getHandler(request); assertTrue(chain.getHandler() instanceof DefaultServletHttpRequestHandler); MockHttpServletResponse response = new MockHttpServletResponse(); ModelAndView mv = adapter.handle(request, response, chain.getHandler()); assertNull(mv); }
Example #4
Source File: MvcNamespaceTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testViewControllersDefaultConfig() { loadBeanDefinitions("mvc-config-view-controllers-minimal.xml"); SimpleUrlHandlerMapping hm = this.appContext.getBean(SimpleUrlHandlerMapping.class); assertNotNull(hm); ParameterizableViewController viewController = (ParameterizableViewController) hm.getUrlMap().get("/path"); assertNotNull(viewController); assertEquals("home", viewController.getViewName()); ParameterizableViewController redirectViewController = (ParameterizableViewController) hm.getUrlMap().get("/old"); assertNotNull(redirectViewController); assertThat(redirectViewController.getView(), Matchers.instanceOf(RedirectView.class)); ParameterizableViewController statusViewController = (ParameterizableViewController) hm.getUrlMap().get("/bad"); assertNotNull(statusViewController); assertEquals(404, statusViewController.getStatusCode().value()); BeanNameUrlHandlerMapping beanNameMapping = this.appContext.getBean(BeanNameUrlHandlerMapping.class); assertNotNull(beanNameMapping); assertEquals(2, beanNameMapping.getOrder()); }
Example #5
Source File: MvcNamespaceTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testPathMatchingHandlerMappings() throws Exception { loadBeanDefinitions("mvc-config-path-matching-mappings.xml"); RequestMappingHandlerMapping requestMapping = appContext.getBean(RequestMappingHandlerMapping.class); assertNotNull(requestMapping); assertEquals(TestPathHelper.class, requestMapping.getUrlPathHelper().getClass()); assertEquals(TestPathMatcher.class, requestMapping.getPathMatcher().getClass()); SimpleUrlHandlerMapping viewController = appContext.getBean(VIEWCONTROLLER_BEAN_NAME, SimpleUrlHandlerMapping.class); assertNotNull(viewController); assertEquals(TestPathHelper.class, viewController.getUrlPathHelper().getClass()); assertEquals(TestPathMatcher.class, viewController.getPathMatcher().getClass()); for (SimpleUrlHandlerMapping handlerMapping : appContext.getBeansOfType(SimpleUrlHandlerMapping.class).values()) { assertNotNull(handlerMapping); assertEquals(TestPathHelper.class, handlerMapping.getUrlPathHelper().getClass()); assertEquals(TestPathMatcher.class, handlerMapping.getPathMatcher().getClass()); } }
Example #6
Source File: ResourceUrlProvider.java From java-technology-stack with MIT License | 6 votes |
protected void detectResourceHandlers(ApplicationContext appContext) { Map<String, SimpleUrlHandlerMapping> beans = appContext.getBeansOfType(SimpleUrlHandlerMapping.class); List<SimpleUrlHandlerMapping> mappings = new ArrayList<>(beans.values()); AnnotationAwareOrderComparator.sort(mappings); for (SimpleUrlHandlerMapping mapping : mappings) { for (String pattern : mapping.getHandlerMap().keySet()) { Object handler = mapping.getHandlerMap().get(pattern); if (handler instanceof ResourceHttpRequestHandler) { ResourceHttpRequestHandler resourceHandler = (ResourceHttpRequestHandler) handler; this.handlerMap.put(pattern, resourceHandler); } } } if (this.handlerMap.isEmpty()) { logger.trace("No resource handling mappings found"); } }
Example #7
Source File: DefaultServletHandlerConfigurerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void enable() throws Exception { configurer.enable(); SimpleUrlHandlerMapping getHandlerMapping = getHandlerMapping(); SimpleUrlHandlerMapping handlerMapping = getHandlerMapping; DefaultServletHttpRequestHandler handler = (DefaultServletHttpRequestHandler) handlerMapping.getUrlMap().get("/**"); assertNotNull(handler); assertEquals(Integer.MAX_VALUE, handlerMapping.getOrder()); handler.handleRequest(new MockHttpServletRequest(), response); String expected = "default"; assertEquals("The ServletContext was not called with the default servlet name", expected, servletContext.url); assertEquals("The request was not forwarded", expected, response.getForwardedUrl()); }
Example #8
Source File: ViewControllerBeanDefinitionParser.java From java-technology-stack with MIT License | 6 votes |
private BeanDefinition registerHandlerMapping(ParserContext context, @Nullable Object source) { if (context.getRegistry().containsBeanDefinition(HANDLER_MAPPING_BEAN_NAME)) { return context.getRegistry().getBeanDefinition(HANDLER_MAPPING_BEAN_NAME); } RootBeanDefinition beanDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class); beanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); context.getRegistry().registerBeanDefinition(HANDLER_MAPPING_BEAN_NAME, beanDef); context.registerComponent(new BeanComponentDefinition(beanDef, HANDLER_MAPPING_BEAN_NAME)); beanDef.setSource(source); beanDef.getPropertyValues().add("order", "1"); beanDef.getPropertyValues().add("pathMatcher", MvcNamespaceUtils.registerPathMatcher(null, context, source)); beanDef.getPropertyValues().add("urlPathHelper", MvcNamespaceUtils.registerUrlPathHelper(null, context, source)); RuntimeBeanReference corsConfigurationsRef = MvcNamespaceUtils.registerCorsConfigurations(null, context, source); beanDef.getPropertyValues().add("corsConfigurations", corsConfigurationsRef); return beanDef; }
Example #9
Source File: MvcNamespaceTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testDefaultServletHandler() throws Exception { loadBeanDefinitions("mvc-config-default-servlet.xml"); HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class); assertNotNull(adapter); DefaultServletHttpRequestHandler handler = appContext.getBean(DefaultServletHttpRequestHandler.class); assertNotNull(handler); SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class); assertNotNull(mapping); assertEquals(Ordered.LOWEST_PRECEDENCE, mapping.getOrder()); MockHttpServletRequest request = new MockHttpServletRequest(); request.setRequestURI("/foo.css"); request.setMethod("GET"); HandlerExecutionChain chain = mapping.getHandler(request); assertTrue(chain.getHandler() instanceof DefaultServletHttpRequestHandler); MockHttpServletResponse response = new MockHttpServletResponse(); ModelAndView mv = adapter.handle(request, response, chain.getHandler()); assertNull(mv); }
Example #10
Source File: MvcNamespaceTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testViewControllersDefaultConfig() { loadBeanDefinitions("mvc-config-view-controllers-minimal.xml"); SimpleUrlHandlerMapping hm = this.appContext.getBean(SimpleUrlHandlerMapping.class); assertNotNull(hm); ParameterizableViewController viewController = (ParameterizableViewController) hm.getUrlMap().get("/path"); assertNotNull(viewController); assertEquals("home", viewController.getViewName()); ParameterizableViewController redirectViewController = (ParameterizableViewController) hm.getUrlMap().get("/old"); assertNotNull(redirectViewController); assertThat(redirectViewController.getView(), Matchers.instanceOf(RedirectView.class)); ParameterizableViewController statusViewController = (ParameterizableViewController) hm.getUrlMap().get("/bad"); assertNotNull(statusViewController); assertEquals(404, statusViewController.getStatusCode().value()); BeanNameUrlHandlerMapping beanNameMapping = this.appContext.getBean(BeanNameUrlHandlerMapping.class); assertNotNull(beanNameMapping); assertEquals(2, beanNameMapping.getOrder()); }
Example #11
Source File: MvcNamespaceTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testPathMatchingHandlerMappings() throws Exception { loadBeanDefinitions("mvc-config-path-matching-mappings.xml"); RequestMappingHandlerMapping requestMapping = appContext.getBean(RequestMappingHandlerMapping.class); assertNotNull(requestMapping); assertEquals(TestPathHelper.class, requestMapping.getUrlPathHelper().getClass()); assertEquals(TestPathMatcher.class, requestMapping.getPathMatcher().getClass()); SimpleUrlHandlerMapping viewController = appContext.getBean(VIEWCONTROLLER_BEAN_NAME, SimpleUrlHandlerMapping.class); assertNotNull(viewController); assertEquals(TestPathHelper.class, viewController.getUrlPathHelper().getClass()); assertEquals(TestPathMatcher.class, viewController.getPathMatcher().getClass()); for (SimpleUrlHandlerMapping handlerMapping : appContext.getBeansOfType(SimpleUrlHandlerMapping.class).values()) { assertNotNull(handlerMapping); assertEquals(TestPathHelper.class, handlerMapping.getUrlPathHelper().getClass()); assertEquals(TestPathMatcher.class, handlerMapping.getPathMatcher().getClass()); } }
Example #12
Source File: ViewControllerBeanDefinitionParser.java From lams with GNU General Public License v2.0 | 6 votes |
private BeanDefinition registerHandlerMapping(ParserContext context, Object source) { if (context.getRegistry().containsBeanDefinition(HANDLER_MAPPING_BEAN_NAME)) { return context.getRegistry().getBeanDefinition(HANDLER_MAPPING_BEAN_NAME); } RootBeanDefinition beanDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class); beanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); context.getRegistry().registerBeanDefinition(HANDLER_MAPPING_BEAN_NAME, beanDef); context.registerComponent(new BeanComponentDefinition(beanDef, HANDLER_MAPPING_BEAN_NAME)); beanDef.setSource(source); beanDef.getPropertyValues().add("order", "1"); beanDef.getPropertyValues().add("pathMatcher", MvcNamespaceUtils.registerPathMatcher(null, context, source)); beanDef.getPropertyValues().add("urlPathHelper", MvcNamespaceUtils.registerUrlPathHelper(null, context, source)); RuntimeBeanReference corsConfigurationsRef = MvcNamespaceUtils.registerCorsConfigurations(null, context, source); beanDef.getPropertyValues().add("corsConfigurations", corsConfigurationsRef); return beanDef; }
Example #13
Source File: ResourceUrlProvider.java From spring4-understanding with Apache License 2.0 | 6 votes |
protected void detectResourceHandlers(ApplicationContext appContext) { logger.debug("Looking for resource handler mappings"); Map<String, SimpleUrlHandlerMapping> map = appContext.getBeansOfType(SimpleUrlHandlerMapping.class); List<SimpleUrlHandlerMapping> handlerMappings = new ArrayList<SimpleUrlHandlerMapping>(map.values()); AnnotationAwareOrderComparator.sort(handlerMappings); for (SimpleUrlHandlerMapping hm : handlerMappings) { for (String pattern : hm.getHandlerMap().keySet()) { Object handler = hm.getHandlerMap().get(pattern); if (handler instanceof ResourceHttpRequestHandler) { ResourceHttpRequestHandler resourceHandler = (ResourceHttpRequestHandler) handler; if (logger.isDebugEnabled()) { logger.debug("Found resource handler mapping: URL pattern=\"" + pattern + "\", " + "locations=" + resourceHandler.getLocations() + ", " + "resolvers=" + resourceHandler.getResourceResolvers()); } this.handlerMap.put(pattern, resourceHandler); } } } }
Example #14
Source File: ViewControllerBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 6 votes |
private BeanDefinition registerHandlerMapping(ParserContext context, Object source) { if (context.getRegistry().containsBeanDefinition(HANDLER_MAPPING_BEAN_NAME)) { return context.getRegistry().getBeanDefinition(HANDLER_MAPPING_BEAN_NAME); } RootBeanDefinition beanDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class); beanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); context.getRegistry().registerBeanDefinition(HANDLER_MAPPING_BEAN_NAME, beanDef); context.registerComponent(new BeanComponentDefinition(beanDef, HANDLER_MAPPING_BEAN_NAME)); beanDef.setSource(source); beanDef.getPropertyValues().add("order", "1"); beanDef.getPropertyValues().add("pathMatcher", MvcNamespaceUtils.registerPathMatcher(null, context, source)); beanDef.getPropertyValues().add("urlPathHelper", MvcNamespaceUtils.registerUrlPathHelper(null, context, source)); RuntimeBeanReference corsConfigurationsRef = MvcNamespaceUtils.registerCorsConfigurations(null, context, source); beanDef.getPropertyValues().add("corsConfigurations", corsConfigurationsRef); return beanDef; }
Example #15
Source File: MvcNamespaceTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testDefaultServletHandler() throws Exception { loadBeanDefinitions("mvc-config-default-servlet.xml", 6); HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class); assertNotNull(adapter); DefaultServletHttpRequestHandler handler = appContext.getBean(DefaultServletHttpRequestHandler.class); assertNotNull(handler); SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class); assertNotNull(mapping); assertEquals(Ordered.LOWEST_PRECEDENCE, mapping.getOrder()); MockHttpServletRequest request = new MockHttpServletRequest(); request.setRequestURI("/foo.css"); request.setMethod("GET"); HandlerExecutionChain chain = mapping.getHandler(request); assertTrue(chain.getHandler() instanceof DefaultServletHttpRequestHandler); MockHttpServletResponse response = new MockHttpServletResponse(); ModelAndView mv = adapter.handle(request, response, chain.getHandler()); assertNull(mv); }
Example #16
Source File: MvcNamespaceTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testDefaultServletHandlerWithOptionalAttributes() throws Exception { loadBeanDefinitions("mvc-config-default-servlet-optional-attrs.xml"); HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class); assertNotNull(adapter); DefaultServletHttpRequestHandler handler = appContext.getBean(DefaultServletHttpRequestHandler.class); assertNotNull(handler); SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class); assertNotNull(mapping); assertEquals(Ordered.LOWEST_PRECEDENCE, mapping.getOrder()); MockHttpServletRequest request = new MockHttpServletRequest(); request.setRequestURI("/foo.css"); request.setMethod("GET"); HandlerExecutionChain chain = mapping.getHandler(request); assertTrue(chain.getHandler() instanceof DefaultServletHttpRequestHandler); MockHttpServletResponse response = new MockHttpServletResponse(); ModelAndView mv = adapter.handle(request, response, chain.getHandler()); assertNull(mv); }
Example #17
Source File: MvcNamespaceTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testDefaultServletHandlerWithOptionalAttributes() throws Exception { loadBeanDefinitions("mvc-config-default-servlet-optional-attrs.xml", 6); HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class); assertNotNull(adapter); DefaultServletHttpRequestHandler handler = appContext.getBean(DefaultServletHttpRequestHandler.class); assertNotNull(handler); SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class); assertNotNull(mapping); assertEquals(Ordered.LOWEST_PRECEDENCE, mapping.getOrder()); MockHttpServletRequest request = new MockHttpServletRequest(); request.setRequestURI("/foo.css"); request.setMethod("GET"); HandlerExecutionChain chain = mapping.getHandler(request); assertTrue(chain.getHandler() instanceof DefaultServletHttpRequestHandler); MockHttpServletResponse response = new MockHttpServletResponse(); ModelAndView mv = adapter.handle(request, response, chain.getHandler()); assertNull(mv); }
Example #18
Source File: ResourceUrlProvider.java From spring-analysis-note with MIT License | 6 votes |
protected void detectResourceHandlers(ApplicationContext appContext) { Map<String, SimpleUrlHandlerMapping> beans = appContext.getBeansOfType(SimpleUrlHandlerMapping.class); List<SimpleUrlHandlerMapping> mappings = new ArrayList<>(beans.values()); AnnotationAwareOrderComparator.sort(mappings); for (SimpleUrlHandlerMapping mapping : mappings) { for (String pattern : mapping.getHandlerMap().keySet()) { Object handler = mapping.getHandlerMap().get(pattern); if (handler instanceof ResourceHttpRequestHandler) { ResourceHttpRequestHandler resourceHandler = (ResourceHttpRequestHandler) handler; this.handlerMap.put(pattern, resourceHandler); } } } if (this.handlerMap.isEmpty()) { logger.trace("No resource handling mappings found"); } }
Example #19
Source File: HandlersBeanDefinitionParserTests.java From java-technology-stack with MIT License | 5 votes |
@Test @SuppressWarnings("unchecked") public void sockJsAttributes() { loadBeanDefinitions("websocket-config-handlers-sockjs-attributes.xml"); SimpleUrlHandlerMapping handlerMapping = appContext.getBean(SimpleUrlHandlerMapping.class); assertNotNull(handlerMapping); SockJsHttpRequestHandler handler = (SockJsHttpRequestHandler) handlerMapping.getUrlMap().get("/test/**"); assertNotNull(handler); unwrapAndCheckDecoratedHandlerType(handler.getWebSocketHandler(), TestWebSocketHandler.class); SockJsService sockJsService = handler.getSockJsService(); assertNotNull(sockJsService); assertThat(sockJsService, instanceOf(TransportHandlingSockJsService.class)); TransportHandlingSockJsService transportService = (TransportHandlingSockJsService) sockJsService; assertThat(transportService.getTaskScheduler(), instanceOf(TestTaskScheduler.class)); assertThat(transportService.getTransportHandlers().values(), containsInAnyOrder( instanceOf(XhrPollingTransportHandler.class), instanceOf(XhrStreamingTransportHandler.class))); assertEquals("testSockJsService", transportService.getName()); assertFalse(transportService.isWebSocketEnabled()); assertFalse(transportService.isSessionCookieNeeded()); assertEquals(2048, transportService.getStreamBytesLimit()); assertEquals(256, transportService.getDisconnectDelay()); assertEquals(1024, transportService.getHttpMessageCacheSize()); assertEquals(20, transportService.getHeartbeatTime()); assertEquals("/js/sockjs.min.js", transportService.getSockJsClientLibraryUrl()); assertEquals(TestMessageCodec.class, transportService.getMessageCodec().getClass()); List<HandshakeInterceptor> interceptors = transportService.getHandshakeInterceptors(); assertThat(interceptors, contains(instanceOf(OriginHandshakeInterceptor.class))); assertTrue(transportService.shouldSuppressCors()); assertTrue(transportService.getAllowedOrigins().contains("http://mydomain1.com")); assertTrue(transportService.getAllowedOrigins().contains("http://mydomain2.com")); }
Example #20
Source File: ViewControllerRegistryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void order() { this.registry.addViewController("/path"); SimpleUrlHandlerMapping handlerMapping = this.registry.buildHandlerMapping(); assertEquals(1, handlerMapping.getOrder()); this.registry.setOrder(2); handlerMapping = this.registry.buildHandlerMapping(); assertEquals(2, handlerMapping.getOrder()); }
Example #21
Source File: DefaultServletHandlerConfigurerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void enableWithServletName() throws Exception { configurer.enable("defaultServlet"); SimpleUrlHandlerMapping handlerMapping = configurer.buildHandlerMapping(); DefaultServletHttpRequestHandler handler = (DefaultServletHttpRequestHandler) handlerMapping.getUrlMap().get("/**"); assertNotNull(handler); assertEquals(Integer.MAX_VALUE, handlerMapping.getOrder()); handler.handleRequest(new MockHttpServletRequest(), response); String expected = "defaultServlet"; assertEquals("The ServletContext was not called with the default servlet name", expected, servletContext.url); assertEquals("The request was not forwarded", expected, response.getForwardedUrl()); }
Example #22
Source File: ServletConfiguration.java From airsonic-advanced with GNU General Public License v3.0 | 5 votes |
@Bean public SimpleUrlHandlerMapping podcastMapping(PodcastController podcastController) { SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); mapping.setAlwaysUseFullPath(true); Properties properties = new Properties(); properties.put("/podcast/**", podcastController); mapping.setMappings(properties); return mapping; }
Example #23
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 #24
Source File: ServletConfiguration.java From airsonic with GNU General Public License v3.0 | 5 votes |
@Bean public SimpleUrlHandlerMapping podcastUrlMapping(PodcastController podcastController) { SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping(); handlerMapping.setAlwaysUseFullPath(true); Properties properties = new Properties(); properties.put("/podcast/**", podcastController); handlerMapping.setMappings(properties); return handlerMapping; }
Example #25
Source File: WebSocketMessageBrokerConfigurationSupportTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void handlerMapping() { ApplicationContext config = createConfig(TestChannelConfig.class, TestConfigurer.class); SimpleUrlHandlerMapping hm = (SimpleUrlHandlerMapping) config.getBean(HandlerMapping.class); assertEquals(1, hm.getOrder()); Map<String, Object> handlerMap = hm.getHandlerMap(); assertEquals(1, handlerMap.size()); assertNotNull(handlerMap.get("/simpleBroker")); }
Example #26
Source File: DefaultServletHandlerConfigurer.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Return a handler mapping instance ordered at {@link Integer#MAX_VALUE} containing the * {@link DefaultServletHttpRequestHandler} instance mapped to {@code "/**"}; * or {@code null} if default servlet handling was not been enabled. * @since 4.3.12 */ protected SimpleUrlHandlerMapping buildHandlerMapping() { if (this.handler == null) { return null; } SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping(); handlerMapping.setUrlMap(Collections.singletonMap("/**", this.handler)); handlerMapping.setOrder(Integer.MAX_VALUE); return handlerMapping; }
Example #27
Source File: ResourceHandlerRegistry.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Return a handler mapping with the mapped resource handlers; or {@code null} in case * of no registrations. */ protected AbstractHandlerMapping getHandlerMapping() { if (this.registrations.isEmpty()) { return null; } Map<String, HttpRequestHandler> urlMap = new LinkedHashMap<String, HttpRequestHandler>(); for (ResourceHandlerRegistration registration : this.registrations) { for (String pathPattern : registration.getPathPatterns()) { ResourceHttpRequestHandler handler = registration.getRequestHandler(); handler.setServletContext(this.servletContext); handler.setApplicationContext(this.applicationContext); handler.setContentNegotiationManager(this.contentNegotiationManager); try { handler.afterPropertiesSet(); } catch (Throwable ex) { throw new BeanInitializationException("Failed to init ResourceHttpRequestHandler", ex); } urlMap.put(pathPattern, handler); } } SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping(); handlerMapping.setOrder(order); handlerMapping.setUrlMap(urlMap); return handlerMapping; }
Example #28
Source File: HandlerMappingPrioritiesConfig.java From tutorials with MIT License | 5 votes |
@Bean public SimpleUrlHandlerMapping simpleUrlHandlerMappingOrder0() { SimpleUrlHandlerMapping simpleUrlHandlerMapping = new SimpleUrlHandlerMapping(); simpleUrlHandlerMapping.setOrder(0); Map<String, Object> urlMap = new HashMap<>(); urlMap.put("/welcome", simpleUrlMapping()); simpleUrlHandlerMapping.setUrlMap(urlMap); return simpleUrlHandlerMapping; }
Example #29
Source File: MVCConf.java From codenjoy with GNU General Public License v3.0 | 5 votes |
@Bean public SimpleUrlHandlerMapping sampleServletMapping(){ return new SimpleUrlHandlerMapping(){{ setOrder(Integer.MAX_VALUE - 2); setMappings(new Properties(){{ put(RESOURCES_URI, "resourceHttpRequestHandler"); }}); }}; }
Example #30
Source File: BlazeDsAutoConfiguration.java From flex-blazeds with Apache License 2.0 | 5 votes |
/** * Tell the Dispatcher Servlet to redirect any requests in the * "/messagebroker/" context to the BlazeDS MessageBroker. * * @return SimpleUrlHandlerMapping instance. */ @Bean public SimpleUrlHandlerMapping sampleServletMapping() { SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); mapping.setOrder(Integer.MAX_VALUE - 2); Properties urlProperties = new Properties(); urlProperties.put("/messagebroker/*", "_messageBroker"); mapping.setMappings(urlProperties); return mapping; }