Java Code Examples for org.springframework.web.reactive.handler.SimpleUrlHandlerMapping#setOrder()

The following examples show how to use org.springframework.web.reactive.handler.SimpleUrlHandlerMapping#setOrder() . 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: WebSocketMessagingHandlerConfiguration.java    From jetlinks-community with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: WebSocketIT.java    From vertx-spring-boot with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: WebSocketConfig.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 6 votes vote down vote up
@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 4
Source File: EmployeeConfig.java    From tutorials with MIT License 5 votes vote down vote up
@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 5
Source File: ResourceHandlerRegistry.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Return a handler mapping with the mapped resource handlers; or {@code null} in case
 * of no registrations.
 */
@Nullable
protected AbstractUrlHandlerMapping getHandlerMapping() {
	if (this.registrations.isEmpty()) {
		return null;
	}
	Map<String, WebHandler> urlMap = new LinkedHashMap<>();
	for (ResourceHandlerRegistration registration : this.registrations) {
		for (String pathPattern : registration.getPathPatterns()) {
			ResourceWebHandler handler = registration.getRequestHandler();
			handler.getResourceTransformers().forEach(transformer -> {
				if (transformer instanceof ResourceTransformerSupport) {
					((ResourceTransformerSupport) transformer).setResourceUrlProvider(this.resourceUrlProvider);
				}
			});
			try {
				handler.afterPropertiesSet();
			}
			catch (Throwable ex) {
				throw new BeanInitializationException("Failed to init ResourceHttpRequestHandler", ex);
			}
			urlMap.put(pathPattern, handler);
		}
	}
	SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
	handlerMapping.setOrder(this.order);
	handlerMapping.setUrlMap(urlMap);
	return handlerMapping;
}
 
Example 6
Source File: WebSocketConfiguration.java    From tools-journey with Apache License 2.0 5 votes vote down vote up
@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 7
Source File: WebSocketConfiguration.java    From springboot-learning-example with Apache License 2.0 5 votes vote down vote up
@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 8
Source File: ReactiveChatSocketConfig.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
@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 9
Source File: ReservationServiceApplication.java    From bootiful-reactive-microservices with Apache License 2.0 5 votes vote down vote up
@Bean
HandlerMapping hm() {
	SimpleUrlHandlerMapping simpleUrlHandlerMapping = new SimpleUrlHandlerMapping();
	simpleUrlHandlerMapping.setOrder(10);
	simpleUrlHandlerMapping.setUrlMap(Collections.singletonMap("/ws/greetings", this.wsh()));
	return simpleUrlHandlerMapping;
}
 
Example 10
Source File: WebSocketConfig.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 5 votes vote down vote up
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 11
Source File: WebSocketConfig.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 5 votes vote down vote up
@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 12
Source File: WebSocketConfig.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 5 votes vote down vote up
@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 13
Source File: WebSocketConfig.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 5 votes vote down vote up
@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 14
Source File: ServiceInstanceLogStreamAutoConfiguration.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@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 15
Source File: WebSocketConfiguration.java    From reactor-workshop with GNU General Public License v3.0 5 votes vote down vote up
@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 16
Source File: WebSocketConfiguration.java    From Hands-On-Reactive-Programming-in-Spring-5 with MIT License 5 votes vote down vote up
@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: WebSocketRouter.java    From webFluxTemplate with MIT License 5 votes vote down vote up
@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 18
Source File: ReactiveWebSocketConfig.java    From spring-redis-websocket with Apache License 2.0 5 votes vote down vote up
@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 19
Source File: WebSocketConfiguration.java    From soul with Apache License 2.0 5 votes vote down vote up
/**
 * 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 20
Source File: ReactiveWebSocketConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
@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;
}