Example usage for org.springframework.messaging.simp.stomp StompHeaderAccessor setLeaveMutable

List of usage examples for org.springframework.messaging.simp.stomp StompHeaderAccessor setLeaveMutable

Introduction

In this page you can find the example usage for org.springframework.messaging.simp.stomp StompHeaderAccessor setLeaveMutable.

Prototype

public void setLeaveMutable(boolean leaveMutable) 

Source Link

Document

By default when #getMessageHeaders() is called, "this" MessageHeaderAccessor instance can no longer be used to modify the underlying message headers and the returned MessageHeaders is immutable.

Usage

From source file:org.springframework.messaging.simp.stomp.DefaultStompSession.java

private StompHeaderAccessor createHeaderAccessor(StompCommand command) {
    StompHeaderAccessor accessor = StompHeaderAccessor.create(command);
    accessor.setSessionId(this.sessionId);
    accessor.setLeaveMutable(true);
    return accessor;
}

From source file:org.springframework.messaging.simp.stomp.StompDecoder.java

/**
 * Decode a single STOMP frame from the given {@code buffer} into a {@link Message}.
 *//*from   w ww .j av  a2 s .c o  m*/
@Nullable
private Message<byte[]> decodeMessage(ByteBuffer byteBuffer, @Nullable MultiValueMap<String, String> headers) {
    Message<byte[]> decodedMessage = null;
    skipLeadingEol(byteBuffer);

    // Explicit mark/reset access via Buffer base type for compatibility
    // with covariant return type on JDK 9's ByteBuffer...
    Buffer buffer = byteBuffer;
    buffer.mark();

    String command = readCommand(byteBuffer);
    if (command.length() > 0) {
        StompHeaderAccessor headerAccessor = null;
        byte[] payload = null;
        if (byteBuffer.remaining() > 0) {
            StompCommand stompCommand = StompCommand.valueOf(command);
            headerAccessor = StompHeaderAccessor.create(stompCommand);
            initHeaders(headerAccessor);
            readHeaders(byteBuffer, headerAccessor);
            payload = readPayload(byteBuffer, headerAccessor);
        }
        if (payload != null) {
            if (payload.length > 0) {
                StompCommand stompCommand = headerAccessor.getCommand();
                if (stompCommand != null && !stompCommand.isBodyAllowed()) {
                    throw new StompConversionException(stompCommand + " shouldn't have a payload: length="
                            + payload.length + ", headers=" + headers);
                }
            }
            headerAccessor.updateSimpMessageHeadersFromStompHeaders();
            headerAccessor.setLeaveMutable(true);
            decodedMessage = MessageBuilder.createMessage(payload, headerAccessor.getMessageHeaders());
            if (logger.isTraceEnabled()) {
                logger.trace("Decoded " + headerAccessor.getDetailedLogMessage(payload));
            }
        } else {
            logger.trace("Incomplete frame, resetting input buffer...");
            if (headers != null && headerAccessor != null) {
                String name = NativeMessageHeaderAccessor.NATIVE_HEADERS;
                @SuppressWarnings("unchecked")
                MultiValueMap<String, String> map = (MultiValueMap<String, String>) headerAccessor
                        .getHeader(name);
                if (map != null) {
                    headers.putAll(map);
                }
            }
            buffer.reset();
        }
    } else {
        StompHeaderAccessor headerAccessor = StompHeaderAccessor.createForHeartbeat();
        initHeaders(headerAccessor);
        headerAccessor.setLeaveMutable(true);
        decodedMessage = MessageBuilder.createMessage(HEARTBEAT_PAYLOAD, headerAccessor.getMessageHeaders());
        if (logger.isTraceEnabled()) {
            logger.trace("Decoded " + headerAccessor.getDetailedLogMessage(null));
        }
    }

    return decodedMessage;
}