/** * Set the value for the given header name only if the header name is not already * associated with a value. */ public MessageBuilder<T> setHeaderIfAbsent(String headerName, Object headerValue) { this.headerAccessor.setHeaderIfAbsent(headerName, headerValue); return this; }
/** * Copy the name-value pairs from the provided Map. * <p>This operation will <em>not</em> overwrite any existing values. */ public void copyHeadersIfAbsent(@Nullable Map<String, ?> headersToCopy) { if (headersToCopy != null) { headersToCopy.forEach((key, value) -> { if (!isReadOnly(key)) { setHeaderIfAbsent(key, value); } }); } }
@Override @Nullable 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(); }
/** * Set the value for the given header name only if the header name is not already * associated with a value. */ public MessageBuilder<T> setHeaderIfAbsent(String headerName, Object headerValue) { this.headerAccessor.setHeaderIfAbsent(headerName, headerValue); return this; }
/** * Copy the name-value pairs from the provided Map. * <p>This operation will <em>not</em> overwrite any existing values. */ public void copyHeadersIfAbsent(@Nullable Map<String, ?> headersToCopy) { if (headersToCopy != null) { headersToCopy.forEach((key, value) -> { if (!isReadOnly(key)) { setHeaderIfAbsent(key, value); } }); } }
@Override @Nullable 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(); }
/** * Set the value for the given header name only if the header name is not already * associated with a value. */ public MessageBuilder<T> setHeaderIfAbsent(String headerName, Object headerValue) { this.headerAccessor.setHeaderIfAbsent(headerName, headerValue); return this; }
/** * Set the value for the given header name only if the header name is not already * associated with a value. */ public MessageBuilder<T> setHeaderIfAbsent(String headerName, Object headerValue) { this.headerAccessor.setHeaderIfAbsent(headerName, headerValue); return this; }
/** * Copy the name-value pairs from the provided Map. * <p>This operation will <em>not</em> overwrite any existing values. */ public void copyHeadersIfAbsent(@Nullable Map<String, ?> headersToCopy) { if (headersToCopy != null) { headersToCopy.forEach((key, value) -> { if (!isReadOnly(key)) { setHeaderIfAbsent(key, value); } }); } }
/** * Copy the name-value pairs from the provided Map. * <p>This operation will <em>not</em> overwrite any existing values. */ public void copyHeadersIfAbsent(@Nullable Map<String, ?> headersToCopy) { if (headersToCopy != null) { headersToCopy.forEach((key, value) -> { if (!isReadOnly(key)) { setHeaderIfAbsent(key, value); } }); } }
@Override @Nullable 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(); }
@Override @Nullable 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(); }