Search in sources :

Example 1 with StandardWebSocketClient

use of org.springframework.web.socket.client.standard.StandardWebSocketClient in project spring-boot by spring-projects.

the class WebSocketMessagingAutoConfigurationTests method setup.

@Before
public void setup() {
    List<Transport> transports = Arrays.asList(new WebSocketTransport(new StandardWebSocketClient(new WsWebSocketContainer())), new RestTemplateXhrTransport(new RestTemplate()));
    this.sockJsClient = new SockJsClient(transports);
}
Also used : RestTemplateXhrTransport(org.springframework.web.socket.sockjs.client.RestTemplateXhrTransport) WsWebSocketContainer(org.apache.tomcat.websocket.WsWebSocketContainer) SockJsClient(org.springframework.web.socket.sockjs.client.SockJsClient) RestTemplate(org.springframework.web.client.RestTemplate) StandardWebSocketClient(org.springframework.web.socket.client.standard.StandardWebSocketClient) Transport(org.springframework.web.socket.sockjs.client.Transport) WebSocketTransport(org.springframework.web.socket.sockjs.client.WebSocketTransport) RestTemplateXhrTransport(org.springframework.web.socket.sockjs.client.RestTemplateXhrTransport) WebSocketTransport(org.springframework.web.socket.sockjs.client.WebSocketTransport) Before(org.junit.Before)

Example 2 with StandardWebSocketClient

use of org.springframework.web.socket.client.standard.StandardWebSocketClient in project portal by ixinportal.

the class KeySegmentationTask method buildTask.

public static void buildTask(final WebSocketSession session, final WebSocketMessage<?> message) throws UnsupportedEncodingException, NoSuchAlgorithmException, URISyntaxException {
    // header 获取云盾秘钥连接 // TODO: 2017/11/29
    final WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
    MobileSecretKeyConfigExample configExample = new MobileSecretKeyConfigExample();
    MobileSecretKeyConfig keyConfig = accesskeyLiensConfigService.selectByConfig(configExample);
    // keyConfig.getPasswordNumber()
    headers.add("appId", keyConfig.getPasswordNumber());
    headers.add("Content-Signature", Base64.encode(HMACSHA1.getHmacSHA1(/*keyConfig.getPasswordNumber(),keyConfig.getPassword()*/
    "1", "123"), false));
    final URI uri = new URI(/*keyConfig.getConnectAddress()*/
    "ws://192.168.102.237:8080/km/webSocketServer");
    Runnable task = new Runnable() {

        @Override
        public void run() {
            WebSocketClient webSocketClient = new StandardWebSocketClient();
            webSocketClient.doHandshake(new KeySegmentationWebSocketHandler(session, message), headers, uri);
        }
    };
    threadPool.execute(task);
}
Also used : MobileSecretKeyConfig(com.itrus.portal.db.MobileSecretKeyConfig) WebSocketHttpHeaders(org.springframework.web.socket.WebSocketHttpHeaders) KeySegmentationWebSocketHandler(com.itrus.portal.mobile.controller.websocket.handler.KeySegmentationWebSocketHandler) MobileSecretKeyConfigExample(com.itrus.portal.db.MobileSecretKeyConfigExample) StandardWebSocketClient(org.springframework.web.socket.client.standard.StandardWebSocketClient) WebSocketClient(org.springframework.web.socket.client.WebSocketClient) StandardWebSocketClient(org.springframework.web.socket.client.standard.StandardWebSocketClient) URI(java.net.URI)

Example 3 with StandardWebSocketClient

use of org.springframework.web.socket.client.standard.StandardWebSocketClient in project elastest-torm by elastest.

the class StompTestUtils method connectToRabbitMQ.

public static StompSession connectToRabbitMQ(int serverPort) throws InterruptedException, ExecutionException, TimeoutException {
    WebSocketContainer cont = ContainerProvider.getWebSocketContainer();
    cont.setDefaultMaxTextMessageBufferSize(65500);
    WebSocketClient webSocketClient = new StandardWebSocketClient(cont);
    WebSocketStompClient stompClient = new WebSocketStompClient(webSocketClient);
    stompClient.setMessageConverter(new StringMessageConverter());
    ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
    taskScheduler.initialize();
    // for heartbeats
    stompClient.setTaskScheduler(taskScheduler);
    stompClient.setDefaultHeartbeat(new long[] { 10000, 10000 });
    String url = "ws://localhost:" + serverPort + "/rabbitMq";
    StompSessionHandler sessionHandler = new LogConnectedSessionHandler();
    final int MAX_RETRIES = 5;
    int retry = 0;
    while (true) {
        try {
            StompSession stompSession = stompClient.connect(url, sessionHandler).get(10, TimeUnit.SECONDS);
            log.info("Test connected to RabbitMQ in URL '{}'", url);
            return stompSession;
        } catch (Exception e) {
            if (retry < MAX_RETRIES) {
                retry++;
                log.warn("Exception trying to connect to RabbitMQ: {}:{}", e.getClass().getName(), e.getMessage());
                log.info("Retrying {}/{} in 5 second", retry, MAX_RETRIES);
                Thread.sleep(5000);
            } else {
                throw e;
            }
        }
    }
}
Also used : StringMessageConverter(org.springframework.messaging.converter.StringMessageConverter) WebSocketContainer(javax.websocket.WebSocketContainer) StompSession(org.springframework.messaging.simp.stomp.StompSession) StompSessionHandler(org.springframework.messaging.simp.stomp.StompSessionHandler) WebSocketStompClient(org.springframework.web.socket.messaging.WebSocketStompClient) StandardWebSocketClient(org.springframework.web.socket.client.standard.StandardWebSocketClient) StandardWebSocketClient(org.springframework.web.socket.client.standard.StandardWebSocketClient) WebSocketClient(org.springframework.web.socket.client.WebSocketClient) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler)

Example 4 with StandardWebSocketClient

use of org.springframework.web.socket.client.standard.StandardWebSocketClient in project spring-framework by spring-projects.

the class WebSocketStompClientIntegrationTests method setUp.

@BeforeEach
void setUp(TestInfo testInfo) throws Exception {
    logger.debug("Setting up before '" + testInfo.getTestMethod().get().getName() + "'");
    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());
}
Also used : StringMessageConverter(org.springframework.messaging.converter.StringMessageConverter) TomcatWebSocketTestServer(org.springframework.web.socket.TomcatWebSocketTestServer) StandardWebSocketClient(org.springframework.web.socket.client.standard.StandardWebSocketClient) WebSocketClient(org.springframework.web.socket.client.WebSocketClient) StandardWebSocketClient(org.springframework.web.socket.client.standard.StandardWebSocketClient) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with StandardWebSocketClient

use of org.springframework.web.socket.client.standard.StandardWebSocketClient in project spring-boot by spring-projects.

the class WebSocketMessagingAutoConfigurationTests method setup.

@BeforeEach
void setup() {
    List<Transport> transports = Arrays.asList(new WebSocketTransport(new StandardWebSocketClient(new WsWebSocketContainer())), new RestTemplateXhrTransport(new RestTemplate()));
    this.sockJsClient = new SockJsClient(transports);
}
Also used : RestTemplateXhrTransport(org.springframework.web.socket.sockjs.client.RestTemplateXhrTransport) WsWebSocketContainer(org.apache.tomcat.websocket.WsWebSocketContainer) SockJsClient(org.springframework.web.socket.sockjs.client.SockJsClient) RestTemplate(org.springframework.web.client.RestTemplate) StandardWebSocketClient(org.springframework.web.socket.client.standard.StandardWebSocketClient) Transport(org.springframework.web.socket.sockjs.client.Transport) WebSocketTransport(org.springframework.web.socket.sockjs.client.WebSocketTransport) RestTemplateXhrTransport(org.springframework.web.socket.sockjs.client.RestTemplateXhrTransport) WebSocketTransport(org.springframework.web.socket.sockjs.client.WebSocketTransport) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

StandardWebSocketClient (org.springframework.web.socket.client.standard.StandardWebSocketClient)12 WebSocketClient (org.springframework.web.socket.client.WebSocketClient)8 WebSocketStompClient (org.springframework.web.socket.messaging.WebSocketStompClient)4 SockJsClient (org.springframework.web.socket.sockjs.client.SockJsClient)4 Transport (org.springframework.web.socket.sockjs.client.Transport)4 WebSocketTransport (org.springframework.web.socket.sockjs.client.WebSocketTransport)4 WsWebSocketContainer (org.apache.tomcat.websocket.WsWebSocketContainer)3 MappingJackson2MessageConverter (org.springframework.messaging.converter.MappingJackson2MessageConverter)3 StringMessageConverter (org.springframework.messaging.converter.StringMessageConverter)3 StompSessionHandler (org.springframework.messaging.simp.stomp.StompSessionHandler)3 RestTemplateXhrTransport (org.springframework.web.socket.sockjs.client.RestTemplateXhrTransport)3 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Scanner (java.util.Scanner)2 Before (org.junit.Before)2 Test (org.junit.Test)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 RestTemplate (org.springframework.web.client.RestTemplate)2 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)2 TomcatWebSocketTestServer (org.springframework.web.socket.TomcatWebSocketTestServer)2