Java Code Examples for org.springframework.web.reactive.handler.SimpleUrlHandlerMapping#setCorsConfigurations()
The following examples show how to use
org.springframework.web.reactive.handler.SimpleUrlHandlerMapping#setCorsConfigurations() .
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: 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 2
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 3
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 4
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 5
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 6
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; }