INT-937, INT-87 Message History (work in progress)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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,6 +20,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageHistoryEvent;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -47,6 +48,9 @@ import org.springframework.util.CollectionUtils;
|
||||
public abstract class AbstractMessageAggregator extends
|
||||
AbstractMessageBarrierHandler<List<Message<?>>> {
|
||||
|
||||
private static final String COMPONENT_TYPE_LABEL = "aggregator";
|
||||
|
||||
|
||||
private volatile CompletionStrategy completionStrategy = new SequenceSizeCompletionStrategy();
|
||||
|
||||
|
||||
@@ -85,6 +89,11 @@ public abstract class AbstractMessageAggregator extends
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcessHistoryEvent(MessageHistoryEvent event) {
|
||||
event.setComponentType(COMPONENT_TYPE_LABEL);
|
||||
}
|
||||
|
||||
protected abstract Message<?> aggregateMessages(List<Message<?>> messages);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,6 +22,7 @@ import org.springframework.integration.channel.NullChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHeaders;
|
||||
import org.springframework.integration.core.MessageHistoryEvent;
|
||||
import org.springframework.integration.handler.AbstractMessageHandler;
|
||||
import org.springframework.integration.store.MessageStore;
|
||||
import org.springframework.integration.store.SimpleMessageStore;
|
||||
@@ -118,6 +119,12 @@ public class CorrelatingMessageHandler extends AbstractMessageHandler implements
|
||||
this.sendPartialResultOnTimeout = sendPartialResultOnTimeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcessHistoryEvent(MessageHistoryEvent event) {
|
||||
// TODO: need to support 'resequencer' as well
|
||||
event.setComponentType("aggregator");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMessageInternal(Message<?> message) throws Exception {
|
||||
Object correlationKey = correlationStrategy.getCorrelationKey(message);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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,6 +23,7 @@ import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageHistoryEvent;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
@@ -53,10 +54,13 @@ import org.springframework.util.CollectionUtils;
|
||||
*/
|
||||
public class Resequencer extends AbstractMessageBarrierHandler<SortedSet<Message<?>>> {
|
||||
|
||||
private static final String COMPONENT_TYPE_LABEL = "resequencer";
|
||||
|
||||
|
||||
private volatile boolean releasePartialSequences = true;
|
||||
|
||||
private static final String LAST_RELEASED_SEQUENCE_NUMBER = "last.released.sequence.number";
|
||||
|
||||
|
||||
|
||||
public void setReleasePartialSequences(boolean releasePartialSequences) {
|
||||
this.releasePartialSequences = releasePartialSequences;
|
||||
@@ -143,4 +147,9 @@ public class Resequencer extends AbstractMessageBarrierHandler<SortedSet<Message
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcessHistoryEvent(MessageHistoryEvent event) {
|
||||
event.setComponentType(COMPONENT_TYPE_LABEL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -29,7 +29,6 @@ import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessagingException;
|
||||
import org.springframework.integration.core.MessageHistory.ComponentType;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.MessageDeliveryException;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -171,7 +170,7 @@ public abstract class AbstractMessageChannel implements MessageChannel, BeanFact
|
||||
Assert.notNull(message, "message must not be null");
|
||||
Assert.notNull(message.getPayload(), "message payload must not be null");
|
||||
message = this.convertPayloadIfNecessary(message);
|
||||
message.getHeaders().getHistory().add(ComponentType.channel, this.getName());
|
||||
message.getHeaders().getHistory().addEvent(this.getName()).setComponentType("channel");
|
||||
message = this.interceptors.preSend(message, this);
|
||||
if (message == null) {
|
||||
return false;
|
||||
|
||||
@@ -17,79 +17,59 @@
|
||||
package org.springframework.integration.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
public class MessageHistory implements Iterable<MessageHistory.Event>, Serializable {
|
||||
public class MessageHistory implements Iterable<MessageHistoryEvent>, Serializable {
|
||||
|
||||
private final List<Event> events = new CopyOnWriteArrayList<Event>();
|
||||
private final List<MessageHistoryEvent> events = new ArrayList<MessageHistoryEvent>();
|
||||
|
||||
private final ReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
|
||||
|
||||
public void add(ComponentType componentType, String componentName) {
|
||||
this.events.add(new Event(componentType, componentName));
|
||||
public MessageHistoryEvent addEvent(String componentName) {
|
||||
try {
|
||||
this.lock.writeLock().lock();
|
||||
MessageHistoryEvent event = new MessageHistoryEvent(componentName);
|
||||
this.events.add(event);
|
||||
return event;
|
||||
}
|
||||
finally {
|
||||
this.lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public Iterator<Event> iterator() {
|
||||
return Collections.unmodifiableList(this.events).iterator();
|
||||
public MessageHistoryEvent getCurrentEvent() {
|
||||
try {
|
||||
this.lock.readLock().lock();
|
||||
int size = this.events.size();
|
||||
return (size > 0) ? this.events.get(size - 1) : null;
|
||||
}
|
||||
finally {
|
||||
this.lock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public Iterator<MessageHistoryEvent> iterator() {
|
||||
try {
|
||||
this.lock.readLock().lock();
|
||||
return Collections.unmodifiableList(this.events).iterator();
|
||||
}
|
||||
finally {
|
||||
this.lock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.events.toString();
|
||||
}
|
||||
|
||||
|
||||
public static enum ComponentType {
|
||||
channel, endpoint, gateway;
|
||||
}
|
||||
|
||||
|
||||
public static class Event implements Serializable {
|
||||
|
||||
private final ComponentType componentType;
|
||||
|
||||
private final String componentName;
|
||||
|
||||
private final long timestamp;
|
||||
|
||||
|
||||
public Event(ComponentType componentType, String componentName) {
|
||||
this.componentType = componentType;
|
||||
this.componentName = componentName;
|
||||
this.timestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
|
||||
public ComponentType getComponentType() {
|
||||
return this.componentType;
|
||||
}
|
||||
|
||||
public String getComponentName() {
|
||||
return this.componentName;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return this.timestamp;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("[");
|
||||
if (this.componentName != null) {
|
||||
sb.append("{name=" + this.componentName + "}");
|
||||
}
|
||||
if (this.componentType != null) {
|
||||
sb.append("{type=" + this.componentType + "}");
|
||||
}
|
||||
sb.append("{timestamp=" + new Date(this.timestamp) + "}");
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on 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.core;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
public class MessageHistoryEvent {
|
||||
|
||||
public static final String COMPONENT_NAME = "componentName";
|
||||
|
||||
public static final String COMPONENT_TYPE = "componentType";
|
||||
|
||||
public static final String TIMESTAMP = "timestamp";
|
||||
|
||||
|
||||
private final Map<String, Object> properties = new HashMap<String, Object>();
|
||||
|
||||
|
||||
public MessageHistoryEvent(String componentName) {
|
||||
this.setProperty(COMPONENT_NAME, componentName);
|
||||
this.setProperty(TIMESTAMP, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
|
||||
public MessageHistoryEvent setComponentType(String componentType) {
|
||||
this.setProperty(COMPONENT_TYPE, componentType);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getComponentType() {
|
||||
return this.getProperty(COMPONENT_TYPE, String.class);
|
||||
}
|
||||
|
||||
public String getComponentName() {
|
||||
return this.getProperty(COMPONENT_NAME, String.class);
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return this.getProperty(TIMESTAMP, long.class);
|
||||
}
|
||||
|
||||
public MessageHistoryEvent setProperty(String key, String value) {
|
||||
this.properties.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageHistoryEvent setProperty(String key, Number value) {
|
||||
this.properties.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageHistoryEvent setProperty(String key, Boolean value) {
|
||||
this.properties.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Object getProperty(String key) {
|
||||
return this.properties.get(key);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getProperty(String key, Class<T> type) {
|
||||
Object value = this.properties.get(key);
|
||||
if (value != null && type.isAssignableFrom(value.getClass())) {
|
||||
return (T) value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.properties.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -19,6 +19,7 @@ package org.springframework.integration.endpoint;
|
||||
import org.springframework.integration.channel.MessageChannelTemplate;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHistoryEvent;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -48,7 +49,16 @@ public abstract class MessageProducerSupport extends AbstractEndpoint {
|
||||
}
|
||||
|
||||
protected boolean sendMessage(Message<?> message) {
|
||||
String componentName = this.getBeanName();
|
||||
if (componentName != null) {
|
||||
MessageHistoryEvent event = message.getHeaders().getHistory().addEvent(componentName);
|
||||
this.postProcessHistoryEvent(event);
|
||||
}
|
||||
return this.channelTemplate.send(message, this.outputChannel);
|
||||
}
|
||||
|
||||
protected void postProcessHistoryEvent(MessageHistoryEvent event) {
|
||||
event.setComponentType("producer");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -18,6 +18,7 @@ package org.springframework.integration.filter;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHistoryEvent;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.message.MessageDeliveryException;
|
||||
import org.springframework.integration.message.MessageRejectedException;
|
||||
@@ -37,6 +38,9 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class MessageFilter extends AbstractReplyProducingMessageHandler {
|
||||
|
||||
private static final String COMPONENT_TYPE_LABEL = "filter";
|
||||
|
||||
|
||||
private final MessageSelector selector;
|
||||
|
||||
private volatile boolean throwExceptionOnRejection;
|
||||
@@ -99,4 +103,9 @@ public class MessageFilter extends AbstractReplyProducingMessageHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcessHistoryEvent(MessageHistoryEvent e) {
|
||||
e.setComponentType(COMPONENT_TYPE_LABEL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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,9 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.gateway;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageHistoryEvent;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -26,14 +28,17 @@ import org.springframework.util.Assert;
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.0
|
||||
*/
|
||||
public class GatewayInvokingMessageHandler extends
|
||||
AbstractReplyProducingMessageHandler {
|
||||
public class GatewayInvokingMessageHandler extends AbstractReplyProducingMessageHandler {
|
||||
|
||||
private static final String COMPONENT_TYPE_LABEL = "gateway";
|
||||
|
||||
|
||||
private GenericSendAndRecieveGateway gateway;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param gateway
|
||||
*/
|
||||
public GatewayInvokingMessageHandler(GenericSendAndRecieveGateway gateway){
|
||||
public GatewayInvokingMessageHandler(GenericSendAndRecieveGateway gateway) {
|
||||
Assert.notNull(gateway, "gateway must not be null");
|
||||
this.gateway = gateway;
|
||||
}
|
||||
@@ -44,4 +49,10 @@ public class GatewayInvokingMessageHandler extends
|
||||
protected Object handleRequestMessage(Message<?> requestMessage) {
|
||||
return gateway.sendAndRecieve(requestMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcessHistoryEvent(MessageHistoryEvent event) {
|
||||
event.setComponentType(COMPONENT_TYPE_LABEL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint implements Factory
|
||||
|
||||
private MessagingGateway createGatewayForMethod(Method method) throws Exception {
|
||||
SimpleMessagingGateway gateway = new SimpleMessagingGateway(
|
||||
new ArgumentArrayMessageMapper(method), new SimpleMessageMapper());
|
||||
new ArgumentArrayMessageMapper(method, this.getBeanName()), new SimpleMessageMapper());
|
||||
if (this.getTaskScheduler() != null) {
|
||||
gateway.setTaskScheduler(this.getTaskScheduler());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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,14 +20,14 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessagingException;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHistory.ComponentType;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.integration.channel.ChannelResolutionException;
|
||||
import org.springframework.integration.channel.ChannelResolver;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHistoryEvent;
|
||||
import org.springframework.integration.core.MessagingException;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -59,7 +59,8 @@ public abstract class AbstractMessageHandler implements MessageHandler, Ordered
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug(this + " received message: " + message);
|
||||
}
|
||||
message.getHeaders().getHistory().add(ComponentType.endpoint, this.toString());
|
||||
MessageHistoryEvent event = message.getHeaders().getHistory().addEvent(this.toString());
|
||||
this.postProcessHistoryEvent(event);
|
||||
try {
|
||||
this.handleMessageInternal(message);
|
||||
}
|
||||
@@ -72,6 +73,16 @@ public abstract class AbstractMessageHandler implements MessageHandler, Ordered
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Post process the history event. For example, this method is commonly overridden
|
||||
* to set the 'componentType' label for the specific handler implementation. As a
|
||||
* result, the "logical" name is available in MessageHistory events. Such a name
|
||||
* should typically match the corresponding configuration element's name (in XML or
|
||||
* Annotations), such as "router" or "splitter". By default this method is a no-op.
|
||||
*/
|
||||
protected void postProcessHistoryEvent(MessageHistoryEvent event) {
|
||||
}
|
||||
|
||||
protected abstract void handleMessageInternal(Message<?> message) throws Exception;
|
||||
|
||||
protected final MessageChannel resolveReplyChannel(Message<?> requestMessage,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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,11 @@ import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.context.expression.MapAccessor;
|
||||
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.ParameterNameDiscoverer;
|
||||
@@ -34,21 +32,13 @@ import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.converter.ConverterRegistry;
|
||||
import org.springframework.core.convert.support.ConversionServiceFactory;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.expression.spel.support.StandardTypeConverter;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.annotation.Headers;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessagingException;
|
||||
import org.springframework.integration.core.MessageHistory.ComponentType;
|
||||
import org.springframework.integration.message.InboundMessageMapper;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.integration.message.OutboundMessageMapper;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -109,7 +99,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.0
|
||||
*/
|
||||
public class ArgumentArrayMessageMapper implements InboundMessageMapper<Object[]>, OutboundMessageMapper<Object[]> {
|
||||
public class ArgumentArrayMessageMapper implements InboundMessageMapper<Object[]> {
|
||||
|
||||
private static ConversionService conversionService;
|
||||
|
||||
@@ -128,26 +118,21 @@ public class ArgumentArrayMessageMapper implements InboundMessageMapper<Object[]
|
||||
}
|
||||
|
||||
|
||||
private final ExpressionParser expressionParser = new SpelExpressionParser();
|
||||
|
||||
private final Method method;
|
||||
|
||||
private final String gatewayName;
|
||||
|
||||
private final List<MethodParameter> parameterList;
|
||||
|
||||
|
||||
public ArgumentArrayMessageMapper(Method method) {
|
||||
public ArgumentArrayMessageMapper(Method method, String gatewayName) {
|
||||
Assert.notNull(method, "method must not be null");
|
||||
Assert.notNull(gatewayName, "gatewayName must not be null");
|
||||
this.method = method;
|
||||
this.gatewayName = gatewayName;
|
||||
this.parameterList = this.getMethodParameterList(method);
|
||||
}
|
||||
|
||||
|
||||
public Object[] fromMessage(Message<?> message) {
|
||||
Assert.notNull(message, "cannot map a null Message");
|
||||
this.validateMessageMapppings(message);
|
||||
return this.mapMessageToArguments(message);
|
||||
}
|
||||
|
||||
public Message<?> toMessage(Object[] arguments) {
|
||||
Assert.notNull(arguments, "cannot map null arguments to Message");
|
||||
if (arguments.length != this.parameterList.size()) {
|
||||
@@ -157,60 +142,14 @@ public class ArgumentArrayMessageMapper implements InboundMessageMapper<Object[]
|
||||
}
|
||||
Message<?> message = this.mapArgumentsToMessage(arguments);
|
||||
if (message != null) {
|
||||
message.getHeaders().getHistory().add(ComponentType.gateway, this.method.getName());
|
||||
message.getHeaders().getHistory().addEvent(this.gatewayName)
|
||||
.setComponentType("gateway")
|
||||
// TODO: add METHOD_NAME key for props?
|
||||
.setProperty("method", this.method.getName());
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
private Object[] mapMessageToArguments(Message<?> message) {
|
||||
final Map<String, Object> messageArgumentsMap = new LinkedHashMap<String, Object>();
|
||||
for (MethodParameter methodParameter : this.parameterList) {
|
||||
String parameterName = methodParameter.getParameterName();
|
||||
Annotation mappingAnnotation = null;
|
||||
Object value = null;
|
||||
mappingAnnotation = this.findMappingAnnotation(methodParameter.getParameterAnnotations());
|
||||
if (mappingAnnotation == null) {
|
||||
String[] expressions = null;
|
||||
if ("headers".equals(parameterName) || "payload".equals(parameterName)) {
|
||||
expressions = new String[] { parameterName };
|
||||
}
|
||||
else if ("message".equals(parameterName)) {
|
||||
// just in case 'parameterName' is 'message' but type is not Message
|
||||
expressions = new String[] { "#this", "payload" };
|
||||
}
|
||||
else {
|
||||
expressions = new String[] { "payload." + parameterName, "headers." + parameterName, "payload", "headers", "#this" };
|
||||
}
|
||||
value = this.getValueFromMessageBasedOnEL(message, methodParameter.getParameterType(), false, expressions);
|
||||
}
|
||||
else {
|
||||
if (mappingAnnotation.annotationType().equals(Header.class)) {
|
||||
value = this.retrieveHeaderFromMessage((Header) mappingAnnotation, message, methodParameter)[1];
|
||||
}
|
||||
else if (mappingAnnotation.annotationType().equals(Headers.class)) {
|
||||
String[] expressions = new String[] {"headers"};
|
||||
value = this.getValueFromMessageBasedOnEL(message, methodParameter.getParameterType(), false, expressions);
|
||||
}
|
||||
else if (mappingAnnotation.annotationType().isAssignableFrom(Payload.class)) {
|
||||
String[] expressions = null;
|
||||
String payloadExpression = ((Payload) mappingAnnotation).value();
|
||||
if (payloadExpression.length() == 0) {
|
||||
expressions = new String[] { "payload" };
|
||||
}
|
||||
else {
|
||||
expressions = new String[] { "payload." + payloadExpression };
|
||||
}
|
||||
value = this.getValueFromMessageBasedOnEL(message, methodParameter.getParameterType(), true, expressions);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("unsupported mapping annotation: " + mappingAnnotation);
|
||||
}
|
||||
}
|
||||
messageArgumentsMap.put(methodParameter.getParameterIndex() + ":" + parameterName, value);
|
||||
}
|
||||
return messageArgumentsMap.values().toArray();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Message<?> mapArgumentsToMessage(Object[] arguments) {
|
||||
Object messageOrPayload = null;
|
||||
@@ -312,18 +251,6 @@ public class ArgumentArrayMessageMapper implements InboundMessageMapper<Object[]
|
||||
"found more than one on method [" + methodParameter.getMethod() + "]");
|
||||
}
|
||||
|
||||
private Object[] retrieveHeaderFromMessage(Header headerAnnotation, Message<?> message, MethodParameter methodParameter) {
|
||||
Object headerValue = null;
|
||||
String headerName = this.determineHeaderName(headerAnnotation, methodParameter);
|
||||
if (message != null) {
|
||||
headerValue = this.getValueFromMessageBasedOnEL(message, methodParameter.getParameterType(), false, "headers." + headerName);
|
||||
}
|
||||
if (headerAnnotation.required() && headerValue == null) {
|
||||
throw new MessageHandlingException(message, "Message is missing required header: '" + headerName + "'");
|
||||
}
|
||||
return new Object[] {headerName, headerValue};
|
||||
}
|
||||
|
||||
private String determineHeaderName(Header headerAnnotation, MethodParameter methodParameter) {
|
||||
String valueAttribute = headerAnnotation.value();
|
||||
String headerName = StringUtils.hasText(valueAttribute) ? valueAttribute : methodParameter.getParameterName();
|
||||
@@ -332,34 +259,6 @@ public class ArgumentArrayMessageMapper implements InboundMessageMapper<Object[]
|
||||
return headerName;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Object getValueFromMessageBasedOnEL(Message message, Class targetType, boolean rethrowException, String... expressions) {
|
||||
Object value = null;
|
||||
for (String expression : expressions) {
|
||||
StandardEvaluationContext context = new StandardEvaluationContext(message);
|
||||
context.setTypeConverter(new StandardTypeConverter(conversionService));
|
||||
try {
|
||||
Expression exp = expressionParser.parseExpression(expression);
|
||||
context.addPropertyAccessor(new MapAccessor());
|
||||
value = exp.getValue(context);
|
||||
if (value != null && conversionService.canConvert(value.getClass(), targetType)) {
|
||||
// to accommodate Map->Properties conversion
|
||||
value = expression.equals("headers") ? conversionService.convert(value, targetType) : value;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
value = null;
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {
|
||||
if (rethrowException) {
|
||||
throw new MessageHandlingException(message, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private List<MethodParameter> getMethodParameterList(Method method) {
|
||||
List<MethodParameter> parameterList = new LinkedList<MethodParameter>();
|
||||
ParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.integration.handler;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageHistoryEvent;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -35,6 +36,9 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class BridgeHandler extends AbstractReplyProducingMessageHandler {
|
||||
|
||||
private static final String COMPONENT_TYPE_LABEL = "bridge";
|
||||
|
||||
|
||||
@Override
|
||||
protected Object handleRequestMessage(Message<?> requestMessage) {
|
||||
if (requestMessage.getHeaders().getReplyChannel() == null) {
|
||||
@@ -43,6 +47,11 @@ public class BridgeHandler extends AbstractReplyProducingMessageHandler {
|
||||
return requestMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcessHistoryEvent(MessageHistoryEvent e) {
|
||||
e.setComponentType(COMPONENT_TYPE_LABEL);
|
||||
}
|
||||
|
||||
private void verifyOutputChannel() {
|
||||
Assert.state(super.getOutputChannel() != null, "Bridge handler requires an output channel");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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,6 +20,7 @@ import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageHistoryEvent;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -33,7 +34,9 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class LoggingHandler extends AbstractMessageHandler {
|
||||
|
||||
private static enum Level { FATAL, ERROR, WARN, INFO, DEBUG, TRACE };
|
||||
private static enum Level { FATAL, ERROR, WARN, INFO, DEBUG, TRACE }
|
||||
|
||||
private static final String COMPONENT_TYPE_LABEL = "logging-channel-adapter";
|
||||
|
||||
|
||||
private boolean shouldLogFullMessage;
|
||||
@@ -106,4 +109,9 @@ public class LoggingHandler extends AbstractMessageHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcessHistoryEvent(MessageHistoryEvent e) {
|
||||
e.setComponentType(COMPONENT_TYPE_LABEL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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,6 +20,7 @@ import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageHistoryEvent;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
|
||||
/**
|
||||
@@ -27,6 +28,9 @@ import org.springframework.integration.message.MessageHandlingException;
|
||||
*/
|
||||
public class ServiceActivatingHandler extends AbstractReplyProducingMessageHandler {
|
||||
|
||||
private static final String COMPONENT_TYPE_LABEL = "service-activator";
|
||||
|
||||
|
||||
private final MethodInvokingMessageProcessor processor;
|
||||
|
||||
|
||||
@@ -56,6 +60,11 @@ public class ServiceActivatingHandler extends AbstractReplyProducingMessageHandl
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcessHistoryEvent(MessageHistoryEvent event) {
|
||||
event.setComponentType(COMPONENT_TYPE_LABEL);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ServiceActivator for [" + this.processor + "]";
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -21,6 +21,7 @@ import java.util.Collection;
|
||||
import org.springframework.integration.channel.MessageChannelTemplate;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHistoryEvent;
|
||||
import org.springframework.integration.handler.AbstractMessageHandler;
|
||||
import org.springframework.integration.message.MessageDeliveryException;
|
||||
|
||||
@@ -31,6 +32,9 @@ import org.springframework.integration.message.MessageDeliveryException;
|
||||
*/
|
||||
public abstract class AbstractMessageRouter extends AbstractMessageHandler {
|
||||
|
||||
private static final String COMPONENT_TYPE_LABEL = "router";
|
||||
|
||||
|
||||
private volatile MessageChannel defaultOutputChannel;
|
||||
|
||||
private volatile boolean resolutionRequired;
|
||||
@@ -90,6 +94,11 @@ public abstract class AbstractMessageRouter extends AbstractMessageHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcessHistoryEvent(MessageHistoryEvent event) {
|
||||
event.setComponentType(COMPONENT_TYPE_LABEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses must implement this method to return the target channels for
|
||||
* a given Message.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -21,6 +21,7 @@ import org.springframework.integration.channel.MessageChannelTemplate;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHeaders;
|
||||
import org.springframework.integration.core.MessageHistoryEvent;
|
||||
import org.springframework.integration.handler.AbstractMessageHandler;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.MessageDeliveryException;
|
||||
@@ -59,7 +60,10 @@ import java.util.*;
|
||||
*/
|
||||
public class RecipientListRouter extends AbstractMessageHandler implements InitializingBean {
|
||||
|
||||
private volatile boolean ignoreSendFailures;
|
||||
private static final String COMPONENT_TYPE_LABEL = "recipient-list-router";
|
||||
|
||||
|
||||
private volatile boolean ignoreSendFailures;
|
||||
|
||||
private volatile boolean applySequence;
|
||||
|
||||
@@ -155,4 +159,9 @@ public class RecipientListRouter extends AbstractMessageHandler implements Initi
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcessHistoryEvent(MessageHistoryEvent event) {
|
||||
event.setComponentType(COMPONENT_TYPE_LABEL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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,6 +24,7 @@ import java.util.UUID;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHeaders;
|
||||
import org.springframework.integration.core.MessageHistoryEvent;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
|
||||
@@ -34,6 +35,9 @@ import org.springframework.integration.message.MessageBuilder;
|
||||
*/
|
||||
public abstract class AbstractMessageSplitter extends AbstractReplyProducingMessageHandler {
|
||||
|
||||
private static final String COMPONENT_TYPE_LABEL = "splitter";
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected final Object handleRequestMessage(Message<?> message) {
|
||||
@@ -66,6 +70,11 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess
|
||||
return messageBuilders;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcessHistoryEvent(MessageHistoryEvent event) {
|
||||
event.setComponentType(COMPONENT_TYPE_LABEL);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private MessageBuilder createBuilder(Object item, Object correlationId, int sequenceNumber, int sequenceSize) {
|
||||
MessageBuilder builder = (item instanceof Message) ?
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.integration.transformer;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageHistoryEvent;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -29,6 +30,9 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class MessageTransformingHandler extends AbstractReplyProducingMessageHandler {
|
||||
|
||||
private static final String COMPONENT_TYPE_LABEL = "transformer";
|
||||
|
||||
|
||||
private final Transformer transformer;
|
||||
|
||||
|
||||
@@ -55,4 +59,9 @@ public class MessageTransformingHandler extends AbstractReplyProducingMessageHan
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcessHistoryEvent(MessageHistoryEvent event) {
|
||||
event.setComponentType(COMPONENT_TYPE_LABEL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -35,8 +35,7 @@ import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHistory.ComponentType;
|
||||
import org.springframework.integration.core.MessageHistory.Event;
|
||||
import org.springframework.integration.core.MessageHistoryEvent;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.handler.BridgeHandler;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
@@ -55,6 +54,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
|
||||
proxyFactory.setDefaultRequestChannel(requestChannel);
|
||||
proxyFactory.setServiceInterface(TestService.class);
|
||||
proxyFactory.setBeanName("testGateway");
|
||||
proxyFactory.afterPropertiesSet();
|
||||
TestService service = (TestService) proxyFactory.getObject();
|
||||
String result = service.requestReply("foo");
|
||||
@@ -67,6 +67,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
|
||||
proxyFactory.setServiceInterface(TestService.class);
|
||||
proxyFactory.setDefaultRequestChannel(requestChannel);
|
||||
proxyFactory.setBeanName("testGateway");
|
||||
proxyFactory.afterPropertiesSet();
|
||||
TestService service = (TestService) proxyFactory.getObject();
|
||||
service.oneWay("test");
|
||||
@@ -83,6 +84,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
proxyFactory.setServiceInterface(TestService.class);
|
||||
proxyFactory.setDefaultRequestChannel(new DirectChannel());
|
||||
proxyFactory.setDefaultReplyChannel(replyChannel);
|
||||
proxyFactory.setBeanName("testGateway");
|
||||
proxyFactory.afterPropertiesSet();
|
||||
TestService service = (TestService) proxyFactory.getObject();
|
||||
String result = service.solicitResponse();
|
||||
@@ -103,6 +105,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
|
||||
proxyFactory.setServiceInterface(TestService.class);
|
||||
proxyFactory.setDefaultRequestChannel(requestChannel);
|
||||
proxyFactory.setBeanName("testGateway");
|
||||
proxyFactory.afterPropertiesSet();
|
||||
TestService service = (TestService) proxyFactory.getObject();
|
||||
Integer result = service.requestReplyWithIntegers(123);
|
||||
@@ -171,6 +174,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
|
||||
proxyFactory.setServiceInterface(TestService.class);
|
||||
proxyFactory.setDefaultRequestChannel(requestChannel);
|
||||
proxyFactory.setBeanName("testGateway");
|
||||
proxyFactory.afterPropertiesSet();
|
||||
TestService service = (TestService) proxyFactory.getObject();
|
||||
String result = service.requestReplyWithMessageParameter(new StringMessage("foo"));
|
||||
@@ -190,6 +194,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
|
||||
proxyFactory.setServiceInterface(TestService.class);
|
||||
proxyFactory.setDefaultRequestChannel(requestChannel);
|
||||
proxyFactory.setBeanName("testGateway");
|
||||
proxyFactory.afterPropertiesSet();
|
||||
TestService service = (TestService) proxyFactory.getObject();
|
||||
Message<?> result = service.requestReplyWithMessageReturnValue("foo");
|
||||
@@ -217,6 +222,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
|
||||
proxyFactory.setDefaultRequestChannel(new DirectChannel());
|
||||
proxyFactory.setServiceInterface(TestService.class);
|
||||
proxyFactory.setBeanName("testGateway");
|
||||
proxyFactory.afterPropertiesSet();
|
||||
Object proxy = proxyFactory.getObject();
|
||||
String expected = "gateway proxy for";
|
||||
@@ -237,6 +243,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
consumer.start();
|
||||
proxyFactory.setDefaultRequestChannel(channel);
|
||||
proxyFactory.setServiceInterface(TestExceptionThrowingInterface.class);
|
||||
proxyFactory.setBeanName("testGateway");
|
||||
proxyFactory.afterPropertiesSet();
|
||||
TestExceptionThrowingInterface proxy = (TestExceptionThrowingInterface) proxyFactory.getObject();
|
||||
proxy.throwCheckedException("test");
|
||||
@@ -256,21 +263,23 @@ public class GatewayProxyFactoryBeanTests {
|
||||
@Test
|
||||
public void testMethodNameInHistory() throws Exception {
|
||||
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
|
||||
proxyFactory.setBeanName("testGateway");
|
||||
DirectChannel channel = new DirectChannel();
|
||||
channel.setBeanName("testChannel");
|
||||
EventDrivenConsumer consumer = new EventDrivenConsumer(channel, new BridgeHandler());
|
||||
consumer.setBeanName("testBridge");
|
||||
consumer.start();
|
||||
proxyFactory.setDefaultRequestChannel(channel);
|
||||
proxyFactory.setServiceInterface(TestEchoService.class);
|
||||
proxyFactory.afterPropertiesSet();
|
||||
TestEchoService proxy = (TestEchoService) proxyFactory.getObject();
|
||||
Message<?> message = proxy.echo("test");
|
||||
Iterator<Event> historyIterator = message.getHeaders().getHistory().iterator();
|
||||
Event event1 = historyIterator.next();
|
||||
Event event2 = historyIterator.next();
|
||||
assertEquals(ComponentType.gateway, event1.getComponentType());
|
||||
assertEquals("echo", event1.getComponentName());
|
||||
assertEquals(ComponentType.channel, event2.getComponentType());
|
||||
Iterator<MessageHistoryEvent> historyIterator = message.getHeaders().getHistory().iterator();
|
||||
MessageHistoryEvent event1 = historyIterator.next();
|
||||
MessageHistoryEvent event2 = historyIterator.next();
|
||||
assertEquals("testGateway", event1.getComponentName());
|
||||
assertEquals("echo", event1.getProperty("method", String.class));
|
||||
assertEquals("channel", event2.getComponentType());
|
||||
assertEquals("testChannel", event2.getComponentName());
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ public class GatewayProxyMessageMappingTests {
|
||||
GatewayProxyFactoryBean factoryBean = new GatewayProxyFactoryBean();
|
||||
factoryBean.setServiceInterface(TestGateway.class);
|
||||
factoryBean.setDefaultRequestChannel(channel);
|
||||
factoryBean.setBeanName("testGateway");
|
||||
factoryBean.afterPropertiesSet();
|
||||
this.gateway = (TestGateway) factoryBean.getObject();
|
||||
}
|
||||
|
||||
@@ -1,425 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2009 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on 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.handler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.annotation.Headers;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessagingException;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Iwein Fuld
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class ArgumentArrayMessageMapperFromMessageTests {
|
||||
private final Employee employee = new Employee("oleg", "zhurakousky");
|
||||
@Test
|
||||
public void fromMessageWithOptionalHeader() throws Exception {
|
||||
Method method = TestService.class.getMethod("optionalHeader", Integer.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
Object[] args = mapper.fromMessage(new StringMessage("foo"));
|
||||
assertEquals(1, args.length);
|
||||
assertNull(args[0]);
|
||||
}
|
||||
|
||||
@Test(expected = MessageHandlingException.class)
|
||||
public void fromMessageWithRequiredHeaderNotProvided() throws Exception {
|
||||
Method method = TestService.class.getMethod("requiredHeader", Integer.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
mapper.fromMessage(new StringMessage("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromMessageWithRequiredHeaderProvided() throws Exception {
|
||||
Method method = TestService.class.getMethod("requiredHeader", Integer.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
Message<String> message = MessageBuilder.withPayload("foo")
|
||||
.setHeader("num", new Integer(123)).build();
|
||||
Object[] args = mapper.fromMessage(message);
|
||||
assertEquals(1, args.length);
|
||||
assertEquals(new Integer(123), args[0]);
|
||||
}
|
||||
|
||||
@Test(expected = MessageHandlingException.class)
|
||||
public void fromMessageWithOptionalAndRequiredHeaderAndOnlyOptionalHeaderProvided() throws Exception {
|
||||
Method method = TestService.class.getMethod("optionalAndRequiredHeader", String.class, Integer.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
Message<String> message = MessageBuilder.withPayload("foo")
|
||||
.setHeader("prop", "bar").build();
|
||||
mapper.fromMessage(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromMessageWithOptionalAndRequiredHeaderAndOnlyRequiredHeaderProvided() throws Exception {
|
||||
Method method = TestService.class.getMethod("optionalAndRequiredHeader", String.class, Integer.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
Message<String> message = MessageBuilder.withPayload("foo")
|
||||
.setHeader("num", new Integer(123)).build();
|
||||
Object[] args = mapper.fromMessage(message);
|
||||
assertEquals(2, args.length);
|
||||
assertNull(args[0]);
|
||||
assertEquals(123, args[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromMessageWithOptionalAndRequiredHeaderAndBothHeadersProvided() throws Exception {
|
||||
Method method = TestService.class.getMethod("optionalAndRequiredHeader", String.class, Integer.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
Message<String> message = MessageBuilder.withPayload("foo")
|
||||
.setHeader("num", new Integer(123))
|
||||
.setHeader("prop", "bar")
|
||||
.build();
|
||||
Object[] args = mapper.fromMessage(message);
|
||||
assertEquals(2, args.length);
|
||||
assertEquals("bar", args[0]);
|
||||
assertEquals(123, args[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromMessageWithPropertiesMethodAndHeadersAnnotation() throws Exception {
|
||||
Method method = TestService.class.getMethod("propertiesHeaders", Properties.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
Message<String> message = MessageBuilder.withPayload("test")
|
||||
.setHeader("prop1", "foo").setHeader("prop2", "bar").build();
|
||||
Object[] args = mapper.fromMessage(message);
|
||||
Properties result = (Properties) args[0];
|
||||
assertEquals("foo", result.getProperty("prop1"));
|
||||
assertEquals("bar", result.getProperty("prop2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromMessageWithPropertiesAndObjectMethod() throws Exception {
|
||||
Method method = TestService.class.getMethod("propertiesHeadersAndPayload", Properties.class, Object.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
Message<String> message = MessageBuilder.withPayload("test")
|
||||
.setHeader("prop1", "foo").setHeader("prop2", "bar").build();
|
||||
Object[] args = mapper.fromMessage(message);
|
||||
Properties result = (Properties) args[0];
|
||||
assertEquals("foo", result.getProperty("prop1"));
|
||||
assertEquals("bar", result.getProperty("prop2"));
|
||||
assertEquals("test", args[1]);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void fromMessageWithMapAndObjectMethod() throws Exception {
|
||||
Method method = TestService.class.getMethod("mapHeadersAndPayload", Map.class, Object.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
Message<String> message = MessageBuilder.withPayload("test")
|
||||
.setHeader("prop1", "foo").setHeader("prop2", "bar").build();
|
||||
Object[] args = mapper.fromMessage(message);
|
||||
Map result = (Map) args[0];
|
||||
//Map also contains id, timestamp, and history
|
||||
assertEquals(5, result.size());
|
||||
assertEquals("foo", result.get("prop1"));
|
||||
assertEquals("bar", result.get("prop2"));
|
||||
assertEquals("test", args[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromMessageWithPropertiesMethodAndPropertiesPayload() throws Exception {
|
||||
Method method = TestService.class.getMethod("propertiesPayload", Properties.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
Properties payload = new Properties();
|
||||
payload.setProperty("prop1", "foo");
|
||||
payload.setProperty("prop2", "bar");
|
||||
Message<Properties> message = MessageBuilder.withPayload(payload)
|
||||
.setHeader("prop1", "not").setHeader("prop2", "these").build();
|
||||
Object[] args = mapper.fromMessage(message);
|
||||
Properties result = (Properties) args[0];
|
||||
//assertEquals(2, result.size());
|
||||
assertEquals("foo", result.getProperty("prop1"));
|
||||
assertEquals("bar", result.getProperty("prop2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void fromMessageWithMapMethodAndHeadersAnnotation() throws Exception {
|
||||
Method method = TestService.class.getMethod("mapHeaders", Map.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
Message<String> message = MessageBuilder.withPayload("test")
|
||||
.setHeader("attrib1", new Integer(123))
|
||||
.setHeader("attrib2", new Integer(456)).build();
|
||||
Object[] args = mapper.fromMessage(message);
|
||||
Map<String, Object> result = (Map<String, Object>) args[0];
|
||||
assertEquals(new Integer(123), result.get("attrib1"));
|
||||
assertEquals(new Integer(456), result.get("attrib2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void fromMessageWithMapMethodAndMapPayload() throws Exception {
|
||||
Method method = TestService.class.getMethod("mapPayload", Map.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
Map<String, Integer> payload = new HashMap<String, Integer>();
|
||||
payload.put("attrib1", new Integer(88));
|
||||
payload.put("attrib2", new Integer(99));
|
||||
Message<Map<String, Integer>> message = MessageBuilder.withPayload(payload)
|
||||
.setHeader("attrib1", new Integer(123))
|
||||
.setHeader("attrib2", new Integer(456)).build();
|
||||
Object[] args = mapper.fromMessage(message);
|
||||
Map<String, Integer> result = (Map<String, Integer>) args[0];
|
||||
assertEquals(2, result.size());
|
||||
assertEquals(new Integer(88), result.get("attrib1"));
|
||||
assertEquals(new Integer(99), result.get("attrib2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromMessageToMessageMappingAnnotation() throws Exception {
|
||||
Message<?> message = this.getMessage();
|
||||
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(TestService.class.getMethod("fromMessageToMessageMappingAnnotation", String.class));
|
||||
Object[] parameters = mapper.fromMessage(message);
|
||||
Assert.assertNotNull(parameters);
|
||||
Assert.assertTrue(parameters.length == 1);
|
||||
Assert.assertTrue(parameters[0].equals("monday"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromMessageIrrelevantAnnotation() throws Exception {
|
||||
Message<?> message = MessageBuilder.withPayload("foo").build();
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(TestService.class.getMethod("fromMessageIrrelevantAnnotation", String.class));
|
||||
Object args[] = mapper.fromMessage(message);
|
||||
assertEquals(1, args.length);
|
||||
assertEquals("foo", args[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromMessageToMessageMappingAnnotationMultiArguments() throws Exception {
|
||||
Message<?> message = this.getMessage();
|
||||
|
||||
ArgumentArrayMessageMapper mapper =
|
||||
new ArgumentArrayMessageMapper(TestService.class.getMethod("fromMessageToMessageMappingAnnotationMultiArguments",
|
||||
String.class,
|
||||
String.class,
|
||||
Message.class,
|
||||
Employee.class,
|
||||
String.class,
|
||||
Map.class));
|
||||
Object[] parameters = mapper.fromMessage(message);
|
||||
Assert.assertNotNull(parameters);
|
||||
Assert.assertTrue(parameters.length == 6);
|
||||
Assert.assertTrue(parameters[0].equals("monday"));
|
||||
Assert.assertTrue(parameters[1].equals("September"));
|
||||
Assert.assertTrue(parameters[2].equals(message));
|
||||
Assert.assertTrue(parameters[3].equals(employee));
|
||||
Assert.assertTrue(parameters[4].equals("oleg"));
|
||||
Assert.assertTrue(parameters[5] instanceof Map);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromMessageToPayload() throws Exception {
|
||||
Method method = TestService.class.getMethod("payloadOnly", Map.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
Message<Employee> message = MessageBuilder.withPayload(employee).setHeader("number", "jkl").build();
|
||||
Object[] args = mapper.fromMessage(message);
|
||||
Assert.assertTrue(args[0] instanceof Map);
|
||||
Assert.assertTrue(((Map)args[0]).get("number").equals("jkl"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromMessageToPayloadArg() throws Exception {
|
||||
Method method = TestService.class.getMethod("payloadOnlyPayloadArg", String.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
Message<Employee> message = MessageBuilder.withPayload(employee).setHeader("number", "jkl").build();
|
||||
Object[] args = mapper.fromMessage(message);
|
||||
Assert.assertTrue(args[0] instanceof String);
|
||||
Assert.assertTrue(args[0].equals("oleg"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromMessageToPayloadArgs() throws Exception {
|
||||
Method method = TestService.class.getMethod("payloadOnlyPayloadArgs", String.class, String.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
Message<Employee> message = MessageBuilder.withPayload(employee).setHeader("number", "jkl").build();
|
||||
Object[] args = mapper.fromMessage(message);
|
||||
Assert.assertTrue(args[0] instanceof String);
|
||||
Assert.assertTrue(args[0].equals("oleg"));
|
||||
Assert.assertTrue(args[1] instanceof String);
|
||||
Assert.assertTrue(args[1].equals("zhurakousky"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromMessageToPayloadArgsHeaderArgs() throws Exception {
|
||||
Method method = TestService.class.getMethod("payloadOnlyPayloadArgsHeaderArg", String.class, String.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
Message<Employee> message = MessageBuilder.withPayload(employee).setHeader("day", "monday").build();
|
||||
Object[] args = mapper.fromMessage(message);
|
||||
Assert.assertTrue(args[0] instanceof String);
|
||||
Assert.assertTrue(args[0].equals("oleg"));
|
||||
Assert.assertTrue(args[1] instanceof String);
|
||||
Assert.assertTrue(args[1].equals("monday"));
|
||||
}
|
||||
|
||||
@Test(expected = MessagingException.class)
|
||||
public void fromMessageInvalidMethodWithMultipleMappingAnnotations() throws Exception {
|
||||
Method method = MultipleMappingAnnotationTestBean.class.getMethod("test", String.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
Message<?> message = MessageBuilder.withPayload("payload").setHeader("foo", "bar").build();
|
||||
mapper.fromMessage(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromMessageToHeadersWithExpressions() throws Exception {
|
||||
Method method = TestService.class.getMethod("headersWithExpressions", String.class, String.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
Employee employee = new Employee("John", "Doe");
|
||||
Message<?> message = MessageBuilder.withPayload("payload").setHeader("emp", employee).build();
|
||||
Object[] args = mapper.fromMessage(message);
|
||||
assertEquals("John", args[0]);
|
||||
assertEquals("DOE", args[1]);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class MultipleMappingAnnotationTestBean {
|
||||
public void test(@Payload("payload") @Header("foo") String s) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class TestService {
|
||||
|
||||
public void payloadOnly(Map<?,?> employee){}
|
||||
public void payloadOnlyPayloadArg(String fname){}
|
||||
public void payloadOnlyPayloadArgs(String fname, String lname){}
|
||||
public void payloadOnlyPayloadArgsHeaderArg(String fname, String day){}
|
||||
|
||||
public String messageOnly(Message<?> message) {
|
||||
return (String) message.getPayload();
|
||||
}
|
||||
|
||||
public String messageAndHeader(Message<?> message, @Header("number") Integer num) {
|
||||
return (String) message.getPayload() + "-" + num.toString();
|
||||
}
|
||||
|
||||
public String twoHeaders(@Header String prop, @Header("number") Integer num) {
|
||||
return prop + "-" + num.toString();
|
||||
}
|
||||
|
||||
public Integer optionalHeader(@Header(required=false) Integer num) {
|
||||
return num;
|
||||
}
|
||||
|
||||
public Integer requiredHeader(@Header(value="num", required=true) Integer num) {
|
||||
return num;
|
||||
}
|
||||
|
||||
public String headersWithExpressions(@Header("emp.fname") String firstName,
|
||||
@Header("emp.lname.toUpperCase()") String lastName) {
|
||||
return lastName + ", " + firstName;
|
||||
}
|
||||
|
||||
public String optionalAndRequiredHeader(@Header(required=false) String prop, @Header(value="num", required=true) Integer num) {
|
||||
return prop + num;
|
||||
}
|
||||
|
||||
public Properties propertiesPayload(Properties properties) {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public Properties propertiesHeaders(@Headers Properties properties) {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public Object propertiesHeadersAndPayload(Properties headers, Object payload) {
|
||||
return payload;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map mapPayload(Map map) {
|
||||
return map;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map mapHeaders(@Headers Map map) {
|
||||
return map;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object mapHeadersAndPayload(Map headers, Object payload) {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public Integer integerMethod(Integer i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
public void fromMessageToArgWithConversion(@Header("number") String sArg) {} //
|
||||
|
||||
public void fromMessageToArgWithConversion(@Header("number") Integer iArg) {} //
|
||||
|
||||
public void fromMessageToArgWithConversion(@Header("numberA")Integer valueA, @Header("numberB") Integer valueB) {} //
|
||||
|
||||
public void fromMessageToMessageMappingAnnotation(@Header("day") String value) {} //
|
||||
|
||||
public void fromMessageToMessageMappingAnnotationMultiArguments(@Header("day") String argA,
|
||||
@Header("month") String argB,
|
||||
Message<?> message,
|
||||
@Payload Employee payloadArg,
|
||||
@Payload("fname") String value,
|
||||
@Headers Map<?,?> headers){} //
|
||||
|
||||
public void fromMessageIrrelevantAnnotation(@BogusAnnotation() String value){} //
|
||||
}
|
||||
|
||||
private Message<?> getMessage() {
|
||||
MessageBuilder<Employee> builder = MessageBuilder.withPayload(employee);
|
||||
builder.setHeader("day", "monday");
|
||||
builder.setHeader("month", "September");
|
||||
Message<Employee> message = builder.build();
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
public static class Employee {
|
||||
|
||||
private String fname;
|
||||
|
||||
private String lname;
|
||||
|
||||
public Employee(String fname, String lname) {
|
||||
this.fname = fname;
|
||||
this.lname = lname;
|
||||
}
|
||||
|
||||
public String getFname() {
|
||||
return fname;
|
||||
}
|
||||
|
||||
public String getLname() {
|
||||
return lname;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -39,7 +39,7 @@ public class ArgumentArrayMessageMapperToMessageTests {
|
||||
@Test
|
||||
public void toMessageWithPayload() throws Exception {
|
||||
Method method = TestService.class.getMethod("sendPayload", String.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway");
|
||||
Message<?> message = mapper.toMessage(new Object[] { "test" });
|
||||
assertEquals("test", message.getPayload());
|
||||
}
|
||||
@@ -47,14 +47,14 @@ public class ArgumentArrayMessageMapperToMessageTests {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void toMessageWithTooManyParameters() throws Exception {
|
||||
Method method = TestService.class.getMethod("sendPayload", String.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway");
|
||||
mapper.toMessage(new Object[] { "test" , "oops" });
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void toMessageWithEmptyParameterArray() throws Exception {
|
||||
Method method = TestService.class.getMethod("sendPayload", String.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway");
|
||||
mapper.toMessage(new Object[] {});
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class ArgumentArrayMessageMapperToMessageTests {
|
||||
public void toMessageWithPayloadAndHeader() throws Exception {
|
||||
Method method = TestService.class.getMethod(
|
||||
"sendPayloadAndHeader", String.class, String.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway");
|
||||
Message<?> message = mapper.toMessage(new Object[] { "test", "bar" });
|
||||
assertEquals("test", message.getPayload());
|
||||
assertEquals("bar", message.getHeaders().get("foo"));
|
||||
@@ -72,7 +72,7 @@ public class ArgumentArrayMessageMapperToMessageTests {
|
||||
public void toMessageWithPayloadAndRequiredHeaderButNullValue() throws Exception {
|
||||
Method method = TestService.class.getMethod(
|
||||
"sendPayloadAndHeader", String.class, String.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway");
|
||||
mapper.toMessage(new Object[] { "test", null });
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class ArgumentArrayMessageMapperToMessageTests {
|
||||
public void toMessageWithPayloadAndOptionalHeaderWithValueProvided() throws Exception {
|
||||
Method method = TestService.class.getMethod(
|
||||
"sendPayloadAndOptionalHeader", String.class, String.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway");
|
||||
Message<?> message = mapper.toMessage(new Object[] { "test", "bar" });
|
||||
assertEquals("test", message.getPayload());
|
||||
assertEquals("bar", message.getHeaders().get("foo"));
|
||||
@@ -90,7 +90,7 @@ public class ArgumentArrayMessageMapperToMessageTests {
|
||||
public void toMessageWithPayloadAndOptionalHeaderWithNullValue() throws Exception {
|
||||
Method method = TestService.class.getMethod(
|
||||
"sendPayloadAndOptionalHeader", String.class, String.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway");
|
||||
Message<?> message = mapper.toMessage(new Object[] { "test", null });
|
||||
assertEquals("test", message.getPayload());
|
||||
assertNull(message.getHeaders().get("foo"));
|
||||
@@ -100,7 +100,7 @@ public class ArgumentArrayMessageMapperToMessageTests {
|
||||
public void toMessageWithPayloadAndHeadersMap() throws Exception {
|
||||
Method method = TestService.class.getMethod(
|
||||
"sendPayloadAndHeadersMap", String.class, Map.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway");
|
||||
Map<String, Object> headers = new HashMap<String, Object>();
|
||||
headers.put("abc", 123);
|
||||
headers.put("def", 456);
|
||||
@@ -114,7 +114,7 @@ public class ArgumentArrayMessageMapperToMessageTests {
|
||||
public void toMessageWithPayloadAndNullHeadersMap() throws Exception {
|
||||
Method method = TestService.class.getMethod(
|
||||
"sendPayloadAndHeadersMap", String.class, Map.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway");
|
||||
Message<?> message = mapper.toMessage(new Object[] { "test", null });
|
||||
assertEquals("test", message.getPayload());
|
||||
}
|
||||
@@ -123,7 +123,7 @@ public class ArgumentArrayMessageMapperToMessageTests {
|
||||
public void toMessageWithPayloadAndHeadersMapWithNonStringKey() throws Exception {
|
||||
Method method = TestService.class.getMethod(
|
||||
"sendPayloadAndHeadersMap", String.class, Map.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway");
|
||||
Map<Integer, String> headers = new HashMap<Integer, String>();
|
||||
headers.put(123, "abc");
|
||||
mapper.toMessage(new Object[] { "test", headers });
|
||||
@@ -132,7 +132,7 @@ public class ArgumentArrayMessageMapperToMessageTests {
|
||||
@Test
|
||||
public void toMessageWithMessageParameter() throws Exception {
|
||||
Method method = TestService.class.getMethod("sendMessage", Message.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway");
|
||||
Message<?> inputMessage = MessageBuilder.withPayload("test message").build();
|
||||
Message<?> message = mapper.toMessage(new Object[] { inputMessage });
|
||||
assertEquals("test message", message.getPayload());
|
||||
@@ -141,7 +141,7 @@ public class ArgumentArrayMessageMapperToMessageTests {
|
||||
@Test
|
||||
public void toMessageWithMessageParameterAndHeader() throws Exception {
|
||||
Method method = TestService.class.getMethod("sendMessageAndHeader", Message.class, String.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway");
|
||||
Message<?> inputMessage = MessageBuilder.withPayload("test message").build();
|
||||
Message<?> message = mapper.toMessage(new Object[] { inputMessage, "bar" });
|
||||
assertEquals("test message", message.getPayload());
|
||||
@@ -151,7 +151,7 @@ public class ArgumentArrayMessageMapperToMessageTests {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void toMessageWithMessageParameterAndRequiredHeaderButNullValue() throws Exception {
|
||||
Method method = TestService.class.getMethod("sendMessageAndHeader", Message.class, String.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway");
|
||||
Message<?> inputMessage = MessageBuilder.withPayload("test message").build();
|
||||
mapper.toMessage(new Object[] { inputMessage, null });
|
||||
}
|
||||
@@ -159,7 +159,7 @@ public class ArgumentArrayMessageMapperToMessageTests {
|
||||
@Test
|
||||
public void toMessageWithMessageParameterAndOptionalHeaderWithValue() throws Exception {
|
||||
Method method = TestService.class.getMethod("sendMessageAndOptionalHeader", Message.class, String.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway");
|
||||
Message<?> inputMessage = MessageBuilder.withPayload("test message").build();
|
||||
Message<?> message = mapper.toMessage(new Object[] { inputMessage, "bar" });
|
||||
assertEquals("test message", message.getPayload());
|
||||
@@ -169,7 +169,7 @@ public class ArgumentArrayMessageMapperToMessageTests {
|
||||
@Test
|
||||
public void toMessageWithMessageParameterAndOptionalHeaderWithNull() throws Exception {
|
||||
Method method = TestService.class.getMethod("sendMessageAndOptionalHeader", Message.class, String.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway");
|
||||
Message<?> inputMessage = MessageBuilder.withPayload("test message").build();
|
||||
Message<?> message = mapper.toMessage(new Object[] { inputMessage, null });
|
||||
assertEquals("test message", message.getPayload());
|
||||
@@ -179,14 +179,14 @@ public class ArgumentArrayMessageMapperToMessageTests {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void noArgs() throws Exception {
|
||||
Method method = TestService.class.getMethod("noArgs", new Class<?>[] {});
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway");
|
||||
mapper.toMessage(new Object[] {});
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void onlyHeaders() throws Exception {
|
||||
Method method = TestService.class.getMethod("onlyHeaders", String.class, String.class);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method);
|
||||
ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway");
|
||||
mapper.toMessage(new Object[] { "abc", "def" });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user