Finally I have my websocket client connecting to the endpoint but I can't extract message payload. I can get headers but payload is not recognized.
My WebSocket client looks like below:
WebSocketTransport webSocketTransport = new WebSocketTransport(standardWebSocketClient);
SockJsClient sockJsClient = new SockJsClient(Arrays.asList(webSocketTransport));
WebSocketStompClient stompClient = new WebSocketStompClient(sockJsClient);
stompClient.setMessageConverter(new StringMessageConverter());
StompSessionHandler sessionHandler = new MyStompSessionHandler();
ListenableFuture<StompSession> connect = stompClient.connect(URL, sessionHandler);
StompSession stompSession = connect.get();
System.out.println("sessionId: " + stompSession.getSessionId());
String path = "/queue/orders";
stompSession.subscribe(path, new MySimpleStompFrameHandler());
Stomp Frame Handler:
private class MySimpleStompFrameHandler implements StompFrameHandler {
@Override
public Type getPayloadType(StompHeaders stompHeaders) {
System.out.println("Headers " + stompHeaders.toString());
return String.class;
}
@Override
public void handleFrame(StompHeaders stompHeaders, Object payload) {
System.out.println("Msg " + payload.toString());
completableFuture.complete(payload.toString());
}
}
I have headers written in the terminal but there is nothing from handleFrame method. Any idea ?
Edited: After debugging i see that the problem is in DefaultStompSession class which uses my implementation of frameHandler
private void invokeHandler(StompFrameHandler handler, Message<byte[]> message, StompHeaders stompHeaders) {
if (message.getPayload().length == 0) {
handler.handleFrame(stompHeaders, null);
return;
}
Type type = handler.getPayloadType(stompHeaders);
Class<?> payloadType = ResolvableType.forType(type).resolve();
Object object = getMessageConverter().fromMessage(message, payloadType);
if (object == null) {
throw new MessageConversionException("No suitable converter, payloadType=" + payloadType +
", handlerType=" + handler.getClass());
}
handler.handleFrame(stompHeaders, object);
}
Problem is after this line Type type = handler.getPayloadType(stompHeaders);
After that nothing more is executed and my program just ends so handleFrame() is not even executed.
What is wrong there ? Maybe with Type returned from getPayloadType - I choose String because I think every message can be presented as string.