use of org.springframework.messaging.simp.stomp.StompSessionHandler in project spring-integration by spring-projects.
the class StompSessionManagerTests method testDoConnectFailure.
@Test
public void testDoConnectFailure() throws Exception {
StompClientSupport stompClient = mock(StompClientSupport.class);
stompClient.setTaskScheduler(new ConcurrentTaskScheduler());
AbstractStompSessionManager sessionManager = new AbstractStompSessionManager(stompClient) {
private final AtomicBoolean thrown = new AtomicBoolean();
@Override
protected ListenableFuture<StompSession> doConnect(StompSessionHandler handler) {
if (!this.thrown.getAndSet(true)) {
throw new RuntimeException("intentional");
} else {
SettableListenableFuture<StompSession> future = new SettableListenableFuture<StompSession>();
StompSession stompSession = mock(StompSession.class);
future.set(stompSession);
handler.afterConnected(stompSession, getConnectHeaders());
return future;
}
}
};
sessionManager.start();
final SettableListenableFuture<StompSession> stompSessionFuture = new SettableListenableFuture<StompSession>();
sessionManager.connect(new StompSessionHandlerAdapter() {
@Override
public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
stompSessionFuture.set(session);
}
});
assertNotNull(stompSessionFuture.get(10, TimeUnit.SECONDS));
sessionManager.stop();
}
use of org.springframework.messaging.simp.stomp.StompSessionHandler 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;
}
}
}
}
use of org.springframework.messaging.simp.stomp.StompSessionHandler in project spring-boot by spring-projects.
the class WebSocketMessagingAutoConfigurationTests method performStompSubscription.
private Object performStompSubscription(final String topic) throws Throwable {
EnvironmentTestUtils.addEnvironment(this.context, "server.port:0", "spring.jackson.serialization.indent-output:true");
this.context.register(WebSocketMessagingConfiguration.class);
new ServerPortInfoApplicationContextInitializer().initialize(this.context);
this.context.refresh();
WebSocketStompClient stompClient = new WebSocketStompClient(this.sockJsClient);
final AtomicReference<Throwable> failure = new AtomicReference<>();
final AtomicReference<Object> result = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
StompSessionHandler handler = new StompSessionHandlerAdapter() {
@Override
public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
session.subscribe(topic, new StompFrameHandler() {
@Override
public void handleFrame(StompHeaders headers, Object payload) {
result.set(payload);
latch.countDown();
}
@Override
public Type getPayloadType(StompHeaders headers) {
return Object.class;
}
});
}
@Override
public void handleFrame(StompHeaders headers, Object payload) {
latch.countDown();
}
@Override
public void handleException(StompSession session, StompCommand command, StompHeaders headers, byte[] payload, Throwable exception) {
failure.set(exception);
latch.countDown();
}
@Override
public void handleTransportError(StompSession session, Throwable exception) {
failure.set(exception);
latch.countDown();
}
};
stompClient.setMessageConverter(new SimpleMessageConverter());
stompClient.connect("ws://localhost:{port}/messaging", handler, this.context.getEnvironment().getProperty("local.server.port"));
if (!latch.await(30000, TimeUnit.SECONDS)) {
if (failure.get() != null) {
throw failure.get();
}
fail("Response was not received within 30 seconds");
}
return result.get();
}
use of org.springframework.messaging.simp.stomp.StompSessionHandler in project tutorials by eugenp.
the class StompClient method main.
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);
// Don't close immediately.
new Scanner(System.in).nextLine();
}
use of org.springframework.messaging.simp.stomp.StompSessionHandler in project CVE-2018-1270 by CaledoniaProject.
the class ServiceClient method main.
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);
// Don't close immediately.
new Scanner(System.in).nextLine();
}
Aggregations