diff --git a/spring-messaging/src/main/java/org/springframework/messaging/MessageHeaders.java b/spring-messaging/src/main/java/org/springframework/messaging/MessageHeaders.java index 45747f37241..a227e8d6e8e 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/MessageHeaders.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/MessageHeaders.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -70,16 +70,8 @@ import org.springframework.util.IdGenerator; */ public class MessageHeaders implements Map, Serializable { - private static final long serialVersionUID = 7035068984263400920L; - - private static final Log logger = LogFactory.getLog(MessageHeaders.class); - public static final UUID ID_VALUE_NONE = new UUID(0,0); - private static volatile IdGenerator idGenerator = null; - - private static final IdGenerator defaultIdGenerator = new AlternativeJdkIdGenerator(); - /** * The key for the Message ID. This is an automatically generated UUID and * should never be explicitly set in the header map except in the @@ -90,11 +82,20 @@ public class MessageHeaders implements Map, Serializable { public static final String TIMESTAMP = "timestamp"; + public static final String CONTENT_TYPE = "contentType"; + public static final String REPLY_CHANNEL = "replyChannel"; public static final String ERROR_CHANNEL = "errorChannel"; - public static final String CONTENT_TYPE = "contentType"; + + private static final long serialVersionUID = 7035068984263400920L; + + private static final Log logger = LogFactory.getLog(MessageHeaders.class); + + private static final IdGenerator defaultIdGenerator = new AlternativeJdkIdGenerator(); + + private static volatile IdGenerator idGenerator = null; private final Map headers; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java b/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java index 4416d14985c..1036de0c4ba 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -418,11 +418,31 @@ public class MessageHeaderAccessor { // Specific header accessors public UUID getId() { - return (UUID) getHeader(MessageHeaders.ID); + Object value = getHeader(MessageHeaders.ID); + if (value == null) { + return null; + } + return (value instanceof UUID ? (UUID) value : UUID.fromString(value.toString())); } public Long getTimestamp() { - return (Long) getHeader(MessageHeaders.TIMESTAMP); + Object value = getHeader(MessageHeaders.TIMESTAMP); + if (value == null) { + return null; + } + return (value instanceof Long ? (Long) value : Long.parseLong(value.toString())); + } + + public void setContentType(MimeType contentType) { + setHeader(MessageHeaders.CONTENT_TYPE, contentType); + } + + public MimeType getContentType() { + Object value = getHeader(MessageHeaders.CONTENT_TYPE); + if (value == null) { + return null; + } + return (value instanceof MimeType ? (MimeType) value : MimeType.valueOf(value.toString())); } public void setReplyChannelName(String replyChannelName) { @@ -449,14 +469,6 @@ public class MessageHeaderAccessor { return getHeader(MessageHeaders.ERROR_CHANNEL); } - public void setContentType(MimeType contentType) { - setHeader(MessageHeaders.CONTENT_TYPE, contentType); - } - - public MimeType getContentType() { - return (MimeType) getHeader(MessageHeaders.CONTENT_TYPE); - } - // Log message stuff @@ -508,7 +520,7 @@ public class MessageHeaderAccessor { protected String getDetailedPayloadLogMessage(Object payload) { if (payload instanceof String) { - return " payload=" + ((String) payload); + return " payload=" + payload; } else if (payload instanceof byte[]) { byte[] bytes = (byte[]) payload;