Java Code Examples for org.springframework.web.socket.sockjs.client.Transport

The following examples show how to use org.springframework.web.socket.sockjs.client.Transport. These examples are extracted from open source projects. 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 Project: WeEvent   Source File: Stomp.java    License: Apache License 2.0 6 votes vote down vote up
private void testOverSockJS() throws InterruptedException {
    // sock js transport
    List<Transport> transports = new ArrayList<>(2);
    transports.add(new WebSocketTransport(new StandardWebSocketClient()));
    transports.add(new RestTemplateXhrTransport());

    SockJsClient sockjsClient = new SockJsClient(transports);
    WebSocketStompClient stompClient = new WebSocketStompClient(sockjsClient);

    // StringMessageConverter
    stompClient.setMessageConverter(new MappingJackson2MessageConverter());
    stompClient.setTaskScheduler(taskScheduler); // for heartbeats

    stompClient.connect(brokerSockJS, getSockJSSessionHandlerAdapter());

    Thread.sleep(100000L);
}
 
Example 2
Source Project: bearchoke   Source File: QuotesWebSocketIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws Exception {
	log.info("Setting up Quotes Web Socket Integration test....");
	port = SocketUtils.findAvailableTcpPort();

	server = new TomcatWebSocketTestServer(port);
	server.deployConfig(FrontendWebApplicationInitializer.class);
	server.start();

	loginAndSaveXAuthToken("harrymitchell", "HarryMitchell5!", headers);

	List<Transport> transports = new ArrayList<>();
	transports.add(new WebSocketTransport(new StandardWebSocketClient()));
	RestTemplateXhrTransport xhrTransport = new RestTemplateXhrTransport(new RestTemplate());
	xhrTransport.setRequestHeaders(headers);
	transports.add(xhrTransport);

	sockJsClient = new SockJsClient(transports);
       sockJsClient.setHttpHeaderNames("X-Auth-Token");
	log.info("Setup complete!");
}
 
Example 3
Source Project: seppb   Source File: WebsocketTest.java    License: MIT License 5 votes vote down vote up
@Before
public void setup() {
	List<Transport> transports = new ArrayList<>();
	transports.add(new WebSocketTransport(new StandardWebSocketClient()));
	transports.add(new RestTemplateXhrTransport());
	this.sockJsClient = new SockJsClient(transports);
}
 
Example 4
Source Project: code   Source File: GreetingIntegrationTests.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setup() {
	List<Transport> transports = new ArrayList<>();
	transports.add(new WebSocketTransport(new StandardWebSocketClient()));
	this.sockJsClient = new SockJsClient(transports);

	this.stompClient = new WebSocketStompClient(sockJsClient);
	this.stompClient.setMessageConverter(new MappingJackson2MessageConverter());
}
 
Example 5
Source Project: football-events   Source File: WebSocket.java    License: MIT License 5 votes vote down vote up
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 6
Source Project: spring-websocket-client   Source File: Application.java    License: MIT License 5 votes vote down vote up
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 7
Source Project: spring-session   Source File: ApplicationTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void run() {
	List<Transport> transports = new ArrayList<>(2);
	transports.add(new WebSocketTransport(new StandardWebSocketClient()));
	transports.add(new RestTemplateXhrTransport());

	SockJsClient sockJsClient = new SockJsClient(transports);
	ListenableFuture<WebSocketSession> wsSession = sockJsClient.doHandshake(this.webSocketHandler,
			"ws://localhost:" + this.port + "/sockjs");

	assertThatExceptionOfType(ExecutionException.class)
			.isThrownBy(() -> wsSession.get().sendMessage(new TextMessage("a")));
}
 
Example 8
Source Project: java-specialagent   Source File: SpringWebSocketITest.java    License: Apache License 2.0 4 votes vote down vote up
private static List<Transport> createTransportClient() {
  final List<Transport> transports = new ArrayList<>();
  transports.add(new WebSocketTransport(new StandardWebSocketClient()));
  return transports;
}
 
Example 9
Source Project: kafka-webview   Source File: AbstractStreamControllerTest.java    License: MIT License 4 votes vote down vote up
private List<Transport> createTransportClient() {
    final List<Transport> transports = new ArrayList<>();
    transports.add(new WebSocketTransport(new StandardWebSocketClient()));
    transports.add(new RestTemplateXhrTransport(new RestTemplate()));
    return transports;
}
 
Example 10
private List<Transport> createTransportClient() {
  return Collections.singletonList(new WebSocketTransport(new StandardWebSocketClient()));
}