use of org.springframework.web.reactive.socket.client.WebSocketClient in project tutorials by eugenp.
the class ReactiveJavaClientWebSocket method main.
public static void main(String[] args) throws InterruptedException {
WebSocketClient client = new ReactorNettyWebSocketClient();
client.execute(URI.create("ws://localhost:8080/event-emitter"), session -> session.send(Mono.just(session.textMessage("event-spring-reactive-client-websocket"))).thenMany(session.receive().map(WebSocketMessage::getPayloadAsText).log()).then()).block(Duration.ofSeconds(10L));
}
use of org.springframework.web.reactive.socket.client.WebSocketClient in project spring-framework by spring-projects.
the class AbstractWebSocketIntegrationTests method arguments.
static Stream<Object[]> arguments() throws IOException {
WebSocketClient[] clients = new WebSocketClient[] { new TomcatWebSocketClient(), new JettyWebSocketClient(), new ReactorNettyWebSocketClient(), new UndertowWebSocketClient(Xnio.getInstance().createWorker(OptionMap.EMPTY)) };
Map<HttpServer, Class<?>> servers = new LinkedHashMap<>();
servers.put(new TomcatHttpServer(TMP_DIR.getAbsolutePath(), WsContextListener.class), TomcatConfig.class);
servers.put(new JettyHttpServer(), JettyConfig.class);
servers.put(new ReactorHttpServer(), ReactorNettyConfig.class);
servers.put(new UndertowHttpServer(), UndertowConfig.class);
// Try each client once against each server..
Flux<WebSocketClient> f1 = Flux.fromArray(clients).concatMap(c -> Mono.just(c).repeat(servers.size() - 1));
Flux<Map.Entry<HttpServer, Class<?>>> f2 = Flux.fromIterable(servers.entrySet()).repeat(clients.length - 1).share();
return Flux.zip(f1, f2.map(Map.Entry::getKey), f2.map(Map.Entry::getValue)).map(Tuple3::toArray).toStream();
}
use of org.springframework.web.reactive.socket.client.WebSocketClient in project spring-framework by spring-projects.
the class WebSocketIntegrationTests method customHeader.
@ParameterizedWebSocketTest
void customHeader(WebSocketClient client, HttpServer server, Class<?> serverConfigClass) throws Exception {
startServer(client, server, serverConfigClass);
HttpHeaders headers = new HttpHeaders();
headers.add("my-header", "my-value");
AtomicReference<Object> headerRef = new AtomicReference<>();
this.client.execute(getUrl("/custom-header"), headers, session -> session.receive().map(WebSocketMessage::getPayloadAsText).doOnNext(headerRef::set).doOnError(headerRef::set).then()).block(TIMEOUT);
assertThat(headerRef.get()).isEqualTo("my-header:my-value");
}
Aggregations