Browse Source

Polishing

pull/602/merge
Juergen Hoeller 10 years ago
parent
commit
9fa4dad13c
  1. 5
      spring-messaging/src/main/java/org/springframework/messaging/core/GenericMessagingTemplate.java
  2. 15
      spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/AbstractNamedValueMethodArgumentResolver.java
  3. 16
      spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/HeaderMethodArgumentResolver.java
  4. 9
      spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/PayloadArgumentResolver.java

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

@ -149,9 +149,9 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag @@ -149,9 +149,9 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
try {
doSend(channel, requestMessage);
}
catch (RuntimeException e) {
catch (RuntimeException ex) {
tempReplyChannel.setSendFailed(true);
throw e;
throw ex;
}
Message<?> replyMessage = this.doReceive(tempReplyChannel);
@ -183,7 +183,6 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag @@ -183,7 +183,6 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
private volatile boolean hasSendFailed;
public void setSendFailed(boolean hasSendError) {
this.hasSendFailed = hasSendError;
}

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@ -58,15 +58,15 @@ import org.springframework.util.ClassUtils; @@ -58,15 +58,15 @@ import org.springframework.util.ClassUtils;
*/
public abstract class AbstractNamedValueMethodArgumentResolver implements HandlerMethodArgumentResolver {
private final ConversionService conversionService;
private final ConfigurableBeanFactory configurableBeanFactory;
private final BeanExpressionContext expressionContext;
private Map<MethodParameter, NamedValueInfo> namedValueInfoCache =
private final Map<MethodParameter, NamedValueInfo> namedValueInfoCache =
new ConcurrentHashMap<MethodParameter, NamedValueInfo>(256);
private ConversionService conversionService;
/**
* Constructor with a {@link ConversionService} and a {@link BeanFactory}.
@ -77,15 +77,14 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle @@ -77,15 +77,14 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
* values are not expected to contain expressions
*/
protected AbstractNamedValueMethodArgumentResolver(ConversionService cs, ConfigurableBeanFactory beanFactory) {
this.conversionService = (cs != null) ? cs : new DefaultConversionService();
this.conversionService = (cs != null ? cs : new DefaultConversionService());
this.configurableBeanFactory = beanFactory;
this.expressionContext = (beanFactory != null) ? new BeanExpressionContext(beanFactory, null) : null;
this.expressionContext = (beanFactory != null ? new BeanExpressionContext(beanFactory, null) : null);
}
@Override
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
Class<?> paramType = parameter.getParameterType();
NamedValueInfo namedValueInfo = getNamedValueInfo(parameter);
@ -99,7 +98,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle @@ -99,7 +98,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
}
value = handleNullValue(namedValueInfo.name, value, paramType);
}
else if ("".equals(value) && (namedValueInfo.defaultValue != null)) {
else if ("".equals(value) && namedValueInfo.defaultValue != null) {
value = resolveDefaultValue(namedValueInfo.defaultValue);
}

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

@ -21,6 +21,7 @@ import java.util.Map; @@ -21,6 +21,7 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.core.MethodParameter;
import org.springframework.core.convert.ConversionService;
@ -44,6 +45,7 @@ public class HeaderMethodArgumentResolver extends AbstractNamedValueMethodArgume @@ -44,6 +45,7 @@ public class HeaderMethodArgumentResolver extends AbstractNamedValueMethodArgume
super(cs, beanFactory);
}
@Override
public boolean supportsParameter(MethodParameter parameter) {
return parameter.hasParameterAnnotation(Header.class);
@ -56,8 +58,8 @@ public class HeaderMethodArgumentResolver extends AbstractNamedValueMethodArgume @@ -56,8 +58,8 @@ public class HeaderMethodArgumentResolver extends AbstractNamedValueMethodArgume
}
@Override
protected Object resolveArgumentInternal(MethodParameter parameter, Message<?> message,
String name) throws Exception {
protected Object resolveArgumentInternal(MethodParameter parameter, Message<?> message, String name)
throws Exception {
Object headerValue = message.getHeaders().get(name);
Object nativeHeaderValue = getNativeHeaderValue(message, name);
@ -71,23 +73,19 @@ public class HeaderMethodArgumentResolver extends AbstractNamedValueMethodArgume @@ -71,23 +73,19 @@ public class HeaderMethodArgumentResolver extends AbstractNamedValueMethodArgume
}
}
return (headerValue != null) ? headerValue : nativeHeaderValue;
return (headerValue != null ? headerValue : nativeHeaderValue);
}
private Object getNativeHeaderValue(Message<?> message, String name) {
Map<String, List<String>> nativeHeaders = getNativeHeaders(message);
if (name.startsWith("nativeHeaders.")) {
name = name.substring("nativeHeaders.".length());
}
if ((nativeHeaders == null) || !nativeHeaders.containsKey(name)) {
if (nativeHeaders == null || !nativeHeaders.containsKey(name)) {
return null;
}
List<?> nativeHeaderValues = nativeHeaders.get(name);
return (nativeHeaderValues.size() == 1) ? nativeHeaderValues.get(0) : nativeHeaderValues;
return (nativeHeaderValues.size() == 1 ? nativeHeaderValues.get(0) : nativeHeaderValues);
}
@SuppressWarnings("unchecked")

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

@ -62,6 +62,7 @@ public class PayloadArgumentResolver implements HandlerMethodArgumentResolver { @@ -62,6 +62,7 @@ public class PayloadArgumentResolver implements HandlerMethodArgumentResolver {
this.validator = validator;
}
@Override
public boolean supportsParameter(MethodParameter parameter) {
return true;
@ -69,14 +70,12 @@ public class PayloadArgumentResolver implements HandlerMethodArgumentResolver { @@ -69,14 +70,12 @@ public class PayloadArgumentResolver implements HandlerMethodArgumentResolver {
@Override
public Object resolveArgument(MethodParameter param, Message<?> message) throws Exception {
Payload annot = param.getParameterAnnotation(Payload.class);
if ((annot != null) && StringUtils.hasText(annot.value())) {
throw new IllegalStateException("@Payload SpEL expressions not supported by this resolver.");
throw new IllegalStateException("@Payload SpEL expressions not supported by this resolver");
}
Object payload = message.getPayload();
if (isEmptyPayload(payload)) {
if (annot == null || annot.required()) {
String paramName = getParameterName(param);
@ -122,7 +121,7 @@ public class PayloadArgumentResolver implements HandlerMethodArgumentResolver { @@ -122,7 +121,7 @@ public class PayloadArgumentResolver implements HandlerMethodArgumentResolver {
return ((byte[]) payload).length == 0;
}
else if (payload instanceof String) {
return ((String) payload).trim().equals("");
return !StringUtils.hasText((String) payload);
}
else {
return false;
@ -130,14 +129,12 @@ public class PayloadArgumentResolver implements HandlerMethodArgumentResolver { @@ -130,14 +129,12 @@ public class PayloadArgumentResolver implements HandlerMethodArgumentResolver {
}
protected void validate(Message<?> message, MethodParameter parameter, Object target) {
if (this.validator == null) {
return;
}
for (Annotation annot : parameter.getParameterAnnotations()) {
if (annot.annotationType().getSimpleName().startsWith("Valid")) {
BeanPropertyBindingResult bindingResult =
new BeanPropertyBindingResult(target, getParameterName(parameter));

Loading…
Cancel
Save