Refactored stream targets to outboundChannelAdapters.
This commit is contained in:
@@ -28,22 +28,22 @@ import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
|
||||
/**
|
||||
* A target that writes a byte array to an {@link OutputStream}.
|
||||
* An outbound Channel Adapter that writes a byte array to an {@link OutputStream}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ByteStreamTarget extends AbstractMessageConsumingEndpoint {
|
||||
public class ByteStreamOutboundChannelAdapter extends AbstractMessageConsumingEndpoint {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private final BufferedOutputStream stream;
|
||||
|
||||
|
||||
public ByteStreamTarget(OutputStream stream) {
|
||||
public ByteStreamOutboundChannelAdapter(OutputStream stream) {
|
||||
this(stream, -1);
|
||||
}
|
||||
|
||||
public ByteStreamTarget(OutputStream stream, int bufferSize) {
|
||||
public ByteStreamOutboundChannelAdapter(OutputStream stream, int bufferSize) {
|
||||
if (bufferSize > 0) {
|
||||
this.stream = new BufferedOutputStream(stream, bufferSize);
|
||||
}
|
||||
@@ -33,15 +33,15 @@ import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A target that writes to a {@link Writer}. String-based objects will be
|
||||
* written directly, but if the object is not itself a {@link String}, the
|
||||
* target will write the result of the object's {@link #toString()} method.
|
||||
* To append a new-line after each write, set the {@link #shouldAppendNewLine}
|
||||
* flag to <em>true</em>. It is <em>false</em> by default.
|
||||
* An outbound Channel Adapter that writes to a {@link Writer}. String-based objects
|
||||
* will be written directly, but if the object is not itself a {@link String}, the
|
||||
* target will write the result of the object's {@link #toString()} method. To
|
||||
* append a new-line after each write, set the {@link #shouldAppendNewLine} flag to
|
||||
* <em>true</em>. It is <em>false</em> by default.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class CharacterStreamTarget extends AbstractMessageConsumingEndpoint {
|
||||
public class CharacterStreamOutboundChannelAdapter extends AbstractMessageConsumingEndpoint {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
@@ -50,11 +50,11 @@ public class CharacterStreamTarget extends AbstractMessageConsumingEndpoint {
|
||||
private volatile boolean shouldAppendNewLine = false;
|
||||
|
||||
|
||||
public CharacterStreamTarget(Writer writer) {
|
||||
public CharacterStreamOutboundChannelAdapter(Writer writer) {
|
||||
this(writer, -1);
|
||||
}
|
||||
|
||||
public CharacterStreamTarget(Writer writer, int bufferSize) {
|
||||
public CharacterStreamOutboundChannelAdapter(Writer writer, int bufferSize) {
|
||||
Assert.notNull(writer, "writer must not be null");
|
||||
if (writer instanceof BufferedWriter) {
|
||||
this.writer = (BufferedWriter) writer;
|
||||
@@ -72,7 +72,7 @@ public class CharacterStreamTarget extends AbstractMessageConsumingEndpoint {
|
||||
* Factory method that creates a target for stdout (System.out) with the
|
||||
* default charset encoding.
|
||||
*/
|
||||
public static CharacterStreamTarget stdout() {
|
||||
public static CharacterStreamOutboundChannelAdapter stdout() {
|
||||
return stdout(null);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class CharacterStreamTarget extends AbstractMessageConsumingEndpoint {
|
||||
* Factory method that creates a target for stdout (System.out) with the
|
||||
* specified charset encoding.
|
||||
*/
|
||||
public static CharacterStreamTarget stdout(String charsetName) {
|
||||
public static CharacterStreamOutboundChannelAdapter stdout(String charsetName) {
|
||||
return createTargetForStream(System.out, charsetName);
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public class CharacterStreamTarget extends AbstractMessageConsumingEndpoint {
|
||||
* Factory method that creates a target for stderr (System.err) with the
|
||||
* default charset encoding.
|
||||
*/
|
||||
public static CharacterStreamTarget stderr() {
|
||||
public static CharacterStreamOutboundChannelAdapter stderr() {
|
||||
return stderr(null);
|
||||
}
|
||||
|
||||
@@ -96,16 +96,16 @@ public class CharacterStreamTarget extends AbstractMessageConsumingEndpoint {
|
||||
* Factory method that creates a target for stderr (System.err) with the
|
||||
* specified charset encoding.
|
||||
*/
|
||||
public static CharacterStreamTarget stderr(String charsetName) {
|
||||
public static CharacterStreamOutboundChannelAdapter stderr(String charsetName) {
|
||||
return createTargetForStream(System.err, charsetName);
|
||||
}
|
||||
|
||||
private static CharacterStreamTarget createTargetForStream(OutputStream stream, String charsetName) {
|
||||
private static CharacterStreamOutboundChannelAdapter createTargetForStream(OutputStream stream, String charsetName) {
|
||||
if (charsetName == null) {
|
||||
return new CharacterStreamTarget(new OutputStreamWriter(stream));
|
||||
return new CharacterStreamOutboundChannelAdapter(new OutputStreamWriter(stream));
|
||||
}
|
||||
try {
|
||||
return new CharacterStreamTarget(new OutputStreamWriter(stream, charsetName));
|
||||
return new CharacterStreamOutboundChannelAdapter(new OutputStreamWriter(stream, charsetName));
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
throw new ConfigurationException("unsupported encoding: " + charsetName, e);
|
||||
@@ -30,7 +30,7 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ConsoleSourceParser extends AbstractPollingInboundChannelAdapterParser {
|
||||
public class ConsoleInboundChannelAdapterParser extends AbstractPollingInboundChannelAdapterParser {
|
||||
|
||||
@Override
|
||||
protected String parseSource(Element element, ParserContext parserContext) {
|
||||
@@ -27,7 +27,7 @@ import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.stream.CharacterStreamTarget;
|
||||
import org.springframework.integration.stream.CharacterStreamOutboundChannelAdapter;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -35,11 +35,11 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ConsoleTargetParser extends AbstractSingleBeanDefinitionParser {
|
||||
public class ConsoleOutboundChannelAdapterParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return CharacterStreamTarget.class;
|
||||
return CharacterStreamOutboundChannelAdapter.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -24,9 +24,9 @@ import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
|
||||
public class StreamNamespaceHandler extends NamespaceHandlerSupport {
|
||||
|
||||
public void init() {
|
||||
this.registerBeanDefinitionParser("stdin-channel-adapter", new ConsoleSourceParser());
|
||||
this.registerBeanDefinitionParser("stdout-channel-adapter", new ConsoleTargetParser());
|
||||
this.registerBeanDefinitionParser("stderr-channel-adapter", new ConsoleTargetParser());
|
||||
this.registerBeanDefinitionParser("stdin-channel-adapter", new ConsoleInboundChannelAdapterParser());
|
||||
this.registerBeanDefinitionParser("stdout-channel-adapter", new ConsoleOutboundChannelAdapterParser());
|
||||
this.registerBeanDefinitionParser("stderr-channel-adapter", new ConsoleOutboundChannelAdapterParser());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.integration.scheduling.PollingSchedule;
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ByteStreamTargetTests {
|
||||
public class ByteStreamOutboundChannelAdapterTests {
|
||||
|
||||
private QueueChannel channel;
|
||||
|
||||
@@ -50,8 +50,8 @@ public class ByteStreamTargetTests {
|
||||
@Test
|
||||
public void testSingleByteArray() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ByteStreamTarget target = new ByteStreamTarget(stream);
|
||||
target.onMessage(new GenericMessage<byte[]>(new byte[] {1,2,3}));
|
||||
ByteStreamOutboundChannelAdapter adapter = new ByteStreamOutboundChannelAdapter(stream);
|
||||
adapter.onMessage(new GenericMessage<byte[]>(new byte[] {1,2,3}));
|
||||
byte[] result = stream.toByteArray();
|
||||
assertEquals(3, result.length);
|
||||
assertEquals(1, result[0]);
|
||||
@@ -62,7 +62,7 @@ public class ByteStreamTargetTests {
|
||||
@Test
|
||||
public void testSingleString() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ByteStreamTarget target = new ByteStreamTarget(stream);
|
||||
ByteStreamOutboundChannelAdapter target = new ByteStreamOutboundChannelAdapter(stream);
|
||||
target.onMessage(new StringMessage("foo"));
|
||||
byte[] result = stream.toByteArray();
|
||||
assertEquals(3, result.length);
|
||||
@@ -72,7 +72,7 @@ public class ByteStreamTargetTests {
|
||||
@Test
|
||||
public void testMaxMessagesPerTaskSameAsMessageCount() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ByteStreamTarget target = new ByteStreamTarget(stream);
|
||||
ByteStreamOutboundChannelAdapter target = new ByteStreamOutboundChannelAdapter(stream);
|
||||
poller.setMaxMessagesPerPoll(3);
|
||||
poller.subscribe(target);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {1,2,3}), 0);
|
||||
@@ -88,7 +88,7 @@ public class ByteStreamTargetTests {
|
||||
@Test
|
||||
public void testMaxMessagesPerTaskLessThanMessageCount() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ByteStreamTarget target = new ByteStreamTarget(stream);
|
||||
ByteStreamOutboundChannelAdapter target = new ByteStreamOutboundChannelAdapter(stream);
|
||||
poller.setMaxMessagesPerPoll(2);
|
||||
poller.subscribe(target);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {1,2,3}), 0);
|
||||
@@ -103,7 +103,7 @@ public class ByteStreamTargetTests {
|
||||
@Test
|
||||
public void testMaxMessagesPerTaskExceedsMessageCount() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ByteStreamTarget target = new ByteStreamTarget(stream);
|
||||
ByteStreamOutboundChannelAdapter target = new ByteStreamOutboundChannelAdapter(stream);
|
||||
poller.setMaxMessagesPerPoll(5);
|
||||
poller.setReceiveTimeout(0);
|
||||
poller.subscribe(target);
|
||||
@@ -119,7 +119,7 @@ public class ByteStreamTargetTests {
|
||||
@Test
|
||||
public void testMaxMessagesLessThanMessageCountWithMultipleDispatches() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ByteStreamTarget target = new ByteStreamTarget(stream);
|
||||
ByteStreamOutboundChannelAdapter target = new ByteStreamOutboundChannelAdapter(stream);
|
||||
poller.setMaxMessagesPerPoll(2);
|
||||
poller.setReceiveTimeout(0);
|
||||
poller.subscribe(target);
|
||||
@@ -140,7 +140,7 @@ public class ByteStreamTargetTests {
|
||||
@Test
|
||||
public void testMaxMessagesExceedsMessageCountWithMultipleDispatches() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ByteStreamTarget target = new ByteStreamTarget(stream);
|
||||
ByteStreamOutboundChannelAdapter target = new ByteStreamOutboundChannelAdapter(stream);
|
||||
poller.setMaxMessagesPerPoll(5);
|
||||
poller.setReceiveTimeout(0);
|
||||
poller.subscribe(target);
|
||||
@@ -160,7 +160,7 @@ public class ByteStreamTargetTests {
|
||||
@Test
|
||||
public void testStreamResetBetweenDispatches() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ByteStreamTarget target = new ByteStreamTarget(stream);
|
||||
ByteStreamOutboundChannelAdapter target = new ByteStreamOutboundChannelAdapter(stream);
|
||||
poller.setMaxMessagesPerPoll(2);
|
||||
poller.setReceiveTimeout(0);
|
||||
poller.subscribe(target);
|
||||
@@ -180,7 +180,7 @@ public class ByteStreamTargetTests {
|
||||
@Test
|
||||
public void testStreamWriteBetweenDispatches() throws IOException {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ByteStreamTarget target = new ByteStreamTarget(stream);
|
||||
ByteStreamOutboundChannelAdapter target = new ByteStreamOutboundChannelAdapter(stream);
|
||||
poller.setMaxMessagesPerPoll(2);
|
||||
poller.setReceiveTimeout(0);
|
||||
poller.subscribe(target);
|
||||
@@ -32,7 +32,7 @@ import org.springframework.integration.scheduling.PollingSchedule;
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class CharacterStreamTargetTests {
|
||||
public class CharacterStreamOutboundChannelAdapterTests {
|
||||
|
||||
private QueueChannel channel;
|
||||
|
||||
@@ -49,7 +49,7 @@ public class CharacterStreamTargetTests {
|
||||
@Test
|
||||
public void testSingleString() {
|
||||
StringWriter writer = new StringWriter();
|
||||
CharacterStreamTarget target = new CharacterStreamTarget(writer);
|
||||
CharacterStreamOutboundChannelAdapter target = new CharacterStreamOutboundChannelAdapter(writer);
|
||||
target.onMessage(new StringMessage("foo"));
|
||||
assertEquals("foo", writer.toString());
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class CharacterStreamTargetTests {
|
||||
@Test
|
||||
public void testTwoStringsAndNoNewLinesByDefault() {
|
||||
StringWriter writer = new StringWriter();
|
||||
CharacterStreamTarget target = new CharacterStreamTarget(writer);
|
||||
CharacterStreamOutboundChannelAdapter target = new CharacterStreamOutboundChannelAdapter(writer);
|
||||
poller.subscribe(target);
|
||||
poller.setMaxMessagesPerPoll(1);
|
||||
channel.send(new StringMessage("foo"), 0);
|
||||
@@ -71,7 +71,7 @@ public class CharacterStreamTargetTests {
|
||||
@Test
|
||||
public void testTwoStringsWithNewLines() {
|
||||
StringWriter writer = new StringWriter();
|
||||
CharacterStreamTarget target = new CharacterStreamTarget(writer);
|
||||
CharacterStreamOutboundChannelAdapter target = new CharacterStreamOutboundChannelAdapter(writer);
|
||||
target.setShouldAppendNewLine(true);
|
||||
poller.subscribe(target);
|
||||
poller.setMaxMessagesPerPoll(1);
|
||||
@@ -87,7 +87,7 @@ public class CharacterStreamTargetTests {
|
||||
@Test
|
||||
public void testMaxMessagesPerTaskSameAsMessageCount() {
|
||||
StringWriter writer = new StringWriter();
|
||||
CharacterStreamTarget target = new CharacterStreamTarget(writer);
|
||||
CharacterStreamOutboundChannelAdapter target = new CharacterStreamOutboundChannelAdapter(writer);
|
||||
poller.setMaxMessagesPerPoll(2);
|
||||
poller.subscribe(target);
|
||||
channel.send(new StringMessage("foo"), 0);
|
||||
@@ -99,7 +99,7 @@ public class CharacterStreamTargetTests {
|
||||
@Test
|
||||
public void testMaxMessagesPerTaskExceedsMessageCountWithAppendedNewLines() {
|
||||
StringWriter writer = new StringWriter();
|
||||
CharacterStreamTarget target = new CharacterStreamTarget(writer);
|
||||
CharacterStreamOutboundChannelAdapter target = new CharacterStreamOutboundChannelAdapter(writer);
|
||||
poller.setMaxMessagesPerPoll(10);
|
||||
poller.setReceiveTimeout(0);
|
||||
poller.subscribe(target);
|
||||
@@ -114,7 +114,7 @@ public class CharacterStreamTargetTests {
|
||||
@Test
|
||||
public void testSingleNonStringObject() {
|
||||
StringWriter writer = new StringWriter();
|
||||
CharacterStreamTarget target = new CharacterStreamTarget(writer);
|
||||
CharacterStreamOutboundChannelAdapter target = new CharacterStreamOutboundChannelAdapter(writer);
|
||||
poller.subscribe(target);
|
||||
poller.setMaxMessagesPerPoll(1);
|
||||
TestObject testObject = new TestObject("foo");
|
||||
@@ -126,7 +126,7 @@ public class CharacterStreamTargetTests {
|
||||
@Test
|
||||
public void testTwoNonStringObjectWithOutNewLines() {
|
||||
StringWriter writer = new StringWriter();
|
||||
CharacterStreamTarget target = new CharacterStreamTarget(writer);
|
||||
CharacterStreamOutboundChannelAdapter target = new CharacterStreamOutboundChannelAdapter(writer);
|
||||
poller.setReceiveTimeout(0);
|
||||
poller.setMaxMessagesPerPoll(2);
|
||||
poller.subscribe(target);
|
||||
@@ -141,7 +141,7 @@ public class CharacterStreamTargetTests {
|
||||
@Test
|
||||
public void testTwoNonStringObjectWithNewLines() {
|
||||
StringWriter writer = new StringWriter();
|
||||
CharacterStreamTarget target = new CharacterStreamTarget(writer);
|
||||
CharacterStreamOutboundChannelAdapter target = new CharacterStreamOutboundChannelAdapter(writer);
|
||||
target.setShouldAppendNewLine(true);
|
||||
poller.setReceiveTimeout(0);
|
||||
poller.setMaxMessagesPerPoll(2);
|
||||
@@ -40,7 +40,7 @@ import org.springframework.integration.message.PollableSource;
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ConsoleSourceParserTests {
|
||||
public class ConsoleInboundChannelAdapterParserTests {
|
||||
|
||||
@Before
|
||||
public void writeTestInput() {
|
||||
@@ -49,11 +49,11 @@ public class ConsoleSourceParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConsoleSourceWithDefaultCharset() {
|
||||
public void adapterWithDefaultCharset() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"consoleSourceParserTests.xml", ConsoleSourceParserTests.class);
|
||||
"consoleInboundChannelAdapterParserTests.xml", ConsoleInboundChannelAdapterParserTests.class);
|
||||
SourcePollingChannelAdapter adapter =
|
||||
(SourcePollingChannelAdapter) context.getBean("sourceWithDefaultCharset.adapter");
|
||||
(SourcePollingChannelAdapter) context.getBean("adapterWithDefaultCharset.adapter");
|
||||
PollableSource<?> source = (PollableSource<?>) new DirectFieldAccessor(adapter).getPropertyValue("source");
|
||||
DirectFieldAccessor sourceAccessor = new DirectFieldAccessor(source);
|
||||
Reader bufferedReader = (Reader) sourceAccessor.getPropertyValue("reader");
|
||||
@@ -69,11 +69,11 @@ public class ConsoleSourceParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConsoleSourceWithProvidedCharset() {
|
||||
public void adapterWithProvidedCharset() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"consoleSourceParserTests.xml", ConsoleSourceParserTests.class);
|
||||
"consoleInboundChannelAdapterParserTests.xml", ConsoleInboundChannelAdapterParserTests.class);
|
||||
SourcePollingChannelAdapter adapter =
|
||||
(SourcePollingChannelAdapter) context.getBean("sourceWithProvidedCharset.adapter");
|
||||
(SourcePollingChannelAdapter) context.getBean("adapterWithProvidedCharset.adapter");
|
||||
PollableSource<?> source = (PollableSource<?>) new DirectFieldAccessor(adapter).getPropertyValue("source");
|
||||
DirectFieldAccessor sourceAccessor = new DirectFieldAccessor(source);
|
||||
Reader bufferedReader = (Reader) sourceAccessor.getPropertyValue("reader");
|
||||
@@ -93,7 +93,7 @@ public class ConsoleSourceParserTests {
|
||||
BeanCreationException beanCreationException = null;
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(
|
||||
"invalidConsoleSourceParserTests.xml", ConsoleSourceParserTests.class);
|
||||
"invalidConsoleInboundChannelAdapterParserTests.xml", ConsoleInboundChannelAdapterParserTests.class);
|
||||
}
|
||||
catch (BeanCreationException e) {
|
||||
beanCreationException = e;
|
||||
@@ -34,12 +34,12 @@ import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.stream.CharacterStreamTarget;
|
||||
import org.springframework.integration.stream.CharacterStreamOutboundChannelAdapter;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ConsoleTargetParserTests {
|
||||
public class ConsoleOutboundChannelAdapterParserTests {
|
||||
|
||||
private final ByteArrayOutputStream err = new ByteArrayOutputStream();
|
||||
|
||||
@@ -58,13 +58,13 @@ public class ConsoleTargetParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConsoleTargetWithDefaultCharset() {
|
||||
public void stdoutAdapterWithDefaultCharset() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"consoleTargetParserTests.xml", ConsoleTargetParserTests.class);
|
||||
CharacterStreamTarget target =
|
||||
(CharacterStreamTarget) context.getBean("targetWithDefaultCharset");
|
||||
DirectFieldAccessor targetAccessor = new DirectFieldAccessor(target);
|
||||
Writer bufferedWriter = (Writer) targetAccessor.getPropertyValue("writer");
|
||||
"consoleOutboundChannelAdapterParserTests.xml", ConsoleOutboundChannelAdapterParserTests.class);
|
||||
CharacterStreamOutboundChannelAdapter adapter =
|
||||
(CharacterStreamOutboundChannelAdapter) context.getBean("stdoutAdapterWithDefaultCharset");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(adapter);
|
||||
Writer bufferedWriter = (Writer) accessor.getPropertyValue("writer");
|
||||
assertEquals(BufferedWriter.class, bufferedWriter.getClass());
|
||||
DirectFieldAccessor bufferedWriterAccessor = new DirectFieldAccessor(bufferedWriter);
|
||||
Writer writer = (Writer) bufferedWriterAccessor.getPropertyValue("out");
|
||||
@@ -72,19 +72,19 @@ public class ConsoleTargetParserTests {
|
||||
Charset writerCharset = Charset.forName(((OutputStreamWriter) writer).getEncoding());
|
||||
assertEquals(Charset.defaultCharset(), writerCharset);
|
||||
this.resetStreams();
|
||||
target.onMessage(new StringMessage("foo"));
|
||||
adapter.onMessage(new StringMessage("foo"));
|
||||
assertEquals("foo", out.toString());
|
||||
assertEquals("", err.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConsoleTargetWithProvidedCharset() {
|
||||
public void stdoutAdapterWithProvidedCharset() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"consoleTargetParserTests.xml", ConsoleTargetParserTests.class);
|
||||
CharacterStreamTarget target =
|
||||
(CharacterStreamTarget) context.getBean("targetWithProvidedCharset");
|
||||
DirectFieldAccessor targetAccessor = new DirectFieldAccessor(target);
|
||||
Writer bufferedWriter = (Writer) targetAccessor.getPropertyValue("writer");
|
||||
"consoleOutboundChannelAdapterParserTests.xml", ConsoleOutboundChannelAdapterParserTests.class);
|
||||
CharacterStreamOutboundChannelAdapter adapter =
|
||||
(CharacterStreamOutboundChannelAdapter) context.getBean("stdoutAdapterWithProvidedCharset");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(adapter);
|
||||
Writer bufferedWriter = (Writer) accessor.getPropertyValue("writer");
|
||||
assertEquals(BufferedWriter.class, bufferedWriter.getClass());
|
||||
DirectFieldAccessor bufferedWriterAccessor = new DirectFieldAccessor(bufferedWriter);
|
||||
Writer writer = (Writer) bufferedWriterAccessor.getPropertyValue("out");
|
||||
@@ -92,17 +92,17 @@ public class ConsoleTargetParserTests {
|
||||
Charset writerCharset = Charset.forName(((OutputStreamWriter) writer).getEncoding());
|
||||
assertEquals(Charset.forName("UTF-8"), writerCharset);
|
||||
this.resetStreams();
|
||||
target.onMessage(new StringMessage("bar"));
|
||||
adapter.onMessage(new StringMessage("bar"));
|
||||
assertEquals("bar", out.toString());
|
||||
assertEquals("", err.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConsoleTargetWithInvalidCharset() {
|
||||
public void stdoutAdapterWithInvalidCharset() {
|
||||
BeanCreationException beanCreationException = null;
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(
|
||||
"invalidConsoleTargetParserTests.xml", ConsoleTargetParserTests.class);
|
||||
"invalidConsoleOutboundChannelAdapterParserTests.xml", ConsoleOutboundChannelAdapterParserTests.class);
|
||||
}
|
||||
catch (BeanCreationException e) {
|
||||
beanCreationException = e;
|
||||
@@ -114,13 +114,13 @@ public class ConsoleTargetParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorTarget() {
|
||||
public void stderrAdapter() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"consoleTargetParserTests.xml", ConsoleTargetParserTests.class);
|
||||
CharacterStreamTarget target =
|
||||
(CharacterStreamTarget) context.getBean("stderrTarget");
|
||||
DirectFieldAccessor targetAccessor = new DirectFieldAccessor(target);
|
||||
Writer bufferedWriter = (Writer) targetAccessor.getPropertyValue("writer");
|
||||
"consoleOutboundChannelAdapterParserTests.xml", ConsoleOutboundChannelAdapterParserTests.class);
|
||||
CharacterStreamOutboundChannelAdapter adapter =
|
||||
(CharacterStreamOutboundChannelAdapter) context.getBean("stderrAdapter");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(adapter);
|
||||
Writer bufferedWriter = (Writer) accessor.getPropertyValue("writer");
|
||||
assertEquals(BufferedWriter.class, bufferedWriter.getClass());
|
||||
DirectFieldAccessor bufferedWriterAccessor = new DirectFieldAccessor(bufferedWriter);
|
||||
Writer writer = (Writer) bufferedWriterAccessor.getPropertyValue("out");
|
||||
@@ -128,19 +128,19 @@ public class ConsoleTargetParserTests {
|
||||
Charset writerCharset = Charset.forName(((OutputStreamWriter) writer).getEncoding());
|
||||
assertEquals(Charset.defaultCharset(), writerCharset);
|
||||
this.resetStreams();
|
||||
target.onMessage(new StringMessage("bad"));
|
||||
adapter.onMessage(new StringMessage("bad"));
|
||||
assertEquals("", out.toString());
|
||||
assertEquals("bad", err.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAppendNewLine() {
|
||||
public void stdoutAdatperWithAppendNewLine() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"consoleTargetParserTests.xml", ConsoleTargetParserTests.class);
|
||||
CharacterStreamTarget target =
|
||||
(CharacterStreamTarget) context.getBean("newlineTarget");
|
||||
DirectFieldAccessor targetAccessor = new DirectFieldAccessor(target);
|
||||
Writer bufferedWriter = (Writer) targetAccessor.getPropertyValue("writer");
|
||||
"consoleOutboundChannelAdapterParserTests.xml", ConsoleOutboundChannelAdapterParserTests.class);
|
||||
CharacterStreamOutboundChannelAdapter adapter =
|
||||
(CharacterStreamOutboundChannelAdapter) context.getBean("newlineAdapter");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(adapter);
|
||||
Writer bufferedWriter = (Writer) accessor.getPropertyValue("writer");
|
||||
assertEquals(BufferedWriter.class, bufferedWriter.getClass());
|
||||
DirectFieldAccessor bufferedWriterAccessor = new DirectFieldAccessor(bufferedWriter);
|
||||
Writer writer = (Writer) bufferedWriterAccessor.getPropertyValue("out");
|
||||
@@ -148,7 +148,7 @@ public class ConsoleTargetParserTests {
|
||||
Charset writerCharset = Charset.forName(((OutputStreamWriter) writer).getEncoding());
|
||||
assertEquals(Charset.defaultCharset(), writerCharset);
|
||||
this.resetStreams();
|
||||
target.onMessage(new StringMessage("foo"));
|
||||
adapter.onMessage(new StringMessage("foo"));
|
||||
assertEquals("foo\n", out.toString());
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
http://www.springframework.org/schema/integration/stream
|
||||
http://www.springframework.org/schema/integration/stream/spring-integration-stream-1.0.xsd">
|
||||
|
||||
<stdin-channel-adapter id="sourceWithDefaultCharset"/>
|
||||
<stdin-channel-adapter id="adapterWithDefaultCharset"/>
|
||||
|
||||
<stdin-channel-adapter id="sourceWithProvidedCharset" charset="UTF-8"/>
|
||||
<stdin-channel-adapter id="adapterWithProvidedCharset" charset="UTF-8"/>
|
||||
|
||||
</beans:beans>
|
||||
@@ -12,12 +12,12 @@
|
||||
|
||||
<integration:channel id="testChannel"/>
|
||||
|
||||
<stdout-channel-adapter id="targetWithDefaultCharset" channel="testChannel"/>
|
||||
<stdout-channel-adapter id="stdoutAdapterWithDefaultCharset" channel="testChannel"/>
|
||||
|
||||
<stdout-channel-adapter id="targetWithProvidedCharset" charset="UTF-8" channel="testChannel"/>
|
||||
<stdout-channel-adapter id="stdoutAdapterWithProvidedCharset" charset="UTF-8" channel="testChannel"/>
|
||||
|
||||
<stderr-channel-adapter id="stderrTarget" channel="testChannel"/>
|
||||
<stderr-channel-adapter id="stderrAdapter" channel="testChannel"/>
|
||||
|
||||
<stdout-channel-adapter id="newlineTarget" append-newline="true" channel="testChannel"/>
|
||||
<stdout-channel-adapter id="newlineAdapter" append-newline="true" channel="testChannel"/>
|
||||
|
||||
</beans:beans>
|
||||
@@ -10,6 +10,6 @@
|
||||
http://www.springframework.org/schema/integration/stream
|
||||
http://www.springframework.org/schema/integration/stream/spring-integration-stream-1.0.xsd">
|
||||
|
||||
<stdout-channel-adapter id="targetWithInvalidCharset" charset="invalid-charset-name"/>
|
||||
<stdin-channel-adapter id="adapterWithInvalidCharset" charset="invalid-charset-name"/>
|
||||
|
||||
</beans:beans>
|
||||
@@ -10,6 +10,6 @@
|
||||
http://www.springframework.org/schema/integration/stream
|
||||
http://www.springframework.org/schema/integration/stream/spring-integration-stream-1.0.xsd">
|
||||
|
||||
<stdin-channel-adapter id="sourceWithInvalidCharset" charset="invalid-charset-name"/>
|
||||
<stdout-channel-adapter id="adapterWithInvalidCharset" charset="invalid-charset-name"/>
|
||||
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user