org.springframework.web.reactive.handler.SimpleUrlHandlerMapping Java Examples
The following examples show how to use
org.springframework.web.reactive.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: WebSocketConfig.java From Learning-Spring-Boot-2.0-Second-Edition with MIT License | 6 votes |
@Bean HandlerMapping webSocketMapping(CommentService commentService) { Map<String, WebSocketHandler> urlMap = new HashMap<>(); urlMap.put("/topic/comments.new", commentService); Map<String, CorsConfiguration> corsConfigurationMap = new HashMap<>(); CorsConfiguration corsConfiguration = new CorsConfiguration(); corsConfiguration.addAllowedOrigin("http://localhost:8080"); corsConfigurationMap.put( "/topic/comments.new", corsConfiguration); SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); mapping.setOrder(10); mapping.setUrlMap(urlMap); mapping.setCorsConfigurations(corsConfigurationMap); return mapping; }
Example #2
Source File: ResourceUrlProvider.java From spring-analysis-note with MIT License | 6 votes |
private void detectResourceHandlers(ApplicationContext context) { Map<String, SimpleUrlHandlerMapping> beans = context.getBeansOfType(SimpleUrlHandlerMapping.class); List<SimpleUrlHandlerMapping> mappings = new ArrayList<>(beans.values()); AnnotationAwareOrderComparator.sort(mappings); mappings.forEach(mapping -> mapping.getHandlerMap().forEach((pattern, handler) -> { if (handler instanceof ResourceWebHandler) { ResourceWebHandler resourceHandler = (ResourceWebHandler) handler; this.handlerMap.put(pattern, resourceHandler); } })); if (this.handlerMap.isEmpty()) { logger.trace("No resource handling mappings found"); } }
Example #3
Source File: SimpleUrlHandlerMappingIntegrationTests.java From spring-analysis-note with MIT License | 6 votes |
@Bean public SimpleUrlHandlerMapping handlerMapping() { return new SimpleUrlHandlerMapping() { { Map<String, Object> map = new HashMap<>(); map.put("/foo", (WebHandler) exchange -> exchange.getResponse().writeWith(Flux.just(asDataBuffer("foo")))); map.put("/bar", (WebHandler) exchange -> exchange.getResponse().writeWith(Flux.just(asDataBuffer("bar")))); map.put("/header", (WebHandler) exchange -> { exchange.getResponse().getHeaders().add("foo", "bar"); return Mono.empty(); }); setUrlMap(map); } }; }
Example #4
Source File: WebSocketMessagingHandlerConfiguration.java From jetlinks-community with Apache License 2.0 | 6 votes |
@Bean public HandlerMapping webSocketMessagingHandlerMapping(MessagingManager messagingManager, UserTokenManager userTokenManager, ReactiveAuthenticationManager authenticationManager) { WebSocketMessagingHandler messagingHandler=new WebSocketMessagingHandler( messagingManager, userTokenManager, authenticationManager ); final Map<String, WebSocketHandler> map = new HashMap<>(1); map.put("/messaging/**", messagingHandler); final SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); mapping.setOrder(Ordered.HIGHEST_PRECEDENCE); mapping.setUrlMap(map); return mapping; }
Example #5
Source File: ResourceUrlProvider.java From java-technology-stack with MIT License | 6 votes |
private void detectResourceHandlers(ApplicationContext context) { Map<String, SimpleUrlHandlerMapping> beans = context.getBeansOfType(SimpleUrlHandlerMapping.class); List<SimpleUrlHandlerMapping> mappings = new ArrayList<>(beans.values()); AnnotationAwareOrderComparator.sort(mappings); mappings.forEach(mapping -> mapping.getHandlerMap().forEach((pattern, handler) -> { if (handler instanceof ResourceWebHandler) { ResourceWebHandler resourceHandler = (ResourceWebHandler) handler; this.handlerMap.put(pattern, resourceHandler); } })); if (this.handlerMap.isEmpty()) { logger.trace("No resource handling mappings found"); } }
Example #6
Source File: WebSocketConfig.java From Learning-Spring-Boot-2.0-Second-Edition with MIT License | 6 votes |
@Bean HandlerMapping webSocketMapping(CommentService commentService, InboundChatService inboundChatService, OutboundChatService outboundChatService) { SimpleUrlHandlerMapping mapping = configureUrlMappings(commentService, inboundChatService, outboundChatService); Map<String, CorsConfiguration> corsConfigurationMap = new HashMap<>(); CorsConfiguration corsConfiguration = new CorsConfiguration(); corsConfiguration.addAllowedOrigin(chatConfigProperties.getOrigin()); mapping.getUrlMap().keySet().forEach(route -> corsConfigurationMap.put(route, corsConfiguration) ); mapping.setCorsConfigurations(corsConfigurationMap); return mapping; }
Example #7
Source File: WebSocketIT.java From vertx-spring-boot with Apache License 2.0 | 6 votes |
@Bean public HandlerMapping handlerMapping() { Map<String, WebSocketHandler> map = new HashMap<>(); map.put("/echo", this::echoHandler); map.put("/sink", this::sinkHandler); map.put("/double-producer", this::doubleProducerHandler); map.put("/close", this::closeHandler); SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); mapping.setUrlMap(map); mapping.setOrder(-1); CorsConfiguration cors = new CorsConfiguration(); cors.addAllowedOrigin("http://snowdrop.dev"); mapping.setCorsConfigurations(Collections.singletonMap("/sink", cors)); return mapping; }
Example #8
Source File: SimpleUrlHandlerMappingIntegrationTests.java From java-technology-stack with MIT License | 6 votes |
@Bean public SimpleUrlHandlerMapping handlerMapping() { return new SimpleUrlHandlerMapping() { { Map<String, Object> map = new HashMap<>(); map.put("/foo", (WebHandler) exchange -> exchange.getResponse().writeWith(Flux.just(asDataBuffer("foo")))); map.put("/bar", (WebHandler) exchange -> exchange.getResponse().writeWith(Flux.just(asDataBuffer("bar")))); map.put("/header", (WebHandler) exchange -> { exchange.getResponse().getHeaders().add("foo", "bar"); return Mono.empty(); }); setUrlMap(map); } }; }
Example #9
Source File: ReactiveChatSocketConfig.java From Spring-5.0-Cookbook with MIT License | 5 votes |
@Bean public HandlerMapping webSocketMapping() { Map<String, WebSocketHandler> map = new HashMap<>(); map.put("/react", messageWebSocketHandler); SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); mapping.setOrder(10); mapping.setUrlMap(map); return mapping; }
Example #10
Source File: WebSocketConfig.java From Learning-Spring-Boot-2.0-Second-Edition with MIT License | 5 votes |
@Bean HandlerMapping webSocketMapping(CommentService commentService, InboundChatService inboundChatService, OutboundChatService outboundChatService) { Map<String, WebSocketHandler> urlMap = new HashMap<>(); urlMap.put("/topic/comments.new", commentService); urlMap.put("/app/chatMessage.new", inboundChatService); urlMap.put("/topic/chatMessage.new", outboundChatService); SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); mapping.setOrder(10); mapping.setUrlMap(urlMap); return mapping; }
Example #11
Source File: WebSocketConfig.java From Learning-Spring-Boot-2.0-Second-Edition with MIT License | 5 votes |
@Bean HandlerMapping webSocketMapping(CommentService commentService, InboundChatService inboundChatService, OutboundChatService outboundChatService) { Map<String, WebSocketHandler> urlMap = new HashMap<>(); urlMap.put("/topic/comments.new", commentService); urlMap.put("/app/chatMessage.new", inboundChatService); urlMap.put("/topic/chatMessage.new", outboundChatService); Map<String, CorsConfiguration> corsConfigurationMap = new HashMap<>(); CorsConfiguration corsConfiguration = new CorsConfiguration(); corsConfiguration.addAllowedOrigin("http://localhost:8080"); corsConfigurationMap.put( "/topic/comments.new", corsConfiguration); corsConfigurationMap.put( "/app/chatMessage.new", corsConfiguration); corsConfigurationMap.put( "/topic/chatMessage.new", corsConfiguration); SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); mapping.setOrder(10); mapping.setUrlMap(urlMap); mapping.setCorsConfigurations(corsConfigurationMap); return mapping; }
Example #12
Source File: WebSocketConfig.java From Learning-Spring-Boot-2.0-Second-Edition with MIT License | 5 votes |
@Bean HandlerMapping webSocketMapping(CommentService commentService, InboundChatService inboundChatService, OutboundChatService outboundChatService) { Map<String, WebSocketHandler> urlMap = new HashMap<>(); urlMap.put("/topic/comments.new", commentService); urlMap.put("/app/chatMessage.new", inboundChatService); urlMap.put("/topic/chatMessage.new", outboundChatService); // tag::cors[] Map<String, CorsConfiguration> corsConfigurationMap = new HashMap<>(); CorsConfiguration corsConfiguration = new CorsConfiguration(); corsConfiguration.addAllowedOrigin("http://localhost:8080"); corsConfigurationMap.put( "/topic/comments.new", corsConfiguration); corsConfigurationMap.put( "/app/chatMessage.new", corsConfiguration); corsConfigurationMap.put( "/topic/chatMessage.new", corsConfiguration); // end::cors[] SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); mapping.setOrder(10); mapping.setUrlMap(urlMap); mapping.setCorsConfigurations(corsConfigurationMap); return mapping; }
Example #13
Source File: WebSocketConfig.java From Learning-Spring-Boot-2.0-Second-Edition with MIT License | 5 votes |
private static SimpleUrlHandlerMapping configureUrlMappings(CommentService commentService, InboundChatService inboundChatService, OutboundChatService outboundChatService) { Map<String, WebSocketHandler> urlMap = new HashMap<>(); urlMap.put("/topic/comments.new", commentService); urlMap.put("/app/chatMessage.new", inboundChatService); urlMap.put("/topic/chatMessage.new", outboundChatService); SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); mapping.setOrder(10); mapping.setUrlMap(urlMap); return mapping; }
Example #14
Source File: ReservationServiceApplication.java From bootiful-reactive-microservices with Apache License 2.0 | 5 votes |
@Bean HandlerMapping hm() { SimpleUrlHandlerMapping simpleUrlHandlerMapping = new SimpleUrlHandlerMapping(); simpleUrlHandlerMapping.setOrder(10); simpleUrlHandlerMapping.setUrlMap(Collections.singletonMap("/ws/greetings", this.wsh())); return simpleUrlHandlerMapping; }
Example #15
Source File: ReservationServiceApplication.java From bootiful-reactive-microservices with Apache License 2.0 | 5 votes |
@Bean SimpleUrlHandlerMapping simpleUrlHandlerMapping(WebSocketHandler wsh) { return new SimpleUrlHandlerMapping() { { setOrder(10); setUrlMap(Map.of("/ws/greetings", wsh)); } }; }
Example #16
Source File: WebSocketConfiguration.java From Hands-On-Reactive-Programming-in-Spring-5 with MIT License | 5 votes |
@Bean public HandlerMapping handlerMapping() { SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); mapping.setUrlMap(Collections.singletonMap("/ws/echo", new EchoWebSocketHandler())); mapping.setOrder(-1); return mapping; }
Example #17
Source File: WebConfig.java From spring-reactive-sample with GNU General Public License v3.0 | 5 votes |
@Bean public HandlerMapping handlerMapping() { Map<String, WebSocketHandler> map = new HashMap<>(); map.put("/echo", new EchoWebSocketHandler()); map.put("/posts", new PostsWebSocketHandler(this.posts)); // map.put("/custom-header", new CustomHeaderHandler()); SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); mapping.setUrlMap(map); return mapping; }
Example #18
Source File: WebSocketConfiguration.java From springboot-learning-example with Apache License 2.0 | 5 votes |
@Autowired @Bean public HandlerMapping webSocketMapping(final EchoHandler echoHandler) { final Map<String, WebSocketHandler> map = new HashMap<>(); map.put("/echo", echoHandler); final SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); mapping.setOrder(Ordered.HIGHEST_PRECEDENCE); mapping.setUrlMap(map); return mapping; }
Example #19
Source File: WebSocketConfiguration.java From tools-journey with Apache License 2.0 | 5 votes |
@Autowired @Bean public HandlerMapping webSocketMapping(final EchoHandler echoHandler) { final Map<String, WebSocketHandler> map = new HashMap<>(1); map.put("/objectecho", echoHandler); final SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); mapping.setOrder(Ordered.HIGHEST_PRECEDENCE); mapping.setUrlMap(map); return mapping; }
Example #20
Source File: WebSocketIntegrationTests.java From spring-cloud-gateway with Apache License 2.0 | 5 votes |
@Bean public HandlerMapping handlerMapping() { Map<String, WebSocketHandler> map = new HashMap<>(); map.put("/echo", new EchoWebSocketHandler()); map.put("/echoForHttp", new EchoWebSocketHandler()); map.put("/sub-protocol", new SubProtocolWebSocketHandler()); map.put("/custom-header", new CustomHeaderHandler()); map.put("/close", new SessionClosingHandler()); SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); mapping.setUrlMap(map); return mapping; }
Example #21
Source File: Application.java From spring-reactive-playground with Apache License 2.0 | 5 votes |
@Bean public HandlerMapping handlerMapping() { Map<String, WebSocketHandler> map = new HashMap<>(); map.put("/websocket/echo", new EchoWebSocketHandler()); SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); mapping.setUrlMap(map); return mapping; }
Example #22
Source File: EmployeeConfig.java From tutorials with MIT License | 5 votes |
@Bean public HandlerMapping handlerMapping() { Map<String, WebSocketHandler> map = new HashMap<>(); map.put("/employee-feed", new EmployeeWebSocketHandler()); SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); mapping.setUrlMap(map); mapping.setOrder(10); return mapping; }
Example #23
Source File: ReactiveWebSocketConfiguration.java From tutorials with MIT License | 5 votes |
@Bean public HandlerMapping webSocketHandlerMapping() { Map<String, WebSocketHandler> map = new HashMap<>(); map.put("/event-emitter", webSocketHandler); SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping(); handlerMapping.setOrder(1); handlerMapping.setUrlMap(map); return handlerMapping; }
Example #24
Source File: ServiceInstanceLogStreamAutoConfiguration.java From spring-cloud-app-broker with Apache License 2.0 | 5 votes |
@Bean public HandlerMapping logsHandlerMapping(StreamingLogWebSocketHandler webSocketHandler) { Map<String, WebSocketHandler> map = new HashMap<>(); map.put("/logs/**/stream", webSocketHandler); SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping(); handlerMapping.setOrder(1); handlerMapping.setUrlMap(map); return handlerMapping; }
Example #25
Source File: WebSocketConfiguration.java From reactor-workshop with GNU General Public License v3.0 | 5 votes |
@Bean public HandlerMapping handlerMapping() { Map<String, WebSocketHandler> map = Map.of( "/echo", new EchoHandler(), "/time", new TimeHandler() ); SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); mapping.setUrlMap(map); mapping.setOrder(-1); return mapping; }
Example #26
Source File: SpringWebFluxDemoApplication.java From Spring-5.0-Projects with MIT License | 5 votes |
@Bean public HandlerMapping webSockertHandlerMapping() { Map<String, WebSocketHandler> map = new HashMap<>(); map.put("/student", studentWebSocketHandler); SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); mapping.setUrlMap(map); return mapping; }
Example #27
Source File: WebSocketRouter.java From webFluxTemplate with MIT License | 5 votes |
@Bean public HandlerMapping handlerMapping() { Map<String, WebSocketHandler> map = new HashMap<>(); map.put("/api/ws/echotest", new DefaultWebSocketHandler()); SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); mapping.initApplicationContext(); mapping.setOrder(10); mapping.setUrlMap(map); return mapping; }
Example #28
Source File: ReactiveWebSocketConfig.java From spring-redis-websocket with Apache License 2.0 | 5 votes |
@Bean public HandlerMapping webSocketHandlerMapping(ChatWebSocketHandler webSocketHandler) { Map<String, WebSocketHandler> map = new HashMap<>(); map.put(WEBSOCKET_MESSAGE_MAPPING, webSocketHandler); SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping(); handlerMapping.setCorsConfigurations(Collections.singletonMap("*", new CorsConfiguration().applyPermitDefaultValues())); handlerMapping.setOrder(1); handlerMapping.setUrlMap(map); return handlerMapping; }
Example #29
Source File: WebSocketConfiguration.java From soul with Apache License 2.0 | 5 votes |
/** * Web socket mapping handler mapping. * * @param echoHandler the echo handler * @return the handler mapping */ @Bean public HandlerMapping webSocketMapping(final EchoHandler echoHandler) { final Map<String, WebSocketHandler> map = new HashMap<>(1); map.put("/echo", echoHandler); final SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); mapping.setOrder(Ordered.HIGHEST_PRECEDENCE); mapping.setUrlMap(map); return mapping; }
Example #30
Source File: WebFluxConfigurationSupportTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void resourceHandler() throws Exception { ApplicationContext context = loadConfig(CustomResourceHandlingConfig.class); String name = "resourceHandlerMapping"; AbstractUrlHandlerMapping handlerMapping = context.getBean(name, AbstractUrlHandlerMapping.class); assertNotNull(handlerMapping); assertEquals(Ordered.LOWEST_PRECEDENCE - 1, handlerMapping.getOrder()); SimpleUrlHandlerMapping urlHandlerMapping = (SimpleUrlHandlerMapping) handlerMapping; WebHandler webHandler = (WebHandler) urlHandlerMapping.getUrlMap().get("/images/**"); assertNotNull(webHandler); }