Skip to content

Commit 54ba5c5

Browse files
committed
Polishing
1 parent 249c688 commit 54ba5c5

File tree

10 files changed

+93
-89
lines changed

10 files changed

+93
-89
lines changed

spring-messaging/src/main/java/org/springframework/messaging/Message.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
public interface Message<T> {
2828

2929
/**
30-
* Return message headers for the message (never {@code null}).
30+
* Return the message payload.
3131
*/
32-
MessageHeaders getHeaders();
32+
T getPayload();
3333

3434
/**
35-
* Return the message payload.
35+
* Return message headers for the message (never {@code null} but may be empty).
3636
*/
37-
T getPayload();
37+
MessageHeaders getHeaders();
3838

3939
}

spring-messaging/src/main/java/org/springframework/messaging/MessageHeaders.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
* </pre>
6161
*
6262
* A third option is to use {@link org.springframework.messaging.support.MessageHeaderAccessor}
63-
* or one of its sub-classes to create specific categories of headers.
63+
* or one of its subclasses to create specific categories of headers.
6464
*
6565
* @author Arjen Poutsma
6666
* @author Mark Fisher
@@ -135,6 +135,7 @@ public <T> T get(Object key, Class<T> type) {
135135
return (T) value;
136136
}
137137

138+
138139
@Override
139140
public boolean equals(Object other) {
140141
return (this == other ||
@@ -193,28 +194,32 @@ public Collection<Object> values() {
193194
// Unsupported Map operations
194195

195196
/**
196-
* Since MessageHeaders are immutable, the call to this method will result in {@link UnsupportedOperationException}.
197+
* Since MessageHeaders are immutable, the call to this method
198+
* will result in {@link UnsupportedOperationException}.
197199
*/
198200
public Object put(String key, Object value) {
199201
throw new UnsupportedOperationException("MessageHeaders is immutable");
200202
}
201203

202204
/**
203-
* Since MessageHeaders are immutable, the call to this method will result in {@link UnsupportedOperationException}.
205+
* Since MessageHeaders are immutable, the call to this method
206+
* will result in {@link UnsupportedOperationException}.
204207
*/
205-
public void putAll(Map<? extends String, ? extends Object> t) {
208+
public void putAll(Map<? extends String, ? extends Object> map) {
206209
throw new UnsupportedOperationException("MessageHeaders is immutable");
207210
}
208211

209212
/**
210-
* Since MessageHeaders are immutable, the call to this method will result in {@link UnsupportedOperationException}.
213+
* Since MessageHeaders are immutable, the call to this method
214+
* will result in {@link UnsupportedOperationException}.
211215
*/
212216
public Object remove(Object key) {
213217
throw new UnsupportedOperationException("MessageHeaders is immutable");
214218
}
215219

216220
/**
217-
* Since MessageHeaders are immutable, the call to this method will result in {@link UnsupportedOperationException}.
221+
* Since MessageHeaders are immutable, the call to this method
222+
* will result in {@link UnsupportedOperationException}.
218223
*/
219224
public void clear() {
220225
throw new UnsupportedOperationException("MessageHeaders is immutable");

spring-messaging/src/main/java/org/springframework/messaging/support/ErrorMessage.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@
2424
* @author Mark Fisher
2525
* @author Oleg Zhurakousky
2626
* @since 4.0
27-
*
2827
* @see MessageBuilder
2928
*/
3029
public class ErrorMessage extends GenericMessage<Throwable> {
@@ -34,17 +33,15 @@ public class ErrorMessage extends GenericMessage<Throwable> {
3433

3534
/**
3635
* Create a new message with the given payload.
37-
*
38-
* @param payload the message payload, never {@code null}
36+
* @param payload the message payload (never {@code null})
3937
*/
4038
public ErrorMessage(Throwable payload) {
4139
super(payload);
4240
}
4341

4442
/**
4543
* Create a new message with the given payload and headers.
46-
*
47-
* @param payload the message payload, never {@code null}
44+
* @param payload the message payload (never {@code null})
4845
* @param headers message headers
4946
*/
5047
public ErrorMessage(Throwable payload, Map<String, Object> headers) {

spring-messaging/src/main/java/org/springframework/messaging/support/GenericMessage.java

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
*
3131
* @author Mark Fisher
3232
* @since 4.0
33-
*
3433
* @see MessageBuilder
3534
*/
3635
public class GenericMessage<T> implements Message<T>, Serializable {
@@ -45,32 +44,47 @@ public class GenericMessage<T> implements Message<T>, Serializable {
4544

4645
/**
4746
* Create a new message with the given payload.
48-
*
49-
* @param payload the message payload, never {@code null}
47+
* @param payload the message payload (never {@code null})
5048
*/
5149
public GenericMessage(T payload) {
52-
this(payload, null);
50+
this(payload, new MessageHeaders(null));
5351
}
5452

5553
/**
5654
* Create a new message with the given payload and headers.
57-
*
58-
* @param payload the message payload, never {@code null}
55+
* @param payload the message payload (never {@code null})
5956
* @param headers message headers
6057
*/
6158
public GenericMessage(T payload, Map<String, Object> headers) {
62-
Assert.notNull(payload, "payload must not be null");
59+
Assert.notNull(payload, "Payload must not be null");
6360
this.headers = new MessageHeaders(headers);
6461
this.payload = payload;
6562
}
6663

6764

65+
public T getPayload() {
66+
return this.payload;
67+
}
68+
6869
public MessageHeaders getHeaders() {
6970
return this.headers;
7071
}
7172

72-
public T getPayload() {
73-
return this.payload;
73+
74+
public boolean equals(Object obj) {
75+
if (this == obj) {
76+
return true;
77+
}
78+
if (obj != null && obj instanceof GenericMessage<?>) {
79+
GenericMessage<?> other = (GenericMessage<?>) obj;
80+
return (ObjectUtils.nullSafeEquals(this.headers.getId(), other.headers.getId()) &&
81+
this.headers.equals(other.headers) && this.payload.equals(other.payload));
82+
}
83+
return false;
84+
}
85+
86+
public int hashCode() {
87+
return (this.headers.hashCode() * 23 + ObjectUtils.nullSafeHashCode(this.payload));
7488
}
7589

7690
public String toString() {
@@ -86,20 +100,4 @@ public String toString() {
86100
return sb.toString();
87101
}
88102

89-
public int hashCode() {
90-
return this.headers.hashCode() * 23 + ObjectUtils.nullSafeHashCode(this.payload);
91-
}
92-
93-
public boolean equals(Object obj) {
94-
if (this == obj) {
95-
return true;
96-
}
97-
if (obj != null && obj instanceof GenericMessage<?>) {
98-
GenericMessage<?> other = (GenericMessage<?>) obj;
99-
return (this.headers.getId().equals(other.headers.getId()) &&
100-
this.headers.equals(other.headers) && this.payload.equals(other.payload));
101-
}
102-
return false;
103-
}
104-
105103
}

spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public Map<String, Object> toMap() {
9494
}
9595

9696
public boolean isModified() {
97-
return (!this.headers.isEmpty());
97+
return !this.headers.isEmpty();
9898
}
9999

100100
public Object getHeader(String headerName) {
@@ -132,10 +132,6 @@ protected void verifyType(String headerName, Object headerValue) {
132132
}
133133
}
134134

135-
protected boolean isReadOnly(String headerName) {
136-
return MessageHeaders.ID.equals(headerName) || MessageHeaders.TIMESTAMP.equals(headerName);
137-
}
138-
139135
/**
140136
* Set the value for the given header name only if the header name is not
141137
* already associated with a value.
@@ -146,6 +142,15 @@ public void setHeaderIfAbsent(String name, Object value) {
146142
}
147143
}
148144

145+
/**
146+
* Remove the value for the given header name.
147+
*/
148+
public void removeHeader(String headerName) {
149+
if (StringUtils.hasLength(headerName) && !isReadOnly(headerName)) {
150+
setHeader(headerName, null);
151+
}
152+
}
153+
149154
/**
150155
* Removes all headers provided via array of 'headerPatterns'.
151156
* <p>As the name suggests, array may contain simple matching patterns for header
@@ -181,15 +186,6 @@ private List<String> getMatchingHeaderNames(String pattern, Map<String, Object>
181186
return matchingHeaderNames;
182187
}
183188

184-
/**
185-
* Remove the value for the given header name.
186-
*/
187-
public void removeHeader(String headerName) {
188-
if (StringUtils.hasLength(headerName) && !isReadOnly(headerName)) {
189-
setHeader(headerName, null);
190-
}
191-
}
192-
193189
/**
194190
* Copy the name-value pairs from the provided Map.
195191
* <p>This operation will overwrite any existing values. Use
@@ -214,13 +210,18 @@ public void copyHeadersIfAbsent(Map<String, ?> headersToCopy) {
214210
if (headersToCopy != null) {
215211
Set<String> keys = headersToCopy.keySet();
216212
for (String key : keys) {
217-
if (!this.isReadOnly(key)) {
213+
if (!isReadOnly(key)) {
218214
setHeaderIfAbsent(key, headersToCopy.get(key));
219215
}
220216
}
221217
}
222218
}
223219

220+
protected boolean isReadOnly(String headerName) {
221+
return (MessageHeaders.ID.equals(headerName) || MessageHeaders.TIMESTAMP.equals(headerName));
222+
}
223+
224+
224225
public UUID getId() {
225226
return (UUID) getHeader(MessageHeaders.ID);
226227
}
@@ -229,6 +230,10 @@ public Long getTimestamp() {
229230
return (Long) getHeader(MessageHeaders.TIMESTAMP);
230231
}
231232

233+
public void setReplyChannelName(String replyChannelName) {
234+
setHeader(MessageHeaders.REPLY_CHANNEL, replyChannelName);
235+
}
236+
232237
public void setReplyChannel(MessageChannel replyChannel) {
233238
setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel);
234239
}
@@ -237,8 +242,8 @@ public Object getReplyChannel() {
237242
return getHeader(MessageHeaders.REPLY_CHANNEL);
238243
}
239244

240-
public void setReplyChannelName(String replyChannelName) {
241-
setHeader(MessageHeaders.REPLY_CHANNEL, replyChannelName);
245+
public void setErrorChannelName(String errorChannelName) {
246+
setHeader(MessageHeaders.ERROR_CHANNEL, errorChannelName);
242247
}
243248

244249
public void setErrorChannel(MessageChannel errorChannel) {
@@ -249,18 +254,14 @@ public Object getErrorChannel() {
249254
return getHeader(MessageHeaders.ERROR_CHANNEL);
250255
}
251256

252-
public void setErrorChannelName(String errorChannelName) {
253-
setHeader(MessageHeaders.ERROR_CHANNEL, errorChannelName);
254-
}
255-
256-
public MimeType getContentType() {
257-
return (MimeType) getHeader(MessageHeaders.CONTENT_TYPE);
258-
}
259-
260257
public void setContentType(MimeType contentType) {
261258
setHeader(MessageHeaders.CONTENT_TYPE, contentType);
262259
}
263260

261+
public MimeType getContentType() {
262+
return (MimeType) getHeader(MessageHeaders.CONTENT_TYPE);
263+
}
264+
264265

265266
@Override
266267
public String toString() {

spring-web/src/main/java/org/springframework/http/ResponseEntity.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,15 +21,19 @@
2121

2222
/**
2323
* Extension of {@link HttpEntity} that adds a {@link HttpStatus} status code.
24+
* Used in {@code RestTemplate} as well {@code @Controller} methods.
2425
*
25-
* <p>Returned by {@link org.springframework.web.client.RestTemplate#getForEntity}:
26+
* <p>In {@code RestTemplate}, this class is returned by
27+
* {@link org.springframework.web.client.RestTemplate#getForEntity getForEntity()} and
28+
* {@link org.springframework.web.client.RestTemplate#exchange exchange()}:
2629
* <pre class="code">
2730
* ResponseEntity&lt;String&gt; entity = template.getForEntity("http://example.com", String.class);
2831
* String body = entity.getBody();
2932
* MediaType contentType = entity.getHeaders().getContentType();
3033
* HttpStatus statusCode = entity.getStatusCode();
3134
* </pre>
32-
* <p>Can also be used in Spring MVC, as a return value from a @Controller method:
35+
*
36+
* <p>Can also be used in Spring MVC, as the return value from a @Controller method:
3337
* <pre class="code">
3438
* &#64;RequestMapping("/handle")
3539
* public ResponseEntity&lt;String&gt; handle() {

spring-web/src/main/java/org/springframework/http/server/ServerHttpAsyncRequestControl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.http.server;
1718

1819
/**
@@ -39,17 +40,17 @@ public interface ServerHttpAsyncRequestControl {
3940
void start(long timeout);
4041

4142
/**
42-
* Whether asynchronous request processing has been started.
43+
* Return whether asynchronous request processing has been started.
4344
*/
4445
boolean isStarted();
4546

4647
/**
47-
* Causes asynchronous request processing to be completed.
48+
* Mark asynchronous request processing as completed.
4849
*/
4950
void complete();
5051

5152
/**
52-
* Whether asynchronous request processing has been completed.
53+
* Return whether asynchronous request processing has been completed.
5354
*/
5455
boolean isCompleted();
5556

0 commit comments

Comments
 (0)