Browse Source

Introduce alias for 'value' attribute in @Payload

This commit introduces 'expression' as an alias for 'value' in @Payload.

Issue: SPR-11393
pull/811/head
Sam Brannen 11 years ago
parent
commit
250787a35a
  1. 21
      spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/Payload.java
  2. 2
      spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/PayloadArgumentResolver.java

21
spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/Payload.java

@ -1,5 +1,5 @@ @@ -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.
@ -22,6 +22,7 @@ import java.lang.annotation.Retention; @@ -22,6 +22,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.core.annotation.AliasFor;
import org.springframework.messaging.converter.MessageConverter;
/**
@ -31,6 +32,7 @@ import org.springframework.messaging.converter.MessageConverter; @@ -31,6 +32,7 @@ import org.springframework.messaging.converter.MessageConverter;
* specific MIME type to an Object matching the target method parameter.
*
* @author Rossen Stoyanchev
* @author Sam Brannen
* @since 4.0
*/
@Target({ElementType.PARAMETER, ElementType.METHOD})
@ -38,14 +40,23 @@ import org.springframework.messaging.converter.MessageConverter; @@ -38,14 +40,23 @@ import org.springframework.messaging.converter.MessageConverter;
@Documented
public @interface Payload {
/**
* Alias for {@link #expression}.
*/
@AliasFor(attribute="expression")
String value() default "";
/**
* A SpEL expression to be evaluated against the payload object as the root context.
* <p>
* This attribute may or may not be supported depending on whether the message being
* handled contains a non-primitive Object as its payload or is in serialized form
* and requires message conversion.
* <p>When processing STOMP over WebSocket messages this attribute is not supported.
* handled contains a non-primitive Object as its payload or is in serialized form and
* requires message conversion.
* <p>
* When processing STOMP over WebSocket messages this attribute is not supported.
*/
String value() default "";
@AliasFor(attribute="value")
String expression() default "";
/**
* Whether payload content is required.

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

@ -87,7 +87,7 @@ public class PayloadArgumentResolver implements HandlerMethodArgumentResolver { @@ -87,7 +87,7 @@ public class PayloadArgumentResolver implements HandlerMethodArgumentResolver {
@Override
public Object resolveArgument(MethodParameter param, Message<?> message) throws Exception {
Payload ann = param.getParameterAnnotation(Payload.class);
if (ann != null && StringUtils.hasText(ann.value())) {
if (ann != null && StringUtils.hasText(ann.expression())) {
throw new IllegalStateException("@Payload SpEL expressions not supported by this resolver");
}

Loading…
Cancel
Save