|
1 | 1 | package org.feuyeux.websocket.config;
|
2 | 2 |
|
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.List; |
3 | 5 | import org.feuyeux.websocket.handler.ClientTextWebSocketHandler;
|
4 | 6 | import org.springframework.context.annotation.Bean;
|
5 | 7 | import org.springframework.context.annotation.Configuration;
|
|
12 | 14 | import org.springframework.web.socket.sockjs.client.Transport;
|
13 | 15 | import org.springframework.web.socket.sockjs.client.WebSocketTransport;
|
14 | 16 |
|
15 |
| -import java.util.ArrayList; |
16 |
| -import java.util.List; |
17 |
| - |
18 | 17 | @Configuration
|
19 | 18 | public class ClientWebSocketSockJsConfig {
|
20 |
| - @Bean |
21 |
| - public WebSocketConnectionManager webSocketSockJsConnectionManager() { |
22 |
| - WebSocketConnectionManager manager = new WebSocketConnectionManager( |
23 |
| - webSocketSockJsClient(), |
24 |
| - webSocketSockJsHandler(), |
25 |
| - "http://localhost:8080/websocket-sockjs" |
26 |
| - ); |
27 |
| - manager.setAutoStartup(true); |
28 |
| - return manager; |
29 |
| - } |
| 19 | + @Bean |
| 20 | + public WebSocketConnectionManager webSocketSockJsConnectionManager() { |
| 21 | + WebSocketConnectionManager manager = |
| 22 | + new WebSocketConnectionManager( |
| 23 | + webSocketSockJsClient(), |
| 24 | + webSocketSockJsHandler(), |
| 25 | + "http://localhost:8080/websocket-sockjs"); |
| 26 | + manager.setAutoStartup(true); |
| 27 | + return manager; |
| 28 | + } |
30 | 29 |
|
31 |
| - @Bean |
32 |
| - public WebSocketClient webSocketSockJsClient() { |
33 |
| - List<Transport> transports = new ArrayList<>(); |
34 |
| - transports.add(new WebSocketTransport(new StandardWebSocketClient())); |
35 |
| - transports.add(new RestTemplateXhrTransport()); |
36 |
| - return new SockJsClient(transports); |
37 |
| - } |
| 30 | + @Bean |
| 31 | + public WebSocketClient webSocketSockJsClient() { |
| 32 | + List<Transport> transports = new ArrayList<>(); |
| 33 | + transports.add(new WebSocketTransport(new StandardWebSocketClient())); |
| 34 | + transports.add(new RestTemplateXhrTransport()); |
| 35 | + return new SockJsClient(transports); |
| 36 | + } |
38 | 37 |
|
39 |
| - @Bean |
40 |
| - public WebSocketHandler webSocketSockJsHandler() { |
41 |
| - ClientTextWebSocketHandler clientTextWebSocketHandler = new ClientTextWebSocketHandler(); |
42 |
| - clientTextWebSocketHandler.setType("websocket-sockjs"); |
43 |
| - return clientTextWebSocketHandler; |
44 |
| - } |
| 38 | + @Bean |
| 39 | + public WebSocketHandler webSocketSockJsHandler() { |
| 40 | + ClientTextWebSocketHandler clientTextWebSocketHandler = new ClientTextWebSocketHandler(); |
| 41 | + clientTextWebSocketHandler.setType("websocket-sockjs"); |
| 42 | + return clientTextWebSocketHandler; |
| 43 | + } |
45 | 44 | }
|
0 commit comments