use of org.springframework.messaging.simp.stomp.StompHeaderAccessor in project spring-framework by spring-projects.
the class StompSubProtocolErrorHandler method handleClientMessageProcessingError.
@Override
public Message<byte[]> handleClientMessageProcessingError(Message<byte[]> clientMessage, Throwable ex) {
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.ERROR);
accessor.setMessage(ex.getMessage());
accessor.setLeaveMutable(true);
StompHeaderAccessor clientHeaderAccessor = null;
if (clientMessage != null) {
clientHeaderAccessor = MessageHeaderAccessor.getAccessor(clientMessage, StompHeaderAccessor.class);
String receiptId = clientHeaderAccessor.getReceipt();
if (receiptId != null) {
accessor.setReceiptId(receiptId);
}
}
return handleInternal(accessor, EMPTY_PAYLOAD, ex, clientHeaderAccessor);
}
use of org.springframework.messaging.simp.stomp.StompHeaderAccessor in project spring-framework by spring-projects.
the class StompSubProtocolErrorHandler method handleErrorMessageToClient.
@Override
public Message<byte[]> handleErrorMessageToClient(Message<byte[]> errorMessage) {
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(errorMessage, StompHeaderAccessor.class);
Assert.notNull(accessor, "Expected STOMP headers");
if (!accessor.isMutable()) {
accessor = StompHeaderAccessor.wrap(errorMessage);
}
return handleInternal(accessor, errorMessage.getPayload(), null, null);
}
use of org.springframework.messaging.simp.stomp.StompHeaderAccessor in project spring-framework by spring-projects.
the class StompSubProtocolHandler method getDisconnectReceipt.
private String getDisconnectReceipt(SimpMessageHeaderAccessor simpHeaders) {
String name = StompHeaderAccessor.DISCONNECT_MESSAGE_HEADER;
Message<?> message = (Message<?>) simpHeaders.getHeader(name);
if (message != null) {
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
return accessor.getReceipt();
}
return null;
}
use of org.springframework.messaging.simp.stomp.StompHeaderAccessor in project spring-framework by spring-projects.
the class StompSubProtocolHandler method createDisconnectMessage.
private Message<byte[]> createDisconnectMessage(WebSocketSession session) {
StompHeaderAccessor headerAccessor = StompHeaderAccessor.create(StompCommand.DISCONNECT);
if (getHeaderInitializer() != null) {
getHeaderInitializer().initHeaders(headerAccessor);
}
headerAccessor.setSessionId(session.getId());
headerAccessor.setSessionAttributes(session.getAttributes());
headerAccessor.setUser(getUser(session));
return MessageBuilder.createMessage(EMPTY_PAYLOAD, headerAccessor.getMessageHeaders());
}
use of org.springframework.messaging.simp.stomp.StompHeaderAccessor in project spring-framework by spring-projects.
the class StompSubProtocolHandler method getStompHeaderAccessor.
private StompHeaderAccessor getStompHeaderAccessor(Message<?> message) {
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class);
if (accessor instanceof StompHeaderAccessor) {
return (StompHeaderAccessor) accessor;
} else {
StompHeaderAccessor stompAccessor = StompHeaderAccessor.wrap(message);
SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(message.getHeaders());
if (SimpMessageType.CONNECT_ACK.equals(messageType)) {
stompAccessor = convertConnectAcktoStompConnected(stompAccessor);
} else if (SimpMessageType.DISCONNECT_ACK.equals(messageType)) {
String receipt = getDisconnectReceipt(stompAccessor);
if (receipt != null) {
stompAccessor = StompHeaderAccessor.create(StompCommand.RECEIPT);
stompAccessor.setReceiptId(receipt);
} else {
stompAccessor = StompHeaderAccessor.create(StompCommand.ERROR);
stompAccessor.setMessage("Session closed.");
}
} else if (SimpMessageType.HEARTBEAT.equals(messageType)) {
stompAccessor = StompHeaderAccessor.createForHeartbeat();
} else if (stompAccessor.getCommand() == null || StompCommand.SEND.equals(stompAccessor.getCommand())) {
stompAccessor.updateStompCommandAsServerMessage();
}
return stompAccessor;
}
}
Aggregations