org.springframework.messaging.simp.stomp.StompSessionHandler Java Examples
The following examples show how to use
org.springframework.messaging.simp.stomp.StompSessionHandler.
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: 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 #2
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 #3
Source File: WebSocketStompClientTests.java From java-technology-stack with MIT License | 5 votes |
private WebSocketHandler connect() { this.stompClient.connect("/foo", mock(StompSessionHandler.class)); verify(this.stompSession).getSessionFuture(); verifyNoMoreInteractions(this.stompSession); WebSocketHandler webSocketHandler = this.webSocketHandlerCaptor.getValue(); assertNotNull(webSocketHandler); return webSocketHandler; }
Example #4
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 #5
Source File: WebSocketStompClientTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
private WebSocketHandler connect() { this.stompClient.connect("/foo", mock(StompSessionHandler.class)); verify(this.stompSession).getSessionFuture(); verifyNoMoreInteractions(this.stompSession); WebSocketHandler webSocketHandler = this.webSocketHandlerCaptor.getValue(); assertNotNull(webSocketHandler); return webSocketHandler; }
Example #6
Source File: WebSocketStompClient.java From java-technology-stack with MIT License | 5 votes |
/** * An overloaded version of * {@link #connect(String, WebSocketHttpHeaders, StompSessionHandler, Object...)} * that accepts a fully prepared {@link java.net.URI}. * @param url the url to connect to * @param handshakeHeaders the headers for the WebSocket handshake * @param connectHeaders headers for the STOMP CONNECT frame * @param sessionHandler the STOMP session handler * @return a ListenableFuture for access to the session when ready for use */ public ListenableFuture<StompSession> connect(URI url, @Nullable WebSocketHttpHeaders handshakeHeaders, @Nullable StompHeaders connectHeaders, StompSessionHandler sessionHandler) { Assert.notNull(url, "'url' must not be null"); ConnectionHandlingStompSession session = createSession(connectHeaders, sessionHandler); WebSocketTcpConnectionHandlerAdapter adapter = new WebSocketTcpConnectionHandlerAdapter(session); getWebSocketClient().doHandshake(adapter, handshakeHeaders, url).addCallback(adapter); return session.getSessionFuture(); }
Example #7
Source File: WebSocketStompClientTests.java From spring-analysis-note with MIT License | 5 votes |
@Override protected ConnectionHandlingStompSession createSession(StompHeaders headers, StompSessionHandler handler) { return this.stompSession; }
Example #8
Source File: WebSocketStompClientTests.java From spring-analysis-note with MIT License | 5 votes |
private WebSocketHandler connect() { this.stompClient.connect("/foo", mock(StompSessionHandler.class)); verify(this.stompSession).getSessionFuture(); verifyNoMoreInteractions(this.stompSession); WebSocketHandler webSocketHandler = this.webSocketHandlerCaptor.getValue(); assertNotNull(webSocketHandler); return webSocketHandler; }
Example #9
Source File: WebSocketStompClientTests.java From java-technology-stack with MIT License | 4 votes |
@Override protected ConnectionHandlingStompSession createSession(StompHeaders headers, StompSessionHandler handler) { return this.stompSession; }
Example #10
Source File: WebSocketStompClientTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override protected ConnectionHandlingStompSession createSession(StompHeaders headers, StompSessionHandler handler) { return this.stompSession; }
Example #11
Source File: WebSocketStompClient.java From java-technology-stack with MIT License | 3 votes |
/** * An overloaded version of * {@link #connect(String, StompSessionHandler, Object...)} that also accepts * {@link WebSocketHttpHeaders} to use for the WebSocket handshake and * {@link StompHeaders} for the STOMP CONNECT frame. * @param url the url to connect to * @param handshakeHeaders headers for the WebSocket handshake * @param connectHeaders headers for the STOMP CONNECT frame * @param handler the session handler * @param uriVariables the URI variables to expand into the URL * @return a ListenableFuture for access to the session when ready for use */ public ListenableFuture<StompSession> connect(String url, @Nullable WebSocketHttpHeaders handshakeHeaders, @Nullable StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables) { Assert.notNull(url, "'url' must not be null"); URI uri = UriComponentsBuilder.fromUriString(url).buildAndExpand(uriVariables).encode().toUri(); return connect(uri, handshakeHeaders, connectHeaders, handler); }
Example #12
Source File: WebSocketStompClient.java From spring-analysis-note with MIT License | 3 votes |
/** * An overloaded version of * {@link #connect(String, WebSocketHttpHeaders, StompSessionHandler, Object...)} * that accepts a fully prepared {@link java.net.URI}. * @param url the url to connect to * @param handshakeHeaders the headers for the WebSocket handshake * @param connectHeaders headers for the STOMP CONNECT frame * @param sessionHandler the STOMP session handler * @return a ListenableFuture for access to the session when ready for use */ public ListenableFuture<StompSession> connect(URI url, @Nullable WebSocketHttpHeaders handshakeHeaders, @Nullable StompHeaders connectHeaders, StompSessionHandler sessionHandler) { Assert.notNull(url, "'url' must not be null"); ConnectionHandlingStompSession session = createSession(connectHeaders, sessionHandler); WebSocketTcpConnectionHandlerAdapter adapter = new WebSocketTcpConnectionHandlerAdapter(session); getWebSocketClient().doHandshake(adapter, handshakeHeaders, url).addCallback(adapter); return session.getSessionFuture(); }
Example #13
Source File: WebSocketStompClient.java From spring4-understanding with Apache License 2.0 | 3 votes |
/** * An overloaded version of * {@link #connect(String, StompSessionHandler, Object...)} that also * accepts {@link WebSocketHttpHeaders} to use for the WebSocket handshake. * @param url the url to connect to * @param handshakeHeaders the headers for the WebSocket handshake * @param handler the session handler * @param uriVariables URI variables to expand into the URL * @return ListenableFuture for access to the session when ready for use */ public ListenableFuture<StompSession> connect(String url, WebSocketHttpHeaders handshakeHeaders, StompSessionHandler handler, Object... uriVariables) { return connect(url, handshakeHeaders, null, handler, uriVariables); }
Example #14
Source File: WebSocketStompClient.java From spring4-understanding with Apache License 2.0 | 3 votes |
/** * An overloaded version of * {@link #connect(String, StompSessionHandler, Object...)} that also accepts * {@link WebSocketHttpHeaders} to use for the WebSocket handshake and * {@link StompHeaders} for the STOMP CONNECT frame. * @param url the url to connect to * @param handshakeHeaders headers for the WebSocket handshake * @param connectHeaders headers for the STOMP CONNECT frame * @param handler the session handler * @param uriVariables URI variables to expand into the URL * @return ListenableFuture for access to the session when ready for use */ public ListenableFuture<StompSession> connect(String url, WebSocketHttpHeaders handshakeHeaders, StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables) { Assert.notNull(url, "uriTemplate must not be null"); URI uri = UriComponentsBuilder.fromUriString(url).buildAndExpand(uriVariables).encode().toUri(); return connect(uri, handshakeHeaders, connectHeaders, handler); }
Example #15
Source File: WebSocketStompClient.java From spring4-understanding with Apache License 2.0 | 3 votes |
/** * An overloaded version of * {@link #connect(String, WebSocketHttpHeaders, StompSessionHandler, Object...)} * that accepts a fully prepared {@link java.net.URI}. * @param url the url to connect to * @param handshakeHeaders the headers for the WebSocket handshake * @param connectHeaders headers for the STOMP CONNECT frame * @param sessionHandler the STOMP session handler * @return ListenableFuture for access to the session when ready for use */ public ListenableFuture<StompSession> connect(URI url, WebSocketHttpHeaders handshakeHeaders, StompHeaders connectHeaders, StompSessionHandler sessionHandler) { Assert.notNull(url, "'uri' must not be null"); ConnectionHandlingStompSession session = createSession(connectHeaders, sessionHandler); WebSocketTcpConnectionHandlerAdapter adapter = new WebSocketTcpConnectionHandlerAdapter(session); getWebSocketClient().doHandshake(adapter, handshakeHeaders, url).addCallback(adapter); return session.getSessionFuture(); }
Example #16
Source File: WebSocketStompClient.java From spring-analysis-note with MIT License | 3 votes |
/** * An overloaded version of * {@link #connect(String, StompSessionHandler, Object...)} that also accepts * {@link WebSocketHttpHeaders} to use for the WebSocket handshake and * {@link StompHeaders} for the STOMP CONNECT frame. * @param url the url to connect to * @param handshakeHeaders headers for the WebSocket handshake * @param connectHeaders headers for the STOMP CONNECT frame * @param handler the session handler * @param uriVariables the URI variables to expand into the URL * @return a ListenableFuture for access to the session when ready for use */ public ListenableFuture<StompSession> connect(String url, @Nullable WebSocketHttpHeaders handshakeHeaders, @Nullable StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables) { Assert.notNull(url, "'url' must not be null"); URI uri = UriComponentsBuilder.fromUriString(url).buildAndExpand(uriVariables).encode().toUri(); return connect(uri, handshakeHeaders, connectHeaders, handler); }
Example #17
Source File: WebSocketStompClient.java From java-technology-stack with MIT License | 2 votes |
/** * Connect to the given WebSocket URL and notify the given * {@link org.springframework.messaging.simp.stomp.StompSessionHandler} * when connected on the STOMP level after the CONNECTED frame is received. * @param url the url to connect to * @param handler the session handler * @param uriVars the URI variables to expand into the URL * @return a ListenableFuture for access to the session when ready for use */ public ListenableFuture<StompSession> connect(String url, StompSessionHandler handler, Object... uriVars) { return connect(url, null, handler, uriVars); }
Example #18
Source File: WebSocketStompClient.java From java-technology-stack with MIT License | 2 votes |
/** * An overloaded version of * {@link #connect(String, StompSessionHandler, Object...)} that also * accepts {@link WebSocketHttpHeaders} to use for the WebSocket handshake. * @param url the url to connect to * @param handshakeHeaders the headers for the WebSocket handshake * @param handler the session handler * @param uriVariables the URI variables to expand into the URL * @return a ListenableFuture for access to the session when ready for use */ public ListenableFuture<StompSession> connect(String url, @Nullable WebSocketHttpHeaders handshakeHeaders, StompSessionHandler handler, Object... uriVariables) { return connect(url, handshakeHeaders, null, handler, uriVariables); }
Example #19
Source File: WebSocketStompClient.java From spring-analysis-note with MIT License | 2 votes |
/** * Connect to the given WebSocket URL and notify the given * {@link org.springframework.messaging.simp.stomp.StompSessionHandler} * when connected on the STOMP level after the CONNECTED frame is received. * @param url the url to connect to * @param handler the session handler * @param uriVars the URI variables to expand into the URL * @return a ListenableFuture for access to the session when ready for use */ public ListenableFuture<StompSession> connect(String url, StompSessionHandler handler, Object... uriVars) { return connect(url, null, handler, uriVars); }
Example #20
Source File: WebSocketStompClient.java From spring4-understanding with Apache License 2.0 | 2 votes |
/** * Connect to the given WebSocket URL and notify the given * {@link org.springframework.messaging.simp.stomp.StompSessionHandler} * when connected on the STOMP level after the CONNECTED frame is received. * @param url the url to connect to * @param handler the session handler * @param uriVars URI variables to expand into the URL * @return ListenableFuture for access to the session when ready for use */ public ListenableFuture<StompSession> connect(String url, StompSessionHandler handler, Object... uriVars) { return connect(url, null, handler, uriVars); }
Example #21
Source File: WebSocketStompClient.java From spring-analysis-note with MIT License | 2 votes |
/** * An overloaded version of * {@link #connect(String, StompSessionHandler, Object...)} that also * accepts {@link WebSocketHttpHeaders} to use for the WebSocket handshake. * @param url the url to connect to * @param handshakeHeaders the headers for the WebSocket handshake * @param handler the session handler * @param uriVariables the URI variables to expand into the URL * @return a ListenableFuture for access to the session when ready for use */ public ListenableFuture<StompSession> connect(String url, @Nullable WebSocketHttpHeaders handshakeHeaders, StompSessionHandler handler, Object... uriVariables) { return connect(url, handshakeHeaders, null, handler, uriVariables); }