MessageEndpoint no longer extends the MessageTarget interface.
This commit is contained in:
@@ -254,9 +254,6 @@
|
||||
<xsd:attribute name="mail-convertor" type="xsd:string" use="optional"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
|
||||
|
||||
|
||||
<xsd:element name="console-source">
|
||||
<xsd:complexType>
|
||||
@@ -270,20 +267,22 @@
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="console-target">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Configures a target that writes to stdout (System.out) or to stderr (System.err)
|
||||
if the "error" attribute is set to true.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="charset" type="xsd:string"/>
|
||||
<xsd:attribute name="error" type="xsd:boolean" default="false"/>
|
||||
<xsd:attribute name="append-newline" type="xsd:boolean" default="false"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="stdout-channel-adapter" type="consoleOutboundChannelAdapterType"/>
|
||||
|
||||
<xsd:element name="stderr-channel-adapter" type="consoleOutboundChannelAdapterType"/>
|
||||
|
||||
<xsd:complexType name="consoleOutboundChannelAdapterType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Configures an outbound Channel Adapter that writes to stdout (System.out)
|
||||
or to stderr (System.err) depending on the element name.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="channel" type="xsd:string"/>
|
||||
<xsd:attribute name="charset" type="xsd:string"/>
|
||||
<xsd:attribute name="append-newline" type="xsd:boolean" default="false"/>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="gatewayType">
|
||||
<xsd:annotation>
|
||||
|
||||
@@ -26,9 +26,9 @@ import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.integration.adapter.mail.monitor.AsyncMonitoringStrategy;
|
||||
import org.springframework.integration.dispatcher.BroadcastingDispatcher;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.message.MessageSource;
|
||||
import org.springframework.integration.message.MessageTarget;
|
||||
import org.springframework.integration.message.SubscribableSource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -38,11 +38,11 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Jonas Partner
|
||||
*/
|
||||
public class SubscribableMailSource implements SubscribableSource, Lifecycle, DisposableBean {
|
||||
public class SubscribableMailSource implements MessageSource, Lifecycle, DisposableBean {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private final BroadcastingDispatcher dispatcher = new BroadcastingDispatcher();
|
||||
private volatile MessageChannel outputChannel;
|
||||
|
||||
private final TaskExecutor taskExecutor;
|
||||
|
||||
@@ -61,16 +61,8 @@ public class SubscribableMailSource implements SubscribableSource, Lifecycle, Di
|
||||
}
|
||||
|
||||
|
||||
public void setApplySequence(boolean applySequence) {
|
||||
this.dispatcher.setApplySequence(applySequence);
|
||||
}
|
||||
|
||||
public boolean subscribe(MessageTarget target) {
|
||||
return this.dispatcher.subscribe(target);
|
||||
}
|
||||
|
||||
public boolean unsubscribe(MessageTarget target) {
|
||||
return this.dispatcher.unsubscribe(target);
|
||||
public void setOutputChannel(MessageChannel outputChannel) {
|
||||
this.outputChannel = outputChannel;
|
||||
}
|
||||
|
||||
public void setConverter(MailMessageConverter converter) {
|
||||
@@ -146,7 +138,7 @@ public class SubscribableMailSource implements SubscribableSource, Lifecycle, Di
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
Message[] messages = this.folderConnection.receive();
|
||||
for (Message message : messages) {
|
||||
dispatcher.send(converter.create((MimeMessage) message));
|
||||
outputChannel.send(converter.create((MimeMessage) message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,16 +23,16 @@ import java.io.OutputStream;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.message.MessageTarget;
|
||||
|
||||
/**
|
||||
* A target that writes a byte array to an {@link OutputStream}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ByteStreamTarget implements MessageTarget {
|
||||
public class ByteStreamTarget extends AbstractEndpoint {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
@@ -53,7 +53,8 @@ public class ByteStreamTarget implements MessageTarget {
|
||||
}
|
||||
|
||||
|
||||
public boolean send(Message message) {
|
||||
@Override
|
||||
public boolean sendInternal(Message message) {
|
||||
Object payload = message.getPayload();
|
||||
if (payload == null) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
|
||||
@@ -27,9 +27,9 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.message.MessageTarget;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -41,7 +41,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class CharacterStreamTarget implements MessageTarget {
|
||||
public class CharacterStreamTarget extends AbstractEndpoint {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
@@ -117,7 +117,8 @@ public class CharacterStreamTarget implements MessageTarget {
|
||||
this.shouldAppendNewLine = shouldAppendNewLine;
|
||||
}
|
||||
|
||||
public boolean send(Message message) {
|
||||
@Override
|
||||
public boolean sendInternal(Message message) {
|
||||
Object payload = message.getPayload();
|
||||
if (payload == null) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
|
||||
@@ -18,13 +18,20 @@ package org.springframework.integration.adapter.stream.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.adapter.stream.CharacterStreamTarget;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the <console-target> element.
|
||||
* Parser for the "stdout-" and "stderr-channel-adapter" elements.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@@ -36,18 +43,21 @@ public class ConsoleTargetParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateId() {
|
||||
return false;
|
||||
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) throws BeanDefinitionStoreException {
|
||||
String id = element.getAttribute("id");
|
||||
if (!element.hasAttribute("channel")) {
|
||||
// the created channel will get the 'id', so the adapter's bean name includes a suffix
|
||||
id = id + ".adapter";
|
||||
}
|
||||
else if (!StringUtils.hasText(id)) {
|
||||
id = parserContext.getReaderContext().generateBeanName(definition);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, BeanDefinitionBuilder builder) {
|
||||
if ("true".equals(element.getAttribute("error"))) {
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
if (element.getLocalName().startsWith("stderr")) {
|
||||
builder.setFactoryMethod("stderr");
|
||||
}
|
||||
else {
|
||||
@@ -60,6 +70,25 @@ public class ConsoleTargetParser extends AbstractSingleBeanDefinitionParser {
|
||||
if ("true".equals(element.getAttribute("append-newline"))) {
|
||||
builder.addPropertyValue("shouldAppendNewLine", Boolean.TRUE);
|
||||
}
|
||||
String channelName = element.getAttribute("channel");
|
||||
if (StringUtils.hasText(channelName)) {
|
||||
builder.addPropertyReference("source", channelName);
|
||||
}
|
||||
else {
|
||||
builder.addPropertyReference("source", this.createDirectChannel(element, parserContext));
|
||||
}
|
||||
}
|
||||
|
||||
private String createDirectChannel(Element element, ParserContext parserContext) {
|
||||
String channelId = element.getAttribute("id");
|
||||
if (!StringUtils.hasText(channelId)) {
|
||||
throw new ConfigurationException("The channel-adapter's 'id' attribute is required when no 'channel' "
|
||||
+ "reference has been provided, because that 'id' would be used for the created channel.");
|
||||
}
|
||||
BeanDefinitionBuilder channelBuilder = BeanDefinitionBuilder.genericBeanDefinition(DirectChannel.class);
|
||||
BeanDefinitionHolder holder = new BeanDefinitionHolder(channelBuilder.getBeanDefinition(), channelId);
|
||||
BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry());
|
||||
return channelId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
console-source=org.springframework.integration.adapter.stream.config.ConsoleSourceParser
|
||||
console-target=org.springframework.integration.adapter.stream.config.ConsoleTargetParser
|
||||
file-source=org.springframework.integration.adapter.file.config.FileSourceParser
|
||||
file-target=org.springframework.integration.adapter.file.config.FileTargetParser
|
||||
ftp-source=org.springframework.integration.adapter.ftp.config.FtpSourceParser
|
||||
@@ -12,4 +11,6 @@ mail-target=org.springframework.integration.adapter.mail.config.MailTargetParser
|
||||
polling-mail-source=org.springframework.integration.adapter.mail.config.PollingMailSourceParser
|
||||
imap-idle-mail-source=org.springframework.integration.adapter.mail.config.SubscribableImapIdleMailSourceParser
|
||||
rmi-gateway=org.springframework.integration.adapter.rmi.config.RmiGatewayParser
|
||||
rmi-handler=org.springframework.integration.adapter.rmi.config.RmiHandlerParser
|
||||
rmi-handler=org.springframework.integration.adapter.rmi.config.RmiHandlerParser
|
||||
stderr-channel-adapter=org.springframework.integration.adapter.stream.config.ConsoleTargetParser
|
||||
stdout-channel-adapter=org.springframework.integration.adapter.stream.config.ConsoleTargetParser
|
||||
@@ -1,9 +1,24 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.adapter.mail;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import javax.mail.internet.MimeMessage;
|
||||
@@ -12,15 +27,13 @@ import org.easymock.classextension.EasyMock;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageTarget;
|
||||
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jonas Partner
|
||||
*
|
||||
*/
|
||||
public class SubscribableMailSourceTests {
|
||||
|
||||
@@ -34,24 +47,19 @@ public class SubscribableMailSourceTests {
|
||||
@Test
|
||||
public void testReceive() throws Exception {
|
||||
javax.mail.Message message = EasyMock.createMock(MimeMessage.class);
|
||||
StubFolderConnection folderConnection = new StubFolderConnection(
|
||||
message);
|
||||
StubTarget target = new StubTarget();
|
||||
|
||||
SubscribableMailSource mailSource = new SubscribableMailSource(
|
||||
folderConnection, executor);
|
||||
mailSource.subscribe(target);
|
||||
StubFolderConnection folderConnection = new StubFolderConnection(message);
|
||||
QueueChannel channel = new QueueChannel();
|
||||
SubscribableMailSource mailSource = new SubscribableMailSource(folderConnection, executor);
|
||||
mailSource.setOutputChannel(channel);
|
||||
mailSource.setConverter(new StubMessageConvertor());
|
||||
|
||||
mailSource.start();
|
||||
Thread.sleep(1000);
|
||||
Message<?> result = channel.receive(1000);
|
||||
mailSource.stop();
|
||||
|
||||
assertEquals("Wrong message count", 1, target.messages.size());
|
||||
assertEquals("Wrong payload", message, target.messages.get(0)
|
||||
.getPayload());
|
||||
assertNotNull(result);
|
||||
assertEquals("Wrong payload", message, result.getPayload());
|
||||
}
|
||||
|
||||
|
||||
private static class StubFolderConnection implements FolderConnection {
|
||||
|
||||
ConcurrentLinkedQueue<javax.mail.Message> messages = new ConcurrentLinkedQueue<javax.mail.Message>();
|
||||
@@ -73,25 +81,12 @@ public class SubscribableMailSourceTests {
|
||||
}
|
||||
|
||||
public void start() {
|
||||
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class StubTarget implements MessageTarget {
|
||||
|
||||
List<Message<?>> messages = new ArrayList<Message<?>>();
|
||||
|
||||
public boolean send(Message<?> message) {
|
||||
messages.add(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class StubMessageConvertor implements MailMessageConverter {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user