提交 dbd353bb 编写于 作者: J Juergen Hoeller

MessageHeaderAccessor defensively checks id, timestamp and contentType values

Issue: SPR-12730
上级 c7a456c0
/*
* 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<String, Object>, 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 <b>except</b> in the
......@@ -90,11 +82,20 @@ public class MessageHeaders implements Map<String, Object>, 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<String, Object> headers;
......
/*
* 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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册