Class MessageBuilder<T>
java.lang.Object
org.springframework.integration.support.AbstractIntegrationMessageBuilder<T>
org.springframework.integration.support.MessageBuilder<T>
public final class MessageBuilder<T> extends AbstractIntegrationMessageBuilder<T>
The default message builder; creates immutable
GenericMessage
s.
Named MessageBuilder instead of DefaultMessageBuilder for backwards
compatibility.- Author:
- Arjen Poutsma, Mark Fisher, Oleg Zhurakousky, Dave Syer, Gary Russell, Artem Bilan
-
Method Summary
Modifier and Type Method Description Message<T>
build()
MessageBuilder<T>
copyHeaders(Map<String,?> headersToCopy)
Copy the name-value pairs from the provided Map.MessageBuilder<T>
copyHeadersIfAbsent(Map<String,?> headersToCopy)
Copy the name-value pairs from the provided Map.static <T> MessageBuilder<T>
fromMessage(Message<T> message)
Create a builder for a newMessage
instance pre-populated with all of the headers copied from the provided message.protected Object
getCorrelationId()
<V> V
getHeader(String key, Class<V> type)
Map<String,Object>
getHeaders()
T
getPayload()
protected List<List<Object>>
getSequenceDetails()
protected Object
getSequenceNumber()
protected Object
getSequenceSize()
MessageBuilder<T>
popSequenceDetails()
MessageBuilder<T>
pushSequenceDetails(Object correlationId, int sequenceNumber, int sequenceSize)
MessageBuilder<T>
readOnlyHeaders(String... readOnlyHeaders)
Specify a list of headers which should be considered as read only and prohibited from being populated in the message.MessageBuilder<T>
removeHeader(String headerName)
Remove the value for the given header name.MessageBuilder<T>
removeHeaders(String... headerPatterns)
Removes all headers provided via array of 'headerPatterns'.MessageBuilder<T>
setCorrelationId(Object correlationId)
MessageBuilder<T>
setErrorChannel(MessageChannel errorChannel)
MessageBuilder<T>
setErrorChannelName(String errorChannelName)
MessageBuilder<T>
setExpirationDate(Long expirationDate)
MessageBuilder<T>
setExpirationDate(Date expirationDate)
MessageBuilder<T>
setHeader(String headerName, Object headerValue)
Set the value for the given header name.MessageBuilder<T>
setHeaderIfAbsent(String headerName, Object headerValue)
Set the value for the given header name only if the header name is not already associated with a value.MessageBuilder<T>
setPriority(Integer priority)
MessageBuilder<T>
setReplyChannel(MessageChannel replyChannel)
MessageBuilder<T>
setReplyChannelName(String replyChannelName)
MessageBuilder<T>
setSequenceNumber(Integer sequenceNumber)
MessageBuilder<T>
setSequenceSize(Integer sequenceSize)
static <T> MessageBuilder<T>
withPayload(T payload)
Create a builder for a newMessage
instance with the provided payload.Methods inherited from class org.springframework.integration.support.AbstractIntegrationMessageBuilder
filterAndCopyHeadersIfAbsent
-
Method Details
-
getPayload
- Specified by:
getPayload
in classAbstractIntegrationMessageBuilder<T>
-
getHeaders
- Specified by:
getHeaders
in classAbstractIntegrationMessageBuilder<T>
-
getHeader
- Specified by:
getHeader
in classAbstractIntegrationMessageBuilder<T>
-
fromMessage
Create a builder for a newMessage
instance pre-populated with all of the headers copied from the provided message. The payload of the provided Message will also be used as the payload for the new message.- Type Parameters:
T
- The type of the payload.- Parameters:
message
- the Message from which the payload and all headers will be copied- Returns:
- A MessageBuilder.
-
withPayload
Create a builder for a newMessage
instance with the provided payload.- Type Parameters:
T
- The type of the payload.- Parameters:
payload
- the payload for the new message- Returns:
- A MessageBuilder.
-
setHeader
Set the value for the given header name. If the provided value isnull
, the header will be removed.- Specified by:
setHeader
in classAbstractIntegrationMessageBuilder<T>
- Parameters:
headerName
- The header name.headerValue
- The header value.- Returns:
- this MessageBuilder.
-
setHeaderIfAbsent
Set the value for the given header name only if the header name is not already associated with a value.- Specified by:
setHeaderIfAbsent
in classAbstractIntegrationMessageBuilder<T>
- Parameters:
headerName
- The header name.headerValue
- The header value.- Returns:
- this MessageBuilder.
-
removeHeaders
Removes all headers provided via array of 'headerPatterns'. As the name suggests the array may contain simple matching patterns for header names. Supported pattern styles are: "xxx*", "*xxx", "*xxx*" and "xxx*yyy".- Specified by:
removeHeaders
in classAbstractIntegrationMessageBuilder<T>
- Parameters:
headerPatterns
- The header patterns.- Returns:
- this MessageBuilder.
-
removeHeader
Remove the value for the given header name.- Specified by:
removeHeader
in classAbstractIntegrationMessageBuilder<T>
- Parameters:
headerName
- The header name.- Returns:
- this MessageBuilder.
-
copyHeaders
Copy the name-value pairs from the provided Map. This operation will overwrite any existing values. Use {copyHeadersIfAbsent(Map)
to avoid overwriting values. Note that the 'id' and 'timestamp' header values will never be overwritten.- Specified by:
copyHeaders
in classAbstractIntegrationMessageBuilder<T>
- Parameters:
headersToCopy
- The headers to copy.- Returns:
- this MessageBuilder.
- See Also:
MessageHeaders.ID
,MessageHeaders.TIMESTAMP
-
copyHeadersIfAbsent
Copy the name-value pairs from the provided Map. This operation will not overwrite any existing values.- Specified by:
copyHeadersIfAbsent
in classAbstractIntegrationMessageBuilder<T>
- Parameters:
headersToCopy
- The headers to copy.- Returns:
- this MessageBuilder.
-
getSequenceDetails
- Specified by:
getSequenceDetails
in classAbstractIntegrationMessageBuilder<T>
-
getCorrelationId
- Specified by:
getCorrelationId
in classAbstractIntegrationMessageBuilder<T>
-
getSequenceNumber
- Specified by:
getSequenceNumber
in classAbstractIntegrationMessageBuilder<T>
-
getSequenceSize
- Specified by:
getSequenceSize
in classAbstractIntegrationMessageBuilder<T>
-
pushSequenceDetails
public MessageBuilder<T> pushSequenceDetails(Object correlationId, int sequenceNumber, int sequenceSize)- Overrides:
pushSequenceDetails
in classAbstractIntegrationMessageBuilder<T>
-
popSequenceDetails
- Overrides:
popSequenceDetails
in classAbstractIntegrationMessageBuilder<T>
-
setExpirationDate
- Overrides:
setExpirationDate
in classAbstractIntegrationMessageBuilder<T>
-
setExpirationDate
- Overrides:
setExpirationDate
in classAbstractIntegrationMessageBuilder<T>
-
setCorrelationId
- Overrides:
setCorrelationId
in classAbstractIntegrationMessageBuilder<T>
-
setReplyChannel
- Overrides:
setReplyChannel
in classAbstractIntegrationMessageBuilder<T>
-
setReplyChannelName
- Overrides:
setReplyChannelName
in classAbstractIntegrationMessageBuilder<T>
-
setErrorChannel
- Overrides:
setErrorChannel
in classAbstractIntegrationMessageBuilder<T>
-
setErrorChannelName
- Overrides:
setErrorChannelName
in classAbstractIntegrationMessageBuilder<T>
-
setSequenceNumber
- Overrides:
setSequenceNumber
in classAbstractIntegrationMessageBuilder<T>
-
setSequenceSize
- Overrides:
setSequenceSize
in classAbstractIntegrationMessageBuilder<T>
-
setPriority
- Overrides:
setPriority
in classAbstractIntegrationMessageBuilder<T>
-
readOnlyHeaders
Specify a list of headers which should be considered as read only and prohibited from being populated in the message.- Parameters:
readOnlyHeaders
- the list of headers forreadOnly
mode. Defaults toMessageHeaders.ID
andMessageHeaders.TIMESTAMP
.- Returns:
- the current
MessageBuilder
- Since:
- 4.3.2
- See Also:
IntegrationMessageHeaderAccessor.isReadOnly(String)
-
build
- Specified by:
build
in classAbstractIntegrationMessageBuilder<T>
-