org.springframework.web.socket.client.WebSocketClient Java Examples
The following examples show how to use
org.springframework.web.socket.client.WebSocketClient.
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: WebSocketStompClientIntegrationTests.java From java-technology-stack with MIT License | 6 votes |
@Before public void setUp() throws Exception { logger.debug("Setting up before '" + this.testName.getMethodName() + "'"); this.wac = new AnnotationConfigWebApplicationContext(); this.wac.register(TestConfig.class); this.wac.refresh(); this.server = new TomcatWebSocketTestServer(); this.server.setup(); this.server.deployConfig(this.wac); this.server.start(); WebSocketClient webSocketClient = new StandardWebSocketClient(); this.stompClient = new WebSocketStompClient(webSocketClient); this.stompClient.setMessageConverter(new StringMessageConverter()); }
Example #2
Source File: WebSocketStompClientIntegrationTests.java From spring-analysis-note with MIT License | 6 votes |
@Before public void setUp() throws Exception { logger.debug("Setting up before '" + this.testName.getMethodName() + "'"); this.wac = new AnnotationConfigWebApplicationContext(); this.wac.register(TestConfig.class); this.wac.refresh(); this.server = new TomcatWebSocketTestServer(); this.server.setup(); this.server.deployConfig(this.wac); this.server.start(); WebSocketClient webSocketClient = new StandardWebSocketClient(); this.stompClient = new WebSocketStompClient(webSocketClient); this.stompClient.setMessageConverter(new StringMessageConverter()); }
Example #3
Source File: WebSocketStompClientIntegrationTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { logger.debug("Setting up before '" + this.testName.getMethodName() + "'"); this.wac = new AnnotationConfigWebApplicationContext(); this.wac.register(TestConfig.class); this.wac.refresh(); this.server = new TomcatWebSocketTestServer(); this.server.setup(); this.server.deployConfig(this.wac); this.server.start(); WebSocketClient webSocketClient = new StandardWebSocketClient(); this.stompClient = new WebSocketStompClient(webSocketClient); this.stompClient.setMessageConverter(new StringMessageConverter()); }
Example #4
Source File: ServiceClient.java From spring-boot-websocket-client with MIT License | 6 votes |
public static void main(String... argv) { WebSocketClient webSocketClient = new StandardWebSocketClient(); WebSocketStompClient stompClient = new WebSocketStompClient(webSocketClient); stompClient.setMessageConverter(new MappingJackson2MessageConverter()); stompClient.setTaskScheduler(new ConcurrentTaskScheduler()); String url = "ws://127.0.0.1:8080/hello"; StompSessionHandler sessionHandler = new MySessionHandler(); stompClient.connect(url, sessionHandler); new Scanner(System.in).nextLine(); //Don't close immediately. }
Example #5
Source File: Application.java From spring-websocket-client with MIT License | 6 votes |
public static void main(String args[]) throws Exception { WebSocketClient simpleWebSocketClient = new StandardWebSocketClient(); List<Transport> transports = new ArrayList<>(1); transports.add(new WebSocketTransport(simpleWebSocketClient)); SockJsClient sockJsClient = new SockJsClient(transports); WebSocketStompClient stompClient = new WebSocketStompClient(sockJsClient); stompClient.setMessageConverter(new MappingJackson2MessageConverter()); String url = "ws://localhost:9090/chat"; String userId = "spring-" + ThreadLocalRandom.current().nextInt(1, 99); StompSessionHandler sessionHandler = new MyStompSessionHandler(userId); StompSession session = stompClient.connect(url, sessionHandler) .get(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); for (;;) { System.out.print(userId + " >> "); System.out.flush(); String line = in.readLine(); if ( line == null ) break; if ( line.length() == 0 ) continue; ClientMessage msg = new ClientMessage(userId, line); session.send("/app/chat/java", msg); } }
Example #6
Source File: SendMessageClientImpl.java From simpleblockchain with Apache License 2.0 | 5 votes |
@Override public void process() { BlockchainWebSocketHandler handler = new BlockchainWebSocketHandler(); WebSocketClient client = new StandardWebSocketClient(); try { WebSocketSession session = client.doHandshake(handler, WS_URI).get(); session.sendMessage(new TextMessage("Hello World test.")); session.close(); } catch (Exception e) { logger.info(e); } }
Example #7
Source File: WebSocketStompClientTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void heartbeatDefaultValueWithScheduler() throws Exception { WebSocketStompClient stompClient = new WebSocketStompClient(mock(WebSocketClient.class)); stompClient.setTaskScheduler(mock(TaskScheduler.class)); assertArrayEquals(new long[] {10000, 10000}, stompClient.getDefaultHeartbeat()); StompHeaders connectHeaders = stompClient.processConnectHeaders(null); assertArrayEquals(new long[] {10000, 10000}, connectHeaders.getHeartbeat()); }
Example #8
Source File: WebSocketStompClientTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void heartbeatDefaultValueSetWithoutScheduler() throws Exception { WebSocketStompClient stompClient = new WebSocketStompClient(mock(WebSocketClient.class)); stompClient.setDefaultHeartbeat(new long[] {5, 5}); try { stompClient.processConnectHeaders(null); fail("Expected IllegalStateException"); } catch (IllegalStateException ex) { // ignore } }
Example #9
Source File: RsvpApplication.java From -Data-Stream-Development-with-Apache-Spark-Kafka-and-Spring-Boot with MIT License | 5 votes |
@Bean public ApplicationRunner initializeConnection( RsvpsWebSocketHandler rsvpsWebSocketHandler) { return args -> { WebSocketClient rsvpsSocketClient = new StandardWebSocketClient(); rsvpsSocketClient.doHandshake( rsvpsWebSocketHandler, MEETUP_RSVPS_ENDPOINT); }; }
Example #10
Source File: WebSocket.java From football-events with MIT License | 5 votes |
public WebSocket(String url) { this.url = url; var transports = new ArrayList<Transport>(1); transports.add(new WebSocketTransport(new StandardWebSocketClient())); WebSocketClient webSocketClient = new SockJsClient(transports); client = new WebSocketStompClient(webSocketClient); client.setMessageConverter(new MappingJackson2MessageConverter()); }
Example #11
Source File: ZuulWebSocketConfiguration.java From spring-cloud-netflix-zuul-websocket with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean(WebSocketStompClient.class) public WebSocketStompClient stompClient(WebSocketClient webSocketClient, MessageConverter messageConverter, @Qualifier("proxyStompClientTaskScheduler") TaskScheduler taskScheduler) { int bufferSizeLimit = 1024 * 1024 * 8; WebSocketStompClient client = new WebSocketStompClient(webSocketClient); client.setInboundMessageSizeLimit(bufferSizeLimit); client.setMessageConverter(messageConverter); client.setTaskScheduler(taskScheduler); client.setDefaultHeartbeat(new long[]{0, 0}); return client; }
Example #12
Source File: RsvpApplication.java From -Data-Stream-Development-with-Apache-Spark-Kafka-and-Spring-Boot with MIT License | 5 votes |
@Bean public ApplicationRunner initializeConnection( RsvpsWebSocketHandler rsvpsWebSocketHandler) { return args -> { WebSocketClient rsvpsSocketClient = new StandardWebSocketClient(); rsvpsSocketClient.doHandshake( rsvpsWebSocketHandler, MEETUP_RSVPS_ENDPOINT); }; }
Example #13
Source File: WebSocketStompClientTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); WebSocketClient webSocketClient = mock(WebSocketClient.class); this.stompClient = new TestWebSocketStompClient(webSocketClient); this.stompClient.setTaskScheduler(this.taskScheduler); this.stompClient.setStompSession(this.stompSession); this.webSocketHandlerCaptor = ArgumentCaptor.forClass(WebSocketHandler.class); this.handshakeFuture = new SettableListenableFuture<>(); when(webSocketClient.doHandshake(this.webSocketHandlerCaptor.capture(), any(), any(URI.class))) .thenReturn(this.handshakeFuture); }
Example #14
Source File: WebSocketStompClientTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void heartbeatDefaultValue() throws Exception { WebSocketStompClient stompClient = new WebSocketStompClient(mock(WebSocketClient.class)); assertArrayEquals(new long[] {0, 0}, stompClient.getDefaultHeartbeat()); StompHeaders connectHeaders = stompClient.processConnectHeaders(null); assertArrayEquals(new long[] {0, 0}, connectHeaders.getHeartbeat()); }
Example #15
Source File: WebSocketStompClientTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void heartbeatDefaultValueWithScheduler() throws Exception { WebSocketStompClient stompClient = new WebSocketStompClient(mock(WebSocketClient.class)); stompClient.setTaskScheduler(mock(TaskScheduler.class)); assertArrayEquals(new long[] {10000, 10000}, stompClient.getDefaultHeartbeat()); StompHeaders connectHeaders = stompClient.processConnectHeaders(null); assertArrayEquals(new long[] {10000, 10000}, connectHeaders.getHeartbeat()); }
Example #16
Source File: WebSocketStompClientTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void heartbeatDefaultValueSetWithoutScheduler() throws Exception { WebSocketStompClient stompClient = new WebSocketStompClient(mock(WebSocketClient.class)); stompClient.setDefaultHeartbeat(new long[] {5, 5}); try { stompClient.processConnectHeaders(null); fail("Expected exception"); } catch (IllegalArgumentException ex) { // Ignore } }
Example #17
Source File: StompClient.java From tutorials with MIT License | 5 votes |
public static void main(String[] args) { WebSocketClient client = new StandardWebSocketClient(); WebSocketStompClient stompClient = new WebSocketStompClient(client); stompClient.setMessageConverter(new MappingJackson2MessageConverter()); StompSessionHandler sessionHandler = new MyStompSessionHandler(); stompClient.connect(URL, sessionHandler); new Scanner(System.in).nextLine(); // Don't close immediately. }
Example #18
Source File: WebSocketStompClientTests.java From java-technology-stack with MIT License | 5 votes |
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); WebSocketClient webSocketClient = mock(WebSocketClient.class); this.stompClient = new TestWebSocketStompClient(webSocketClient); this.stompClient.setTaskScheduler(this.taskScheduler); this.stompClient.setStompSession(this.stompSession); this.webSocketHandlerCaptor = ArgumentCaptor.forClass(WebSocketHandler.class); this.handshakeFuture = new SettableListenableFuture<>(); when(webSocketClient.doHandshake(this.webSocketHandlerCaptor.capture(), any(), any(URI.class))) .thenReturn(this.handshakeFuture); }
Example #19
Source File: WebSocketStompClientTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void heartbeatDefaultValue() throws Exception { WebSocketStompClient stompClient = new WebSocketStompClient(mock(WebSocketClient.class)); assertArrayEquals(new long[] {0, 0}, stompClient.getDefaultHeartbeat()); StompHeaders connectHeaders = stompClient.processConnectHeaders(null); assertArrayEquals(new long[] {0, 0}, connectHeaders.getHeartbeat()); }
Example #20
Source File: WebSocketStompClientTests.java From spring-analysis-note with MIT License | 5 votes |
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); WebSocketClient webSocketClient = mock(WebSocketClient.class); this.stompClient = new TestWebSocketStompClient(webSocketClient); this.stompClient.setTaskScheduler(this.taskScheduler); this.stompClient.setStompSession(this.stompSession); this.webSocketHandlerCaptor = ArgumentCaptor.forClass(WebSocketHandler.class); this.handshakeFuture = new SettableListenableFuture<>(); given(webSocketClient.doHandshake(this.webSocketHandlerCaptor.capture(), any(), any(URI.class))) .willReturn(this.handshakeFuture); }
Example #21
Source File: WebSocketStompClientTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void heartbeatDefaultValue() throws Exception { WebSocketStompClient stompClient = new WebSocketStompClient(mock(WebSocketClient.class)); assertArrayEquals(new long[] {0, 0}, stompClient.getDefaultHeartbeat()); StompHeaders connectHeaders = stompClient.processConnectHeaders(null); assertArrayEquals(new long[] {0, 0}, connectHeaders.getHeartbeat()); }
Example #22
Source File: WebSocketStompClientTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void heartbeatDefaultValueWithScheduler() throws Exception { WebSocketStompClient stompClient = new WebSocketStompClient(mock(WebSocketClient.class)); stompClient.setTaskScheduler(mock(TaskScheduler.class)); assertArrayEquals(new long[] {10000, 10000}, stompClient.getDefaultHeartbeat()); StompHeaders connectHeaders = stompClient.processConnectHeaders(null); assertArrayEquals(new long[] {10000, 10000}, connectHeaders.getHeartbeat()); }
Example #23
Source File: Stomp.java From WeEvent with Apache License 2.0 | 5 votes |
private void testOverWebSocket() throws InterruptedException { // standard web socket transport WebSocketClient webSocketClient = new StandardWebSocketClient(); WebSocketStompClient stompClient = new WebSocketStompClient(webSocketClient); // MappingJackson2MessageConverter stompClient.setMessageConverter(new StringMessageConverter()); stompClient.setTaskScheduler(taskScheduler); // for heartbeats stompClient.connect(brokerStomp, getWebSocketSessionHandlerAdapter()); Thread.sleep(100000L); }
Example #24
Source File: WebSocketStompClientTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void heartbeatDefaultValueSetWithoutScheduler() throws Exception { WebSocketStompClient stompClient = new WebSocketStompClient(mock(WebSocketClient.class)); stompClient.setDefaultHeartbeat(new long[] {5, 5}); try { stompClient.processConnectHeaders(null); fail("Expected IllegalStateException"); } catch (IllegalStateException ex) { // ignore } }
Example #25
Source File: WebSocketTransport.java From spring-analysis-note with MIT License | 4 votes |
/** * Return the configured {@code WebSocketClient}. */ public WebSocketClient getWebSocketClient() { return this.webSocketClient; }
Example #26
Source File: WebSocketStompClient.java From bearchoke with Apache License 2.0 | 4 votes |
public WebSocketStompClient(URI uri, WebSocketHttpHeaders headers, WebSocketClient webSocketClient) { this.uri = uri; this.headers = headers; this.webSocketClient = webSocketClient; }
Example #27
Source File: WebSocketConfiguration.java From haven-platform with Apache License 2.0 | 4 votes |
@Bean WebSocketClient webSocketClient() { return new StandardWebSocketClient(); }
Example #28
Source File: WebSocketStompClientTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
public TestWebSocketStompClient(WebSocketClient webSocketClient) { super(webSocketClient); }
Example #29
Source File: WebSocketStompClient.java From spring-analysis-note with MIT License | 4 votes |
/** * Return the configured WebSocketClient. */ public WebSocketClient getWebSocketClient() { return this.webSocketClient; }
Example #30
Source File: WebSocketStompClient.java From spring4-understanding with Apache License 2.0 | 4 votes |
/** * Return the configured WebSocketClient. */ public WebSocketClient getWebSocketClient() { return this.webSocketClient; }