Added Target interface and split DefaultMessageEndpoint into TargetEndpoint and HandlerEndpoint. All "one-way" adapters now implement Target instead of MessageHandler, the ConcurrentHandler is now ConcurrentTarget, and the MessageDispatcher also operates on Targets rather than MessageHandlers.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 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,35 +16,33 @@
|
||||
|
||||
package org.springframework.integration.adapter.event;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.integration.adapter.AbstractTargetAdapter;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageMapper;
|
||||
import org.springframework.integration.message.Target;
|
||||
|
||||
/**
|
||||
* A target adapter for publishing {@link MessagingEvent MessagingEvents}. The
|
||||
* {@link MessagingEvent} is a subclass of Spring's {@link ApplicationEvent}
|
||||
* used by this adapter to wrap any {@link Message} received on its channel.
|
||||
* used by this adapter to wrap any {@link Message} sent to this target.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ApplicationEventTargetAdapter extends AbstractTargetAdapter<MessagingEvent> implements
|
||||
ApplicationEventPublisherAware {
|
||||
public class ApplicationEventTargetAdapter<T> implements Target, ApplicationEventPublisherAware {
|
||||
|
||||
private final MessageMapper<T, MessagingEvent<T>> mapper = new MessagingEventMapper<T>();
|
||||
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
|
||||
public ApplicationEventTargetAdapter() {
|
||||
this.setMessageMapper(new MessagingEventMapper());
|
||||
}
|
||||
|
||||
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.applicationEventPublisher = applicationEventPublisher;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean sendToTarget(MessagingEvent event) {
|
||||
this.applicationEventPublisher.publishEvent(event);
|
||||
public boolean send(Message<?> message) {
|
||||
this.applicationEventPublisher.publishEvent(this.mapper.mapMessage((Message<T>) message));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 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,22 +17,22 @@
|
||||
package org.springframework.integration.adapter.event;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageCreator;
|
||||
import org.springframework.integration.message.MessageMapper;
|
||||
|
||||
/**
|
||||
* A {@link MessageMapper} implementation for mapping to and from
|
||||
* {@link MessagingEvent MessagingEvents}.
|
||||
* Maps between {@link Message Messages} and {@link MessagingEvent MessagingEvents}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class MessagingEventMapper<T> implements MessageMapper<T, MessagingEvent<T>> {
|
||||
public class MessagingEventMapper<T> implements MessageCreator<MessagingEvent<T>, T>, MessageMapper<T, MessagingEvent<T>> {
|
||||
|
||||
public MessagingEvent<T> fromMessage(Message<T> message) {
|
||||
return new MessagingEvent<T>(message);
|
||||
}
|
||||
|
||||
public Message<T> toMessage(MessagingEvent<T> event) {
|
||||
public Message<T> createMessage(MessagingEvent<T> event) {
|
||||
return event.getMessage();
|
||||
}
|
||||
|
||||
public MessagingEvent<T> mapMessage(Message<T> message) {
|
||||
return new MessagingEvent<T>(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,10 +23,11 @@ import java.io.FileWriter;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.message.AbstractMessageMapper;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageCreator;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.integration.message.MessageMapper;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
@@ -36,7 +37,7 @@ import org.springframework.util.FileCopyUtils;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public abstract class AbstractFileMapper<T> extends AbstractMessageMapper<T, File> {
|
||||
public abstract class AbstractFileMapper<T> implements MessageCreator<File, T>, MessageMapper<T, File> {
|
||||
|
||||
protected Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
@@ -60,7 +61,7 @@ public abstract class AbstractFileMapper<T> extends AbstractMessageMapper<T, Fil
|
||||
this.fileNameGenerator = fileNameGenerator;
|
||||
}
|
||||
|
||||
public File fromMessage(Message<T> message) {
|
||||
public File mapMessage(Message<T> message) {
|
||||
try {
|
||||
File file = new File(parentDirectory, this.fileNameGenerator.generateFileName(message));
|
||||
this.writeToFile(file, message.getPayload());
|
||||
@@ -71,7 +72,7 @@ public abstract class AbstractFileMapper<T> extends AbstractMessageMapper<T, Fil
|
||||
}
|
||||
}
|
||||
|
||||
public Message<T> toMessage(File file) {
|
||||
public Message<T> createMessage(File file) {
|
||||
try {
|
||||
T payload = this.readMessagePayload(file);
|
||||
if (payload == null) {
|
||||
|
||||
@@ -37,7 +37,7 @@ public class FileSource implements PollableSource<Object>, InitializingBean {
|
||||
|
||||
private volatile boolean textBased = true;
|
||||
|
||||
private volatile AbstractFileMapper mapper;
|
||||
private volatile AbstractFileMapper<?> mapper;
|
||||
|
||||
private volatile FileNameGenerator fileNameGenerator;
|
||||
|
||||
@@ -84,7 +84,7 @@ public class FileSource implements PollableSource<Object>, InitializingBean {
|
||||
}
|
||||
}
|
||||
|
||||
public Message<Object> poll() {
|
||||
public Message poll() {
|
||||
File[] files = null;
|
||||
if (this.fileFilter != null) {
|
||||
files = this.directory.listFiles(this.fileFilter);
|
||||
@@ -101,7 +101,7 @@ public class FileSource implements PollableSource<Object>, InitializingBean {
|
||||
}
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].isFile()) {
|
||||
return this.mapper.toMessage(files[i]);
|
||||
return this.mapper.createMessage(files[i]);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 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,8 +18,8 @@ package org.springframework.integration.adapter.file;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.springframework.integration.adapter.AbstractTargetAdapter;
|
||||
import org.springframework.integration.message.MessageMapper;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.Target;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,10 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class FileTargetAdapter extends AbstractTargetAdapter<File> {
|
||||
public class FileTargetAdapter implements Target {
|
||||
|
||||
private AbstractFileMapper<?> mapper;
|
||||
|
||||
|
||||
public FileTargetAdapter(File directory) {
|
||||
this(directory, true);
|
||||
@@ -36,23 +39,22 @@ public class FileTargetAdapter extends AbstractTargetAdapter<File> {
|
||||
|
||||
public FileTargetAdapter(File directory, boolean isTextBased) {
|
||||
if (isTextBased) {
|
||||
this.setMessageMapper(new TextFileMapper(directory));
|
||||
this.mapper = new TextFileMapper(directory);
|
||||
}
|
||||
else {
|
||||
this.setMessageMapper(new ByteArrayFileMapper(directory));
|
||||
this.mapper = new ByteArrayFileMapper(directory);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFileNameGenerator(FileNameGenerator fileNameGenerator) {
|
||||
Assert.notNull(fileNameGenerator, "'fileNameGenerator' must not be null");
|
||||
MessageMapper<?,?> mapper = this.getMessageMapper();
|
||||
if (mapper instanceof AbstractFileMapper<?>) {
|
||||
((AbstractFileMapper<?>) mapper).setFileNameGenerator(fileNameGenerator);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean sendToTarget(File file) {
|
||||
public boolean send(Message message) {
|
||||
File file = this.mapper.mapMessage(message);
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 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 org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.adapter.file.FileTargetAdapter;
|
||||
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
||||
import org.springframework.integration.endpoint.TargetEndpoint;
|
||||
import org.springframework.integration.scheduling.Subscription;
|
||||
|
||||
/**
|
||||
@@ -35,7 +35,7 @@ import org.springframework.integration.scheduling.Subscription;
|
||||
public class FileTargetAdapterParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return DefaultMessageEndpoint.class;
|
||||
return TargetEndpoint.class;
|
||||
}
|
||||
|
||||
protected boolean shouldGenerateId() {
|
||||
|
||||
@@ -32,8 +32,8 @@ import org.springframework.integration.adapter.file.ByteArrayFileMapper;
|
||||
import org.springframework.integration.adapter.file.FileNameGenerator;
|
||||
import org.springframework.integration.adapter.file.TextFileMapper;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageCreator;
|
||||
import org.springframework.integration.message.MessageDeliveryAware;
|
||||
import org.springframework.integration.message.MessageMapper;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.message.PollableSource;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -70,7 +70,7 @@ public class FtpSource implements PollableSource<Object>, MessageDeliveryAware {
|
||||
|
||||
private volatile boolean textBased = true;
|
||||
|
||||
private volatile MessageMapper mapper;
|
||||
private volatile MessageCreator<File, ?> messageCreator;
|
||||
|
||||
private final DirectoryContentManager directoryContentManager = new DirectoryContentManager();
|
||||
|
||||
@@ -113,14 +113,14 @@ public class FtpSource implements PollableSource<Object>, MessageDeliveryAware {
|
||||
|
||||
public void afterPropertiesSet() {
|
||||
if (this.isTextBased()) {
|
||||
this.mapper = new TextFileMapper(this.localWorkingDirectory);
|
||||
this.messageCreator = new TextFileMapper(this.localWorkingDirectory);
|
||||
}
|
||||
else {
|
||||
this.mapper = new ByteArrayFileMapper(this.localWorkingDirectory);
|
||||
this.messageCreator = new ByteArrayFileMapper(this.localWorkingDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
public final Message<Object> poll() {
|
||||
public final Message poll() {
|
||||
try {
|
||||
this.establishConnection();
|
||||
FTPFile[] fileList = this.client.listFiles();
|
||||
@@ -143,7 +143,7 @@ public class FtpSource implements PollableSource<Object>, MessageDeliveryAware {
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(file);
|
||||
this.client.retrieveFile(fileName, fileOutputStream);
|
||||
fileOutputStream.close();
|
||||
return this.mapper.toMessage(file);
|
||||
return this.messageCreator.createMessage(file);
|
||||
}
|
||||
catch (Exception e) {
|
||||
try {
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.adapter.httpinvoker.HttpInvokerTargetAdapter;
|
||||
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
||||
import org.springframework.integration.endpoint.HandlerEndpoint;
|
||||
import org.springframework.integration.scheduling.Subscription;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.springframework.util.StringUtils;
|
||||
public class HttpInvokerTargetAdapterParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return DefaultMessageEndpoint.class;
|
||||
return HandlerEndpoint.class;
|
||||
}
|
||||
|
||||
protected boolean shouldGenerateId() {
|
||||
|
||||
@@ -19,8 +19,8 @@ package org.springframework.integration.adapter.jms;
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.Destination;
|
||||
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.Target;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,7 @@ import org.springframework.jms.core.JmsTemplate;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class JmsTargetAdapter extends AbstractJmsTemplateBasedAdapter implements MessageHandler {
|
||||
public class JmsTargetAdapter extends AbstractJmsTemplateBasedAdapter implements Target {
|
||||
|
||||
public JmsTargetAdapter(JmsTemplate jmsTemplate) {
|
||||
super(jmsTemplate);
|
||||
@@ -47,11 +47,12 @@ public class JmsTargetAdapter extends AbstractJmsTemplateBasedAdapter implements
|
||||
}
|
||||
|
||||
|
||||
public final Message<?> handle(final Message<?> message) {
|
||||
if (message != null) {
|
||||
this.getJmsTemplate().convertAndSend(message);
|
||||
public final boolean send(final Message<?> message) {
|
||||
if (message == null) {
|
||||
throw new IllegalArgumentException("message must not be null");
|
||||
}
|
||||
return null;
|
||||
this.getJmsTemplate().convertAndSend(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 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,7 +26,7 @@ import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.adapter.jms.JmsTargetAdapter;
|
||||
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
||||
import org.springframework.integration.endpoint.TargetEndpoint;
|
||||
import org.springframework.integration.scheduling.Subscription;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -41,7 +41,7 @@ public class JmsTargetAdapterParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return DefaultMessageEndpoint.class;
|
||||
return TargetEndpoint.class;
|
||||
}
|
||||
|
||||
protected boolean shouldGenerateId() {
|
||||
|
||||
@@ -21,8 +21,8 @@ import javax.mail.internet.MimeMessage;
|
||||
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.integration.adapter.MessageMappingException;
|
||||
import org.springframework.integration.message.AbstractMessageMapper;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageMapper;
|
||||
import org.springframework.mail.MailMessage;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMailMessage;
|
||||
@@ -36,7 +36,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class ByteArrayMailMessageMapper extends AbstractMessageMapper<byte[], MailMessage> {
|
||||
public class ByteArrayMailMessageMapper implements MessageMapper<byte[], MailMessage> {
|
||||
|
||||
private final JavaMailSender mailSender;
|
||||
|
||||
@@ -63,7 +63,7 @@ public class ByteArrayMailMessageMapper extends AbstractMessageMapper<byte[], Ma
|
||||
throw new UnsupportedOperationException("mapping from MailMessage to byte array not supported");
|
||||
}
|
||||
|
||||
public MailMessage fromMessage(Message<byte[]> message) {
|
||||
public MailMessage mapMessage(Message<byte[]> message) {
|
||||
try {
|
||||
MimeMessage mimeMessage = this.mailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, this.multipartMode);
|
||||
|
||||
@@ -17,10 +17,9 @@
|
||||
package org.springframework.integration.adapter.mail;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.message.AbstractMessageMapper;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageMapper;
|
||||
import org.springframework.integration.message.Target;
|
||||
import org.springframework.mail.MailMessage;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
@@ -33,7 +32,7 @@ import org.springframework.util.Assert;
|
||||
* @author Marius Bogoevici
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class MailTargetAdapter implements MessageHandler, InitializingBean {
|
||||
public class MailTargetAdapter implements Target, InitializingBean {
|
||||
|
||||
private final JavaMailSender mailSender;
|
||||
|
||||
@@ -84,22 +83,22 @@ public class MailTargetAdapter implements MessageHandler, InitializingBean {
|
||||
this.objectMessageMapper = objectMessageMapper;
|
||||
}
|
||||
|
||||
public Message<?> handle(Message<?> message) {
|
||||
public final boolean send(Message<?> message) {
|
||||
MailMessage mailMessage = this.convertMessageToMailMessage(message);
|
||||
this.mailHeaderGenerator.populateMailMessageHeader(mailMessage, message);
|
||||
this.sendMailMessage(mailMessage);
|
||||
return null;
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private MailMessage convertMessageToMailMessage(Message<?> message) {
|
||||
if (message.getPayload() instanceof String) {
|
||||
return this.textMessageMapper.fromMessage((Message<String>) message);
|
||||
return this.textMessageMapper.mapMessage((Message<String>) message);
|
||||
}
|
||||
else if (message.getPayload() instanceof byte[]) {
|
||||
return this.byteArrayMessageMapper.fromMessage((Message<byte[]>) message);
|
||||
return this.byteArrayMessageMapper.mapMessage((Message<byte[]>) message);
|
||||
}
|
||||
return this.objectMessageMapper.fromMessage((Message<Object>) message);
|
||||
return this.objectMessageMapper.mapMessage((Message<Object>) message);
|
||||
}
|
||||
|
||||
private void sendMailMessage(MailMessage mailMessage) {
|
||||
@@ -116,17 +115,18 @@ public class MailTargetAdapter implements MessageHandler, InitializingBean {
|
||||
}
|
||||
|
||||
|
||||
private static class DefaultObjectMailMessageMapper extends AbstractMessageMapper<Object, MailMessage> {
|
||||
private static class DefaultObjectMailMessageMapper implements MessageMapper<Object, MailMessage> {
|
||||
|
||||
public Message<Object> toMessage(MailMessage source) {
|
||||
throw new UnsupportedOperationException("mapping from MailMessage to Object not supported");
|
||||
}
|
||||
|
||||
public MailMessage fromMessage(Message<Object> objectMessage) {
|
||||
public MailMessage mapMessage(Message<Object> objectMessage) {
|
||||
SimpleMailMessage message = new SimpleMailMessage();
|
||||
message.setText(objectMessage.getPayload().toString());
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 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,8 +16,8 @@
|
||||
|
||||
package org.springframework.integration.adapter.mail;
|
||||
|
||||
import org.springframework.integration.message.AbstractMessageMapper;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageMapper;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.mail.MailMessage;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
@@ -30,14 +30,14 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class TextMailMessageMapper extends AbstractMessageMapper<String, MailMessage> {
|
||||
public class TextMailMessageMapper implements MessageMapper<String, MailMessage> {
|
||||
|
||||
public Message<String> toMessage(MailMessage source) {
|
||||
Assert.isInstanceOf(SimpleMailMessage.class, source, "source must be a SimpleMailMessage");
|
||||
return new StringMessage(((SimpleMailMessage) source).getText());
|
||||
}
|
||||
|
||||
public MailMessage fromMessage(Message<String> stringMessage) {
|
||||
public MailMessage mapMessage(Message<String> stringMessage) {
|
||||
SimpleMailMessage mailMessage = new SimpleMailMessage();
|
||||
mailMessage.setText(stringMessage.getPayload());
|
||||
return mailMessage;
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.adapter.mail.MailTargetAdapter;
|
||||
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
||||
import org.springframework.integration.endpoint.TargetEndpoint;
|
||||
import org.springframework.integration.scheduling.Subscription;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -39,7 +39,7 @@ import org.springframework.util.StringUtils;
|
||||
public class MailTargetAdapterParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return DefaultMessageEndpoint.class;
|
||||
return TargetEndpoint.class;
|
||||
}
|
||||
|
||||
protected boolean shouldGenerateId() {
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.adapter.rmi.RmiSourceAdapter;
|
||||
import org.springframework.integration.adapter.rmi.RmiTargetAdapter;
|
||||
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
||||
import org.springframework.integration.endpoint.HandlerEndpoint;
|
||||
import org.springframework.integration.scheduling.Subscription;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.springframework.util.StringUtils;
|
||||
public class RmiTargetAdapterParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return DefaultMessageEndpoint.class;
|
||||
return HandlerEndpoint.class;
|
||||
}
|
||||
|
||||
protected boolean shouldGenerateId() {
|
||||
|
||||
@@ -20,15 +20,21 @@ import java.io.BufferedOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.springframework.integration.adapter.AbstractTargetAdapter;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.message.Target;
|
||||
|
||||
/**
|
||||
* A target adapter that writes a byte array to an {@link OutputStream}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ByteStreamTargetAdapter extends AbstractTargetAdapter {
|
||||
public class ByteStreamTargetAdapter implements Target {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private BufferedOutputStream stream;
|
||||
|
||||
@@ -46,21 +52,20 @@ public class ByteStreamTargetAdapter extends AbstractTargetAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean sendToTarget(Object object) {
|
||||
if (object == null) {
|
||||
public boolean send(Message message) {
|
||||
Object payload = message.getPayload();
|
||||
if (payload == null) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(this.getClass().getSimpleName() + " received null object");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
if (object instanceof String) {
|
||||
this.stream.write(((String) object).getBytes());
|
||||
if (payload instanceof String) {
|
||||
this.stream.write(((String) payload).getBytes());
|
||||
}
|
||||
else if (object instanceof byte[]){
|
||||
this.stream.write((byte[]) object);
|
||||
else if (payload instanceof byte[]){
|
||||
this.stream.write((byte[]) payload);
|
||||
}
|
||||
else {
|
||||
throw new MessagingException(this.getClass().getSimpleName() +
|
||||
|
||||
@@ -23,9 +23,13 @@ import java.io.OutputStreamWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.adapter.AbstractTargetAdapter;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.message.Target;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -38,7 +42,9 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class CharacterStreamTargetAdapter extends AbstractTargetAdapter {
|
||||
public class CharacterStreamTargetAdapter implements Target {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private final BufferedWriter writer;
|
||||
|
||||
@@ -112,26 +118,26 @@ public class CharacterStreamTargetAdapter extends AbstractTargetAdapter {
|
||||
this.shouldAppendNewLine = shouldAppendNewLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean sendToTarget(Object object) {
|
||||
if (object == null) {
|
||||
public boolean send(Message message) {
|
||||
Object payload = message.getPayload();
|
||||
if (payload == null) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("target adapter received null object");
|
||||
logger.warn("target adapter received null payload");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
if (object instanceof String) {
|
||||
writer.write((String) object);
|
||||
if (payload instanceof String) {
|
||||
writer.write((String) payload);
|
||||
}
|
||||
else if (object instanceof char[]) {
|
||||
this.writer.write((char[]) object);
|
||||
else if (payload instanceof char[]) {
|
||||
this.writer.write((char[]) payload);
|
||||
}
|
||||
else if (object instanceof byte[]) {
|
||||
this.writer.write(new String((byte[]) object));
|
||||
else if (payload instanceof byte[]) {
|
||||
this.writer.write(new String((byte[]) payload));
|
||||
}
|
||||
else {
|
||||
writer.write(object.toString());
|
||||
writer.write(payload.toString());
|
||||
}
|
||||
if (this.shouldAppendNewLine) {
|
||||
writer.newLine();
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.integration.bus.MessageBus;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.SimpleChannel;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.scheduling.Subscription;
|
||||
|
||||
@@ -49,7 +50,7 @@ public class ApplicationEventTargetAdapterTests {
|
||||
adapter.setApplicationEventPublisher(publisher);
|
||||
MessageBus bus = new MessageBus();
|
||||
bus.registerChannel("channel", channel);
|
||||
bus.registerHandler("adapter", adapter, new Subscription(channel));
|
||||
bus.registerTarget("adapter", adapter, new Subscription(channel));
|
||||
bus.start();
|
||||
assertEquals(1, latch.getCount());
|
||||
channel.send(new StringMessage("123", "testing"));
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.file.FileTargetAdapter;
|
||||
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
||||
import org.springframework.integration.endpoint.TargetEndpoint;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -33,8 +33,8 @@ public class FileTargetAdapterParserTests {
|
||||
@Test
|
||||
public void testFileTargetAdapterParser() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileTargetAdapterParserTests.xml", this.getClass());
|
||||
DefaultMessageEndpoint endpoint = (DefaultMessageEndpoint) context.getBean("adapter");
|
||||
assertEquals(FileTargetAdapter.class, endpoint.getHandler().getClass());
|
||||
TargetEndpoint endpoint = (TargetEndpoint) context.getBean("adapter");
|
||||
assertEquals(FileTargetAdapter.class, endpoint.getTarget().getClass());
|
||||
assertEquals("adapter", endpoint.getName());
|
||||
assertEquals("testChannel", endpoint.getSubscription().getChannelName());
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.httpinvoker.HttpInvokerTargetAdapter;
|
||||
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
||||
import org.springframework.integration.endpoint.HandlerEndpoint;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -35,7 +35,7 @@ public class HttpInvokerTargetAdapterParserTests {
|
||||
public void testHttpInvokerTargetAdapter() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"httpInvokerTargetAdapterParserTests.xml", this.getClass());
|
||||
DefaultMessageEndpoint endpoint = (DefaultMessageEndpoint) context.getBean("adapter");
|
||||
HandlerEndpoint endpoint = (HandlerEndpoint) context.getBean("adapter");
|
||||
assertNotNull(endpoint);
|
||||
assertEquals(HttpInvokerTargetAdapter.class, endpoint.getHandler().getClass());
|
||||
assertEquals("testChannel", endpoint.getSubscription().getChannelName());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 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 org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.jms.JmsTargetAdapter;
|
||||
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
||||
import org.springframework.integration.endpoint.TargetEndpoint;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -35,8 +35,8 @@ public class JmsTargetAdapterParserTests {
|
||||
public void testTargetAdapterWithConnectionFactoryAndDestination() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"targetAdapterWithConnectionFactoryAndDestination.xml", this.getClass());
|
||||
DefaultMessageEndpoint endpoint = (DefaultMessageEndpoint) context.getBean("adapter");
|
||||
assertEquals(JmsTargetAdapter.class, endpoint.getHandler().getClass());
|
||||
TargetEndpoint endpoint = (TargetEndpoint) context.getBean("adapter");
|
||||
assertEquals(JmsTargetAdapter.class, endpoint.getTarget().getClass());
|
||||
assertEquals("adapter", endpoint.getName());
|
||||
assertEquals("testChannel", endpoint.getSubscription().getChannelName());
|
||||
}
|
||||
@@ -45,8 +45,8 @@ public class JmsTargetAdapterParserTests {
|
||||
public void testTargetAdapterWithConnectionFactoryAndDestinationName() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"targetAdapterWithConnectionFactoryAndDestinationName.xml", this.getClass());
|
||||
DefaultMessageEndpoint endpoint = (DefaultMessageEndpoint) context.getBean("adapter");
|
||||
assertEquals(JmsTargetAdapter.class, endpoint.getHandler().getClass());
|
||||
TargetEndpoint endpoint = (TargetEndpoint) context.getBean("adapter");
|
||||
assertEquals(JmsTargetAdapter.class, endpoint.getTarget().getClass());
|
||||
assertEquals("adapter", endpoint.getName());
|
||||
assertEquals("testChannel", endpoint.getSubscription().getChannelName());
|
||||
}
|
||||
@@ -55,8 +55,8 @@ public class JmsTargetAdapterParserTests {
|
||||
public void testTargetAdapterWithDefaultConnectionFactory() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"targetAdapterWithDefaultConnectionFactory.xml", this.getClass());
|
||||
DefaultMessageEndpoint endpoint = (DefaultMessageEndpoint) context.getBean("adapter");
|
||||
assertEquals(JmsTargetAdapter.class, endpoint.getHandler().getClass());
|
||||
TargetEndpoint endpoint = (TargetEndpoint) context.getBean("adapter");
|
||||
assertEquals(JmsTargetAdapter.class, endpoint.getTarget().getClass());
|
||||
assertEquals("adapter", endpoint.getName());
|
||||
assertEquals("testChannel", endpoint.getSubscription().getChannelName());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 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.
|
||||
@@ -59,7 +59,7 @@ public class MailTargetAdapterContextTests {
|
||||
|
||||
@Test
|
||||
public void testStringMesssagesWithConfiguration() {
|
||||
this.mailTargetAdapter.handle(new StringMessage(MailTestsHelper.MESSAGE_TEXT));
|
||||
this.mailTargetAdapter.send(new StringMessage(MailTestsHelper.MESSAGE_TEXT));
|
||||
SimpleMailMessage message = MailTestsHelper.createSimpleMailMessage();
|
||||
assertEquals("no mime message should have been sent",
|
||||
0, this.mailSender.getSentMimeMessages().size());
|
||||
@@ -72,7 +72,7 @@ public class MailTargetAdapterContextTests {
|
||||
@Test
|
||||
public void testByteArrayMessage() throws Exception {
|
||||
byte[] payload = {1, 2, 3};
|
||||
mailTargetAdapter.handle(new GenericMessage<byte[]>(payload));
|
||||
mailTargetAdapter.send(new GenericMessage<byte[]>(payload));
|
||||
assertEquals("no mime message should have been sent",
|
||||
1, mailSender.getSentMimeMessages().size());
|
||||
assertEquals("only one simple message must be sent",
|
||||
|
||||
@@ -64,7 +64,7 @@ public class MailTargetAdapterTests {
|
||||
@Test
|
||||
public void testTextMessage() {
|
||||
this.mailTargetAdapter.setHeaderGenerator(this.staticMailHeaderGenerator);
|
||||
this.mailTargetAdapter.handle(new StringMessage(MailTestsHelper.MESSAGE_TEXT));
|
||||
this.mailTargetAdapter.send(new StringMessage(MailTestsHelper.MESSAGE_TEXT));
|
||||
SimpleMailMessage message = MailTestsHelper.createSimpleMailMessage();
|
||||
assertEquals("no mime message should have been sent",
|
||||
0, mailSender.getSentMimeMessages().size());
|
||||
@@ -78,7 +78,7 @@ public class MailTargetAdapterTests {
|
||||
public void testByteArrayMessage() throws Exception {
|
||||
this.mailTargetAdapter.setHeaderGenerator(this.staticMailHeaderGenerator);
|
||||
byte[] payload = {1, 2, 3};
|
||||
this.mailTargetAdapter.handle(new GenericMessage<byte[]>(payload));
|
||||
this.mailTargetAdapter.send(new GenericMessage<byte[]>(payload));
|
||||
byte[] buffer = new byte[1024];
|
||||
MimeMessage mimeMessage = this.mailSender.getSentMimeMessages().get(0);
|
||||
assertTrue("message must be multipart", mimeMessage.getContent() instanceof Multipart);
|
||||
@@ -99,7 +99,7 @@ public class MailTargetAdapterTests {
|
||||
message.getHeader().setAttribute(MailAttributeKeys.BCC, MailTestsHelper.BCC);
|
||||
message.getHeader().setAttribute(MailAttributeKeys.FROM, MailTestsHelper.FROM);
|
||||
message.getHeader().setAttribute(MailAttributeKeys.REPLY_TO, MailTestsHelper.REPLY_TO);
|
||||
this.mailTargetAdapter.handle(message);
|
||||
this.mailTargetAdapter.send(message);
|
||||
SimpleMailMessage mailMessage = MailTestsHelper.createSimpleMailMessage();
|
||||
assertEquals("no mime message should have been sent",
|
||||
0, mailSender.getSentMimeMessages().size());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 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.
|
||||
@@ -27,9 +27,9 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.mail.MailHeaderGenerator;
|
||||
import org.springframework.integration.adapter.mail.MailTargetAdapter;
|
||||
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.endpoint.TargetEndpoint;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.Target;
|
||||
import org.springframework.mail.MailMessage;
|
||||
|
||||
/**
|
||||
@@ -41,31 +41,31 @@ public class MailTargetAdapterParserTests {
|
||||
public void testAdapterWithMailSenderReference() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"mailTargetAdapterParserTests.xml", this.getClass());
|
||||
DefaultMessageEndpoint endpoint = (DefaultMessageEndpoint) context.getBean("adapterWithMailSenderReference");
|
||||
MessageHandler handler = endpoint.getHandler();
|
||||
assertNotNull(handler);
|
||||
assertTrue(handler instanceof MailTargetAdapter);
|
||||
TargetEndpoint endpoint = (TargetEndpoint) context.getBean("adapterWithMailSenderReference");
|
||||
Target target = endpoint.getTarget();
|
||||
assertNotNull(target);
|
||||
assertTrue(target instanceof MailTargetAdapter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterWithHostProperty() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"mailTargetAdapterParserTests.xml", this.getClass());
|
||||
DefaultMessageEndpoint endpoint = (DefaultMessageEndpoint) context.getBean("adapterWithHostProperty");
|
||||
MessageHandler handler = endpoint.getHandler();
|
||||
assertNotNull(handler);
|
||||
assertTrue(handler instanceof MailTargetAdapter);
|
||||
TargetEndpoint endpoint = (TargetEndpoint) context.getBean("adapterWithHostProperty");
|
||||
Target target = endpoint.getTarget();
|
||||
assertNotNull(target);
|
||||
assertTrue(target instanceof MailTargetAdapter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterWithHeaderGeneratorReference() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"mailTargetAdapterParserTests.xml", this.getClass());
|
||||
DefaultMessageEndpoint endpoint = (DefaultMessageEndpoint) context.getBean("adapterWithHeaderGeneratorReference");
|
||||
MessageHandler handler = endpoint.getHandler();
|
||||
assertNotNull(handler);
|
||||
assertTrue(handler instanceof MailTargetAdapter);
|
||||
DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(handler);
|
||||
TargetEndpoint endpoint = (TargetEndpoint) context.getBean("adapterWithHeaderGeneratorReference");
|
||||
Target target = endpoint.getTarget();
|
||||
assertNotNull(target);
|
||||
assertTrue(target instanceof MailTargetAdapter);
|
||||
DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(target);
|
||||
MailHeaderGenerator headerGenerator =
|
||||
(MailHeaderGenerator) fieldAccessor.getPropertyValue("mailHeaderGenerator");
|
||||
assertEquals(TestHeaderGenerator.class, headerGenerator.getClass());
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.rmi.RmiSourceAdapter;
|
||||
import org.springframework.integration.adapter.rmi.RmiTargetAdapter;
|
||||
import org.springframework.integration.channel.SimpleChannel;
|
||||
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
||||
import org.springframework.integration.endpoint.HandlerEndpoint;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
|
||||
/**
|
||||
@@ -50,7 +50,7 @@ public class RmiTargetAdapterParserTests {
|
||||
public void testRmiTargetAdapter() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"rmiTargetAdapterParserTests.xml", this.getClass());
|
||||
DefaultMessageEndpoint endpoint = (DefaultMessageEndpoint) context.getBean("adapter");
|
||||
HandlerEndpoint endpoint = (HandlerEndpoint) context.getBean("adapter");
|
||||
assertNotNull(endpoint);
|
||||
assertEquals(RmiTargetAdapter.class, endpoint.getHandler().getClass());
|
||||
RmiTargetAdapter adapter = (RmiTargetAdapter) endpoint.getHandler();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 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,7 +40,7 @@ public class ByteStreamTargetAdapterTests {
|
||||
public void testSingleByteArray() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ByteStreamTargetAdapter adapter = new ByteStreamTargetAdapter(stream);
|
||||
adapter.handle(new GenericMessage<byte[]>(new byte[] {1,2,3}));
|
||||
adapter.send(new GenericMessage<byte[]>(new byte[] {1,2,3}));
|
||||
byte[] result = stream.toByteArray();
|
||||
assertEquals(3, result.length);
|
||||
assertEquals(1, result[0]);
|
||||
@@ -52,7 +52,7 @@ public class ByteStreamTargetAdapterTests {
|
||||
public void testSingleString() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ByteStreamTargetAdapter adapter = new ByteStreamTargetAdapter(stream);
|
||||
adapter.handle(new StringMessage("foo"));
|
||||
adapter.send(new StringMessage("foo"));
|
||||
byte[] result = stream.toByteArray();
|
||||
assertEquals(3, result.length);
|
||||
assertEquals("foo", new String(result));
|
||||
@@ -67,7 +67,7 @@ public class ByteStreamTargetAdapterTests {
|
||||
SimpleChannel channel = new SimpleChannel(5, dispatcherPolicy);
|
||||
SimpleMessagingTaskScheduler scheduler = new SimpleMessagingTaskScheduler(1);
|
||||
MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler);
|
||||
dispatcher.addHandler(adapter);
|
||||
dispatcher.addTarget(adapter);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {1,2,3}), 0);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {4,5,6}), 0);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {7,8,9}), 0);
|
||||
@@ -87,7 +87,7 @@ public class ByteStreamTargetAdapterTests {
|
||||
SimpleChannel channel = new SimpleChannel(5, dispatcherPolicy);
|
||||
SimpleMessagingTaskScheduler scheduler = new SimpleMessagingTaskScheduler(1);
|
||||
MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler);
|
||||
dispatcher.addHandler(adapter);
|
||||
dispatcher.addTarget(adapter);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {1,2,3}), 0);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {4,5,6}), 0);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {7,8,9}), 0);
|
||||
@@ -107,7 +107,7 @@ public class ByteStreamTargetAdapterTests {
|
||||
SimpleChannel channel = new SimpleChannel(5, dispatcherPolicy);
|
||||
SimpleMessagingTaskScheduler scheduler = new SimpleMessagingTaskScheduler(1);
|
||||
MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler);
|
||||
dispatcher.addHandler(adapter);
|
||||
dispatcher.addTarget(adapter);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {1,2,3}), 0);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {4,5,6}), 0);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {7,8,9}), 0);
|
||||
@@ -127,7 +127,7 @@ public class ByteStreamTargetAdapterTests {
|
||||
SimpleChannel channel = new SimpleChannel(5, dispatcherPolicy);
|
||||
SimpleMessagingTaskScheduler scheduler = new SimpleMessagingTaskScheduler(1);
|
||||
MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler);
|
||||
dispatcher.addHandler(adapter);
|
||||
dispatcher.addTarget(adapter);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {1,2,3}), 0);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {4,5,6}), 0);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {7,8,9}), 0);
|
||||
@@ -152,7 +152,7 @@ public class ByteStreamTargetAdapterTests {
|
||||
SimpleChannel channel = new SimpleChannel(5, dispatcherPolicy);
|
||||
SimpleMessagingTaskScheduler scheduler = new SimpleMessagingTaskScheduler(1);
|
||||
MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler);
|
||||
dispatcher.addHandler(adapter);
|
||||
dispatcher.addTarget(adapter);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {1,2,3}), 0);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {4,5,6}), 0);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {7,8,9}), 0);
|
||||
@@ -176,7 +176,7 @@ public class ByteStreamTargetAdapterTests {
|
||||
SimpleChannel channel = new SimpleChannel(5, dispatcherPolicy);
|
||||
SimpleMessagingTaskScheduler scheduler = new SimpleMessagingTaskScheduler(1);
|
||||
MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler);
|
||||
dispatcher.addHandler(adapter);
|
||||
dispatcher.addTarget(adapter);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {1,2,3}), 0);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {4,5,6}), 0);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {7,8,9}), 0);
|
||||
@@ -200,7 +200,7 @@ public class ByteStreamTargetAdapterTests {
|
||||
SimpleChannel channel = new SimpleChannel(5, dispatcherPolicy);
|
||||
SimpleMessagingTaskScheduler scheduler = new SimpleMessagingTaskScheduler(1);
|
||||
MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler);
|
||||
dispatcher.addHandler(adapter);
|
||||
dispatcher.addTarget(adapter);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {1,2,3}), 0);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {4,5,6}), 0);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {7,8,9}), 0);
|
||||
|
||||
@@ -43,7 +43,7 @@ public class CharacterStreamTargetAdapterTests {
|
||||
public void testSingleString() {
|
||||
StringWriter writer = new StringWriter();
|
||||
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(writer);
|
||||
adapter.handle(new StringMessage("foo"));
|
||||
adapter.send(new StringMessage("foo"));
|
||||
assertEquals("foo", writer.toString());
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class CharacterStreamTargetAdapterTests {
|
||||
StringWriter writer = new StringWriter();
|
||||
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(writer);
|
||||
MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler);
|
||||
dispatcher.addHandler(adapter);
|
||||
dispatcher.addTarget(adapter);
|
||||
channel.send(new StringMessage("foo"), 0);
|
||||
channel.send(new StringMessage("bar"), 0);
|
||||
assertEquals(1, dispatcher.dispatch());
|
||||
@@ -69,7 +69,7 @@ public class CharacterStreamTargetAdapterTests {
|
||||
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(writer);
|
||||
adapter.setShouldAppendNewLine(true);
|
||||
MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler);
|
||||
dispatcher.addHandler(adapter);
|
||||
dispatcher.addTarget(adapter);
|
||||
channel.send(new StringMessage("foo"), 0);
|
||||
channel.send(new StringMessage("bar"), 0);
|
||||
assertEquals(1, dispatcher.dispatch());
|
||||
@@ -87,7 +87,7 @@ public class CharacterStreamTargetAdapterTests {
|
||||
dispatcherPolicy.setMaxMessagesPerTask(2);
|
||||
SimpleChannel channel = new SimpleChannel(5, dispatcherPolicy);
|
||||
MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler);
|
||||
dispatcher.addHandler(adapter);
|
||||
dispatcher.addTarget(adapter);
|
||||
channel.send(new StringMessage("foo"), 0);
|
||||
channel.send(new StringMessage("bar"), 0);
|
||||
assertEquals(2, dispatcher.dispatch());
|
||||
@@ -104,7 +104,7 @@ public class CharacterStreamTargetAdapterTests {
|
||||
SimpleChannel channel = new SimpleChannel(5, dispatcherPolicy);
|
||||
MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler);
|
||||
adapter.setShouldAppendNewLine(true);
|
||||
dispatcher.addHandler(adapter);
|
||||
dispatcher.addTarget(adapter);
|
||||
channel.send(new StringMessage("foo"), 0);
|
||||
channel.send(new StringMessage("bar"), 0);
|
||||
assertEquals(2, dispatcher.dispatch());
|
||||
@@ -118,7 +118,7 @@ public class CharacterStreamTargetAdapterTests {
|
||||
StringWriter writer = new StringWriter();
|
||||
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(writer);
|
||||
MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler);
|
||||
dispatcher.addHandler(adapter);
|
||||
dispatcher.addTarget(adapter);
|
||||
TestObject testObject = new TestObject("foo");
|
||||
channel.send(new GenericMessage<TestObject>(testObject));
|
||||
int count = dispatcher.dispatch();
|
||||
@@ -135,7 +135,7 @@ public class CharacterStreamTargetAdapterTests {
|
||||
dispatcherPolicy.setMaxMessagesPerTask(2);
|
||||
SimpleChannel channel = new SimpleChannel(5, dispatcherPolicy);
|
||||
MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler);
|
||||
dispatcher.addHandler(adapter);
|
||||
dispatcher.addTarget(adapter);
|
||||
TestObject testObject1 = new TestObject("foo");
|
||||
TestObject testObject2 = new TestObject("bar");
|
||||
channel.send(new GenericMessage<TestObject>(testObject1), 0);
|
||||
@@ -154,7 +154,7 @@ public class CharacterStreamTargetAdapterTests {
|
||||
SimpleChannel channel = new SimpleChannel(5, dispatcherPolicy);
|
||||
DefaultMessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler);
|
||||
adapter.setShouldAppendNewLine(true);
|
||||
dispatcher.addHandler(adapter);
|
||||
dispatcher.addTarget(adapter);
|
||||
TestObject testObject1 = new TestObject("foo");
|
||||
TestObject testObject2 = new TestObject("bar");
|
||||
channel.send(new GenericMessage<TestObject>(testObject1), 0);
|
||||
|
||||
Reference in New Issue
Block a user