diff --git a/spring-integration-core/src/main/java/org/springframework/integration/message/MessageHeader.java b/spring-integration-core/src/main/java/org/springframework/integration/message/MessageHeader.java
index bee2950938..1458df107d 100644
--- a/spring-integration-core/src/main/java/org/springframework/integration/message/MessageHeader.java
+++ b/spring-integration-core/src/main/java/org/springframework/integration/message/MessageHeader.java
@@ -17,8 +17,10 @@
package org.springframework.integration.message;
import java.util.Date;
+import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -36,6 +38,8 @@ public class MessageHeader {
private String replyChannelName;
+ private Date timestamp = new Date();
+
private Date expiration;
private int sequenceNumber = 1;
@@ -67,6 +71,10 @@ public class MessageHeader {
return this.sequenceNumber;
}
+ public Date getTimestamp() {
+ return this.timestamp;
+ }
+
/**
* Set the expiration date for this message or null to
* indicate 'never expire'. The default is null.
@@ -103,6 +111,14 @@ public class MessageHeader {
this.properties.setProperty(key, value);
}
+ public Set getPropertyNames() {
+ Set propertyNames = new HashSet();
+ for (Object key : this.properties.keySet()) {
+ propertyNames.add((String) key);
+ }
+ return propertyNames;
+ }
+
public Object getAttribute(String key) {
return this.attributes.get(key);
}
@@ -111,4 +127,8 @@ public class MessageHeader {
this.attributes.put(key, value);
}
+ public Set getAttributeNames() {
+ return this.attributes.keySet();
+ }
+
}
diff --git a/spring-integration-core/src/test/java/org/springframework/integration/message/MessageHeaderTests.java b/spring-integration-core/src/test/java/org/springframework/integration/message/MessageHeaderTests.java
new file mode 100644
index 0000000000..f37d8ac703
--- /dev/null
+++ b/spring-integration-core/src/test/java/org/springframework/integration/message/MessageHeaderTests.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2002-2007 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.integration.message;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Set;
+
+import org.junit.Test;
+
+/**
+ * @author Mark Fisher
+ */
+public class MessageHeaderTests {
+
+ @Test
+ public void testTimestamp() {
+ MessageHeader header = new MessageHeader();
+ assertNotNull(header.getTimestamp());
+ }
+
+ @Test
+ public void testAttributes() {
+ MessageHeader header = new MessageHeader();
+ Integer integer = new Integer(123);
+ header.setAttribute("test", integer);
+ assertEquals(integer, header.getAttribute("test"));
+ assertNull(header.getAttribute("nosuchattribute"));
+ Set names = header.getAttributeNames();
+ assertEquals(1, names.size());
+ assertTrue(names.contains("test"));
+ }
+
+ @Test
+ public void testProperties() {
+ MessageHeader header = new MessageHeader();
+ header.setProperty("foo", "bar");
+ assertEquals("bar", header.getProperty("foo"));
+ assertNull(header.getProperty("nosuchproperty"));
+ Set names = header.getPropertyNames();
+ assertEquals(1, names.size());
+ assertTrue(names.contains("foo"));
+ }
+
+}