INT-3492: Deprecate @Payload and @Header(s)
JIRA: https://jira.spring.io/browse/INT-3492 Since `@Paylod` and `@Header(s)` annotations are in the Spring Framework, there is no more need to support them in Spring Integration. Deprecate them and leave for backward compatibility. Will be removed in future releases. Remove deprecated Gatewa's `#method` expression evaluation context variable Tested `gradlew clean testall` with and without changed to the tests. INT-3492: Add `MessagingAnnotationUtils#findMassagePartAnnotation` Move `MessagingAnnotationUtils` to the `org.springframework.integration.util` package
This commit is contained in:
committed by
Gary Russell
parent
162ef1f227
commit
00c404f383
@@ -39,9 +39,9 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.integration.amqp.AmqpHeaders;
|
||||
import org.springframework.integration.amqp.inbound.ManualAckTests.ManualAckConfig;
|
||||
import org.springframework.integration.amqp.rule.BrokerRunning;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.integration.annotation.MessageEndpoint;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.config.EnableIntegration;
|
||||
|
||||
@@ -30,7 +30,8 @@ import java.lang.annotation.Target;
|
||||
* Message payload's type. Any type conversion supported by default or any
|
||||
* Converters registered with the "integrationConversionService" bean will be
|
||||
* applied to the Message payload if necessary. Header values can also be passed
|
||||
* as Message parameters by using the {@link Header @Header} parameter annotation.
|
||||
* as Message parameters by using the
|
||||
* {@link org.springframework.messaging.handler.annotation.Header @Header} parameter annotation.
|
||||
* <p>
|
||||
* The return type of the annotated method must be a boolean (or Boolean).
|
||||
*
|
||||
|
||||
@@ -32,9 +32,11 @@ import java.lang.annotation.Target;
|
||||
* <p>A method annotated with @Gateway may accept a single non-annotated
|
||||
* parameter of type {@link org.springframework.messaging.Message}
|
||||
* or of the intended Message payload type. Method parameters may be mapped
|
||||
* to individual Message header values by using the {@link Header @Header}
|
||||
* to individual Message header values by using the
|
||||
* {@link org.springframework.messaging.handler.annotation.Header @Header}
|
||||
* parameter annotation. Alternatively, to pass the entire Message headers
|
||||
* map, a Map-typed parameter may be annotated with {@link Headers}.
|
||||
* map, a Map-typed parameter may be annotated with
|
||||
* {@link org.springframework.messaging.handler.annotation.Headers}.
|
||||
*
|
||||
* <p>Return values from the annotated method may be of any type. If the
|
||||
* declared return value is not a Message, the reply Message's payload will be
|
||||
|
||||
@@ -25,18 +25,22 @@ import java.lang.annotation.Target;
|
||||
/**
|
||||
* Annotation indicating that a method parameter's value should be
|
||||
* retrieved from the message headers. The value of the annotation
|
||||
* can either be a header name (e.g., 'foo') or SpEL expression
|
||||
* can either be a header name (e.g., 'foo') or SpEL expression
|
||||
* (e.g., 'payload.getCustomerId()') which is quite useful when
|
||||
* the name of the header has to be dynamically computed. It also
|
||||
* the name of the header has to be dynamically computed. It also
|
||||
* provides an optional 'required' property which
|
||||
* specifies whether the attribute value must be available within
|
||||
* the header. The default value for 'required' is <code>true</code>.
|
||||
*
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*
|
||||
* @deprecated since 4.1 in favor of {@link org.springframework.messaging.handler.annotation.Header}.
|
||||
* Will be removed in a future release.
|
||||
*/
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Deprecated
|
||||
public @interface Header {
|
||||
|
||||
String value() default "";
|
||||
|
||||
@@ -26,12 +26,16 @@ import java.lang.annotation.Target;
|
||||
* Annotation indicating that a method parameter's value should be mapped to or
|
||||
* from the message headers. The annotated parameter must be assignable to
|
||||
* {@link java.util.Map}, and all of the Map's keys must be Strings.
|
||||
*
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*
|
||||
* @deprecated since 4.1 in favor of {@link org.springframework.messaging.handler.annotation.Headers}.
|
||||
* Will be removed in a future release.
|
||||
*/
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Deprecated
|
||||
public @interface Headers {
|
||||
|
||||
}
|
||||
|
||||
@@ -33,10 +33,14 @@ import java.lang.annotation.Target;
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.0
|
||||
*
|
||||
* @deprecated since 4.1 in favor of {@link org.springframework.messaging.handler.annotation.Payload}.
|
||||
* Will be removed in a future release.
|
||||
*/
|
||||
@Target({ElementType.PARAMETER, ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Deprecated
|
||||
public @interface Payload {
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,7 +32,8 @@ import java.lang.annotation.Target;
|
||||
* Message payload's type. Any type conversion supported by
|
||||
* {@link org.springframework.beans.SimpleTypeConverter} will be applied to
|
||||
* the Message payload if necessary. Header values can also be passed as
|
||||
* Message parameters by using the {@link Header @Header} parameter annotation.
|
||||
* Message parameters by using the
|
||||
* {@link org.springframework.messaging.handler.annotation.Header @Header} parameter annotation.
|
||||
* <p>
|
||||
* Return values from the annotated method may be either a Collection or Array
|
||||
* whose elements are either
|
||||
|
||||
@@ -31,7 +31,8 @@ import java.lang.annotation.Target;
|
||||
* Message payload's type. Any type conversion supported by
|
||||
* {@link org.springframework.beans.SimpleTypeConverter} will be applied to
|
||||
* the Message payload if necessary. Header values can also be passed as
|
||||
* Message parameters by using the {@link Header @Header} parameter annotation.
|
||||
* Message parameters by using the
|
||||
* {@link org.springframework.messaging.handler.annotation.Header @Header} parameter annotation.
|
||||
* <p>
|
||||
* Return values from the annotated method may be of any type. If the return
|
||||
* value is not a Message, a reply Message will be created with that object
|
||||
|
||||
@@ -31,7 +31,8 @@ import java.lang.annotation.Target;
|
||||
* Message payload's type. Any type conversion supported by
|
||||
* {@link org.springframework.beans.SimpleTypeConverter} will be applied to
|
||||
* the Message payload if necessary. Header values can also be passed as
|
||||
* Message parameters by using the {@link Header @Header} parameter annotation.
|
||||
* Message parameters by using the
|
||||
* {@link org.springframework.messaging.handler.annotation.Header @Header} parameter annotation.
|
||||
* <p>
|
||||
* Return values from the annotated method may be either a Collection or Array
|
||||
* with elements of any type. If the type is not a Message, each will be used
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 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.
|
||||
@@ -26,17 +26,18 @@ import java.util.Set;
|
||||
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
||||
import org.springframework.core.ParameterNameDiscoverer;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.integration.annotation.Publisher;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* An {@link PublisherMetadataSource} implementation that retrieves the channel
|
||||
* name and expression strings from an annotation.
|
||||
*
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
* @since 2.0
|
||||
*/
|
||||
public class MethodAnnotationPublisherMetadataSource implements PublisherMetadataSource {
|
||||
@@ -71,28 +72,39 @@ public class MethodAnnotationPublisherMetadataSource implements PublisherMetadat
|
||||
return (StringUtils.hasText(channelName) ? channelName : null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public String getPayloadExpression(Method method) {
|
||||
String payloadExpression = null;
|
||||
Payload methodPayloadAnnotation = AnnotationUtils.findAnnotation(method, Payload.class);
|
||||
if (methodPayloadAnnotation != null) {
|
||||
payloadExpression = StringUtils.hasText(methodPayloadAnnotation.value())
|
||||
? methodPayloadAnnotation.value()
|
||||
: "#" + PublisherMetadataSource.RETURN_VALUE_VARIABLE_NAME;
|
||||
Annotation methodPayloadAnnotation =
|
||||
AnnotationUtils.findAnnotation(method, org.springframework.integration.annotation.Payload.class);
|
||||
if (methodPayloadAnnotation == null) {
|
||||
methodPayloadAnnotation = AnnotationUtils.findAnnotation(method, Payload.class);
|
||||
}
|
||||
|
||||
if (methodPayloadAnnotation != null) {
|
||||
payloadExpression = getAnnotationValue(methodPayloadAnnotation, null, String.class);
|
||||
if (!StringUtils.hasText(payloadExpression)) {
|
||||
payloadExpression = "#" + PublisherMetadataSource.RETURN_VALUE_VARIABLE_NAME;
|
||||
}
|
||||
}
|
||||
|
||||
Annotation[][] annotationArray = method.getParameterAnnotations();
|
||||
for (int i = 0; i < annotationArray.length; i++) {
|
||||
Annotation[] parameterAnnotations = annotationArray[i];
|
||||
for (Annotation currentAnnotation : parameterAnnotations) {
|
||||
if (Payload.class.equals(currentAnnotation.annotationType())) {
|
||||
if (org.springframework.integration.annotation.Payload.class.equals(currentAnnotation.annotationType())
|
||||
|| Payload.class.equals(currentAnnotation.annotationType())) {
|
||||
Assert.state(payloadExpression == null,
|
||||
"@Payload can be used at most once on a @Publisher method, either at method-level or on a single parameter");
|
||||
Assert.state("".equals(((Payload) currentAnnotation).value()),
|
||||
"@Payload can be used at most once on a @Publisher method, " +
|
||||
"either at method-level or on a single parameter");
|
||||
Assert.state("".equals(AnnotationUtils.getValue(currentAnnotation)),
|
||||
"@Payload on a parameter for a @Publisher method may not contain an expression");
|
||||
payloadExpression = "#" + PublisherMetadataSource.ARGUMENT_MAP_VARIABLE_NAME + "[" + i + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (payloadExpression == null || payloadExpression.contains("#" + PublisherMetadataSource.RETURN_VALUE_VARIABLE_NAME)) {
|
||||
if (payloadExpression == null
|
||||
|| payloadExpression.contains("#" + PublisherMetadataSource.RETURN_VALUE_VARIABLE_NAME)) {
|
||||
Assert.isTrue(!void.class.equals(method.getReturnType()),
|
||||
"When defining @Publisher on a void-returning method, an explicit payload " +
|
||||
"expression that does not rely upon a #return value is required.");
|
||||
@@ -100,6 +112,7 @@ public class MethodAnnotationPublisherMetadataSource implements PublisherMetadat
|
||||
return payloadExpression;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public Map<String, String> getHeaderExpressions(Method method) {
|
||||
Map<String, String> headerExpressions = new HashMap<String, String>();
|
||||
String[] parameterNames = this.parameterNameDiscoverer.getParameterNames(method);
|
||||
@@ -107,13 +120,14 @@ public class MethodAnnotationPublisherMetadataSource implements PublisherMetadat
|
||||
for (int i = 0; i < annotationArray.length; i++) {
|
||||
Annotation[] parameterAnnotations = annotationArray[i];
|
||||
for (Annotation currentAnnotation : parameterAnnotations) {
|
||||
if (Header.class.equals(currentAnnotation.annotationType())) {
|
||||
Header headerAnnotation = (Header) currentAnnotation;
|
||||
String name = headerAnnotation.value();
|
||||
if (org.springframework.integration.annotation.Header.class.equals(currentAnnotation.annotationType())
|
||||
|| Header.class.equals(currentAnnotation.annotationType())) {
|
||||
String name = getAnnotationValue(currentAnnotation, null, String.class);
|
||||
if (!StringUtils.hasText(name)) {
|
||||
name = parameterNames[i];
|
||||
}
|
||||
headerExpressions.put(name, "#" + PublisherMetadataSource.ARGUMENT_MAP_VARIABLE_NAME + "[" + i + "]");
|
||||
headerExpressions.put(name,
|
||||
"#" + PublisherMetadataSource.ARGUMENT_MAP_VARIABLE_NAME + "[" + i + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.integration.IntegrationMessageHeaderAccessor;
|
||||
import org.springframework.integration.aggregator.CorrelationStrategy;
|
||||
import org.springframework.integration.aggregator.HeaderAttributeCorrelationStrategy;
|
||||
import org.springframework.integration.aggregator.MethodInvokingCorrelationStrategy;
|
||||
import org.springframework.integration.config.annotation.MessagingAnnotationUtils;
|
||||
import org.springframework.integration.util.MessagingAnnotationUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.expression.common.LiteralExpression;
|
||||
import org.springframework.integration.annotation.MessagingGateway;
|
||||
import org.springframework.integration.config.annotation.MessagingAnnotationUtils;
|
||||
import org.springframework.integration.util.MessagingAnnotationUtils;
|
||||
import org.springframework.integration.gateway.GatewayMethodMetadata;
|
||||
import org.springframework.integration.gateway.GatewayProxyFactoryBean;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.integration.aggregator.MethodInvokingReleaseStrategy;
|
||||
import org.springframework.integration.aggregator.ReleaseStrategy;
|
||||
import org.springframework.integration.aggregator.SequenceSizeReleaseStrategy;
|
||||
import org.springframework.integration.config.annotation.MessagingAnnotationUtils;
|
||||
import org.springframework.integration.util.MessagingAnnotationUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,6 +49,7 @@ import org.springframework.integration.endpoint.PollingConsumer;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.scheduling.PollerMetadata;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.util.MessagingAnnotationUtils;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.integration.annotation.Aggregator;
|
||||
import org.springframework.integration.annotation.CorrelationStrategy;
|
||||
import org.springframework.integration.annotation.ReleaseStrategy;
|
||||
import org.springframework.integration.store.SimpleMessageStore;
|
||||
import org.springframework.integration.util.MessagingAnnotationUtils;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.core.env.Environment;
|
||||
import org.springframework.integration.annotation.BridgeFrom;
|
||||
import org.springframework.integration.annotation.BridgeTo;
|
||||
import org.springframework.integration.handler.BridgeHandler;
|
||||
import org.springframework.integration.util.MessagingAnnotationUtils;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.integration.annotation.BridgeFrom;
|
||||
import org.springframework.integration.annotation.BridgeTo;
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.handler.BridgeHandler;
|
||||
import org.springframework.integration.util.MessagingAnnotationUtils;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.integration.annotation.Filter;
|
||||
import org.springframework.integration.core.MessageSelector;
|
||||
import org.springframework.integration.filter.MessageFilter;
|
||||
import org.springframework.integration.filter.MethodInvokingSelector;
|
||||
import org.springframework.integration.util.MessagingAnnotationUtils;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.integration.config.IntegrationConfigUtils;
|
||||
import org.springframework.integration.core.MessageSource;
|
||||
import org.springframework.integration.endpoint.MethodInvokingMessageSource;
|
||||
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
|
||||
import org.springframework.integration.util.MessagingAnnotationUtils;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -54,6 +54,7 @@ import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.integration.annotation.Splitter;
|
||||
import org.springframework.integration.annotation.Transformer;
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.util.MessagingAnnotationUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.core.env.Environment;
|
||||
import org.springframework.integration.annotation.Router;
|
||||
import org.springframework.integration.router.AbstractMessageRouter;
|
||||
import org.springframework.integration.router.MethodInvokingRouter;
|
||||
import org.springframework.integration.util.MessagingAnnotationUtils;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.core.env.Environment;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.handler.ServiceActivatingHandler;
|
||||
import org.springframework.integration.util.MessagingAnnotationUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.core.env.Environment;
|
||||
import org.springframework.integration.annotation.Splitter;
|
||||
import org.springframework.integration.splitter.AbstractMessageSplitter;
|
||||
import org.springframework.integration.splitter.MethodInvokingSplitter;
|
||||
import org.springframework.integration.util.MessagingAnnotationUtils;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -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.
|
||||
@@ -31,21 +31,23 @@ import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.ParameterNameDiscoverer;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.annotation.Headers;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.integration.expression.ExpressionUtils;
|
||||
import org.springframework.integration.mapping.InboundMessageMapper;
|
||||
import org.springframework.integration.mapping.MessageMappingException;
|
||||
import org.springframework.integration.support.AbstractIntegrationMessageBuilder;
|
||||
import org.springframework.integration.support.DefaultMessageBuilderFactory;
|
||||
import org.springframework.integration.support.MessageBuilderFactory;
|
||||
import org.springframework.integration.util.MessagingAnnotationUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Headers;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -72,6 +74,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Iwein Fuld
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
* @since 2.0
|
||||
*/
|
||||
class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]>, BeanFactoryAware {
|
||||
@@ -167,7 +170,8 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> evaluateHeaders(EvaluationContext methodInvocationEvaluationContext, Map<String, Expression> headerExpressions) {
|
||||
private Map<String, Object> evaluateHeaders(EvaluationContext methodInvocationEvaluationContext,
|
||||
Map<String, Expression> headerExpressions) {
|
||||
Map<String, Object> evaluatedHeaders = new HashMap<String, Object>();
|
||||
for (Map.Entry<String, Expression> entry : headerExpressions.entrySet()) {
|
||||
Object value = entry.getValue().getValue(methodInvocationEvaluationContext);
|
||||
@@ -182,9 +186,6 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]
|
||||
StandardEvaluationContext context = ExpressionUtils.createStandardEvaluationContext(this.beanFactory);
|
||||
context.setVariable("args", arguments);
|
||||
|
||||
// TODO deprecated in 3.0/4.0 - retained for backwards compatibility
|
||||
context.setVariable("method", this.method.getName());
|
||||
|
||||
context.setVariable("gatewayMethod", this.method);
|
||||
return context;
|
||||
}
|
||||
@@ -198,23 +199,6 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]
|
||||
return expression.getValue(this.payloadExpressionEvaluationContext, argumentValue);
|
||||
}
|
||||
|
||||
private Annotation findMappingAnnotation(Annotation[] annotations) {
|
||||
if (annotations == null || annotations.length == 0) {
|
||||
return null;
|
||||
}
|
||||
Annotation match = null;
|
||||
for (Annotation annotation : annotations) {
|
||||
Class<? extends Annotation> type = annotation.annotationType();
|
||||
if (type.equals(Payload.class) || type.equals(Header.class) || type.equals(Headers.class)) {
|
||||
if (match != null) {
|
||||
throw new MessagingException("At most one parameter annotation can be provided for message mapping, " +
|
||||
"but found two: [" + match.annotationType().getName() + "] and [" + annotation.annotationType().getName() + "]");
|
||||
}
|
||||
match = annotation;
|
||||
}
|
||||
}
|
||||
return match;
|
||||
}
|
||||
|
||||
private void copyHeaders(Map<?, ?> argumentValue, Map<String, Object> headers) {
|
||||
for (Object key : argumentValue.keySet()) {
|
||||
@@ -237,8 +221,8 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]
|
||||
"payload or Message. Found more than one on method [" + methodParameter.getMethod() + "]");
|
||||
}
|
||||
|
||||
private String determineHeaderName(Header headerAnnotation, MethodParameter methodParameter) {
|
||||
String valueAttribute = headerAnnotation.value();
|
||||
private String determineHeaderName(Annotation headerAnnotation, MethodParameter methodParameter) {
|
||||
String valueAttribute = (String) AnnotationUtils.getValue(headerAnnotation);
|
||||
String headerName = StringUtils.hasText(valueAttribute) ? valueAttribute : methodParameter.getParameterName();
|
||||
Assert.notNull(headerName, "Cannot determine header name. Possible reasons: -debug is " +
|
||||
"disabled or header name is not explicitly provided via @Header annotation.");
|
||||
@@ -257,11 +241,15 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]
|
||||
return parameterList;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static Expression parsePayloadExpression(Method method) {
|
||||
Expression expression = null;
|
||||
Payload payload = method.getAnnotation(Payload.class);
|
||||
Annotation payload = method.getAnnotation(org.springframework.integration.annotation.Payload.class);
|
||||
if (payload == null) {
|
||||
payload = method.getAnnotation(Payload.class);
|
||||
}
|
||||
if (payload != null) {
|
||||
String expressionString = payload.value();
|
||||
String expressionString = (String) AnnotationUtils.getValue(payload);
|
||||
Assert.hasText(expressionString,
|
||||
"@Payload at method-level on a Gateway must provide a non-empty Expression.");
|
||||
expression = PARSER.parseExpression(expressionString);
|
||||
@@ -272,6 +260,7 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]
|
||||
public class DefaultMethodArgsMessageMapper implements MethodArgsMessageMapper {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public Message<?> toMessage(MethodArgsHolder holder) throws Exception {
|
||||
Object messageOrPayload = null;
|
||||
boolean foundPayloadAnnotation = false;
|
||||
@@ -279,35 +268,42 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]
|
||||
EvaluationContext methodInvocationEvaluationContext = createMethodInvocationEvaluationContext(arguments);
|
||||
Map<String, Object> headers = new HashMap<String, Object>();
|
||||
if (GatewayMethodInboundMessageMapper.this.payloadExpression != null) {
|
||||
messageOrPayload = GatewayMethodInboundMessageMapper.this.payloadExpression.getValue(methodInvocationEvaluationContext);
|
||||
messageOrPayload =
|
||||
GatewayMethodInboundMessageMapper.this.payloadExpression.getValue(methodInvocationEvaluationContext);
|
||||
}
|
||||
for (int i = 0; i < GatewayMethodInboundMessageMapper.this.parameterList.size(); i++) {
|
||||
Object argumentValue = arguments[i];
|
||||
MethodParameter methodParameter = GatewayMethodInboundMessageMapper.this.parameterList.get(i);
|
||||
Annotation annotation = GatewayMethodInboundMessageMapper.this.findMappingAnnotation(methodParameter.getParameterAnnotations());
|
||||
Annotation annotation =
|
||||
MessagingAnnotationUtils.findMessagePartAnnotation(methodParameter.getParameterAnnotations());
|
||||
if (annotation != null) {
|
||||
if (annotation.annotationType().equals(Payload.class)) {
|
||||
if (annotation.annotationType().equals(org.springframework.integration.annotation.Payload.class)
|
||||
|| annotation.annotationType().equals(Payload.class)) {
|
||||
if (messageOrPayload != null) {
|
||||
GatewayMethodInboundMessageMapper.this.throwExceptionForMultipleMessageOrPayloadParameters(methodParameter);
|
||||
}
|
||||
String expression = ((Payload) annotation).value();
|
||||
String expression = (String) AnnotationUtils.getValue(annotation);
|
||||
if (!StringUtils.hasText(expression)) {
|
||||
messageOrPayload = argumentValue;
|
||||
}
|
||||
else {
|
||||
messageOrPayload = GatewayMethodInboundMessageMapper.this.evaluatePayloadExpression(expression, argumentValue);
|
||||
messageOrPayload =
|
||||
GatewayMethodInboundMessageMapper.this.evaluatePayloadExpression(expression, argumentValue);
|
||||
}
|
||||
foundPayloadAnnotation = true;
|
||||
}
|
||||
else if (annotation.annotationType().equals(Header.class)) {
|
||||
Header headerAnnotation = (Header) annotation;
|
||||
String headerName = GatewayMethodInboundMessageMapper.this.determineHeaderName(headerAnnotation, methodParameter);
|
||||
if (headerAnnotation.required() && argumentValue == null) {
|
||||
throw new IllegalArgumentException("Received null argument value for required header: '" + headerName + "'");
|
||||
else if (annotation.annotationType().equals(org.springframework.integration.annotation.Header.class)
|
||||
|| annotation.annotationType().equals(Header.class)) {
|
||||
String headerName =
|
||||
GatewayMethodInboundMessageMapper.this.determineHeaderName(annotation, methodParameter);
|
||||
if ((Boolean) AnnotationUtils.getValue(annotation, "required") && argumentValue == null) {
|
||||
throw new IllegalArgumentException("Received null argument value for required header: '"
|
||||
+ headerName + "'");
|
||||
}
|
||||
headers.put(headerName, argumentValue);
|
||||
}
|
||||
else if (annotation.annotationType().equals(Headers.class)) {
|
||||
else if (annotation.annotationType().equals(org.springframework.integration.annotation.Headers.class)
|
||||
|| annotation.annotationType().equals(Headers.class)) {
|
||||
if (argumentValue != null) {
|
||||
if (!(argumentValue instanceof Map)) {
|
||||
throw new IllegalArgumentException("@Headers annotation is only valid for Map-typed parameters");
|
||||
@@ -337,7 +333,8 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]
|
||||
GatewayMethodInboundMessageMapper.this.throwExceptionForMultipleMessageOrPayloadParameters(methodParameter);
|
||||
}
|
||||
}
|
||||
Assert.isTrue(messageOrPayload != null, "unable to determine a Message or payload parameter on method [" + method + "]");
|
||||
Assert.isTrue(messageOrPayload != null,
|
||||
"unable to determine a Message or payload parameter on method [" + method + "]");
|
||||
AbstractIntegrationMessageBuilder<?> builder = (messageOrPayload instanceof Message)
|
||||
? GatewayMethodInboundMessageMapper.this.messageBuilderFactory.fromMessage((Message<?>) messageOrPayload)
|
||||
: GatewayMethodInboundMessageMapper.this.messageBuilderFactory.withPayload(messageOrPayload);
|
||||
|
||||
@@ -46,7 +46,6 @@ import org.springframework.expression.common.LiteralExpression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.integration.annotation.Gateway;
|
||||
import org.springframework.integration.annotation.GatewayHeader;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.history.TrackableComponent;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
@@ -55,6 +54,7 @@ import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.core.DestinationResolver;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -349,7 +349,10 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint
|
||||
boolean shouldReply = returnType != void.class;
|
||||
int paramCount = method.getParameterTypes().length;
|
||||
Object response = null;
|
||||
boolean hasPayloadExpression = method.isAnnotationPresent(Payload.class);
|
||||
@SuppressWarnings("deprecation")
|
||||
boolean hasPayloadExpression =
|
||||
method.isAnnotationPresent(org.springframework.integration.annotation.Payload.class)
|
||||
|| method.isAnnotationPresent(Payload.class);
|
||||
if (!hasPayloadExpression && this.methodMetadataMap != null) {
|
||||
// check for the method metadata next
|
||||
GatewayMethodMetadata metadata = this.methodMetadataMap.get(method.getName());
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.messaging.MessageHeaders;
|
||||
* Generic strategy interface for mapping {@link MessageHeaders} to and from other
|
||||
* types of objects. This would typically be used by adapters where the "other type"
|
||||
* has a concept of headers or properties (HTTP, JMS, AMQP, etc).
|
||||
*
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*
|
||||
* @param <T> type of the instance to and from which headers will be mapped.
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.config.annotation;
|
||||
|
||||
package org.springframework.integration.util;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -23,6 +24,10 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Headers;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -90,6 +95,39 @@ public final class MessagingAnnotationUtils {
|
||||
return reference.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the one of {@link Payload}, {@link Header} or {@link Headers} annotation from
|
||||
* the provided {@code annotations} array.
|
||||
* @param annotations the annotations to scan.
|
||||
* @return the matched annotation or {@code null}.
|
||||
* @throws MessagingException if more than one of {@link Payload}, {@link Header}
|
||||
* or {@link Headers} annotations are presented.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Annotation findMessagePartAnnotation(Annotation[] annotations) {
|
||||
if (annotations == null || annotations.length == 0) {
|
||||
return null;
|
||||
}
|
||||
Annotation match = null;
|
||||
for (Annotation annotation : annotations) {
|
||||
Class<? extends Annotation> type = annotation.annotationType();
|
||||
if (type.equals(org.springframework.integration.annotation.Payload.class)
|
||||
|| type.equals(Payload.class)
|
||||
|| type.equals(org.springframework.integration.annotation.Header.class)
|
||||
|| type.equals(Header.class)
|
||||
|| type.equals(org.springframework.integration.annotation.Headers.class)
|
||||
|| type.equals(Headers.class)) {
|
||||
if (match != null) {
|
||||
throw new MessagingException("At most one parameter annotation can be provided "
|
||||
+ "for message mapping, but found two: [" + match.annotationType().getName() + "] and ["
|
||||
+ annotation.annotationType().getName() + "]");
|
||||
}
|
||||
match = annotation;
|
||||
}
|
||||
}
|
||||
return match;
|
||||
}
|
||||
|
||||
private static Class<?> getTargetClass(Object targetObject) {
|
||||
Class<?> targetClass = targetObject.getClass();
|
||||
if (AopUtils.isAopProxy(targetObject)) {
|
||||
@@ -43,6 +43,7 @@ import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.ParameterNameDiscoverer;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.expression.EvaluationException;
|
||||
@@ -50,14 +51,13 @@ import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.TypeConverter;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.annotation.Headers;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.integration.annotation.Payloads;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandlingException;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Headers;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
@@ -235,7 +235,8 @@ public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator
|
||||
if (method instanceof Method) {
|
||||
context.registerMethodFilter(targetType, new FixedMethodFilter((Method) method));
|
||||
if (expectedType != null) {
|
||||
Assert.state(context.getTypeConverter().canConvert(TypeDescriptor.valueOf(((Method) method).getReturnType()),
|
||||
Assert.state(context.getTypeConverter()
|
||||
.canConvert(TypeDescriptor.valueOf(((Method) method).getReturnType()),
|
||||
TypeDescriptor.valueOf(expectedType)),
|
||||
"Cannot convert to expected type (" + expectedType + ") from " + method);
|
||||
}
|
||||
@@ -250,13 +251,15 @@ public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator
|
||||
context.setVariable("target", targetObject);
|
||||
}
|
||||
|
||||
private boolean canReturnExpectedType(AnnotatedMethodFilter filter, Class<?> targetType, TypeConverter typeConverter) {
|
||||
private boolean canReturnExpectedType(AnnotatedMethodFilter filter, Class<?> targetType,
|
||||
TypeConverter typeConverter) {
|
||||
if (expectedType == null) {
|
||||
return true;
|
||||
}
|
||||
List<Method> methods = filter.filter(Arrays.asList(ReflectionUtils.getAllDeclaredMethods(targetType)));
|
||||
for (Method method : methods) {
|
||||
if (typeConverter.canConvert(TypeDescriptor.valueOf(method.getReturnType()), TypeDescriptor.valueOf(expectedType))) {
|
||||
if (typeConverter.canConvert(TypeDescriptor.valueOf(method.getReturnType()),
|
||||
TypeDescriptor.valueOf(expectedType))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -413,7 +416,8 @@ public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator
|
||||
if ("org.springframework.integration.gateway.RequestReplyExchanger".equals(iface.getName())) {
|
||||
frameworkMethods.add(targetClass.getMethod("exchange", Message.class));
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(targetObject.getClass() + ": Ambiguous fallback methods; using RequestReplyExchanger.exchange()");
|
||||
logger.debug(targetObject.getClass() +
|
||||
": Ambiguous fallback methods; using RequestReplyExchanger.exchange()");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -431,7 +435,8 @@ public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator
|
||||
|
||||
try {
|
||||
Assert.state(!fallbackMethods.isEmpty() || !fallbackMessageMethods.isEmpty(),
|
||||
"Target object of type [" + this.targetObject.getClass() + "] has no eligible methods for handling Messages.");
|
||||
"Target object of type [" + this.targetObject.getClass() +
|
||||
"] has no eligible methods for handling Messages.");
|
||||
}
|
||||
catch (Exception e) {
|
||||
//TODO backward compatibility
|
||||
@@ -536,7 +541,8 @@ public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator
|
||||
|
||||
private static final SpelExpressionParser EXPRESSION_PARSER = new SpelExpressionParser();
|
||||
|
||||
private static final ParameterNameDiscoverer PARAMETER_NAME_DISCOVERER = new LocalVariableTableParameterNameDiscoverer();
|
||||
private static final ParameterNameDiscoverer PARAMETER_NAME_DISCOVERER =
|
||||
new LocalVariableTableParameterNameDiscoverer();
|
||||
|
||||
private static final TypeDescriptor messageTypeDescriptor = TypeDescriptor.valueOf(Message.class);
|
||||
|
||||
@@ -585,6 +591,7 @@ public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator
|
||||
return this.method.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private Expression generateExpression(Method method) {
|
||||
StringBuilder sb = new StringBuilder("#target." + method.getName() + "(");
|
||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
@@ -597,12 +604,14 @@ public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator
|
||||
MethodParameter methodParameter = new MethodParameter(method, i);
|
||||
TypeDescriptor parameterTypeDescriptor = new TypeDescriptor(methodParameter);
|
||||
Class<?> parameterType = parameterTypeDescriptor.getObjectType();
|
||||
Annotation mappingAnnotation = findMappingAnnotation(parameterAnnotations[i]);
|
||||
Annotation mappingAnnotation =
|
||||
MessagingAnnotationUtils.findMessagePartAnnotation(parameterAnnotations[i]);
|
||||
if (mappingAnnotation != null) {
|
||||
Class<? extends Annotation> annotationType = mappingAnnotation.annotationType();
|
||||
if (annotationType.equals(Payload.class)) {
|
||||
if (annotationType.equals(org.springframework.integration.annotation.Payload.class)
|
||||
|| annotationType.equals(Payload.class)) {
|
||||
sb.append("payload");
|
||||
String qualifierExpression = ((Payload) mappingAnnotation).value();
|
||||
String qualifierExpression = (String) AnnotationUtils.getValue(mappingAnnotation);
|
||||
if (StringUtils.hasText(qualifierExpression)) {
|
||||
sb.append("." + qualifierExpression);
|
||||
}
|
||||
@@ -621,14 +630,15 @@ public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator
|
||||
this.setExclusiveTargetParameterType(parameterTypeDescriptor, methodParameter);
|
||||
}
|
||||
}
|
||||
else if (annotationType.equals(Headers.class)) {
|
||||
else if (annotationType.equals(org.springframework.integration.annotation.Headers.class)
|
||||
|| annotationType.equals(Headers.class)) {
|
||||
Assert.isTrue(Map.class.isAssignableFrom(parameterType),
|
||||
"The @Headers annotation can only be applied to a Map-typed parameter.");
|
||||
sb.append("headers");
|
||||
}
|
||||
else if (annotationType.equals(Header.class)) {
|
||||
Header headerAnnotation = (Header) mappingAnnotation;
|
||||
sb.append(this.determineHeaderExpression(headerAnnotation, methodParameter));
|
||||
else if (annotationType.equals(org.springframework.integration.annotation.Header.class)
|
||||
|| annotationType.equals(Header.class)) {
|
||||
sb.append(this.determineHeaderExpression(mappingAnnotation, methodParameter));
|
||||
}
|
||||
}
|
||||
else if (parameterTypeDescriptor.isAssignableTo(messageTypeDescriptor)) {
|
||||
@@ -636,8 +646,8 @@ public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator
|
||||
sb.append("message");
|
||||
this.setExclusiveTargetParameterType(parameterTypeDescriptor, methodParameter);
|
||||
}
|
||||
else if ((parameterTypeDescriptor.isAssignableTo(messageListTypeDescriptor) || parameterTypeDescriptor
|
||||
.isAssignableTo(messageArrayTypeDescriptor))) {
|
||||
else if ((parameterTypeDescriptor.isAssignableTo(messageListTypeDescriptor)
|
||||
|| parameterTypeDescriptor.isAssignableTo(messageArrayTypeDescriptor))) {
|
||||
sb.append("messages");
|
||||
this.setExclusiveTargetParameterType(parameterTypeDescriptor, methodParameter);
|
||||
}
|
||||
@@ -704,31 +714,13 @@ public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator
|
||||
return EXPRESSION_PARSER.parseExpression(sb.toString());
|
||||
}
|
||||
|
||||
private Annotation findMappingAnnotation(Annotation[] annotations) {
|
||||
if (annotations == null || annotations.length == 0) {
|
||||
return null;
|
||||
}
|
||||
Annotation match = null;
|
||||
for (Annotation annotation : annotations) {
|
||||
Class<? extends Annotation> type = annotation.annotationType();
|
||||
if (type.equals(Payload.class) || type.equals(Payloads.class) || type.equals(Header.class) || type.equals(Headers.class)) {
|
||||
if (match != null) {
|
||||
throw new MessagingException(
|
||||
"At most one parameter annotation can be provided for message mapping, "
|
||||
+ "but found two: [" + match.annotationType().getName() + "] and ["
|
||||
+ annotation.annotationType().getName() + "]");
|
||||
}
|
||||
match = annotation;
|
||||
}
|
||||
}
|
||||
return match;
|
||||
}
|
||||
|
||||
private String determineHeaderExpression(Header headerAnnotation, MethodParameter methodParameter) {
|
||||
private String determineHeaderExpression(Annotation headerAnnotation, MethodParameter methodParameter) {
|
||||
methodParameter.initParameterNameDiscovery(PARAMETER_NAME_DISCOVERER);
|
||||
String headerName = null;
|
||||
String relativeExpression = "";
|
||||
String valueAttribute = headerAnnotation.value();
|
||||
AnnotationAttributes annotationAttributes =
|
||||
(AnnotationAttributes) AnnotationUtils.getAnnotationAttributes(headerAnnotation);
|
||||
String valueAttribute = annotationAttributes.getString(AnnotationUtils.VALUE);
|
||||
if (!StringUtils.hasText(valueAttribute)) {
|
||||
headerName = methodParameter.getParameterName();
|
||||
}
|
||||
@@ -746,13 +738,15 @@ public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator
|
||||
+ "disabled or header name is not explicitly provided via @Header annotation.");
|
||||
String headerRetrievalExpression = "headers['" + headerName + "']";
|
||||
String fullHeaderExpression = headerRetrievalExpression + relativeExpression;
|
||||
String fallbackExpression = (headerAnnotation.required())
|
||||
? "T(org.springframework.util.Assert).isTrue(false, 'required header not available: " + headerName + "')"
|
||||
String fallbackExpression = (annotationAttributes.getBoolean("required"))
|
||||
? "T(org.springframework.util.Assert).isTrue(false, 'required header not available: "
|
||||
+ headerName + "')"
|
||||
: "null";
|
||||
return headerRetrievalExpression + " != null ? " + fullHeaderExpression + " : " + fallbackExpression;
|
||||
}
|
||||
|
||||
private synchronized void setExclusiveTargetParameterType(TypeDescriptor targetParameterType, MethodParameter methodParameter) {
|
||||
private synchronized void setExclusiveTargetParameterType(TypeDescriptor targetParameterType,
|
||||
MethodParameter methodParameter) {
|
||||
if (this.targetParameterTypeDescriptor != null) {
|
||||
throw new IneligibleMethodException("Found more than one parameter type candidate: ["
|
||||
+ this.targetParameterTypeDescriptor + "] and [" + targetParameterType + "]");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -13,20 +13,22 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.aggregator;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class CorrelationStrategyAdapterTests {
|
||||
|
||||
@@ -39,7 +41,8 @@ public class CorrelationStrategyAdapterTests {
|
||||
|
||||
@Test
|
||||
public void testMethodName() {
|
||||
MethodInvokingCorrelationStrategy adapter = new MethodInvokingCorrelationStrategy(new SimpleMessageCorrelator(), "getKey");
|
||||
MethodInvokingCorrelationStrategy adapter =
|
||||
new MethodInvokingCorrelationStrategy(new SimpleMessageCorrelator(), "getKey");
|
||||
assertEquals("b", adapter.getCorrelationKey(message));
|
||||
}
|
||||
|
||||
@@ -52,13 +55,15 @@ public class CorrelationStrategyAdapterTests {
|
||||
|
||||
@Test
|
||||
public void testCorrelationStrategyAdapterPojoMethod() {
|
||||
MethodInvokingCorrelationStrategy adapter = new MethodInvokingCorrelationStrategy(new SimplePojoCorrelator(), "getKey");
|
||||
MethodInvokingCorrelationStrategy adapter =
|
||||
new MethodInvokingCorrelationStrategy(new SimplePojoCorrelator(), "getKey");
|
||||
assertEquals("foo", adapter.getCorrelationKey(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeaderPojoMethod() {
|
||||
MethodInvokingCorrelationStrategy adapter = new MethodInvokingCorrelationStrategy(new SimpleHeaderCorrelator(), "getKey");
|
||||
MethodInvokingCorrelationStrategy adapter =
|
||||
new MethodInvokingCorrelationStrategy(new SimpleHeaderCorrelator(), "getKey");
|
||||
assertEquals("b", adapter.getCorrelationKey(message));
|
||||
}
|
||||
|
||||
@@ -74,6 +79,7 @@ public class CorrelationStrategyAdapterTests {
|
||||
public String getKey(@Header("a") String header, @Header("c") String other) {
|
||||
return header + other;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class SimpleHeaderCorrelator {
|
||||
@@ -81,6 +87,7 @@ public class CorrelationStrategyAdapterTests {
|
||||
public String getKey(@Header("a") String header) {
|
||||
return header;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class SimplePojoCorrelator {
|
||||
@@ -88,6 +95,7 @@ public class CorrelationStrategyAdapterTests {
|
||||
public String getKey(String message) {
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class SimpleMessageCorrelator {
|
||||
@@ -95,6 +103,7 @@ public class CorrelationStrategyAdapterTests {
|
||||
public String getKey(Message<?> message) {
|
||||
return (String) message.getHeaders().get("a");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -16,6 +16,13 @@
|
||||
|
||||
package org.springframework.integration.aggregator;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -28,31 +35,23 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.integration.annotation.Aggregator;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.annotation.Headers;
|
||||
import org.springframework.integration.annotation.Payloads;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.integration.store.MessageGroup;
|
||||
import org.springframework.integration.store.SimpleMessageGroup;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Headers;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class MethodInvokingMessageGroupProcessorTests {
|
||||
|
||||
@@ -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.
|
||||
@@ -23,8 +23,8 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.integration.annotation.Publisher;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -24,8 +24,8 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.integration.annotation.Publisher;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -24,8 +24,8 @@ import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.integration.annotation.Publisher;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 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.
|
||||
@@ -30,7 +30,7 @@ import org.junit.Test;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.integration.annotation.Publisher;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ import org.junit.Test;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.integration.annotation.Publisher;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.config.IntegrationEvaluationContextFactoryBean;
|
||||
|
||||
@@ -72,7 +72,7 @@ import org.springframework.integration.annotation.InboundChannelAdapter;
|
||||
import org.springframework.integration.annotation.IntegrationComponentScan;
|
||||
import org.springframework.integration.annotation.MessageEndpoint;
|
||||
import org.springframework.integration.annotation.MessagingGateway;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.integration.annotation.Poller;
|
||||
import org.springframework.integration.annotation.Publisher;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
|
||||
@@ -46,10 +46,10 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.annotation.BridgeTo;
|
||||
import org.springframework.integration.annotation.Gateway;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.integration.annotation.IntegrationComponentScan;
|
||||
import org.springframework.integration.annotation.MessagingGateway;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.config.EnableIntegration;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
|
||||
@@ -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.
|
||||
@@ -31,9 +31,9 @@ import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.common.LiteralExpression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.annotation.Headers;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Headers;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.integration.mapping.MessageMappingException;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -28,18 +28,19 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.annotation.Headers;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Headers;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.config.IntegrationEvaluationContextFactoryBean;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
* @since 2.0
|
||||
*/
|
||||
public class GatewayProxyMessageMappingTests {
|
||||
@@ -214,6 +215,10 @@ public class GatewayProxyMessageMappingTests {
|
||||
|
||||
void payloadAndHeaderMapWithoutAnnotations(String s, Map<String, Object> map);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
void payloadAndHeaderMapWithAnnotationsDeprecated(@org.springframework.integration.annotation.Payload String s,
|
||||
@org.springframework.integration.annotation.Headers Map<String, Object> map);
|
||||
|
||||
void payloadAndHeaderMapWithAnnotations(@Payload String s, @Headers Map<String, Object> map);
|
||||
|
||||
void headerValuesAndPayloadWithAnnotations(@Header("k1") String x, @Payload String s, @Header("k2") String y);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -20,10 +20,11 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.integration.IntegrationMessageHeaderAccessor;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -49,7 +50,9 @@ public class GatewayWithHeaderAnnotations {
|
||||
|
||||
public static interface TestService {
|
||||
// wrt INT-1205, priority no longer has a $ prefix, so here we are testing the $custom header as well
|
||||
public String test(String str, @Header(IntegrationMessageHeaderAccessor.PRIORITY) int priority, @Header("$custom") String custom);
|
||||
public String test(String str, @Header(IntegrationMessageHeaderAccessor.PRIORITY) int priority,
|
||||
@Header("$custom") String custom);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<int:gateway id="gateway" service-interface="org.springframework.integration.gateway.GatewayWithPayloadExpressionTests$SampleGateway">
|
||||
<int:method name="send1" request-channel="input" payload-expression="#args[0] + 'bar'"/>
|
||||
<int:method name="send2" request-channel="input" payload-expression="@testBean.sum(#args[0])"/>
|
||||
<int:method name="send3" request-channel="input" payload-expression="#method"/>
|
||||
<int:method name="send3" request-channel="input" payload-expression="#gatewayMethod.name"/>
|
||||
</int:gateway>
|
||||
|
||||
<int:gateway id="annotatedGateway"
|
||||
|
||||
@@ -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.
|
||||
@@ -23,7 +23,7 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -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.
|
||||
@@ -24,8 +24,8 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -114,6 +114,7 @@ public class HeaderEnrichedGatewayTests {
|
||||
|
||||
public void sendStringWithParameterHeaders(String value,
|
||||
@Header("headerA") String headerA, @Header("headerB") String headerB);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.integration.gateway;
|
||||
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.messaging.Message;
|
||||
|
||||
import reactor.core.composable.Promise;
|
||||
@@ -44,7 +44,7 @@ public interface TestService {
|
||||
|
||||
Message<?> requestReplyWithMessageReturnValue(String input);
|
||||
|
||||
@Payload("#method + #args.length")
|
||||
@Payload("#gatewayMethod.name + #args.length")
|
||||
String requestReplyWithPayloadAnnotation();
|
||||
|
||||
Future<Message<?>> async(String s);
|
||||
|
||||
@@ -24,12 +24,12 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.integration.IntegrationMessageHeaderAccessor;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.transformer.MessageTransformingHandler;
|
||||
import org.springframework.integration.transformer.MethodInvokingTransformer;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -110,17 +110,18 @@ public class HeaderAnnotationTransformerTests {
|
||||
return payload.toString() + correlationId.toString();
|
||||
}
|
||||
|
||||
public String appendFoo(Object payload, @Header(value = "foo") Object header) {
|
||||
public String appendFoo(Object payload, @Header("foo") Object header) {
|
||||
return payload.toString() + header.toString();
|
||||
}
|
||||
|
||||
public String evalCorrelationId(@Header(value = IntegrationMessageHeaderAccessor.CORRELATION_ID + ".toUpperCase()") String result) {
|
||||
return result.toString();
|
||||
public String evalCorrelationId(@Header(IntegrationMessageHeaderAccessor.CORRELATION_ID + ".toUpperCase()") String result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
public String evalFoo(@Header(value = "foo.toUpperCase()", required = true) String result) {
|
||||
return result.toString();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -24,7 +24,7 @@ import java.util.Map;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.transformer.HeaderEnricher;
|
||||
|
||||
@@ -98,6 +98,7 @@ public class MethodInvokingHeaderEnricherTests {
|
||||
map.put("bar", "ABC");
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -40,9 +40,9 @@ import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandlingException;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.annotation.Headers;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Headers;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
|
||||
@@ -114,7 +114,7 @@ public class MethodInvokingMessageProcessorAnnotationTests {
|
||||
.setHeader("num", new Integer(123)).build();
|
||||
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(testService, method);
|
||||
Object result = processor.processMessage(message);
|
||||
assertEquals(new Integer(123), result);
|
||||
assertEquals(123, result);
|
||||
}
|
||||
|
||||
@Test(expected = MessageHandlingException.class)
|
||||
@@ -211,8 +211,8 @@ public class MethodInvokingMessageProcessorAnnotationTests {
|
||||
.setHeader("attrib1", new Integer(123))
|
||||
.setHeader("attrib2", new Integer(456)).build();
|
||||
Map<String, Object> result = (Map<String, Object>) processor.processMessage(message);
|
||||
assertEquals(new Integer(123), result.get("attrib1"));
|
||||
assertEquals(new Integer(456), result.get("attrib2"));
|
||||
assertEquals(123, result.get("attrib1"));
|
||||
assertEquals(456, result.get("attrib2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -220,8 +220,8 @@ public class MethodInvokingMessageProcessorAnnotationTests {
|
||||
Method method = TestService.class.getMethod("mapPayload", Map.class);
|
||||
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(testService, method);
|
||||
Map<String, Integer> payload = new HashMap<String, Integer>();
|
||||
payload.put("attrib1", new Integer(88));
|
||||
payload.put("attrib2", new Integer(99));
|
||||
payload.put("attrib1", 88);
|
||||
payload.put("attrib2", 99);
|
||||
Message<Map<String, Integer>> message = MessageBuilder.withPayload(payload)
|
||||
.setHeader("attrib1", new Integer(123))
|
||||
.setHeader("attrib2", new Integer(456)).build();
|
||||
@@ -447,8 +447,7 @@ public class MethodInvokingMessageProcessorAnnotationTests {
|
||||
MessageBuilder<Employee> builder = MessageBuilder.withPayload(employee);
|
||||
builder.setHeader("day", "monday");
|
||||
builder.setHeader("month", "September");
|
||||
Message<Employee> message = builder.build();
|
||||
return message;
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
package org.springframework.integration.handler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
@@ -39,7 +40,7 @@ import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.expression.spel.SpelEvaluationException;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.integration.gateway.GatewayProxyFactoryBean;
|
||||
import org.springframework.integration.gateway.RequestReplyExchanger;
|
||||
@@ -58,7 +59,7 @@ import org.springframework.messaging.support.GenericMessage;
|
||||
* @author Gary Russell
|
||||
* @author Gunnar Hillert
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public class MethodInvokingMessageProcessorTests {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(MethodInvokingMessageProcessorTests.class);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 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.
|
||||
@@ -31,9 +31,9 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.annotation.Headers;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Headers;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.integration.handler.ServiceActivatingHandler;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 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.
|
||||
@@ -26,16 +26,17 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.channel.TestChannelResolver;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageDeliveryException;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.core.DestinationResolver;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -137,13 +138,13 @@ public class MethodInvokingRouterTests {
|
||||
assertEquals("bar", result2.getPayload());
|
||||
|
||||
try {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
} catch (MessageDeliveryException e) {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
}
|
||||
catch (MessageDeliveryException e) {
|
||||
/* Success */
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -163,7 +164,8 @@ public class MethodInvokingRouterTests {
|
||||
this.doTestChannelInstanceResolutionByPayload(router, channelResolver);
|
||||
}
|
||||
|
||||
private void doTestChannelInstanceResolutionByPayload(MethodInvokingRouter router, TestChannelResolver channelResolver) {
|
||||
private void doTestChannelInstanceResolutionByPayload(MethodInvokingRouter router,
|
||||
TestChannelResolver channelResolver) {
|
||||
Message<String> fooMessage = new GenericMessage<String>("foo");
|
||||
Message<String> barMessage = new GenericMessage<String>("bar");
|
||||
Message<String> badMessage = new GenericMessage<String>("bad");
|
||||
@@ -182,9 +184,10 @@ public class MethodInvokingRouterTests {
|
||||
assertEquals("bar", result2.getPayload());
|
||||
|
||||
try {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
} catch (MessageDeliveryException e) {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
}
|
||||
catch (MessageDeliveryException e) {
|
||||
/* Success */
|
||||
}
|
||||
|
||||
@@ -207,7 +210,8 @@ public class MethodInvokingRouterTests {
|
||||
this.doTestChannelInstanceResolutionByMessage(router, channelResolver);
|
||||
}
|
||||
|
||||
private void doTestChannelInstanceResolutionByMessage(MethodInvokingRouter router, TestChannelResolver channelResolver) {
|
||||
private void doTestChannelInstanceResolutionByMessage(MethodInvokingRouter router,
|
||||
TestChannelResolver channelResolver) {
|
||||
QueueChannel fooChannel = new QueueChannel();
|
||||
QueueChannel barChannel = new QueueChannel();
|
||||
channelResolver.addChannel("foo-channel", fooChannel);
|
||||
@@ -226,9 +230,10 @@ public class MethodInvokingRouterTests {
|
||||
assertEquals("bar", result2.getPayload());
|
||||
|
||||
try {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
} catch (MessageDeliveryException e) {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
}
|
||||
catch (MessageDeliveryException e) {
|
||||
/* Success */
|
||||
}
|
||||
|
||||
@@ -251,7 +256,8 @@ public class MethodInvokingRouterTests {
|
||||
this.doTestMultiChannelNameResolutionByPayload(router, channelResolver);
|
||||
}
|
||||
|
||||
private void doTestMultiChannelNameResolutionByPayload(MethodInvokingRouter router, TestChannelResolver channelResolver) {
|
||||
private void doTestMultiChannelNameResolutionByPayload(MethodInvokingRouter router,
|
||||
TestChannelResolver channelResolver) {
|
||||
QueueChannel fooChannel = new QueueChannel();
|
||||
QueueChannel barChannel = new QueueChannel();
|
||||
channelResolver.addChannel("foo-channel", fooChannel);
|
||||
@@ -276,9 +282,10 @@ public class MethodInvokingRouterTests {
|
||||
assertEquals("bar", result2b.getPayload());
|
||||
|
||||
try {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
} catch (MessageDeliveryException e) {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
}
|
||||
catch (MessageDeliveryException e) {
|
||||
/* Success */
|
||||
}
|
||||
}
|
||||
@@ -300,7 +307,8 @@ public class MethodInvokingRouterTests {
|
||||
this.doTestMultiChannelNameResolutionByMessage(router, channelResolver);
|
||||
}
|
||||
|
||||
private void doTestMultiChannelNameResolutionByMessage(MethodInvokingRouter router, TestChannelResolver channelResolver) {
|
||||
private void doTestMultiChannelNameResolutionByMessage(MethodInvokingRouter router,
|
||||
TestChannelResolver channelResolver) {
|
||||
QueueChannel fooChannel = new QueueChannel();
|
||||
QueueChannel barChannel = new QueueChannel();
|
||||
channelResolver.addChannel("foo-channel", fooChannel);
|
||||
@@ -325,9 +333,10 @@ public class MethodInvokingRouterTests {
|
||||
assertEquals("bar", result2b.getPayload());
|
||||
|
||||
try {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
} catch (MessageDeliveryException e) {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
}
|
||||
catch (MessageDeliveryException e) {
|
||||
/* Success */
|
||||
}
|
||||
}
|
||||
@@ -349,7 +358,8 @@ public class MethodInvokingRouterTests {
|
||||
this.doTestMultiChannelNameArrayResolutionByMessage(router, channelResolver);
|
||||
}
|
||||
|
||||
private void doTestMultiChannelNameArrayResolutionByMessage(MethodInvokingRouter router, TestChannelResolver channelResolver) {
|
||||
private void doTestMultiChannelNameArrayResolutionByMessage(MethodInvokingRouter router,
|
||||
TestChannelResolver channelResolver) {
|
||||
QueueChannel fooChannel = new QueueChannel();
|
||||
QueueChannel barChannel = new QueueChannel();
|
||||
channelResolver.addChannel("foo-channel", fooChannel);
|
||||
@@ -374,9 +384,10 @@ public class MethodInvokingRouterTests {
|
||||
assertEquals("bar", result2b.getPayload());
|
||||
|
||||
try {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
} catch (MessageDeliveryException e) {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
}
|
||||
catch (MessageDeliveryException e) {
|
||||
/* Success */
|
||||
}
|
||||
}
|
||||
@@ -398,7 +409,8 @@ public class MethodInvokingRouterTests {
|
||||
this.doTestMultiChannelListResolutionByPayload(router, channelResolver);
|
||||
}
|
||||
|
||||
private void doTestMultiChannelListResolutionByPayload(MethodInvokingRouter router, TestChannelResolver channelResolver) {
|
||||
private void doTestMultiChannelListResolutionByPayload(MethodInvokingRouter router,
|
||||
TestChannelResolver channelResolver) {
|
||||
QueueChannel fooChannel = new QueueChannel();
|
||||
QueueChannel barChannel = new QueueChannel();
|
||||
channelResolver.addChannel("foo-channel", fooChannel);
|
||||
@@ -423,9 +435,10 @@ public class MethodInvokingRouterTests {
|
||||
assertEquals("bar", result2b.getPayload());
|
||||
|
||||
try {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
} catch (MessageDeliveryException e) {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
}
|
||||
catch (MessageDeliveryException e) {
|
||||
/* Success */
|
||||
}
|
||||
|
||||
@@ -448,7 +461,8 @@ public class MethodInvokingRouterTests {
|
||||
this.doTestMultiChannelListResolutionByMessage(router, channelResolver);
|
||||
}
|
||||
|
||||
private void doTestMultiChannelListResolutionByMessage(MethodInvokingRouter router, TestChannelResolver channelResolver) {
|
||||
private void doTestMultiChannelListResolutionByMessage(MethodInvokingRouter router,
|
||||
TestChannelResolver channelResolver) {
|
||||
QueueChannel fooChannel = new QueueChannel();
|
||||
QueueChannel barChannel = new QueueChannel();
|
||||
channelResolver.addChannel("foo-channel", fooChannel);
|
||||
@@ -473,9 +487,10 @@ public class MethodInvokingRouterTests {
|
||||
assertEquals("bar", result2b.getPayload());
|
||||
|
||||
try {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
} catch (MessageDeliveryException e) {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
}
|
||||
catch (MessageDeliveryException e) {
|
||||
/* Success */
|
||||
}
|
||||
|
||||
@@ -498,7 +513,8 @@ public class MethodInvokingRouterTests {
|
||||
this.doTestMultiChannelArrayResolutionByMessage(router, channelResolver);
|
||||
}
|
||||
|
||||
private void doTestMultiChannelArrayResolutionByMessage(MethodInvokingRouter router, TestChannelResolver channelResolver) {
|
||||
private void doTestMultiChannelArrayResolutionByMessage(MethodInvokingRouter router,
|
||||
TestChannelResolver channelResolver) {
|
||||
QueueChannel fooChannel = new QueueChannel();
|
||||
QueueChannel barChannel = new QueueChannel();
|
||||
channelResolver.addChannel("foo-channel", fooChannel);
|
||||
@@ -523,9 +539,10 @@ public class MethodInvokingRouterTests {
|
||||
assertEquals("bar", result2b.getPayload());
|
||||
|
||||
try {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
} catch (MessageDeliveryException e) {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
}
|
||||
catch (MessageDeliveryException e) {
|
||||
/* Success */
|
||||
}
|
||||
|
||||
@@ -551,6 +568,7 @@ public class MethodInvokingRouterTests {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -583,6 +601,7 @@ public class MethodInvokingRouterTests {
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -607,6 +626,7 @@ public class MethodInvokingRouterTests {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -645,6 +665,7 @@ public class MethodInvokingRouterTests {
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -22,17 +22,18 @@ import static org.junit.Assert.assertNotNull;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.integration.IntegrationMessageHeaderAccessor;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.annotation.Splitter;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -305,7 +306,6 @@ public class MethodInvokingSplitterTests {
|
||||
return list;
|
||||
}
|
||||
}
|
||||
;
|
||||
GenericMessage<List<?>> message = new GenericMessage<List<?>>(Arrays.asList("foo", "bar"));
|
||||
MethodInvokingSplitter splitter = new MethodInvokingSplitter(new ListSplitter(), "split");
|
||||
QueueChannel replyChannel = new QueueChannel();
|
||||
@@ -511,14 +511,11 @@ public class MethodInvokingSplitterTests {
|
||||
public List<String> splitPayloadAndHeader(String payload, @Header("testHeader") String header) {
|
||||
String regex = "\\.";
|
||||
List<String> results = new ArrayList<String>();
|
||||
for (String s : payload.split(regex)) {
|
||||
results.add(s);
|
||||
}
|
||||
for (String s : header.split(regex)) {
|
||||
results.add(s);
|
||||
}
|
||||
Collections.addAll(results, payload.split(regex));
|
||||
Collections.addAll(results, header.split(regex));
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class SingleAnnotationTestBean {
|
||||
@@ -531,6 +528,7 @@ public class MethodInvokingSplitterTests {
|
||||
public String[] anotherMethod(String input) {
|
||||
throw new UnsupportedOperationException("incorrect test invocation");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class AmbiguousTypeMatchTestBean {
|
||||
@@ -544,6 +542,7 @@ public class MethodInvokingSplitterTests {
|
||||
public String[] method2(String input) {
|
||||
throw new UnsupportedOperationException("incorrect test invocation");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class SinglePublicMethodTestBean {
|
||||
@@ -555,6 +554,7 @@ public class MethodInvokingSplitterTests {
|
||||
String[] anotherMethod(String input) {
|
||||
throw new UnsupportedOperationException("incorrect test invocation");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class MultiplePublicMethodTestBean {
|
||||
@@ -566,6 +566,7 @@ public class MethodInvokingSplitterTests {
|
||||
public String[] method2(String input) {
|
||||
throw new UnsupportedOperationException("incorrect test invocation");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -575,5 +576,6 @@ public class MethodInvokingSplitterTests {
|
||||
private TestStringMessage(String payload) {
|
||||
super(payload);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -22,9 +22,9 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.annotation.Headers;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Headers;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.integration.annotation.Transformer;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.integration.history.MessageHistory;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -24,13 +24,13 @@ import java.util.Properties;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandlingException;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.annotation.Transformer;
|
||||
import org.springframework.integration.handler.MethodInvokingMessageProcessor;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandlingException;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -212,7 +212,7 @@ public class MethodInvokingTransformerTests {
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@Test // this changed in 2.0 see INT-785 and INT-1130
|
||||
public void headerEnricherConfiguredWithMethodReference() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
@@ -231,7 +231,7 @@ public class MethodInvokingTransformerTests {
|
||||
assertEquals("baz", result.getHeaders().get("prop3"));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@Test // this changed in 2.0 see INT-785 and INT-1130
|
||||
public void headerEnricherConfiguredWithMethodName() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
@@ -264,7 +264,7 @@ public class MethodInvokingTransformerTests {
|
||||
}
|
||||
|
||||
@Transformer
|
||||
public String optionalHeaderTest(String s, @Header(value="number", required=false) Integer num) {
|
||||
public String optionalHeaderTest(String s, @Header(value = "number", required = false) Integer num) {
|
||||
return s + num;
|
||||
}
|
||||
|
||||
@@ -290,6 +290,7 @@ public class MethodInvokingTransformerTests {
|
||||
public Object nullReturnValueTest(Message<?> message) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
<int:method name="getStudent" request-channel="getStudentChannel" />
|
||||
<int:method name="getStudentWithException" request-channel="getStudentEndpointWithExceptionChannel"/>
|
||||
<int:method name="getStudentWithParameters" request-channel="getStudentWithParametersChannel"/>
|
||||
<int:method name="getAllStudentsDeprecated" request-channel="getAllStudentsChannel" />
|
||||
<int:method name="getAllStudents" request-channel="getAllStudentsChannel" />
|
||||
<int:method name="persistStudent" request-channel="persistStudentChannel" />
|
||||
<int:method name="persistStudentUsingMerge" request-channel="persistStudentUsingMergeChannel" />
|
||||
|
||||
@@ -115,11 +115,13 @@ public class JpaOutboundGatewayTests {
|
||||
|
||||
@Test
|
||||
public void getAllStudents() {
|
||||
|
||||
final List<StudentDomain> students = studentService.getAllStudents();
|
||||
List<StudentDomain> students = studentService.getAllStudentsDeprecated();
|
||||
Assert.assertNotNull(students);
|
||||
Assert.assertTrue(students.size() == 3);
|
||||
|
||||
students = studentService.getAllStudents();
|
||||
Assert.assertNotNull(students);
|
||||
Assert.assertTrue(students.size() == 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -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. You may obtain a copy of the License at
|
||||
@@ -10,13 +10,19 @@
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.jpa.outbound;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.integration.jpa.test.entity.StudentDomain;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
|
||||
/**
|
||||
* @author Amol Nayak
|
||||
* @author Artem Bilan
|
||||
* @since 2.2
|
||||
*/
|
||||
public interface StudentService {
|
||||
|
||||
StudentDomain getStudent(StudentDomain student);
|
||||
@@ -26,6 +32,10 @@ public interface StudentService {
|
||||
StudentDomain getStudent(Long id);
|
||||
StudentDomain deleteStudent(StudentDomain student);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@org.springframework.integration.annotation.Payload("new java.util.Date()")
|
||||
List<StudentDomain> getAllStudentsDeprecated();
|
||||
|
||||
@Payload("new java.util.Date()")
|
||||
List<StudentDomain> getAllStudents();
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -20,13 +20,13 @@ import static org.mockito.Mockito.verify;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -47,10 +47,12 @@ public class ServiceActivatorOnMockitoMockTests {
|
||||
PollableChannel out;
|
||||
|
||||
public static class SingleAnnotatedMethodOnClass {
|
||||
|
||||
@ServiceActivator
|
||||
public String move(String s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@@ -77,10 +79,13 @@ public class ServiceActivatorOnMockitoMockTests {
|
||||
verify(singleMethodOnClass).move("SingleMethodOnClass");
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static class SingleMethodAcceptingHeaderOnClass {
|
||||
public String move(@Header("s") String s) {
|
||||
|
||||
public String move(@org.springframework.integration.annotation.Header("s") String s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@@ -88,7 +93,9 @@ public class ServiceActivatorOnMockitoMockTests {
|
||||
|
||||
@Test
|
||||
public void shouldInvokeMockedSingleMethodAcceptingHeaderOnClass() {
|
||||
in.send(MessageBuilder.withPayload("SingleMethodAcceptingHeaderOnClass").setHeader("s", "SingleMethodAcceptingHeaderOnClass").build());
|
||||
in.send(MessageBuilder.withPayload("SingleMethodAcceptingHeaderOnClass")
|
||||
.setHeader("s", "SingleMethodAcceptingHeaderOnClass")
|
||||
.build());
|
||||
verify(singleMethodAcceptingHeaderOnClass).move("SingleMethodAcceptingHeaderOnClass");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user