Skip to content

Commit 9fa4dad

Browse files
committed
Polishing
1 parent 92c657e commit 9fa4dad

File tree

4 files changed

+19
-26
lines changed

4 files changed

+19
-26
lines changed

spring-messaging/src/main/java/org/springframework/messaging/core/GenericMessagingTemplate.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ protected final Message<?> doSendAndReceive(MessageChannel channel, Message<?> r
149149
try {
150150
doSend(channel, requestMessage);
151151
}
152-
catch (RuntimeException e) {
152+
catch (RuntimeException ex) {
153153
tempReplyChannel.setSendFailed(true);
154-
throw e;
154+
throw ex;
155155
}
156156

157157
Message<?> replyMessage = this.doReceive(tempReplyChannel);
@@ -183,7 +183,6 @@ private class TemporaryReplyChannel implements PollableChannel {
183183

184184
private volatile boolean hasSendFailed;
185185

186-
187186
public void setSendFailed(boolean hasSendError) {
188187
this.hasSendFailed = hasSendError;
189188
}

spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/AbstractNamedValueMethodArgumentResolver.java

Lines changed: 7 additions & 8 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.
@@ -58,15 +58,15 @@
5858
*/
5959
public abstract class AbstractNamedValueMethodArgumentResolver implements HandlerMethodArgumentResolver {
6060

61+
private final ConversionService conversionService;
62+
6163
private final ConfigurableBeanFactory configurableBeanFactory;
6264

6365
private final BeanExpressionContext expressionContext;
6466

65-
private Map<MethodParameter, NamedValueInfo> namedValueInfoCache =
67+
private final Map<MethodParameter, NamedValueInfo> namedValueInfoCache =
6668
new ConcurrentHashMap<MethodParameter, NamedValueInfo>(256);
6769

68-
private ConversionService conversionService;
69-
7070

7171
/**
7272
* Constructor with a {@link ConversionService} and a {@link BeanFactory}.
@@ -77,15 +77,14 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
7777
* values are not expected to contain expressions
7878
*/
7979
protected AbstractNamedValueMethodArgumentResolver(ConversionService cs, ConfigurableBeanFactory beanFactory) {
80-
this.conversionService = (cs != null) ? cs : new DefaultConversionService();
80+
this.conversionService = (cs != null ? cs : new DefaultConversionService());
8181
this.configurableBeanFactory = beanFactory;
82-
this.expressionContext = (beanFactory != null) ? new BeanExpressionContext(beanFactory, null) : null;
82+
this.expressionContext = (beanFactory != null ? new BeanExpressionContext(beanFactory, null) : null);
8383
}
8484

8585

8686
@Override
8787
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
88-
8988
Class<?> paramType = parameter.getParameterType();
9089
NamedValueInfo namedValueInfo = getNamedValueInfo(parameter);
9190

@@ -99,7 +98,7 @@ else if (namedValueInfo.required) {
9998
}
10099
value = handleNullValue(namedValueInfo.name, value, paramType);
101100
}
102-
else if ("".equals(value) && (namedValueInfo.defaultValue != null)) {
101+
else if ("".equals(value) && namedValueInfo.defaultValue != null) {
103102
value = resolveDefaultValue(namedValueInfo.defaultValue);
104103
}
105104

spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/HeaderMethodArgumentResolver.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.apache.commons.logging.Log;
2323
import org.apache.commons.logging.LogFactory;
24+
2425
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
2526
import org.springframework.core.MethodParameter;
2627
import org.springframework.core.convert.ConversionService;
@@ -44,6 +45,7 @@ public HeaderMethodArgumentResolver(ConversionService cs, ConfigurableBeanFactor
4445
super(cs, beanFactory);
4546
}
4647

48+
4749
@Override
4850
public boolean supportsParameter(MethodParameter parameter) {
4951
return parameter.hasParameterAnnotation(Header.class);
@@ -56,8 +58,8 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
5658
}
5759

5860
@Override
59-
protected Object resolveArgumentInternal(MethodParameter parameter, Message<?> message,
60-
String name) throws Exception {
61+
protected Object resolveArgumentInternal(MethodParameter parameter, Message<?> message, String name)
62+
throws Exception {
6163

6264
Object headerValue = message.getHeaders().get(name);
6365
Object nativeHeaderValue = getNativeHeaderValue(message, name);
@@ -71,23 +73,19 @@ protected Object resolveArgumentInternal(MethodParameter parameter, Message<?> m
7173
}
7274
}
7375

74-
return (headerValue != null) ? headerValue : nativeHeaderValue;
76+
return (headerValue != null ? headerValue : nativeHeaderValue);
7577
}
7678

7779
private Object getNativeHeaderValue(Message<?> message, String name) {
78-
7980
Map<String, List<String>> nativeHeaders = getNativeHeaders(message);
80-
8181
if (name.startsWith("nativeHeaders.")) {
8282
name = name.substring("nativeHeaders.".length());
8383
}
84-
85-
if ((nativeHeaders == null) || !nativeHeaders.containsKey(name)) {
84+
if (nativeHeaders == null || !nativeHeaders.containsKey(name)) {
8685
return null;
8786
}
88-
8987
List<?> nativeHeaderValues = nativeHeaders.get(name);
90-
return (nativeHeaderValues.size() == 1) ? nativeHeaderValues.get(0) : nativeHeaderValues;
88+
return (nativeHeaderValues.size() == 1 ? nativeHeaderValues.get(0) : nativeHeaderValues);
9189
}
9290

9391
@SuppressWarnings("unchecked")

spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/PayloadArgumentResolver.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,20 @@ public PayloadArgumentResolver(MessageConverter messageConverter, Validator vali
6262
this.validator = validator;
6363
}
6464

65+
6566
@Override
6667
public boolean supportsParameter(MethodParameter parameter) {
6768
return true;
6869
}
6970

7071
@Override
7172
public Object resolveArgument(MethodParameter param, Message<?> message) throws Exception {
72-
7373
Payload annot = param.getParameterAnnotation(Payload.class);
7474
if ((annot != null) && StringUtils.hasText(annot.value())) {
75-
throw new IllegalStateException("@Payload SpEL expressions not supported by this resolver.");
75+
throw new IllegalStateException("@Payload SpEL expressions not supported by this resolver");
7676
}
7777

7878
Object payload = message.getPayload();
79-
8079
if (isEmptyPayload(payload)) {
8180
if (annot == null || annot.required()) {
8281
String paramName = getParameterName(param);
@@ -122,22 +121,20 @@ else if (payload instanceof byte[]) {
122121
return ((byte[]) payload).length == 0;
123122
}
124123
else if (payload instanceof String) {
125-
return ((String) payload).trim().equals("");
124+
return !StringUtils.hasText((String) payload);
126125
}
127126
else {
128127
return false;
129128
}
130129
}
131130

132131
protected void validate(Message<?> message, MethodParameter parameter, Object target) {
133-
134132
if (this.validator == null) {
135133
return;
136134
}
137135

138136
for (Annotation annot : parameter.getParameterAnnotations()) {
139137
if (annot.annotationType().getSimpleName().startsWith("Valid")) {
140-
141138
BeanPropertyBindingResult bindingResult =
142139
new BeanPropertyBindingResult(target, getParameterName(parameter));
143140

0 commit comments

Comments
 (0)