List of usage examples for org.springframework.messaging.support MessageBuilder copyHeaders
public MessageBuilder<T> copyHeaders(@Nullable Map<String, ?> headersToCopy)
From source file:org.springframework.messaging.converter.AbstractMessageConverter.java
@Override @Nullable//from w w w. j av a 2s .co m public final Message<?> toMessage(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) { if (!canConvertTo(payload, headers)) { return null; } Object payloadToUse = convertToInternal(payload, headers, conversionHint); if (payloadToUse == null) { return null; } MimeType mimeType = getDefaultContentType(payloadToUse); if (headers != null) { MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(headers, MessageHeaderAccessor.class); if (accessor != null && accessor.isMutable()) { if (mimeType != null) { accessor.setHeaderIfAbsent(MessageHeaders.CONTENT_TYPE, mimeType); } return MessageBuilder.createMessage(payloadToUse, accessor.getMessageHeaders()); } } MessageBuilder<?> builder = MessageBuilder.withPayload(payloadToUse); if (headers != null) { builder.copyHeaders(headers); } if (mimeType != null) { builder.setHeaderIfAbsent(MessageHeaders.CONTENT_TYPE, mimeType); } return builder.build(); }
From source file:org.springframework.messaging.support.converter.AbstractMessageConverter.java
@Override public final Message<?> toMessage(Object payload, MessageHeaders headers) { if (!canConvertTo(payload, headers)) { return null; }// ww w.ja va 2 s . c om payload = convertToInternal(payload, headers); MessageBuilder<?> builder = MessageBuilder.withPayload(payload); if (headers != null) { builder.copyHeaders(headers); } MimeType mimeType = getDefaultContentType(payload); if (mimeType != null) { builder.setHeaderIfAbsent(MessageHeaders.CONTENT_TYPE, mimeType); } return builder.build(); }