Example usage for org.springframework.messaging.support MessageHeaderAccessor setLeaveMutable

List of usage examples for org.springframework.messaging.support MessageHeaderAccessor setLeaveMutable

Introduction

In this page you can find the example usage for org.springframework.messaging.support MessageHeaderAccessor 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.cloud.sleuth.instrument.messaging.TracingChannelInterceptor.java

private MessageHeaderAccessor mutableHeaderAccessor(Message<?> message) {
    MessageHeaderAccessor headers = MessageHeaderAccessor.getMutableAccessor(message);
    headers.setLeaveMutable(true);
    return headers;
}

From source file:org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.java

@Override
public void handleMessage(Message<?> message) throws MessagingException {
    String destination = getDestination(message);
    if (destination == null) {
        return;/*from  w  w w  . j  a  v  a2 s  . c  o m*/
    }
    String lookupDestination = getLookupDestination(destination);
    if (lookupDestination == null) {
        return;
    }
    MessageHeaderAccessor headerAccessor = MessageHeaderAccessor.getMutableAccessor(message);
    headerAccessor.setHeader(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER, lookupDestination);
    headerAccessor.setLeaveMutable(true);
    message = MessageBuilder.createMessage(message.getPayload(), headerAccessor.getMessageHeaders());

    if (logger.isDebugEnabled()) {
        logger.debug("Searching methods to handle " + headerAccessor.getShortLogMessage(message.getPayload())
                + ", lookupDestination='" + lookupDestination + "'");
    }

    handleMessageInternal(message, lookupDestination);
    headerAccessor.setImmutable();
}