• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java WebSocketHandler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.web.reactive.socket.WebSocketHandler的典型用法代码示例。如果您正苦于以下问题:Java WebSocketHandler类的具体用法?Java WebSocketHandler怎么用?Java WebSocketHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



WebSocketHandler类属于org.springframework.web.reactive.socket包,在下文中一共展示了WebSocketHandler类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: webSocketMapping

import org.springframework.web.reactive.socket.WebSocketHandler; //导入依赖的package包/类
@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;
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:20,代码来源:WebSocketConfig.java


示例2: handlerMapping

import org.springframework.web.reactive.socket.WebSocketHandler; //导入依赖的package包/类
@Bean
public HandlerMapping handlerMapping() {
    Map<String, WebSocketHandler> mappings = new HashMap<>(2);
    mappings.put("/in", session -> {
        session.receive()
            .map(WebSocketMessage::getPayloadAsText)
            .log()
            .subscribe(out::onNext);

        return session.send(Mono.just(session.textMessage(MESSAGE_HELLO))).then(session.send(in.map(session::textMessage)));
    });

    mappings.put("/out", session -> {
        session.receive()
            .map(WebSocketMessage::getPayloadAsText)
            .log()
            .subscribe();

        return session.send(Mono.just(session.textMessage(MESSAGE_HELLO))).then(session.send(out.map(session::textMessage)));
    });

    SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
    mapping.setUrlMap(mappings);
    mapping.setOrder(10);
    return mapping;
}
 
开发者ID:pzmi,项目名称:webflux-websocket-server,代码行数:27,代码来源:Websocket.java


示例3: handle

import org.springframework.web.reactive.socket.WebSocketHandler; //导入依赖的package包/类
@Override
public Mono<Void> handle(WebSocketSession session) {
	// pass headers along so custom headers can be sent through
	return client.execute(url, this.headers, new WebSocketHandler() {
		@Override
		public Mono<Void> handle(WebSocketSession proxySession) {
			// Use retain() for Reactor Netty
			Mono<Void> proxySessionSend = proxySession
					.send(session.receive().doOnNext(WebSocketMessage::retain));
					// .log("proxySessionSend", Level.FINE);
			Mono<Void> serverSessionSend = session
					.send(proxySession.receive().doOnNext(WebSocketMessage::retain));
					// .log("sessionSend", Level.FINE);
			return Mono.when(proxySessionSend, serverSessionSend).then();
		}

		/**
		 * Copy subProtocols so they are available downstream.
		 * @return
		 */
		@Override
		public List<String> getSubProtocols() {
			return ProxyWebSocketHandler.this.subProtocols;
		}
	});
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:27,代码来源:WebsocketRoutingFilter.java


示例4: webSocketMapping

import org.springframework.web.reactive.socket.WebSocketHandler; //导入依赖的package包/类
@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;
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:16,代码来源:WebSocketConfig.java


示例5: webSocketMapping

import org.springframework.web.reactive.socket.WebSocketHandler; //导入依赖的package包/类
@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;
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:28,代码来源:WebSocketConfig.java


示例6: webSocketMapping

import org.springframework.web.reactive.socket.WebSocketHandler; //导入依赖的package包/类
@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;
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:30,代码来源:WebSocketConfig.java


示例7: configureUrlMappings

import org.springframework.web.reactive.socket.WebSocketHandler; //导入依赖的package包/类
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;
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:15,代码来源:WebSocketConfig.java


示例8: webSocketMapping

import org.springframework.web.reactive.socket.WebSocketHandler; //导入依赖的package包/类
@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;
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:11,代码来源:ReactiveChatSocketConfig.java


示例9: handlerMapping

import org.springframework.web.reactive.socket.WebSocketHandler; //导入依赖的package包/类
@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;
    }
 
开发者ID:hantsy,项目名称:spring-reactive-sample,代码行数:12,代码来源:WebConfig.java


示例10: handlerMapping

import org.springframework.web.reactive.socket.WebSocketHandler; //导入依赖的package包/类
@Bean
public HandlerMapping handlerMapping() {
	Map<String, WebSocketHandler> map = new HashMap<>();
	map.put("/echo", new EchoWebSocketHandler());
	map.put("/sub-protocol", new SubProtocolWebSocketHandler());
	map.put("/custom-header", new CustomHeaderHandler());

	SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
	mapping.setUrlMap(map);
	return mapping;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:12,代码来源:WebSocketIntegrationTests.java


示例11: subProtocol

import org.springframework.web.reactive.socket.WebSocketHandler; //导入依赖的package包/类
@Test
public void subProtocol() throws Exception {
	String protocol = "echo-v1";
	AtomicReference<HandshakeInfo> infoRef = new AtomicReference<>();
	MonoProcessor<Object> output = MonoProcessor.create();

	client.execute(getUrl("/sub-protocol"),
			new WebSocketHandler() {
				@Override
				public List<String> getSubProtocols() {
					return Collections.singletonList(protocol);
				}
				@Override
				public Mono<Void> handle(WebSocketSession session) {
					infoRef.set(session.getHandshakeInfo());
					return session.receive()
							.map(WebSocketMessage::getPayloadAsText)
							.subscribeWith(output)
							.then();
				}
			})
			.block(Duration.ofMillis(5000));

	HandshakeInfo info = infoRef.get();
	assertThat(info.getHeaders().getFirst("Upgrade"), Matchers.equalToIgnoringCase("websocket"));
	assertEquals(protocol, info.getHeaders().getFirst("Sec-WebSocket-Protocol"));
	assertEquals("Wrong protocol accepted", protocol, info.getSubProtocol());
	assertEquals("Wrong protocol detected on the server side", protocol, output.block(Duration.ofMillis(5000)));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:30,代码来源:WebSocketIntegrationTests.java


示例12: handlerMapping

import org.springframework.web.reactive.socket.WebSocketHandler; //导入依赖的package包/类
@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;
}
 
开发者ID:sdeleuze,项目名称:spring-reactive-playground,代码行数:11,代码来源:Application.java


示例13: executeBitstamp

import org.springframework.web.reactive.socket.WebSocketHandler; //导入依赖的package包/类
public Mono<Void> executeBitstamp(WebSocketHandler handler) throws URISyntaxException {
	return wsClient.execute(new URI(BITSTAMP), handler);
}
 
开发者ID:Angular2Guy,项目名称:AngularAndSpring,代码行数:4,代码来源:WebsocketClient.java



注:本文中的org.springframework.web.reactive.socket.WebSocketHandler类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ECDSASignature类代码示例发布时间:2022-05-23
下一篇:
Java UnregisteredDriver类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap