Refactored isEligibleForCopying() to isReadyOnly(). The check is now done in the setHeader() method instead of only when copying header values.

This commit is contained in:
Mark Fisher
2008-09-27 00:44:44 +00:00
parent 1c9e7af1da
commit acd1527470
2 changed files with 15 additions and 17 deletions

View File

@@ -75,7 +75,7 @@ public final class MessageBuilder<T> {
* <code>null</code>, the header will be removed.
*/
public MessageBuilder<T> setHeader(String headerName, Object headerValue) {
if (StringUtils.hasLength(headerName)) {
if (StringUtils.hasLength(headerName) && !(this.isReadOnly(headerName))) {
if (headerValue == null) {
this.headers.remove(headerName);
}
@@ -119,9 +119,7 @@ public final class MessageBuilder<T> {
public MessageBuilder<T> copyHeaders(Map<String, Object> headersToCopy) {
Set<String> keys = headersToCopy.keySet();
for (String key : keys) {
if (this.isEligibleForCopying(key)) {
this.setHeader(key, headersToCopy.get(key));
}
this.setHeader(key, headersToCopy.get(key));
}
return this;
}
@@ -133,9 +131,7 @@ public final class MessageBuilder<T> {
public MessageBuilder<T> copyHeadersIfAbsent(Map<String, Object> headersToCopy) {
Set<String> keys = headersToCopy.keySet();
for (String key : keys) {
if (this.isEligibleForCopying(key)) {
this.setHeaderIfAbsent(key, headersToCopy.get(key));
}
this.setHeaderIfAbsent(key, headersToCopy.get(key));
}
return this;
}
@@ -181,8 +177,8 @@ public final class MessageBuilder<T> {
return new GenericMessage<T>(this.payload, this.headers);
}
private boolean isEligibleForCopying(String key) {
return !(key.equals(MessageHeaders.ID) || key.equals(MessageHeaders.TIMESTAMP));
private boolean isReadOnly(String key) {
return (key.equals(MessageHeaders.ID) || key.equals(MessageHeaders.TIMESTAMP));
}
}

View File

@@ -32,21 +32,23 @@ import java.util.UUID;
*/
public final class MessageHeaders implements Map<String, Object>, Serializable {
public static final String ID = "internal.header.id";
private static final String PREFIX = "spring.integration.";
public static final String TIMESTAMP = "internal.header.timestamp";
public static final String ID = PREFIX + "id";
public static final String CORRELATION_ID = "internal.header.correlationId";
public static final String TIMESTAMP = PREFIX + "timestamp";
public static final String RETURN_ADDRESS = "internal.header.returnAddress";
public static final String CORRELATION_ID = PREFIX + "correlationId";
public static final String EXPIRATION_DATE = "internal.header.exprirationDate";
public static final String RETURN_ADDRESS = PREFIX + "returnAddress";
public static final String PRIORITY = "internal.header.priority";
public static final String EXPIRATION_DATE = PREFIX + "expirationDate";
public static final String SEQUENCE_NUMBER = "internal.header.sequenceNumber";
public static final String PRIORITY = PREFIX + "priority";
public static final String SEQUENCE_SIZE = "internal.header.sequenceSize";
public static final String SEQUENCE_NUMBER = PREFIX + "sequenceNumber";
public static final String SEQUENCE_SIZE = PREFIX + "sequenceSize";
private final Map<String, Object> headers;