Example usage for org.springframework.messaging.support MessageBuilder copyHeadersIfAbsent

List of usage examples for org.springframework.messaging.support MessageBuilder copyHeadersIfAbsent

Introduction

In this page you can find the example usage for org.springframework.messaging.support MessageBuilder copyHeadersIfAbsent.

Prototype

public MessageBuilder<T> copyHeadersIfAbsent(@Nullable Map<String, ?> headersToCopy) 

Source Link

Document

Copy the name-value pairs from the provided Map.

Usage

From source file:com.kinglcc.spring.jms.core.Jackson2PayloadArgumentResolver.java

@Override
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
    Payload ann = parameter.getParameterAnnotation(Payload.class);
    if (ann != null && StringUtils.hasText(ann.value())) {
        throw new IllegalStateException("@Payload SpEL expressions not supported by this resolver");
    }//from  w  w w.j av a  2s  .c o  m

    Object payload = message.getPayload();
    boolean isGeneric = isGenericMessage(payload);
    if (isGeneric) {
        payload = ((GenericMessage) payload).getContent();
        MessageBuilder<Object> builder = MessageBuilder.withPayload(payload);
        message = builder.copyHeadersIfAbsent(message.getHeaders()).build();
    }
    if (isEmptyPayload(payload)) {
        if (ann == null || ann.required()) {
            bindEmptyPayloadError(parameter, message, payload);
        }
        return null;
    }

    if (isGeneric) {
        return convertFromMessage(parameter, message);
    } else {
        if (ClassUtils.isAssignable(parameter.getParameterType(), payload.getClass())) {
            validate(message, parameter, payload);
            return payload;
        }
        return convertFromMessage(parameter, message);
    }
}