From 9da59485cbc2433969f3e2fa6f3b13a8d531c511 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Thu, 21 Feb 2008 22:54:24 +0000 Subject: [PATCH] Migrating adapters to spring-integration-adapters (INT-83). --- .../event/ApplicationEventSourceAdapter.java | 63 ----- .../event/ApplicationEventTargetAdapter.java | 51 ---- .../adapter/event/MessagingEvent.java | 37 --- .../adapter/event/MessagingEventMapper.java | 38 --- .../adapter/file/AbstractFileMapper.java | 101 -------- .../adapter/file/ByteArrayFileMapper.java | 46 ---- .../file/DefaultFileNameGenerator.java | 36 --- .../adapter/file/FileNameGenerator.java | 33 --- .../integration/adapter/file/FileSource.java | 80 ------- .../adapter/file/FileSourceAdapter.java | 65 ------ .../adapter/file/FileTargetAdapter.java | 59 ----- .../adapter/file/TextFileMapper.java | 48 ---- .../file/config/FileSourceAdapterParser.java | 53 ----- .../file/config/FileTargetAdapterParser.java | 60 ----- .../jms/ChannelPublishingJmsListener.java | 96 -------- .../jms/DefaultJmsMessagePostProcessor.java | 48 ---- .../jms/JmsMessageDrivenSourceAdapter.java | 149 ------------ .../adapter/jms/JmsMessagePostProcessor.java | 34 --- .../adapter/jms/JmsPollableSource.java | 116 --------- .../adapter/jms/JmsPollingSourceAdapter.java | 44 ---- .../adapter/jms/JmsTargetAdapter.java | 139 ----------- .../jms/config/JmsSourceAdapterParser.java | 158 ------------- .../jms/config/JmsTargetAdapterParser.java | 109 --------- .../adapter/stream/ByteStreamSource.java | 103 -------- .../stream/ByteStreamSourceAdapter.java | 43 ---- .../stream/ByteStreamTargetAdapter.java | 77 ------ .../adapter/stream/CharacterStreamSource.java | 81 ------- .../stream/CharacterStreamSourceAdapter.java | 45 ---- .../stream/CharacterStreamTargetAdapter.java | 103 -------- .../config/IntegrationNamespaceHandler.java | 68 +++++- .../config/spring-integration-1.0.xsd | 63 +---- .../ApplicationEventSourceAdapterTests.java | 115 --------- .../ApplicationEventTargetAdapterTests.java | 61 ----- .../applicationEventSourceAdapterTests.xml | 15 -- .../file/DefaultFileNameGeneratorTests.java | 50 ---- .../config/FileTargetAdapterParserTests.java | 42 ---- .../config/fileTargetAdapterParserTests.xml | 16 -- .../DefaultJmsMessagePostProcessorTests.java | 102 -------- .../adapter/jms/StubConnection.java | 83 ------- .../integration/adapter/jms/StubConsumer.java | 65 ------ .../adapter/jms/StubDestination.java | 26 --- .../integration/adapter/jms/StubSession.java | 168 ------------- .../adapter/jms/StubTextMessage.java | 188 --------------- .../config/JmsSourceAdapterParserTests.java | 196 ---------------- .../config/JmsTargetAdapterParserTests.java | 52 ----- ...terWithConnectionFactoryAndDestination.xml | 29 --- ...ithConnectionFactoryAndDestinationName.xml | 27 --- ...DrivenAdapterWithConnectionFactoryOnly.xml | 24 -- ...ssageDrivenAdapterWithMessageConverter.xml | 32 --- ...terWithConnectionFactoryAndDestination.xml | 30 --- ...ithConnectionFactoryAndDestinationName.xml | 28 --- ...ollingAdapterWithConnectionFactoryOnly.xml | 24 -- .../pollingAdapterWithDestinationNameOnly.xml | 16 -- .../pollingAdapterWithDestinationOnly.xml | 18 -- .../config/pollingAdapterWithJmsTemplate.xml | 29 --- .../pollingAdapterWithoutPollPeriod.xml | 29 --- ...terWithConnectionFactoryAndDestination.xml | 29 --- ...ithConnectionFactoryAndDestinationName.xml | 27 --- .../stream/ByteStreamSourceAdapterTests.java | 173 -------------- .../stream/ByteStreamTargetAdapterTests.java | 220 ------------------ .../CharacterStreamSourceAdapterTests.java | 111 --------- .../CharacterStreamTargetAdapterTests.java | 191 --------------- 62 files changed, 61 insertions(+), 4401 deletions(-) delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/event/ApplicationEventSourceAdapter.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/event/ApplicationEventTargetAdapter.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/event/MessagingEvent.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/event/MessagingEventMapper.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/file/AbstractFileMapper.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/file/ByteArrayFileMapper.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/file/DefaultFileNameGenerator.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/file/FileNameGenerator.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/file/FileSource.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/file/FileSourceAdapter.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/file/FileTargetAdapter.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/file/TextFileMapper.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/file/config/FileSourceAdapterParser.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/file/config/FileTargetAdapterParser.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/ChannelPublishingJmsListener.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/DefaultJmsMessagePostProcessor.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/JmsMessageDrivenSourceAdapter.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/JmsMessagePostProcessor.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/JmsPollableSource.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/JmsPollingSourceAdapter.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/JmsTargetAdapter.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/config/JmsSourceAdapterParser.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/config/JmsTargetAdapterParser.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/ByteStreamSource.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/ByteStreamSourceAdapter.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/ByteStreamTargetAdapter.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/CharacterStreamSource.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/CharacterStreamSourceAdapter.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/CharacterStreamTargetAdapter.java delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/event/ApplicationEventSourceAdapterTests.java delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/event/ApplicationEventTargetAdapterTests.java delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/event/applicationEventSourceAdapterTests.xml delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/file/DefaultFileNameGeneratorTests.java delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/file/config/FileTargetAdapterParserTests.java delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/file/config/fileTargetAdapterParserTests.xml delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/DefaultJmsMessagePostProcessorTests.java delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/StubConnection.java delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/StubConsumer.java delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/StubDestination.java delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/StubSession.java delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/StubTextMessage.java delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/JmsSourceAdapterParserTests.java delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/JmsTargetAdapterParserTests.java delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/messageDrivenAdapterWithConnectionFactoryAndDestination.xml delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/messageDrivenAdapterWithConnectionFactoryAndDestinationName.xml delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/messageDrivenAdapterWithConnectionFactoryOnly.xml delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/messageDrivenAdapterWithMessageConverter.xml delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithConnectionFactoryAndDestination.xml delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithConnectionFactoryAndDestinationName.xml delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithConnectionFactoryOnly.xml delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithDestinationNameOnly.xml delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithDestinationOnly.xml delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithJmsTemplate.xml delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithoutPollPeriod.xml delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/targetAdapterWithConnectionFactoryAndDestination.xml delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/targetAdapterWithConnectionFactoryAndDestinationName.xml delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/stream/ByteStreamSourceAdapterTests.java delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/stream/ByteStreamTargetAdapterTests.java delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/stream/CharacterStreamSourceAdapterTests.java delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/stream/CharacterStreamTargetAdapterTests.java diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/event/ApplicationEventSourceAdapter.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/event/ApplicationEventSourceAdapter.java deleted file mode 100644 index 78167c383a..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/event/ApplicationEventSourceAdapter.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2002-2007 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.event; - -import java.util.ArrayList; -import java.util.List; - -import org.springframework.context.ApplicationEvent; -import org.springframework.context.ApplicationListener; -import org.springframework.integration.adapter.AbstractSourceAdapter; -import org.springframework.util.Assert; -import org.springframework.util.CollectionUtils; - -/** - * A source adapter for passing Spring - * {@link ApplicationEvent ApplicationEvents} within messages. - * - * @author Mark Fisher - */ -public class ApplicationEventSourceAdapter extends AbstractSourceAdapter implements - ApplicationListener { - - private List> eventTypes = new ArrayList>(); - - - /** - * Set the list of event types (classes that extend ApplicationEvent) that - * this adapter should send to the message channel. By default, all event - * types will be sent. - */ - public void setEventTypes(List> eventTypes) { - Assert.notEmpty(eventTypes, "at least one event type is required"); - this.eventTypes = eventTypes; - } - - public void onApplicationEvent(ApplicationEvent event) { - if (CollectionUtils.isEmpty(this.eventTypes)) { - this.sendToChannel(event); - return; - } - for (Class eventType : this.eventTypes) { - if (eventType.isAssignableFrom(event.getClass())) { - this.sendToChannel(event); - return; - } - } - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/event/ApplicationEventTargetAdapter.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/event/ApplicationEventTargetAdapter.java deleted file mode 100644 index ba0c846bb8..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/event/ApplicationEventTargetAdapter.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2002-2007 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.event; - -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.context.ApplicationEventPublisherAware; -import org.springframework.integration.adapter.AbstractTargetAdapter; - -/** - * 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. - * - * @author Mark Fisher - */ -public class ApplicationEventTargetAdapter extends AbstractTargetAdapter implements - ApplicationEventPublisherAware { - - 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); - return true; - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/event/MessagingEvent.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/event/MessagingEvent.java deleted file mode 100644 index f83d22ca51..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/event/MessagingEvent.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2002-2007 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.event; - -import org.springframework.context.ApplicationEvent; -import org.springframework.integration.message.Message; - -/** - * A subclass of {@link ApplicationEvent} that wraps a {@link Message}. - * - * @author Mark Fisher - */ -public class MessagingEvent extends ApplicationEvent { - - public MessagingEvent(Message message) { - super(message); - } - - public Message getMessage() { - return (Message) this.getSource(); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/event/MessagingEventMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/event/MessagingEventMapper.java deleted file mode 100644 index bb8ebf539c..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/event/MessagingEventMapper.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2002-2007 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.event; - -import org.springframework.integration.message.Message; -import org.springframework.integration.message.MessageMapper; - -/** - * A {@link MessageMapper} implementation for mapping to and from - * {@link MessagingEvent MessagingEvents}. - * - * @author Mark Fisher - */ -public class MessagingEventMapper implements MessageMapper> { - - public MessagingEvent fromMessage(Message message) { - return new MessagingEvent(message); - } - - public Message toMessage(MessagingEvent event) { - return event.getMessage(); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/AbstractFileMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/AbstractFileMapper.java deleted file mode 100644 index bad06e5111..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/AbstractFileMapper.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2002-2007 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.file; - -import java.io.File; -import java.io.FileReader; -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.MessageHandlingException; -import org.springframework.util.Assert; -import org.springframework.util.FileCopyUtils; - -/** - * Base class providing common behavior for file-based message mappers. - * - * @author Mark Fisher - */ -public abstract class AbstractFileMapper extends AbstractMessageMapper { - - protected Log logger = LogFactory.getLog(this.getClass()); - - private File parentDirectory; - - private File backupDirectory; - - private FileNameGenerator fileNameGenerator = new DefaultFileNameGenerator(); - - - public AbstractFileMapper(File parentDirectory) { - this.parentDirectory = parentDirectory; - } - - public void setBackupDirectory(File backupDirectory) { - this.backupDirectory = backupDirectory; - } - - public void setFileNameGenerator(FileNameGenerator fileNameGenerator) { - Assert.notNull(fileNameGenerator, "'fileNameGenerator' must not be null"); - this.fileNameGenerator = fileNameGenerator; - } - - public File fromMessage(Message message) { - try { - File file = new File(parentDirectory, this.fileNameGenerator.generateFileName(message)); - this.writeToFile(file, message.getPayload()); - return file; - } - catch (Exception e) { - throw new MessageHandlingException("failure occurred mapping file to message", e); - } - } - - public Message toMessage(File file) { - try { - T payload = this.readMessagePayload(file); - if (payload == null) { - return null; - } - Message message = new GenericMessage(this.getIdGenerator().generateId(), payload); - if (this.backupDirectory != null) { - FileWriter writer = new FileWriter(this.backupDirectory.getAbsolutePath() + - File.separator + file.getName()); - FileCopyUtils.copy(new FileReader(file), writer); - } - file.delete(); - return message; - } - catch (Exception e) { - String errorMessage = "failure occurred mapping file to message"; - if (logger.isWarnEnabled()) { - logger.warn(errorMessage, e); - } - throw new MessageHandlingException(errorMessage, e); - } - } - - protected abstract T readMessagePayload(File file) throws Exception; - - protected abstract void writeToFile(File file, T payload) throws Exception; - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/ByteArrayFileMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/ByteArrayFileMapper.java deleted file mode 100644 index a8aef0b75b..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/ByteArrayFileMapper.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2002-2007 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.file; - -import java.io.File; - -import org.springframework.util.FileCopyUtils; - -/** - * A {@link org.springframework.integration.message.MessageMapper} - * implementation for messages with a byte array payload. - * - * @author Mark Fisher - */ -public class ByteArrayFileMapper extends AbstractFileMapper { - - public ByteArrayFileMapper(File parentDirectory) { - super(parentDirectory); - } - - - @Override - protected byte[] readMessagePayload(File file) throws Exception { - return FileCopyUtils.copyToByteArray(file); - } - - @Override - protected void writeToFile(File file, byte[] payload) throws Exception { - FileCopyUtils.copy(payload, file); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/DefaultFileNameGenerator.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/DefaultFileNameGenerator.java deleted file mode 100644 index abeb70c3d6..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/DefaultFileNameGenerator.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2002-2007 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.file; - -import org.springframework.integration.message.Message; -import org.springframework.util.StringUtils; - -/** - * Default implementation of the filename generator strategy. Concatenates the - * message id and the current timestamp. - * - * @author Mark Fisher - */ -public class DefaultFileNameGenerator implements FileNameGenerator { - - public String generateFileName(Message message) { - String filenameProperty = message.getHeader().getProperty(FILENAME_PROPERTY_KEY); - return StringUtils.hasText(filenameProperty) ? - filenameProperty : message.getId() + "-" + System.currentTimeMillis() + ".msg"; - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/FileNameGenerator.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/FileNameGenerator.java deleted file mode 100644 index bff13aa640..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/FileNameGenerator.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2002-2007 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.file; - -import org.springframework.integration.message.Message; - -/** - * Strategy interface for generating a file name from a message. - * - * @author Mark Fisher - */ -public interface FileNameGenerator { - - String FILENAME_PROPERTY_KEY = "filename"; - - - String generateFileName(Message message); - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/FileSource.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/FileSource.java deleted file mode 100644 index 5cdc2ed54a..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/FileSource.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2002-2007 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.file; - -import java.io.File; -import java.io.FileFilter; -import java.io.FilenameFilter; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.springframework.integration.adapter.PollableSource; -import org.springframework.integration.message.MessageHandlingException; -import org.springframework.util.Assert; - -/** - * A messaging source that polls a directory to retrieve files. - * - * @author Mark Fisher - */ -public class FileSource implements PollableSource { - - private File directory; - - private FileFilter fileFilter; - - private FilenameFilter filenameFilter; - - - public FileSource(File directory) { - Assert.notNull("directory must not be null"); - this.directory = directory; - } - - public void setFileFilter(FileFilter fileFilter) { - this.fileFilter = fileFilter; - } - - public void setFilenameFilter(FilenameFilter filenameFilter) { - this.filenameFilter = filenameFilter; - } - - public Collection poll(int limit) { - File[] files = null; - if (this.fileFilter != null) { - files = this.directory.listFiles(fileFilter); - } - else if (this.filenameFilter != null) { - files = this.directory.listFiles(filenameFilter); - } - else { - files = this.directory.listFiles(); - } - if (files == null) { - throw new MessageHandlingException("Problem occurred while polling for files. " + - "Is '" + directory.getAbsolutePath() + "' a directory?"); - } - int size = Math.min(limit, files.length); - List results = new ArrayList(size); - for (int i = 0; i < size; i++) { - results.add(files[i]); - } - return results; - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/FileSourceAdapter.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/FileSourceAdapter.java deleted file mode 100644 index adf36b0827..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/FileSourceAdapter.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2002-2007 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.file; - -import java.io.File; - -import org.springframework.integration.adapter.PollingSourceAdapter; -import org.springframework.integration.channel.MessageChannel; -import org.springframework.integration.message.MessageMapper; -import org.springframework.util.Assert; - -/** - * Channel adapter for polling a directory and creating messages from its files. - * - * @author Mark Fisher - */ -public class FileSourceAdapter extends PollingSourceAdapter { - - public FileSourceAdapter(File directory, MessageChannel channel, int period) { - this(directory, channel, period, true); - } - - public FileSourceAdapter(File directory, MessageChannel channel, int period, boolean isTextBased) { - super(new FileSource(directory)); - this.setChannel(channel); - this.setPeriod(period); - if (isTextBased) { - this.setMessageMapper(new TextFileMapper(directory)); - } - else { - this.setMessageMapper(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); - } - } - - public void setBackupDirectory(File backupDirectory) { - Assert.notNull(backupDirectory, "'backupDirectory' must not be null"); - MessageMapper mapper = this.getMessageMapper(); - if (mapper != null && (mapper instanceof AbstractFileMapper)) { - ((AbstractFileMapper) mapper).setBackupDirectory(backupDirectory); - } - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/FileTargetAdapter.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/FileTargetAdapter.java deleted file mode 100644 index 7afead73b1..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/FileTargetAdapter.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2002-2007 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.file; - -import java.io.File; - -import org.springframework.integration.adapter.AbstractTargetAdapter; -import org.springframework.integration.message.MessageMapper; -import org.springframework.util.Assert; - -/** - * A convenience adapter for writing files. The actual file writing occurs in - * the message mapper ({@link TextFileMapper} or {@link ByteArrayFileMapper}). - * - * @author Mark Fisher - */ -public class FileTargetAdapter extends AbstractTargetAdapter { - - public FileTargetAdapter(File directory) { - this(directory, true); - } - - public FileTargetAdapter(File directory, boolean isTextBased) { - if (isTextBased) { - this.setMessageMapper(new TextFileMapper(directory)); - } - else { - this.setMessageMapper(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) { - return file.exists(); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/TextFileMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/TextFileMapper.java deleted file mode 100644 index d1661f21f5..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/TextFileMapper.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2002-2007 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.file; - -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; - -import org.springframework.util.FileCopyUtils; - -/** - * A {@link org.springframework.integration.message.MessageMapper} - * implementation for messages with a String payload. - * - * @author Mark Fisher - */ -public class TextFileMapper extends AbstractFileMapper { - - public TextFileMapper(File parentDirectory) { - super(parentDirectory); - } - - - @Override - protected String readMessagePayload(File file) throws Exception { - return FileCopyUtils.copyToString(new FileReader(file)); - } - - @Override - protected void writeToFile(File file, String payload) throws Exception { - FileCopyUtils.copy(payload, new FileWriter(file)); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/config/FileSourceAdapterParser.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/config/FileSourceAdapterParser.java deleted file mode 100644 index 262f679eed..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/config/FileSourceAdapterParser.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2002-2007 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.file.config; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; -import org.springframework.integration.adapter.file.FileSourceAdapter; - -/** - * Parser for the <file-source/> element. - * - * @author Mark Fisher - */ -public class FileSourceAdapterParser extends AbstractSingleBeanDefinitionParser { - - protected Class getBeanClass(Element element) { - return FileSourceAdapter.class; - } - - protected boolean shouldGenerateId() { - return false; - } - - protected boolean shouldGenerateIdAsFallback() { - return true; - } - - protected void doParse(Element element, BeanDefinitionBuilder builder) { - String directory = element.getAttribute("directory"); - String channel = element.getAttribute("channel"); - String pollPeriod = element.getAttribute("poll-period"); - builder.addConstructorArg(directory); - builder.addConstructorArgReference(channel); - builder.addConstructorArg(pollPeriod); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/config/FileTargetAdapterParser.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/config/FileTargetAdapterParser.java deleted file mode 100644 index 74f8cca7ab..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/file/config/FileTargetAdapterParser.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2002-2007 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.file.config; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.parsing.BeanComponentDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -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.scheduling.Subscription; - -/** - * Parser for the <file-target/> element. - * - * @author Mark Fisher - */ -public class FileTargetAdapterParser extends AbstractSingleBeanDefinitionParser { - - protected Class getBeanClass(Element element) { - return DefaultMessageEndpoint.class; - } - - protected boolean shouldGenerateId() { - return false; - } - - protected boolean shouldGenerateIdAsFallback() { - return true; - } - - protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { - RootBeanDefinition adapterDef = new RootBeanDefinition(FileTargetAdapter.class); - adapterDef.getConstructorArgumentValues().addGenericArgumentValue(element.getAttribute("directory")); - String adapterBeanName = parserContext.getReaderContext().generateBeanName(adapterDef); - parserContext.registerBeanComponent(new BeanComponentDefinition(adapterDef, adapterBeanName)); - builder.addPropertyReference("handler", adapterBeanName); - String channel = element.getAttribute("channel"); - Subscription subscription = new Subscription(channel); - builder.addPropertyValue("subscription", subscription); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/ChannelPublishingJmsListener.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/ChannelPublishingJmsListener.java deleted file mode 100644 index 70b84af3c0..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/ChannelPublishingJmsListener.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2002-2007 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.jms; - -import javax.jms.JMSException; -import javax.jms.MessageListener; - -import org.springframework.integration.MessagingConfigurationException; -import org.springframework.integration.channel.MessageChannel; -import org.springframework.integration.message.Message; -import org.springframework.integration.message.MessageDeliveryException; -import org.springframework.integration.message.MessageMapper; -import org.springframework.integration.message.SimplePayloadMessageMapper; -import org.springframework.jms.support.converter.MessageConverter; -import org.springframework.jms.support.converter.SimpleMessageConverter; -import org.springframework.util.Assert; - -/** - * JMS {@link MessageListener} implementation that converts the received JMS - * message into a Spring Integration message and then sends that to a channel. - * - * @author Mark Fisher - */ -public class ChannelPublishingJmsListener implements MessageListener { - - private MessageChannel channel; - - private long timeout = -1; - - private MessageConverter converter = new SimpleMessageConverter(); - - private MessageMapper mapper = new SimplePayloadMessageMapper(); - - - public ChannelPublishingJmsListener() { - } - - public ChannelPublishingJmsListener(MessageChannel channel) { - Assert.notNull(channel, "'channel' must not be null"); - this.channel = channel; - } - - - public void setChannel(MessageChannel channel) { - Assert.notNull(channel, "'channel' must not be null"); - this.channel = channel; - } - - public void setTimeout(long timeout) { - this.timeout = timeout; - } - - public void setMessageConverter(MessageConverter messageConverter) { - Assert.notNull(messageConverter, "'messageConverter' must not be null"); - this.converter = messageConverter; - } - - public void setMessageMapper(MessageMapper messageMapper) { - Assert.notNull(messageMapper, "'messageMapper' must not be null"); - this.mapper = messageMapper; - } - - public void onMessage(javax.jms.Message jmsMessage) { - if (this.channel == null) { - throw new MessagingConfigurationException("'channel' must not be null"); - } - try { - Object payload = converter.fromMessage(jmsMessage); - Message messageToSend = mapper.toMessage(payload); - if (this.timeout < 0) { - this.channel.send(messageToSend); - } - else { - this.channel.send(messageToSend, timeout); - } - } - catch (JMSException e) { - throw new MessageDeliveryException("failed to convert JMS Message", e); - } - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/DefaultJmsMessagePostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/DefaultJmsMessagePostProcessor.java deleted file mode 100644 index 19151ca83e..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/DefaultJmsMessagePostProcessor.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2002-2007 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.jms; - -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.Message; - -import org.springframework.integration.message.MessageHeader; - -/** - * A {@link JmsMessagePostProcessor} that passes attributes from a - * {@link MessageHeader} to a JMS message before it is sent to its destination. - * - * @author Mark Fisher - */ -public class DefaultJmsMessagePostProcessor implements JmsMessagePostProcessor { - - public void postProcessJmsMessage(Message jmsMessage, MessageHeader header) throws JMSException { - Object jmsCorrelationId = header.getAttribute(JmsTargetAdapter.JMS_CORRELATION_ID); - if (jmsCorrelationId != null && (jmsCorrelationId instanceof String)) { - jmsMessage.setJMSCorrelationID((String) jmsCorrelationId); - } - Object jmsReplyTo = header.getAttribute(JmsTargetAdapter.JMS_REPLY_TO); - if (jmsReplyTo != null && (jmsReplyTo instanceof Destination)) { - jmsMessage.setJMSReplyTo((Destination) jmsReplyTo); - } - Object jmsType = header.getAttribute(JmsTargetAdapter.JMS_TYPE); - if (jmsType != null && (jmsType instanceof String)) { - jmsMessage.setJMSType((String) jmsType); - } - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/JmsMessageDrivenSourceAdapter.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/JmsMessageDrivenSourceAdapter.java deleted file mode 100644 index 2eeeaf1337..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/JmsMessageDrivenSourceAdapter.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright 2002-2007 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.jms; - -import javax.jms.ConnectionFactory; -import javax.jms.Destination; - -import org.springframework.beans.factory.DisposableBean; -import org.springframework.context.Lifecycle; -import org.springframework.core.task.TaskExecutor; -import org.springframework.integration.MessagingConfigurationException; -import org.springframework.integration.adapter.AbstractSourceAdapter; -import org.springframework.jms.listener.AbstractJmsListeningContainer; -import org.springframework.jms.listener.DefaultMessageListenerContainer; -import org.springframework.jms.support.converter.MessageConverter; -import org.springframework.jms.support.converter.SimpleMessageConverter; -import org.springframework.util.Assert; - -/** - * A message-driven adapter for receiving JMS messages and sending to a channel. - * - * @author Mark Fisher - */ -public class JmsMessageDrivenSourceAdapter extends AbstractSourceAdapter implements Lifecycle, DisposableBean { - - private AbstractJmsListeningContainer container; - - private ConnectionFactory connectionFactory; - - private Destination destination; - - private String destinationName; - - private MessageConverter messageConverter = new SimpleMessageConverter(); - - private TaskExecutor taskExecutor; - - private long receiveTimeout = 1000; - - private int concurrentConsumers = 1; - - private int maxConcurrentConsumers = 1; - - private int maxMessagesPerTask = Integer.MIN_VALUE; - - private int idleTaskExecutionLimit = 1; - - private long sendTimeout = -1; - - - public void setContainer(AbstractJmsListeningContainer container) { - this.container = container; - } - - public void setConnectionFactory(ConnectionFactory connectionFactory) { - this.connectionFactory = connectionFactory; - } - - public void setDestination(Destination destination) { - this.destination = destination; - } - - public void setDestinationName(String destinationName) { - this.destinationName = destinationName; - } - - public void setMessageConverter(MessageConverter messageConverter) { - Assert.notNull(messageConverter, "'messageConverter' must not be null"); - this.messageConverter = messageConverter; - } - - public void setSendTimeout(long sendTimeout) { - this.sendTimeout = sendTimeout; - } - - public void setTaskExecutor(TaskExecutor taskExecutor) { - this.taskExecutor = taskExecutor; - } - - @Override - public void initialize() { - if (this.container == null) { - initDefaultContainer(); - } - } - - private void initDefaultContainer() { - if (this.connectionFactory == null || (this.destination == null && this.destinationName == null)) { - throw new MessagingConfigurationException("If a 'container' reference is not provided, then " - + "'connectionFactory' and 'destination' (or 'destinationName') are required."); - } - DefaultMessageListenerContainer dmlc = new DefaultMessageListenerContainer(); - dmlc.setConnectionFactory(this.connectionFactory); - if (this.destination != null) { - dmlc.setDestination(this.destination); - } - if (this.destinationName != null) { - dmlc.setDestinationName(this.destinationName); - } - dmlc.setReceiveTimeout(this.receiveTimeout); - dmlc.setConcurrentConsumers(this.concurrentConsumers); - dmlc.setMaxConcurrentConsumers(this.maxConcurrentConsumers); - dmlc.setMaxMessagesPerTask(this.maxMessagesPerTask); - dmlc.setIdleTaskExecutionLimit(this.idleTaskExecutionLimit); - dmlc.setSessionTransacted(true); - dmlc.setAutoStartup(false); - ChannelPublishingJmsListener listener = new ChannelPublishingJmsListener(this.getChannel()); - listener.setMessageConverter(this.messageConverter); - listener.setMessageMapper(this.getMessageMapper()); - listener.setTimeout(this.sendTimeout); - dmlc.setMessageListener(listener); - if (this.taskExecutor != null) { - dmlc.setTaskExecutor(this.taskExecutor); - } - dmlc.afterPropertiesSet(); - this.container = dmlc; - } - - public boolean isRunning() { - return container.isRunning(); - } - - public void start() { - container.start(); - } - - public void stop() { - container.stop(); - } - - public void destroy() { - container.destroy(); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/JmsMessagePostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/JmsMessagePostProcessor.java deleted file mode 100644 index 2b98a66757..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/JmsMessagePostProcessor.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2002-2007 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.jms; - -import javax.jms.JMSException; -import javax.jms.Message; - -import org.springframework.integration.message.MessageHeader; - -/** - * Strategy interface for post-processing a JMS Message before it is sent to its - * destination. - * - * @author Mark Fisher - */ -public interface JmsMessagePostProcessor { - - void postProcessJmsMessage(Message jmsMessage, MessageHeader header) throws JMSException; - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/JmsPollableSource.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/JmsPollableSource.java deleted file mode 100644 index c2cbf0a1bf..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/JmsPollableSource.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright 2002-2007 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.jms; - -import java.util.Arrays; -import java.util.Collection; - -import javax.jms.ConnectionFactory; -import javax.jms.Destination; - -import org.springframework.beans.factory.InitializingBean; -import org.springframework.integration.MessagingConfigurationException; -import org.springframework.integration.adapter.PollableSource; -import org.springframework.jms.core.JmsTemplate; - -/** - * A source for receiving JMS Messages with a polling listener. This source is - * only recommended for very low message volume. Otherwise, the - * {@link JmsMessageDrivenSourceAdapter} that uses Spring's MessageListener - * container support is highly recommended. - * - * @author Mark Fisher - */ -public class JmsPollableSource implements PollableSource, InitializingBean { - - private ConnectionFactory connectionFactory; - - private Destination destination; - - private String destinationName; - - private JmsTemplate jmsTemplate; - - - public JmsPollableSource(JmsTemplate jmsTemplate) { - this.jmsTemplate = jmsTemplate; - } - - public JmsPollableSource(ConnectionFactory connectionFactory, Destination destination) { - this.connectionFactory = connectionFactory; - this.destination = destination; - this.initJmsTemplate(); - } - - public JmsPollableSource(ConnectionFactory connectionFactory, String destinationName) { - this.connectionFactory = connectionFactory; - this.destinationName = destinationName; - this.initJmsTemplate(); - } - - /** - * No-arg constructor provided for convenience when configuring with - * setters. Note that the initialization callback will validate. - */ - public JmsPollableSource() { - } - - public void setConnectionFactory(ConnectionFactory connectionFactory) { - this.connectionFactory = connectionFactory; - } - - public void setDestination(Destination destination) { - this.destination = destination; - } - - public void setDestinationName(String destinationName) { - this.destinationName = destinationName; - } - - public void setJmsTemplate(JmsTemplate jmsTemplate) { - this.jmsTemplate = jmsTemplate; - } - - public void afterPropertiesSet() { - if (this.jmsTemplate == null) { - if (this.connectionFactory == null || (this.destination == null && this.destinationName == null)) { - throw new MessagingConfigurationException("Either a 'jmsTemplate' or " - + "both 'connectionFactory' and 'destination' (or 'destinationName') are required."); - } - this.initJmsTemplate(); - } - } - - private void initJmsTemplate() { - this.jmsTemplate = new JmsTemplate(); - this.jmsTemplate.setConnectionFactory(this.connectionFactory); - if (this.destination != null) { - this.jmsTemplate.setDefaultDestination(this.destination); - } - else if (this.destinationName != null) { - this.jmsTemplate.setDefaultDestinationName(this.destinationName); - } - else { - throw new MessagingConfigurationException("either 'destination' or 'destinationName' is required"); - } - } - - public Collection poll(int limit) { - return Arrays.asList(this.jmsTemplate.receiveAndConvert()); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/JmsPollingSourceAdapter.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/JmsPollingSourceAdapter.java deleted file mode 100644 index 32e18ea39b..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/JmsPollingSourceAdapter.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2002-2007 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.jms; - -import javax.jms.ConnectionFactory; -import javax.jms.Destination; - -import org.springframework.integration.adapter.PollingSourceAdapter; -import org.springframework.jms.core.JmsTemplate; - -/** - * A convenience adapter that wraps a {@link JmsPollableSource}. - * - * @author Mark Fisher - */ -public class JmsPollingSourceAdapter extends PollingSourceAdapter { - - public JmsPollingSourceAdapter(JmsTemplate jmsTemplate) { - super(new JmsPollableSource(jmsTemplate)); - } - - public JmsPollingSourceAdapter(ConnectionFactory connectionFactory, Destination destination) { - super(new JmsPollableSource(connectionFactory, destination)); - } - - public JmsPollingSourceAdapter(ConnectionFactory connectionFactory, String destinationName) { - super(new JmsPollableSource(connectionFactory, destinationName)); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/JmsTargetAdapter.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/JmsTargetAdapter.java deleted file mode 100644 index 28badc5174..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/JmsTargetAdapter.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright 2002-2007 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.jms; - -import javax.jms.ConnectionFactory; -import javax.jms.Destination; -import javax.jms.JMSException; - -import org.springframework.beans.factory.InitializingBean; -import org.springframework.integration.MessagingConfigurationException; -import org.springframework.integration.handler.MessageHandler; -import org.springframework.integration.message.Message; -import org.springframework.jms.core.JmsTemplate; -import org.springframework.jms.core.MessagePostProcessor; -import org.springframework.jms.support.converter.SimpleMessageConverter; - -/** - * A target adapter for sending JMS Messages. - * - * @author Mark Fisher - */ -public class JmsTargetAdapter implements MessageHandler, InitializingBean { - - public static final String JMS_CORRELATION_ID = "JMSCorrelationID"; - - public static final String JMS_REPLY_TO = "JMSReplyTo"; - - public static final String JMS_TYPE = "JMSType"; - - - private ConnectionFactory connectionFactory; - - private Destination destination; - - private String destinationName; - - private JmsTemplate jmsTemplate; - - private JmsMessagePostProcessor jmsMessagePostProcessor = new DefaultJmsMessagePostProcessor(); - - - public JmsTargetAdapter(JmsTemplate jmsTemplate) { - this.jmsTemplate = jmsTemplate; - } - - public JmsTargetAdapter(ConnectionFactory connectionFactory, Destination destination) { - this.connectionFactory = connectionFactory; - this.destination = destination; - this.initJmsTemplate(); - } - - public JmsTargetAdapter(ConnectionFactory connectionFactory, String destinationName) { - this.connectionFactory = connectionFactory; - this.destinationName = destinationName; - this.initJmsTemplate(); - } - - /** - * No-arg constructor provided for convenience when configuring with - * setters. Note that the initialization callback will validate. - */ - public JmsTargetAdapter() { - } - - - public void setConnectionFactory(ConnectionFactory connectionFactory) { - this.connectionFactory = connectionFactory; - } - - public void setDestination(Destination destination) { - this.destination = destination; - } - - public void setDestinationName(String destinationName) { - this.destinationName = destinationName; - } - - public void setJmsTemplate(JmsTemplate jmsTemplate) { - this.jmsTemplate = jmsTemplate; - } - - public void setJmsMessagePostProcessor(JmsMessagePostProcessor jmsMessagePostProcessor) { - this.jmsMessagePostProcessor = jmsMessagePostProcessor; - } - - public void afterPropertiesSet() { - if (this.jmsTemplate == null) { - if (this.connectionFactory == null || (this.destination == null && this.destinationName == null)) { - throw new MessagingConfigurationException("Either a 'jmsTemplate' or " + - "*both* 'connectionFactory' and 'destination' (or 'destination-name') are required."); - } - this.initJmsTemplate(); - } - if (this.jmsTemplate.getMessageConverter() == null) { - this.jmsTemplate.setMessageConverter(new SimpleMessageConverter()); - } - } - - private void initJmsTemplate() { - this.jmsTemplate = new JmsTemplate(); - this.jmsTemplate.setConnectionFactory(this.connectionFactory); - if (this.destination != null) { - this.jmsTemplate.setDefaultDestination(this.destination); - } - else { - this.jmsTemplate.setDefaultDestinationName(this.destinationName); - } - } - - public final Message handle(final Message message) { - if (message == null) { - return null; - } - this.jmsTemplate.convertAndSend(message.getPayload(), new MessagePostProcessor() { - public javax.jms.Message postProcessMessage(javax.jms.Message jmsMessage) throws JMSException { - if (jmsMessagePostProcessor != null) { - jmsMessagePostProcessor.postProcessJmsMessage(jmsMessage, message.getHeader()); - } - return jmsMessage; - } - }); - return null; - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/config/JmsSourceAdapterParser.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/config/JmsSourceAdapterParser.java deleted file mode 100644 index 0510175c15..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/config/JmsSourceAdapterParser.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright 2002-2007 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.jms.config; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.BeanCreationException; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; -import org.springframework.integration.adapter.jms.JmsMessageDrivenSourceAdapter; -import org.springframework.integration.adapter.jms.JmsPollingSourceAdapter; -import org.springframework.util.StringUtils; - -/** - * Parser for the <jms-source/> element. - * - * @author Mark Fisher - */ -public class JmsSourceAdapterParser extends AbstractSingleBeanDefinitionParser { - - private static final String JMS_TEMPLATE_ATTRIBUTE = "jms-template"; - - private static final String CONNECTION_FACTORY_ATTRIBUTE = "connection-factory"; - - private static final String CONNECTION_FACTORY_PROPERTY = "connectionFactory"; - - private static final String DESTINATION_ATTRIBUTE = "destination"; - - private static final String DESTINATION_PROPERTY = "destination"; - - private static final String DESTINATION_NAME_ATTRIBUTE = "destination-name"; - - private static final String DESTINATION_NAME_PROPERTY = "destinationName"; - - private static final String CHANNEL_ATTRIBUTE = "channel"; - - private static final String CHANNEL_PROPERTY = "channel"; - - private static final String POLL_PERIOD_ATTRIBUTE = "poll-period"; - - private static final String POLL_PERIOD_PROPERTY = "period"; - - private static final String MESSAGE_CONVERTER_ATTRIBUTE = "message-converter"; - - private static final String MESSAGE_CONVERTER_PROPERTY = "messageConverter"; - - - protected Class getBeanClass(Element element) { - if (StringUtils.hasText(element.getAttribute(POLL_PERIOD_ATTRIBUTE))) { - return JmsPollingSourceAdapter.class; - } - return JmsMessageDrivenSourceAdapter.class; - } - - protected boolean shouldGenerateId() { - return false; - } - - protected boolean shouldGenerateIdAsFallback() { - return true; - } - - protected void doParse(Element element, BeanDefinitionBuilder builder) { - if (builder.getBeanDefinition().getBeanClass().equals(JmsPollingSourceAdapter.class)) { - parsePollingSourceAdapter(element, builder); - } - else { - parseMessageDrivenSourceAdapter(element, builder); - } - String channel = element.getAttribute(CHANNEL_ATTRIBUTE); - builder.addPropertyReference(CHANNEL_PROPERTY, channel); - } - - private void parsePollingSourceAdapter(Element element, BeanDefinitionBuilder builder) { - String pollPeriod = element.getAttribute(POLL_PERIOD_ATTRIBUTE); - if (!StringUtils.hasText(pollPeriod)) { - throw new BeanCreationException("'" + POLL_PERIOD_ATTRIBUTE + - "' is required for a " + JmsPollingSourceAdapter.class.getSimpleName()); - } - if (StringUtils.hasText(element.getAttribute(MESSAGE_CONVERTER_ATTRIBUTE))) { - throw new BeanCreationException("The '" + MESSAGE_CONVERTER_ATTRIBUTE + "' attribute is not supported for a " + - JmsPollingSourceAdapter.class.getSimpleName() + ". Consider providing a '" + JMS_TEMPLATE_ATTRIBUTE + - "' reference where the template contains a 'messageConverter' property instead."); - } - builder.addPropertyValue(POLL_PERIOD_PROPERTY, pollPeriod); - String jmsTemplate = element.getAttribute(JMS_TEMPLATE_ATTRIBUTE); - String connectionFactory = element.getAttribute(CONNECTION_FACTORY_ATTRIBUTE); - String destination = element.getAttribute(DESTINATION_ATTRIBUTE); - String destinationName = element.getAttribute(DESTINATION_NAME_ATTRIBUTE); - if (StringUtils.hasText(jmsTemplate)) { - if (StringUtils.hasText(connectionFactory) || StringUtils.hasText(destination) || StringUtils.hasText(destinationName)) { - throw new BeanCreationException("when providing '" + JMS_TEMPLATE_ATTRIBUTE + - "', none of '" + CONNECTION_FACTORY_ATTRIBUTE + "', '" + DESTINATION_ATTRIBUTE + - "', or '" + DESTINATION_NAME_ATTRIBUTE + "' should be provided."); - } - builder.addConstructorArgReference(jmsTemplate); - } - else if (StringUtils.hasText(connectionFactory) && (StringUtils.hasText(destination) || StringUtils.hasText(destinationName))) { - builder.addConstructorArgReference(connectionFactory); - if (StringUtils.hasText(destination)) { - builder.addConstructorArgReference(destination); - } - else if (StringUtils.hasText(destinationName)) { - builder.addConstructorArg(destinationName); - } - } - else { - throw new BeanCreationException("either a '" + JMS_TEMPLATE_ATTRIBUTE + "' or both '" + - CONNECTION_FACTORY_ATTRIBUTE + "' and '" + DESTINATION_ATTRIBUTE + "' (or '" + - DESTINATION_NAME_ATTRIBUTE + "') attributes must be provided for a " + - JmsPollingSourceAdapter.class.getSimpleName()); - } - } - - private void parseMessageDrivenSourceAdapter(Element element, BeanDefinitionBuilder builder) { - String connectionFactory = element.getAttribute(CONNECTION_FACTORY_ATTRIBUTE); - String destination = element.getAttribute(DESTINATION_ATTRIBUTE); - String destinationName = element.getAttribute(DESTINATION_NAME_ATTRIBUTE); - String messageConverter = element.getAttribute(MESSAGE_CONVERTER_ATTRIBUTE); - if (StringUtils.hasText(element.getAttribute(JMS_TEMPLATE_ATTRIBUTE))) { - throw new BeanCreationException(JmsMessageDrivenSourceAdapter.class.getSimpleName() + - " does not accept a '" + JMS_TEMPLATE_ATTRIBUTE + "' reference. Both " + - "'" + CONNECTION_FACTORY_ATTRIBUTE + "' and '" + DESTINATION_ATTRIBUTE + - "' (or '" + DESTINATION_NAME_ATTRIBUTE + "') must be provided."); - } - if (StringUtils.hasText(connectionFactory) && (StringUtils.hasText(destination) || StringUtils.hasText(destinationName))) { - builder.addPropertyReference(CONNECTION_FACTORY_PROPERTY, connectionFactory); - if (StringUtils.hasText(destination)) { - builder.addPropertyReference(DESTINATION_PROPERTY, destination); - } - else { - builder.addPropertyValue(DESTINATION_NAME_PROPERTY, destinationName); - } - } - else { - throw new BeanCreationException("Both '" + CONNECTION_FACTORY_ATTRIBUTE + "' and '" + - DESTINATION_ATTRIBUTE + "' (or '" + DESTINATION_NAME_ATTRIBUTE + "') must be provided."); - } - if (StringUtils.hasText(messageConverter)) { - builder.addPropertyReference(MESSAGE_CONVERTER_PROPERTY, messageConverter); - } - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/config/JmsTargetAdapterParser.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/config/JmsTargetAdapterParser.java deleted file mode 100644 index 5403bfa82e..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/config/JmsTargetAdapterParser.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2002-2007 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.jms.config; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.BeanCreationException; -import org.springframework.beans.factory.config.RuntimeBeanReference; -import org.springframework.beans.factory.parsing.BeanComponentDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -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.scheduling.Subscription; -import org.springframework.util.StringUtils; - -/** - * Parser for the <jms-target/> element. - * - * @author Mark Fisher - */ -public class JmsTargetAdapterParser extends AbstractSingleBeanDefinitionParser { - - private static final String JMS_TEMPLATE_ATTRIBUTE = "jms-template"; - - private static final String JMS_TEMPLATE_PROPERTY = "jmsTemplate"; - - private static final String CONNECTION_FACTORY_ATTRIBUTE = "connection-factory"; - - private static final String CONNECTION_FACTORY_PROPERTY = "connectionFactory"; - - private static final String DESTINATION_ATTRIBUTE = "destination"; - - private static final String DESTINATION_NAME_ATTRIBUTE = "destination-name"; - - private static final String DESTINATION_PROPERTY = "destination"; - - private static final String DESTINATION_NAME_PROPERTY = "destinationName"; - - private static final String CHANNEL_ATTRIBUTE = "channel"; - - private static final String HANDLER_PROPERTY = "handler"; - - private static final String SUBSCRIPTION_PROPERTY = "subscription"; - - - protected Class getBeanClass(Element element) { - return DefaultMessageEndpoint.class; - } - - protected boolean shouldGenerateId() { - return false; - } - - protected boolean shouldGenerateIdAsFallback() { - return true; - } - - protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { - String jmsTemplate = element.getAttribute(JMS_TEMPLATE_ATTRIBUTE); - String connectionFactory = element.getAttribute(CONNECTION_FACTORY_ATTRIBUTE); - String destination = element.getAttribute(DESTINATION_ATTRIBUTE); - String destinationName = element.getAttribute(DESTINATION_NAME_ATTRIBUTE); - RootBeanDefinition adapterDef = new RootBeanDefinition(JmsTargetAdapter.class); - if (StringUtils.hasText(jmsTemplate)) { - if (StringUtils.hasText(connectionFactory) || StringUtils.hasText(destination) || StringUtils.hasText(destinationName)) { - throw new BeanCreationException("when providing a 'jms-template' reference, none of " + - "'connection-factory', 'destination', or 'destination-name' should be provided."); - } - adapterDef.getPropertyValues().addPropertyValue(JMS_TEMPLATE_PROPERTY, new RuntimeBeanReference(jmsTemplate)); - } - else if (StringUtils.hasText(connectionFactory) && (StringUtils.hasText(destination) ^ StringUtils.hasText(destinationName))) { - adapterDef.getPropertyValues().addPropertyValue(CONNECTION_FACTORY_PROPERTY, new RuntimeBeanReference(connectionFactory)); - if (StringUtils.hasText(destination)) { - adapterDef.getPropertyValues().addPropertyValue(DESTINATION_PROPERTY, new RuntimeBeanReference(destination)); - } - else { - adapterDef.getPropertyValues().addPropertyValue(DESTINATION_NAME_PROPERTY, destinationName); - } - } - else { - throw new BeanCreationException("either a 'jms-template' reference or both " + - "'connection-factory' and 'destination' (or 'destination-name') references must be provided."); - } - String channel = element.getAttribute(CHANNEL_ATTRIBUTE); - Subscription subscription = new Subscription(channel); - String adapterBeanName = parserContext.getReaderContext().generateBeanName(adapterDef); - parserContext.registerBeanComponent(new BeanComponentDefinition(adapterDef, adapterBeanName)); - builder.addPropertyReference(HANDLER_PROPERTY, adapterBeanName); - builder.addPropertyValue(SUBSCRIPTION_PROPERTY, subscription); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/ByteStreamSource.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/ByteStreamSource.java deleted file mode 100644 index 0637bd6f02..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/ByteStreamSource.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2002-2007 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.stream; - -import java.io.BufferedInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.springframework.integration.adapter.PollableSource; -import org.springframework.integration.message.MessageDeliveryException; - -/** - * A pollable source for receiving bytes from an {@link InputStream}. - * - * @author Mark Fisher - */ -public class ByteStreamSource implements PollableSource { - - private BufferedInputStream stream; - - private Object streamMonitor; - - private int bytesPerMessage = 1024; - - private boolean shouldTruncate = true; - - - public ByteStreamSource(InputStream stream) { - this(stream, -1); - } - - public ByteStreamSource(InputStream stream, int bufferSize) { - this.streamMonitor = stream; - if (stream instanceof BufferedInputStream) { - this.stream = (BufferedInputStream) stream; - } - else if (bufferSize > 0) { - this.stream = new BufferedInputStream(stream, bufferSize); - } - else { - this.stream = new BufferedInputStream(stream); - } - } - - - public void setBytesPerMessage(int bytesPerMessage) { - this.bytesPerMessage = bytesPerMessage; - } - - public void setShouldTruncate(boolean shouldTruncate) { - this.shouldTruncate = shouldTruncate; - } - - public Collection poll(int limit) { - List results = new ArrayList(); - while (results.size() < limit) { - try { - byte[] bytes; - int bytesRead = 0; - synchronized (this.streamMonitor) { - if (stream.available() == 0) { - return results; - } - bytes = new byte[bytesPerMessage]; - bytesRead = stream.read(bytes, 0, bytes.length); - } - if (bytesRead <= 0) { - return results; - } - if (!this.shouldTruncate) { - results.add(bytes); - } - else { - byte[] result = new byte[bytesRead]; - System.arraycopy(bytes, 0, result, 0, result.length); - results.add(result); - } - } - catch (IOException e) { - throw new MessageDeliveryException("IO failure occurred in adapter", e); - } - } - return results; - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/ByteStreamSourceAdapter.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/ByteStreamSourceAdapter.java deleted file mode 100644 index 97fa46fcfe..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/ByteStreamSourceAdapter.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2002-2007 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.stream; - -import java.io.InputStream; - -import org.springframework.integration.adapter.PollingSourceAdapter; - -/** - * A polling source adapter that wraps a {@link ByteStreamSource}. - * - * @author Mark Fisher - */ -public class ByteStreamSourceAdapter extends PollingSourceAdapter { - - public ByteStreamSourceAdapter(InputStream stream) { - super(new ByteStreamSource(stream)); - } - - - public void setBytesPerMessage(int bytesPerMessage) { - ((ByteStreamSource) this.getSource()).setBytesPerMessage(bytesPerMessage); - } - - public void setShouldTruncate(boolean shouldTruncate) { - ((ByteStreamSource) this.getSource()).setShouldTruncate(shouldTruncate); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/ByteStreamTargetAdapter.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/ByteStreamTargetAdapter.java deleted file mode 100644 index 8e87911e07..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/ByteStreamTargetAdapter.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2002-2007 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.stream; - -import java.io.BufferedOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -import org.springframework.integration.adapter.AbstractTargetAdapter; -import org.springframework.integration.message.MessageHandlingException; - -/** - * A target adapter that writes a byte array to an {@link OutputStream}. - * - * @author Mark Fisher - */ -public class ByteStreamTargetAdapter extends AbstractTargetAdapter { - - private BufferedOutputStream stream; - - - public ByteStreamTargetAdapter(OutputStream stream) { - this(stream, -1); - } - - public ByteStreamTargetAdapter(OutputStream stream, int bufferSize) { - if (bufferSize > 0) { - this.stream = new BufferedOutputStream(stream, bufferSize); - } - else { - this.stream = new BufferedOutputStream(stream); - } - } - - - @Override - protected boolean sendToTarget(Object object) { - if (object == 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()); - } - else if (object instanceof byte[]){ - this.stream.write((byte[]) object); - } - else { - throw new MessageHandlingException(this.getClass().getSimpleName() + - " only supports byte array and String-based messages"); - } - this.stream.flush(); - return true; - } - catch (IOException e) { - throw new MessageHandlingException("IO failure occurred in adapter", e); - } - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/CharacterStreamSource.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/CharacterStreamSource.java deleted file mode 100644 index 0e71df1ce4..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/CharacterStreamSource.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2002-2007 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.stream; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.springframework.integration.adapter.PollableSource; -import org.springframework.integration.message.MessageDeliveryException; - -/** - * A pollable source for text-based {@link InputStream InputStreams}. - * - * @author Mark Fisher - */ -public class CharacterStreamSource implements PollableSource { - - private BufferedReader reader; - - private Object streamMonitor; - - - public CharacterStreamSource(InputStream stream) { - this(stream, -1); - } - - public CharacterStreamSource(InputStream stream, int bufferSize) { - this.streamMonitor = stream; - if (bufferSize > 0) { - this.reader = new BufferedReader(new InputStreamReader(stream), bufferSize); - } - else { - this.reader = new BufferedReader(new InputStreamReader(stream)); - } - } - - - public Collection poll(int limit) { - List results = new ArrayList(); - while (results.size() < limit) { - try { - String line = null; - synchronized (this.streamMonitor) { - boolean isReady = reader.ready(); - if (!isReady) { - return results; - } - line = reader.readLine(); - } - if (line == null) { - return results; - } - results.add(line); - } - catch (IOException e) { - throw new MessageDeliveryException("IO failure occurred in adapter", e); - } - } - return results; - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/CharacterStreamSourceAdapter.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/CharacterStreamSourceAdapter.java deleted file mode 100644 index 69cf8621cf..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/CharacterStreamSourceAdapter.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2002-2007 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.stream; - -import java.io.InputStream; - -import org.springframework.integration.adapter.PollingSourceAdapter; -import org.springframework.integration.channel.MessageChannel; - -/** - * A polling source adapter that wraps a {@link CharacterStreamSource}. - * - * @author Mark Fisher - */ -public class CharacterStreamSourceAdapter extends PollingSourceAdapter { - - public CharacterStreamSourceAdapter(InputStream stream) { - super(new CharacterStreamSource(stream)); - } - - - /** - * Factory method that creates an adapter for stdin (System.in). - */ - public static CharacterStreamSourceAdapter stdinAdapter(MessageChannel channel) { - CharacterStreamSourceAdapter adapter = new CharacterStreamSourceAdapter(System.in); - adapter.setChannel(channel); - return adapter; - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/CharacterStreamTargetAdapter.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/CharacterStreamTargetAdapter.java deleted file mode 100644 index e5cace6b03..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/adapter/stream/CharacterStreamTargetAdapter.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2002-2007 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.stream; - -import java.io.BufferedWriter; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; - -import org.springframework.integration.adapter.AbstractTargetAdapter; -import org.springframework.integration.message.MessageHandlingException; - -/** - * A target adapter that writes to an {@link OutputStream}. String-based - * objects will be written directly, but if the object is not itself a - * {@link String}, the adapter 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 true. It is false - * by default. - * - * @author Mark Fisher - */ -public class CharacterStreamTargetAdapter extends AbstractTargetAdapter { - - private BufferedWriter writer; - - private boolean shouldAppendNewLine = false; - - - public CharacterStreamTargetAdapter(OutputStream stream) { - this(stream, -1); - } - - public CharacterStreamTargetAdapter(OutputStream stream, int bufferSize) { - if (bufferSize > 0) { - this.writer = new BufferedWriter(new OutputStreamWriter(stream), bufferSize); - } - else { - this.writer = new BufferedWriter(new OutputStreamWriter(stream)); - } - } - - - /** - * Factory method that creates an adapter for stdout (System.out). - */ - public static CharacterStreamTargetAdapter stdoutAdapter() { - return new CharacterStreamTargetAdapter(System.out); - } - - /** - * Factory method that creates an adapter for stderr (System.err). - */ - public static CharacterStreamTargetAdapter stderrAdapter() { - return new CharacterStreamTargetAdapter(System.err); - } - - - public void setShouldAppendNewLine(boolean shouldAppendNewLine) { - this.shouldAppendNewLine = shouldAppendNewLine; - } - - @Override - protected boolean sendToTarget(Object object) { - if (object == null) { - if (logger.isWarnEnabled()) { - logger.warn("target adapter received null object"); - } - return false; - } - try { - if (object instanceof String) { - writer.write((String) object); - } - else { - writer.write(object.toString()); - } - if (this.shouldAppendNewLine) { - writer.newLine(); - } - writer.flush(); - return true; - } - catch (IOException e) { - throw new MessageHandlingException("IO failure occurred in adapter", e); - } - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationNamespaceHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationNamespaceHandler.java index 182a59bb72..aca537f8ec 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationNamespaceHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationNamespaceHandler.java @@ -16,11 +16,19 @@ package org.springframework.integration.config; +import java.io.IOException; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.NamespaceHandlerSupport; -import org.springframework.integration.adapter.file.config.FileSourceAdapterParser; -import org.springframework.integration.adapter.file.config.FileTargetAdapterParser; -import org.springframework.integration.adapter.jms.config.JmsSourceAdapterParser; -import org.springframework.integration.adapter.jms.config.JmsTargetAdapterParser; +import org.springframework.core.io.support.PropertiesLoaderUtils; +import org.springframework.util.ClassUtils; /** * Namespace handler for the integration namespace. @@ -29,6 +37,12 @@ import org.springframework.integration.adapter.jms.config.JmsTargetAdapterParser */ public class IntegrationNamespaceHandler extends NamespaceHandlerSupport { + private static final String ADAPTER_PARSER_MAPPINGS_LOCATION = "META-INF/spring-integration.parsers"; + + + private final Log logger = LogFactory.getLog(this.getClass()); + + public void init() { registerBeanDefinitionParser("message-bus", new MessageBusParser()); registerBeanDefinitionParser("annotation-driven", new AnnotationDrivenParser()); @@ -38,10 +52,48 @@ public class IntegrationNamespaceHandler extends NamespaceHandlerSupport { registerBeanDefinitionParser("endpoint", new EndpointParser()); registerBeanDefinitionParser("handler", new HandlerParser()); registerBeanDefinitionParser("handler-chain", new HandlerParser()); - registerBeanDefinitionParser("file-source", new FileSourceAdapterParser()); - registerBeanDefinitionParser("file-target", new FileTargetAdapterParser()); - registerBeanDefinitionParser("jms-source", new JmsSourceAdapterParser()); - registerBeanDefinitionParser("jms-target", new JmsTargetAdapterParser()); + Map> parserMappings = this.loadAdapterParserMappings(); + try { + for (Map.Entry> entry : parserMappings.entrySet()) { + registerBeanDefinitionParser(entry.getKey(), (BeanDefinitionParser) entry.getValue().newInstance()); + } + } + catch (Exception e) { + throw new IllegalStateException("Failed to instantiate BeanDefinitionParser.", e); + } + } + + private Map> loadAdapterParserMappings() { + Map> parserMappings = + new HashMap>(); + ClassLoader classLoader = getClass().getClassLoader(); + try { + Properties mappings = + PropertiesLoaderUtils.loadAllProperties(ADAPTER_PARSER_MAPPINGS_LOCATION, classLoader); + if (logger.isDebugEnabled()) { + logger.debug("Loaded parser mappings [" + mappings + "]"); + } + Enumeration propertyNames = mappings.propertyNames(); + while (propertyNames.hasMoreElements()) { + String name = (String) propertyNames.nextElement(); + String classname = mappings.getProperty(name); + Class parserClass = ClassUtils.forName(classname, classLoader); + if (!BeanDefinitionParser.class.isAssignableFrom(parserClass)) { + throw new IllegalStateException("Expected class of type BeanDefinitionParser, but '" + + name + "' was of type '" + parserClass.getSimpleName() + "'"); + } + parserMappings.put(name, (Class) parserClass); + } + return parserMappings; + } + catch (IOException e) { + throw new IllegalStateException( + "Unable to load BeanDefinitionParser mappings from location [" + + ADAPTER_PARSER_MAPPINGS_LOCATION + "]. Root cause: " + e); + } + catch (ClassNotFoundException e) { + throw new IllegalStateException("Failed to load BeanDefinitionParser.", e); + } } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/spring-integration-1.0.xsd b/spring-integration-core/src/main/java/org/springframework/integration/config/spring-integration-1.0.xsd index d3b53fa9fa..175c14b607 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/spring-integration-1.0.xsd +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/spring-integration-1.0.xsd @@ -13,7 +13,7 @@ @@ -207,65 +207,4 @@ - - - - - Defines a file-based source channel adapter. - - - - - - - - - - - - - - Defines a file-based target channel adapter. - - - - - - - - - - - - - Defines a jms-based source channel adapter. - - - - - - - - - - - - - - - - - - Defines a jms-based target channel adapter. - - - - - - - - - - - \ No newline at end of file diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/event/ApplicationEventSourceAdapterTests.java b/spring-integration-core/src/test/java/org/springframework/integration/adapter/event/ApplicationEventSourceAdapterTests.java deleted file mode 100644 index 16af096948..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/event/ApplicationEventSourceAdapterTests.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2002-2007 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.event; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; - -import org.springframework.context.ApplicationEvent; -import org.springframework.context.event.ContextClosedEvent; -import org.springframework.context.event.ContextRefreshedEvent; -import org.springframework.context.event.ContextStartedEvent; -import org.springframework.context.event.ContextStoppedEvent; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.integration.channel.MessageChannel; -import org.springframework.integration.channel.SimpleChannel; -import org.springframework.integration.message.Message; - -/** - * @author Mark Fisher - */ -public class ApplicationEventSourceAdapterTests { - - @Test - public void testAnyApplicationEventSentByDefault() { - MessageChannel channel = new SimpleChannel(); - ApplicationEventSourceAdapter adapter = new ApplicationEventSourceAdapter(); - adapter.setChannel(channel); - Message message1 = channel.receive(0); - assertNull(message1); - adapter.onApplicationEvent(new TestApplicationEvent1()); - adapter.onApplicationEvent(new TestApplicationEvent2()); - Message message2 = channel.receive(20); - assertNotNull(message2); - assertEquals("event1", ((ApplicationEvent) message2.getPayload()).getSource()); - Message message3 = channel.receive(20); - assertNotNull(message3); - assertEquals("event2", ((ApplicationEvent) message3.getPayload()).getSource()); - } - - @Test - public void testOnlyConfiguredEventTypesAreSent() { - MessageChannel channel = new SimpleChannel(); - ApplicationEventSourceAdapter adapter = new ApplicationEventSourceAdapter(); - List> eventTypes = new ArrayList>(); - eventTypes.add(TestApplicationEvent1.class); - adapter.setEventTypes(eventTypes); - adapter.setChannel(channel); - Message message1 = channel.receive(0); - assertNull(message1); - adapter.onApplicationEvent(new TestApplicationEvent1()); - adapter.onApplicationEvent(new TestApplicationEvent2()); - Message message2 = channel.receive(20); - assertNotNull(message2); - assertEquals("event1", ((ApplicationEvent) message2.getPayload()).getSource()); - Message message3 = channel.receive(0); - assertNull(message3); - } - - @Test - public void testApplicationContextEvents() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationEventSourceAdapterTests.xml", this.getClass()); - MessageChannel channel = (MessageChannel) context.getBean("channel"); - Message refreshedEventMessage = channel.receive(0); - assertNotNull(refreshedEventMessage); - assertEquals(ContextRefreshedEvent.class, refreshedEventMessage.getPayload().getClass()); - context.start(); - Message startedEventMessage = channel.receive(0); - assertNotNull(startedEventMessage); - assertEquals(ContextStartedEvent.class, startedEventMessage.getPayload().getClass()); - context.close(); - Message closedEventMessage = channel.receive(0); - assertNotNull(closedEventMessage); - assertEquals(ContextClosedEvent.class, closedEventMessage.getPayload().getClass()); - Message stoppedEventMessage = channel.receive(0); - assertNotNull(stoppedEventMessage); - assertEquals(ContextStoppedEvent.class, stoppedEventMessage.getPayload().getClass()); - } - - - private static class TestApplicationEvent1 extends ApplicationEvent { - - public TestApplicationEvent1() { - super("event1"); - } - } - - - private static class TestApplicationEvent2 extends ApplicationEvent { - - public TestApplicationEvent2() { - super("event2"); - } - } - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/event/ApplicationEventTargetAdapterTests.java b/spring-integration-core/src/test/java/org/springframework/integration/adapter/event/ApplicationEventTargetAdapterTests.java deleted file mode 100644 index 1e4a20780c..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/event/ApplicationEventTargetAdapterTests.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2002-2007 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.event; - -import static org.junit.Assert.assertEquals; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import org.junit.Test; - -import org.springframework.context.ApplicationEvent; -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.StringMessage; -import org.springframework.integration.scheduling.Subscription; - -/** - * @author Mark Fisher - */ -public class ApplicationEventTargetAdapterTests { - - @Test - public void testSendingEvent() throws InterruptedException { - final CountDownLatch latch = new CountDownLatch(1); - ApplicationEventPublisher publisher = new ApplicationEventPublisher() { - public void publishEvent(ApplicationEvent event) { - latch.countDown(); - } - }; - MessageChannel channel = new SimpleChannel(); - ApplicationEventTargetAdapter adapter = new ApplicationEventTargetAdapter(); - adapter.setApplicationEventPublisher(publisher); - MessageBus bus = new MessageBus(); - bus.registerChannel("channel", channel); - bus.registerHandler("adapter", adapter, new Subscription(channel)); - bus.start(); - assertEquals(1, latch.getCount()); - channel.send(new StringMessage("123", "testing")); - latch.await(100, TimeUnit.MILLISECONDS); - assertEquals(0, latch.getCount()); - bus.stop(); - } - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/event/applicationEventSourceAdapterTests.xml b/spring-integration-core/src/test/java/org/springframework/integration/adapter/event/applicationEventSourceAdapterTests.xml deleted file mode 100644 index 429ff0da6d..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/event/applicationEventSourceAdapterTests.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/file/DefaultFileNameGeneratorTests.java b/spring-integration-core/src/test/java/org/springframework/integration/adapter/file/DefaultFileNameGeneratorTests.java deleted file mode 100644 index adf525f8ca..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/file/DefaultFileNameGeneratorTests.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2002-2007 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.file; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import org.springframework.integration.message.GenericMessage; -import org.springframework.integration.message.Message; - -/** - * @author Mark Fisher - */ -public class DefaultFileNameGeneratorTests { - - @Test - public void testWithFileNamePropertyProvided() { - Message message = new GenericMessage("123", "testing"); - message.getHeader().setProperty(FileNameGenerator.FILENAME_PROPERTY_KEY, "foo.bar"); - FileNameGenerator generator = new DefaultFileNameGenerator(); - String filename = generator.generateFileName(message); - assertEquals("foo.bar", filename); - } - - @Test - public void testWithoutFileNamePropertyProvided() { - Message message = new GenericMessage("123", "testing"); - FileNameGenerator generator = new DefaultFileNameGenerator(); - String filename = generator.generateFileName(message); - assertTrue(filename.startsWith("123-")); - assertTrue(filename.endsWith(".msg")); - } - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/file/config/FileTargetAdapterParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/adapter/file/config/FileTargetAdapterParserTests.java deleted file mode 100644 index 7f427ef72b..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/file/config/FileTargetAdapterParserTests.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2002-2007 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.file.config; - -import static org.junit.Assert.assertEquals; - -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; - -/** - * @author Mark Fisher - */ -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()); - assertEquals("adapter", endpoint.getName()); - assertEquals("testChannel", endpoint.getSubscription().getChannelName()); - } - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/file/config/fileTargetAdapterParserTests.xml b/spring-integration-core/src/test/java/org/springframework/integration/adapter/file/config/fileTargetAdapterParserTests.xml deleted file mode 100644 index f06f7d6b41..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/file/config/fileTargetAdapterParserTests.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/DefaultJmsMessagePostProcessorTests.java b/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/DefaultJmsMessagePostProcessorTests.java deleted file mode 100644 index cc947bf0cb..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/DefaultJmsMessagePostProcessorTests.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2002-2007 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.jms; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; - -import javax.jms.Destination; -import javax.jms.JMSException; - -import org.junit.Test; - -import org.springframework.integration.message.StringMessage; - -/** - * @author Mark Fisher - */ -public class DefaultJmsMessagePostProcessorTests { - - @Test - public void testJmsReplyTo() throws JMSException { - StringMessage message = new StringMessage("test1"); - Destination replyTo = new Destination() {}; - message.getHeader().setAttribute(JmsTargetAdapter.JMS_REPLY_TO, replyTo); - DefaultJmsMessagePostProcessor postProcessor = new DefaultJmsMessagePostProcessor(); - javax.jms.Message jmsMessage = new StubTextMessage(); - postProcessor.postProcessJmsMessage(jmsMessage, message.getHeader()); - assertNotNull(jmsMessage.getJMSReplyTo()); - assertSame(replyTo, jmsMessage.getJMSReplyTo()); - } - - @Test - public void testJmsReplyToIgnoredIfIncorrectType() throws JMSException { - StringMessage message = new StringMessage("test1"); - message.getHeader().setAttribute(JmsTargetAdapter.JMS_REPLY_TO, "not-a-destination"); - DefaultJmsMessagePostProcessor postProcessor = new DefaultJmsMessagePostProcessor(); - javax.jms.Message jmsMessage = new StubTextMessage(); - postProcessor.postProcessJmsMessage(jmsMessage, message.getHeader()); - assertNull(jmsMessage.getJMSReplyTo()); - } - - @Test - public void testJmsCorrelationId() throws JMSException { - StringMessage message = new StringMessage("test1"); - String jmsCorrelationId = "ABC-123"; - message.getHeader().setAttribute(JmsTargetAdapter.JMS_CORRELATION_ID, jmsCorrelationId); - DefaultJmsMessagePostProcessor postProcessor = new DefaultJmsMessagePostProcessor(); - javax.jms.Message jmsMessage = new StubTextMessage(); - postProcessor.postProcessJmsMessage(jmsMessage, message.getHeader()); - assertNotNull(jmsMessage.getJMSCorrelationID()); - assertEquals(jmsCorrelationId, jmsMessage.getJMSCorrelationID()); - } - - @Test - public void testJmsCorrelationIdIgnoredIfIncorrectType() throws JMSException { - StringMessage message = new StringMessage("test1"); - message.getHeader().setAttribute(JmsTargetAdapter.JMS_CORRELATION_ID, new Integer(123)); - DefaultJmsMessagePostProcessor postProcessor = new DefaultJmsMessagePostProcessor(); - javax.jms.Message jmsMessage = new StubTextMessage(); - postProcessor.postProcessJmsMessage(jmsMessage, message.getHeader()); - assertNull(jmsMessage.getJMSCorrelationID()); - } - - @Test - public void testJmsType() throws JMSException { - StringMessage message = new StringMessage("test1"); - String jmsType = "testing"; - message.getHeader().setAttribute(JmsTargetAdapter.JMS_TYPE, jmsType); - DefaultJmsMessagePostProcessor postProcessor = new DefaultJmsMessagePostProcessor(); - javax.jms.Message jmsMessage = new StubTextMessage(); - postProcessor.postProcessJmsMessage(jmsMessage, message.getHeader()); - assertNotNull(jmsMessage.getJMSType()); - assertEquals(jmsType, jmsMessage.getJMSType()); - } - - @Test - public void testJmsTypeIgnoredIfIncorrectType() throws JMSException { - StringMessage message = new StringMessage("test1"); - message.getHeader().setAttribute(JmsTargetAdapter.JMS_TYPE, new Integer(123)); - DefaultJmsMessagePostProcessor postProcessor = new DefaultJmsMessagePostProcessor(); - javax.jms.Message jmsMessage = new StubTextMessage(); - postProcessor.postProcessJmsMessage(jmsMessage, message.getHeader()); - assertNull(jmsMessage.getJMSType()); - } - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/StubConnection.java b/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/StubConnection.java deleted file mode 100644 index abec6a3bef..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/StubConnection.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2002-2007 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.jms; - -import javax.jms.Connection; -import javax.jms.ConnectionConsumer; -import javax.jms.ConnectionMetaData; -import javax.jms.Destination; -import javax.jms.ExceptionListener; -import javax.jms.JMSException; -import javax.jms.ServerSessionPool; -import javax.jms.Session; -import javax.jms.Topic; - -/** - * @author Mark Fisher - */ -public class StubConnection implements Connection { - - private String messageText; - - - public StubConnection(String messageText) { - this.messageText = messageText; - } - - - public void close() throws JMSException { - } - - public ConnectionConsumer createConnectionConsumer(Destination destination, String messageSelector, - ServerSessionPool sessionPool, int maxMessages) throws JMSException { - return null; - } - - public ConnectionConsumer createDurableConnectionConsumer(Topic topic, String subscriptionName, - String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException { - return null; - } - - public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException { - return new StubSession(this.messageText); - } - - public String getClientID() throws JMSException { - return null; - } - - public ExceptionListener getExceptionListener() throws JMSException { - return null; - } - - public ConnectionMetaData getMetaData() throws JMSException { - return null; - } - - public void setClientID(String clientID) throws JMSException { - } - - public void setExceptionListener(ExceptionListener listener) throws JMSException { - } - - public void start() throws JMSException { - } - - public void stop() throws JMSException { - } - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/StubConsumer.java b/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/StubConsumer.java deleted file mode 100644 index e659ef9f14..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/StubConsumer.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2002-2007 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.jms; - -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageConsumer; -import javax.jms.MessageListener; - -/** - * @author Mark Fisher - */ -public class StubConsumer implements MessageConsumer { - - private String messageText; - - - public StubConsumer(String messageText) { - this.messageText = messageText; - } - - - public void close() throws JMSException { - } - - public MessageListener getMessageListener() throws JMSException { - return null; - } - - public String getMessageSelector() throws JMSException { - return null; - } - - public Message receive() throws JMSException { - StubTextMessage message = new StubTextMessage(); - message.setText(this.messageText); - return message; - } - - public Message receive(long timeout) throws JMSException { - return this.receive(); - } - - public Message receiveNoWait() throws JMSException { - return this.receive(); - } - - public void setMessageListener(MessageListener listener) throws JMSException { - } - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/StubDestination.java b/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/StubDestination.java deleted file mode 100644 index e23331e733..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/StubDestination.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2002-2007 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.jms; - -import javax.jms.Destination; - -/** - * @author Mark Fisher - */ -public class StubDestination implements Destination { - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/StubSession.java b/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/StubSession.java deleted file mode 100644 index 55f8a16c09..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/StubSession.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright 2002-2007 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.jms; - -import java.io.Serializable; - -import javax.jms.BytesMessage; -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.MapMessage; -import javax.jms.Message; -import javax.jms.MessageConsumer; -import javax.jms.MessageListener; -import javax.jms.MessageProducer; -import javax.jms.ObjectMessage; -import javax.jms.Queue; -import javax.jms.QueueBrowser; -import javax.jms.Session; -import javax.jms.StreamMessage; -import javax.jms.TemporaryQueue; -import javax.jms.TemporaryTopic; -import javax.jms.TextMessage; -import javax.jms.Topic; -import javax.jms.TopicSubscriber; - -/** - * @author Mark Fisher - */ -public class StubSession implements Session { - - private String messageText; - - - public StubSession(String messageText) { - this.messageText = messageText; - } - - - public void close() throws JMSException { - } - - public void commit() throws JMSException { - } - - public QueueBrowser createBrowser(Queue queue) throws JMSException { - return null; - } - - public QueueBrowser createBrowser(Queue queue, String messageSelector) throws JMSException { - return null; - } - - public BytesMessage createBytesMessage() throws JMSException { - return null; - } - - public MessageConsumer createConsumer(Destination destination) throws JMSException { - return new StubConsumer(this.messageText); - } - - public MessageConsumer createConsumer(Destination destination, String messageSelector) throws JMSException { - return new StubConsumer(this.messageText); - } - - public MessageConsumer createConsumer(Destination destination, String messageSelector, boolean NoLocal) - throws JMSException { - return new StubConsumer(this.messageText); - } - - public TopicSubscriber createDurableSubscriber(Topic topic, String name) throws JMSException { - return null; - } - - public TopicSubscriber createDurableSubscriber(Topic topic, String name, String messageSelector, boolean noLocal) - throws JMSException { - return null; - } - - public MapMessage createMapMessage() throws JMSException { - return null; - } - - public Message createMessage() throws JMSException { - return null; - } - - public ObjectMessage createObjectMessage() throws JMSException { - return null; - } - - public ObjectMessage createObjectMessage(Serializable object) throws JMSException { - return null; - } - - public MessageProducer createProducer(Destination destination) throws JMSException { - return null; - } - - public Queue createQueue(String queueName) throws JMSException { - return null; - } - - public StreamMessage createStreamMessage() throws JMSException { - return null; - } - - public TemporaryQueue createTemporaryQueue() throws JMSException { - return null; - } - - public TemporaryTopic createTemporaryTopic() throws JMSException { - return null; - } - - public TextMessage createTextMessage() throws JMSException { - return null; - } - - public TextMessage createTextMessage(String text) throws JMSException { - return null; - } - - public Topic createTopic(String topicName) throws JMSException { - return null; - } - - public int getAcknowledgeMode() throws JMSException { - return 0; - } - - public MessageListener getMessageListener() throws JMSException { - return null; - } - - public boolean getTransacted() throws JMSException { - return false; - } - - public void recover() throws JMSException { - } - - public void rollback() throws JMSException { - } - - public void run() { - } - - public void setMessageListener(MessageListener listener) throws JMSException { - } - - public void unsubscribe(String name) throws JMSException { - } - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/StubTextMessage.java b/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/StubTextMessage.java deleted file mode 100644 index 08322c33eb..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/StubTextMessage.java +++ /dev/null @@ -1,188 +0,0 @@ -package org.springframework.integration.adapter.jms; - -import java.util.Enumeration; - -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.TextMessage; - -public class StubTextMessage implements TextMessage { - - private String text; - - private Destination replyTo; - - private String correlationID; - - private String type; - - - public String getText() throws JMSException { - return this.text; - } - - public void setText(String text) throws JMSException { - this.text = text; - } - - public void acknowledge() throws JMSException { - } - - public void clearBody() throws JMSException { - } - - public void clearProperties() throws JMSException { - } - - public boolean getBooleanProperty(String name) throws JMSException { - return false; - } - - public byte getByteProperty(String name) throws JMSException { - return 0; - } - - public double getDoubleProperty(String name) throws JMSException { - return 0; - } - - public float getFloatProperty(String name) throws JMSException { - return 0; - } - - public int getIntProperty(String name) throws JMSException { - return 0; - } - - public String getJMSCorrelationID() throws JMSException { - return this.correlationID; - } - - public byte[] getJMSCorrelationIDAsBytes() throws JMSException { - return null; - } - - public int getJMSDeliveryMode() throws JMSException { - return 0; - } - - public Destination getJMSDestination() throws JMSException { - return null; - } - - public long getJMSExpiration() throws JMSException { - return 0; - } - - public String getJMSMessageID() throws JMSException { - return null; - } - - public int getJMSPriority() throws JMSException { - return 0; - } - - public boolean getJMSRedelivered() throws JMSException { - return false; - } - - public Destination getJMSReplyTo() throws JMSException { - return this.replyTo; - } - - public long getJMSTimestamp() throws JMSException { - return 0; - } - - public String getJMSType() throws JMSException { - return this.type; - } - - public long getLongProperty(String name) throws JMSException { - return 0; - } - - public Object getObjectProperty(String name) throws JMSException { - return null; - } - - public Enumeration getPropertyNames() throws JMSException { - return null; - } - - public short getShortProperty(String name) throws JMSException { - return 0; - } - - public String getStringProperty(String name) throws JMSException { - return null; - } - - public boolean propertyExists(String name) throws JMSException { - return false; - } - - public void setBooleanProperty(String name, boolean value) throws JMSException { - } - - public void setByteProperty(String name, byte value) throws JMSException { - } - - public void setDoubleProperty(String name, double value) throws JMSException { - } - - public void setFloatProperty(String name, float value) throws JMSException { - } - - public void setIntProperty(String name, int value) throws JMSException { - } - - public void setJMSCorrelationID(String correlationID) throws JMSException { - this.correlationID = correlationID; - } - - public void setJMSCorrelationIDAsBytes(byte[] correlationID) throws JMSException { - } - - public void setJMSDeliveryMode(int deliveryMode) throws JMSException { - } - - public void setJMSDestination(Destination destination) throws JMSException { - } - - public void setJMSExpiration(long expiration) throws JMSException { - } - - public void setJMSMessageID(String id) throws JMSException { - } - - public void setJMSPriority(int priority) throws JMSException { - } - - public void setJMSRedelivered(boolean redelivered) throws JMSException { - } - - public void setJMSReplyTo(Destination replyTo) throws JMSException { - this.replyTo = replyTo; - } - - public void setJMSTimestamp(long timestamp) throws JMSException { - } - - public void setJMSType(String type) throws JMSException { - this.type = type; - } - - public void setLongProperty(String name, long value) throws JMSException { - } - - public void setObjectProperty(String name, Object value) throws JMSException { - } - - public void setShortProperty(String name, short value) throws JMSException { - } - - public void setStringProperty(String name, String value) throws JMSException { - } - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/JmsSourceAdapterParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/JmsSourceAdapterParserTests.java deleted file mode 100644 index ca3608b01c..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/JmsSourceAdapterParserTests.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright 2002-2007 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.jms.config; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import javax.jms.JMSException; -import javax.jms.Session; -import javax.jms.TextMessage; - -import org.junit.Test; - -import org.springframework.beans.factory.BeanCreationException; -import org.springframework.beans.factory.BeanDefinitionStoreException; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.integration.adapter.jms.JmsMessageDrivenSourceAdapter; -import org.springframework.integration.adapter.jms.JmsPollingSourceAdapter; -import org.springframework.integration.channel.MessageChannel; -import org.springframework.integration.message.Message; -import org.springframework.jms.support.converter.MessageConversionException; -import org.springframework.jms.support.converter.MessageConverter; - -/** - * @author Mark Fisher - */ -public class JmsSourceAdapterParserTests { - - @Test - public void testPollingAdapterWithJmsTemplate() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - "pollingAdapterWithJmsTemplate.xml", this.getClass()); - context.start(); - JmsPollingSourceAdapter adapter = (JmsPollingSourceAdapter) context.getBean("adapter"); - adapter.processMessages(); - MessageChannel channel = (MessageChannel) context.getBean("channel"); - Message message = channel.receive(500); - assertNotNull("message should not be null", message); - assertEquals("polling-test", message.getPayload()); - context.stop(); - } - - @Test - public void testPollingAdapterWithConnectionFactoryAndDestination() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - "pollingAdapterWithConnectionFactoryAndDestination.xml", this.getClass()); - context.start(); - JmsPollingSourceAdapter adapter = (JmsPollingSourceAdapter) context.getBean("adapter"); - adapter.processMessages(); - MessageChannel channel = (MessageChannel) context.getBean("channel"); - Message message = channel.receive(500); - assertNotNull("message should not be null", message); - assertEquals("polling-test", message.getPayload()); - context.stop(); - } - - @Test - public void testPollingAdapterWithConnectionFactoryAndDestinationName() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - "pollingAdapterWithConnectionFactoryAndDestinationName.xml", this.getClass()); - context.start(); - JmsPollingSourceAdapter adapter = (JmsPollingSourceAdapter) context.getBean("adapter"); - adapter.processMessages(); - MessageChannel channel = (MessageChannel) context.getBean("channel"); - Message message = channel.receive(500); - assertNotNull("message should not be null", message); - assertEquals("polling-test", message.getPayload()); - context.stop(); - } - - @Test - public void testMessageDrivenAdapterWithConnectionFactoryAndDestination() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - "messageDrivenAdapterWithConnectionFactoryAndDestination.xml", this.getClass()); - context.start(); - JmsMessageDrivenSourceAdapter adapter = (JmsMessageDrivenSourceAdapter) context.getBean("adapter"); - assertEquals(JmsMessageDrivenSourceAdapter.class, adapter.getClass()); - MessageChannel channel = (MessageChannel) context.getBean("channel"); - Message message = channel.receive(3000); - assertNotNull("message should not be null", message); - assertEquals("message-driven-test", message.getPayload()); - context.stop(); - } - - @Test - public void testMessageDrivenAdapterWithConnectionFactoryAndDestinationName() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - "messageDrivenAdapterWithConnectionFactoryAndDestinationName.xml", this.getClass()); - context.start(); - JmsMessageDrivenSourceAdapter adapter = (JmsMessageDrivenSourceAdapter) context.getBean("adapter"); - assertEquals(JmsMessageDrivenSourceAdapter.class, adapter.getClass()); - MessageChannel channel = (MessageChannel) context.getBean("channel"); - Message message = channel.receive(3000); - assertNotNull("message should not be null", message); - assertEquals("message-driven-test", message.getPayload()); - context.stop(); - } - - @Test - public void testMessageDrivenAdapterWithMessageConverter() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - "messageDrivenAdapterWithMessageConverter.xml", this.getClass()); - JmsMessageDrivenSourceAdapter adapter = (JmsMessageDrivenSourceAdapter) context.getBean("adapter"); - assertEquals(JmsMessageDrivenSourceAdapter.class, adapter.getClass()); - MessageChannel channel = (MessageChannel) context.getBean("channel"); - Message message = channel.receive(3000); - assertNotNull("message should not be null", message); - assertEquals("converted-test-message", message.getPayload()); - context.stop(); - } - - @Test(expected=BeanDefinitionStoreException.class) - public void testPollingAdapterWithConnectionFactoryOnly() { - try { - new ClassPathXmlApplicationContext("pollingAdapterWithConnectionFactoryOnly.xml", this.getClass()); - } - catch (RuntimeException e) { - assertEquals(BeanCreationException.class, e.getCause().getClass()); - throw e; - } - } - - @Test(expected=BeanDefinitionStoreException.class) - public void testPollingAdapterWithDestinationOnly() { - try { - new ClassPathXmlApplicationContext("pollingAdapterWithDestinationOnly.xml", this.getClass()); - } - catch (RuntimeException e) { - assertEquals(BeanCreationException.class, e.getCause().getClass()); - throw e; - } - } - - @Test(expected=BeanDefinitionStoreException.class) - public void testPollingAdapterWithDestinationNameOnly() { - try { - new ClassPathXmlApplicationContext("pollingAdapterWithDestinationNameOnly.xml", this.getClass()); - } - catch (RuntimeException e) { - assertEquals(BeanCreationException.class, e.getCause().getClass()); - throw e; - } - } - - @Test(expected=BeanDefinitionStoreException.class) - public void testPollingAdapterWithoutPollPeriod() { - try { - new ClassPathXmlApplicationContext("pollingAdapterWithoutPollPeriod.xml", this.getClass()); - } - catch (RuntimeException e) { - assertEquals(BeanCreationException.class, e.getCause().getClass()); - throw e; - } - } - - @Test(expected=BeanDefinitionStoreException.class) - public void testMessageDrivenAdapterWithConnectionFactoryOnly() { - try { - new ClassPathXmlApplicationContext("messageDrivenAdapterWithConnectionFactoryOnly.xml", this.getClass()); - } - catch (RuntimeException e) { - assertEquals(BeanCreationException.class, e.getCause().getClass()); - throw e; - } - } - - - public static class TestMessageConverter implements MessageConverter { - - public Object fromMessage(javax.jms.Message message) throws JMSException, MessageConversionException { - String original = ((TextMessage) message).getText(); - return "converted-" + original; - } - - public javax.jms.Message toMessage(Object object, Session session) throws JMSException, - MessageConversionException { - return null; - } - - } - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/JmsTargetAdapterParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/JmsTargetAdapterParserTests.java deleted file mode 100644 index 57ef368a85..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/JmsTargetAdapterParserTests.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2002-2007 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.jms.config; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.integration.adapter.jms.JmsTargetAdapter; -import org.springframework.integration.endpoint.DefaultMessageEndpoint; - -/** - * @author Mark Fisher - */ -public class JmsTargetAdapterParserTests { - - @Test - public void testTargetAdapterWithConnectionFactoryAndDestination() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - "targetAdapterWithConnectionFactoryAndDestination.xml", this.getClass()); - DefaultMessageEndpoint endpoint = (DefaultMessageEndpoint) context.getBean("adapter"); - assertEquals(JmsTargetAdapter.class, endpoint.getHandler().getClass()); - assertEquals("adapter", endpoint.getName()); - assertEquals("testChannel", endpoint.getSubscription().getChannelName()); - } - - @Test - public void testTargetAdapterWithConnectionFactoryAndDestinationName() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - "targetAdapterWithConnectionFactoryAndDestinationName.xml", this.getClass()); - DefaultMessageEndpoint endpoint = (DefaultMessageEndpoint) context.getBean("adapter"); - assertEquals(JmsTargetAdapter.class, endpoint.getHandler().getClass()); - assertEquals("adapter", endpoint.getName()); - assertEquals("testChannel", endpoint.getSubscription().getChannelName()); - } - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/messageDrivenAdapterWithConnectionFactoryAndDestination.xml b/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/messageDrivenAdapterWithConnectionFactoryAndDestination.xml deleted file mode 100644 index e4d1c4bd88..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/messageDrivenAdapterWithConnectionFactoryAndDestination.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/messageDrivenAdapterWithConnectionFactoryAndDestinationName.xml b/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/messageDrivenAdapterWithConnectionFactoryAndDestinationName.xml deleted file mode 100644 index 8f2a733eb0..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/messageDrivenAdapterWithConnectionFactoryAndDestinationName.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/messageDrivenAdapterWithConnectionFactoryOnly.xml b/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/messageDrivenAdapterWithConnectionFactoryOnly.xml deleted file mode 100644 index 90137b3982..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/messageDrivenAdapterWithConnectionFactoryOnly.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/messageDrivenAdapterWithMessageConverter.xml b/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/messageDrivenAdapterWithMessageConverter.xml deleted file mode 100644 index 9589e6c7ed..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/messageDrivenAdapterWithMessageConverter.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithConnectionFactoryAndDestination.xml b/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithConnectionFactoryAndDestination.xml deleted file mode 100644 index bc2fa41d31..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithConnectionFactoryAndDestination.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithConnectionFactoryAndDestinationName.xml b/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithConnectionFactoryAndDestinationName.xml deleted file mode 100644 index 7b22a6591c..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithConnectionFactoryAndDestinationName.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithConnectionFactoryOnly.xml b/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithConnectionFactoryOnly.xml deleted file mode 100644 index a3310e6e44..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithConnectionFactoryOnly.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithDestinationNameOnly.xml b/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithDestinationNameOnly.xml deleted file mode 100644 index 87fe664762..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithDestinationNameOnly.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithDestinationOnly.xml b/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithDestinationOnly.xml deleted file mode 100644 index 4d5de9d2d6..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithDestinationOnly.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithJmsTemplate.xml b/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithJmsTemplate.xml deleted file mode 100644 index 0e427227a3..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithJmsTemplate.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithoutPollPeriod.xml b/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithoutPollPeriod.xml deleted file mode 100644 index 93a535e453..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/pollingAdapterWithoutPollPeriod.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/targetAdapterWithConnectionFactoryAndDestination.xml b/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/targetAdapterWithConnectionFactoryAndDestination.xml deleted file mode 100644 index 7c5aadf267..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/targetAdapterWithConnectionFactoryAndDestination.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/targetAdapterWithConnectionFactoryAndDestinationName.xml b/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/targetAdapterWithConnectionFactoryAndDestinationName.xml deleted file mode 100644 index c50fb87fd0..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/jms/config/targetAdapterWithConnectionFactoryAndDestinationName.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/stream/ByteStreamSourceAdapterTests.java b/spring-integration-core/src/test/java/org/springframework/integration/adapter/stream/ByteStreamSourceAdapterTests.java deleted file mode 100644 index 46cf2ef0b4..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/stream/ByteStreamSourceAdapterTests.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright 2002-2007 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.stream; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import java.io.ByteArrayInputStream; - -import org.junit.Test; - -import org.springframework.integration.channel.MessageChannel; -import org.springframework.integration.channel.SimpleChannel; -import org.springframework.integration.message.Message; - -/** - * @author Mark Fisher - */ -public class ByteStreamSourceAdapterTests { - - @Test - public void testEndOfStream() { - byte[] bytes = new byte[] {1,2,3}; - ByteArrayInputStream stream = new ByteArrayInputStream(bytes); - MessageChannel channel = new SimpleChannel(); - ByteStreamSourceAdapter adapter = new ByteStreamSourceAdapter(stream); - adapter.setChannel(channel); - adapter.start(); - int count = adapter.processMessages(); - assertEquals(1, count); - Message message1 = channel.receive(500); - byte[] payload = (byte[]) message1.getPayload(); - assertEquals(3, payload.length); - assertEquals(1, payload[0]); - assertEquals(2, payload[1]); - assertEquals(3, payload[2]); - Message message2 = channel.receive(0); - assertNull(message2); - adapter.processMessages(); - Message message3 = channel.receive(0); - assertNull(message3); - } - - @Test - public void testEndOfStreamWithMaxMessagesPerTask() throws Exception { - byte[] bytes = new byte[] {0,1,2,3,4,5,6,7}; - ByteArrayInputStream stream = new ByteArrayInputStream(bytes); - MessageChannel channel = new SimpleChannel(); - ByteStreamSourceAdapter adapter = new ByteStreamSourceAdapter(stream); - adapter.setChannel(channel); - adapter.setBytesPerMessage(8); - adapter.setMaxMessagesPerTask(5); - adapter.start(); - int count = adapter.processMessages(); - assertEquals(1, count); - Message message1 = channel.receive(500); - assertEquals(8, ((byte[]) message1.getPayload()).length); - Message message2 = channel.receive(0); - assertNull(message2); - } - - @Test - public void testMultipleMessagesWithSingleMessagePerTask() { - byte[] bytes = new byte[] {0,1,2,3,4,5,6,7}; - ByteArrayInputStream stream = new ByteArrayInputStream(bytes); - MessageChannel channel = new SimpleChannel(); - ByteStreamSourceAdapter adapter = new ByteStreamSourceAdapter(stream); - adapter.setBytesPerMessage(4); - adapter.setInitialDelay(10000); - adapter.setMaxMessagesPerTask(1); - adapter.setChannel(channel); - adapter.start(); - int count = adapter.processMessages(); - assertEquals(1, count); - Message message1 = channel.receive(0); - byte[] bytes1 = (byte[]) message1.getPayload(); - assertEquals(4, bytes1.length); - assertEquals(0, bytes1[0]); - Message message2 = channel.receive(0); - assertNull(message2); - adapter.processMessages(); - Message message3 = channel.receive(0); - byte[] bytes3 = (byte[]) message3.getPayload(); - assertEquals(4, bytes3.length); - assertEquals(4, bytes3[0]); - } - - @Test - public void testLessThanMaxMessagesAvailable() { - byte[] bytes = new byte[] {0,1,2,3,4,5,6,7}; - ByteArrayInputStream stream = new ByteArrayInputStream(bytes); - MessageChannel channel = new SimpleChannel(); - ByteStreamSourceAdapter adapter = new ByteStreamSourceAdapter(stream); - adapter.setInitialDelay(10000); - adapter.setChannel(channel); - adapter.setBytesPerMessage(4); - adapter.setMaxMessagesPerTask(5); - adapter.start(); - int count = adapter.processMessages(); - assertEquals(2, count); - Message message1 = channel.receive(0); - byte[] bytes1 = (byte[]) message1.getPayload(); - assertEquals(4, bytes1.length); - assertEquals(0, bytes1[0]); - Message message2 = channel.receive(0); - byte[] bytes2 = (byte[]) message2.getPayload(); - assertEquals(4, bytes2.length); - assertEquals(4, bytes2[0]); - Message message3 = channel.receive(0); - assertNull(message3); - } - - @Test - public void testByteArrayIsTruncated() { - byte[] bytes = new byte[] {0,1,2,3,4,5}; - ByteArrayInputStream stream = new ByteArrayInputStream(bytes); - MessageChannel channel = new SimpleChannel(); - ByteStreamSourceAdapter adapter = new ByteStreamSourceAdapter(stream); - adapter.setInitialDelay(10000); - adapter.setBytesPerMessage(4); - adapter.setMaxMessagesPerTask(1); - adapter.setChannel(channel); - adapter.start(); - int count = adapter.processMessages(); - assertEquals(1, count); - Message message1 = channel.receive(0); - assertEquals(4, ((byte[]) message1.getPayload()).length); - Message message2 = channel.receive(0); - assertNull(message2); - adapter.processMessages(); - Message message3 = channel.receive(0); - assertEquals(2, ((byte[]) message3.getPayload()).length); - } - - @Test - public void testByteArrayIsNotTruncated() { - byte[] bytes = new byte[] {0,1,2,3,4,5}; - ByteArrayInputStream stream = new ByteArrayInputStream(bytes); - MessageChannel channel = new SimpleChannel(); - ByteStreamSourceAdapter adapter = new ByteStreamSourceAdapter(stream); - adapter.setInitialDelay(10000); - adapter.setBytesPerMessage(4); - adapter.setShouldTruncate(false); - adapter.setMaxMessagesPerTask(1); - adapter.setChannel(channel); - adapter.start(); - int count = adapter.processMessages(); - assertEquals(1, count); - Message message1 = channel.receive(0); - assertEquals(4, ((byte[]) message1.getPayload()).length); - Message message2 = channel.receive(0); - assertNull(message2); - adapter.processMessages(); - Message message3 = channel.receive(0); - assertEquals(4, ((byte[]) message3.getPayload()).length); - assertEquals(0, ((byte[]) message3.getPayload())[3]); - } - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/stream/ByteStreamTargetAdapterTests.java b/spring-integration-core/src/test/java/org/springframework/integration/adapter/stream/ByteStreamTargetAdapterTests.java deleted file mode 100644 index 4f5b47d0a8..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/stream/ByteStreamTargetAdapterTests.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright 2002-2007 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.stream; - -import static org.junit.Assert.assertEquals; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -import org.junit.Test; - -import org.springframework.integration.channel.DispatcherPolicy; -import org.springframework.integration.channel.SimpleChannel; -import org.springframework.integration.dispatcher.DefaultMessageDispatcher; -import org.springframework.integration.dispatcher.MessageDispatcher; -import org.springframework.integration.message.GenericMessage; -import org.springframework.integration.message.StringMessage; -import org.springframework.integration.scheduling.SimpleMessagingTaskScheduler; - -/** - * @author Mark Fisher - */ -public class ByteStreamTargetAdapterTests { - - @Test - public void testSingleByteArray() { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - ByteStreamTargetAdapter adapter = new ByteStreamTargetAdapter(stream); - adapter.handle(new GenericMessage(new byte[] {1,2,3})); - byte[] result = stream.toByteArray(); - assertEquals(3, result.length); - assertEquals(1, result[0]); - assertEquals(2, result[1]); - assertEquals(3, result[2]); - } - - @Test - public void testSingleString() { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - ByteStreamTargetAdapter adapter = new ByteStreamTargetAdapter(stream); - adapter.handle(new StringMessage("foo")); - byte[] result = stream.toByteArray(); - assertEquals(3, result.length); - assertEquals("foo", new String(result)); - } - - @Test - public void testMaxMessagesPerTaskSameAsMessageCount() { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - ByteStreamTargetAdapter adapter = new ByteStreamTargetAdapter(stream); - DispatcherPolicy dispatcherPolicy = new DispatcherPolicy(); - dispatcherPolicy.setMaxMessagesPerTask(3); - SimpleChannel channel = new SimpleChannel(dispatcherPolicy); - SimpleMessagingTaskScheduler scheduler = new SimpleMessagingTaskScheduler(1); - MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler); - dispatcher.addHandler(adapter); - channel.send(new GenericMessage(new byte[] {1,2,3}), 0); - channel.send(new GenericMessage(new byte[] {4,5,6}), 0); - channel.send(new GenericMessage(new byte[] {7,8,9}), 0); - assertEquals(3, dispatcher.dispatch()); - byte[] result = stream.toByteArray(); - assertEquals(9, result.length); - assertEquals(1, result[0]); - assertEquals(9, result[8]); - } - - @Test - public void testMaxMessagesPerTaskLessThanMessageCount() { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - ByteStreamTargetAdapter adapter = new ByteStreamTargetAdapter(stream); - DispatcherPolicy dispatcherPolicy = new DispatcherPolicy(); - dispatcherPolicy.setMaxMessagesPerTask(2); - SimpleChannel channel = new SimpleChannel(dispatcherPolicy); - SimpleMessagingTaskScheduler scheduler = new SimpleMessagingTaskScheduler(1); - MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler); - dispatcher.addHandler(adapter); - channel.send(new GenericMessage(new byte[] {1,2,3}), 0); - channel.send(new GenericMessage(new byte[] {4,5,6}), 0); - channel.send(new GenericMessage(new byte[] {7,8,9}), 0); - assertEquals(2, dispatcher.dispatch()); - byte[] result = stream.toByteArray(); - assertEquals(6, result.length); - assertEquals(1, result[0]); - } - - @Test - public void testMaxMessagesPerTaskExceedsMessageCount() { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - ByteStreamTargetAdapter adapter = new ByteStreamTargetAdapter(stream); - DispatcherPolicy dispatcherPolicy = new DispatcherPolicy(); - dispatcherPolicy.setMaxMessagesPerTask(5); - dispatcherPolicy.setReceiveTimeout(0); - SimpleChannel channel = new SimpleChannel(dispatcherPolicy); - SimpleMessagingTaskScheduler scheduler = new SimpleMessagingTaskScheduler(1); - MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler); - dispatcher.addHandler(adapter); - channel.send(new GenericMessage(new byte[] {1,2,3}), 0); - channel.send(new GenericMessage(new byte[] {4,5,6}), 0); - channel.send(new GenericMessage(new byte[] {7,8,9}), 0); - assertEquals(3, dispatcher.dispatch()); - byte[] result = stream.toByteArray(); - assertEquals(9, result.length); - assertEquals(1, result[0]); - } - - @Test - public void testMaxMessagesLessThanMessageCountWithMultipleDispatches() { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - ByteStreamTargetAdapter adapter = new ByteStreamTargetAdapter(stream); - DispatcherPolicy dispatcherPolicy = new DispatcherPolicy(); - dispatcherPolicy.setMaxMessagesPerTask(2); - dispatcherPolicy.setReceiveTimeout(0); - SimpleChannel channel = new SimpleChannel(dispatcherPolicy); - SimpleMessagingTaskScheduler scheduler = new SimpleMessagingTaskScheduler(1); - MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler); - dispatcher.addHandler(adapter); - channel.send(new GenericMessage(new byte[] {1,2,3}), 0); - channel.send(new GenericMessage(new byte[] {4,5,6}), 0); - channel.send(new GenericMessage(new byte[] {7,8,9}), 0); - assertEquals(2, dispatcher.dispatch()); - byte[] result1 = stream.toByteArray(); - assertEquals(6, result1.length); - assertEquals(1, result1[0]); - assertEquals(1, dispatcher.dispatch()); - byte[] result2 = stream.toByteArray(); - assertEquals(9, result2.length); - assertEquals(1, result2[0]); - assertEquals(7, result2[6]); - } - - @Test - public void testMaxMessagesExceedsMessageCountWithMultipleDispatches() { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - ByteStreamTargetAdapter adapter = new ByteStreamTargetAdapter(stream); - DispatcherPolicy dispatcherPolicy = new DispatcherPolicy(); - dispatcherPolicy.setMaxMessagesPerTask(5); - dispatcherPolicy.setReceiveTimeout(0); - SimpleChannel channel = new SimpleChannel(dispatcherPolicy); - SimpleMessagingTaskScheduler scheduler = new SimpleMessagingTaskScheduler(1); - MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler); - dispatcher.addHandler(adapter); - channel.send(new GenericMessage(new byte[] {1,2,3}), 0); - channel.send(new GenericMessage(new byte[] {4,5,6}), 0); - channel.send(new GenericMessage(new byte[] {7,8,9}), 0); - assertEquals(3, dispatcher.dispatch()); - byte[] result1 = stream.toByteArray(); - assertEquals(9, result1.length); - assertEquals(1, result1[0]); - assertEquals(0, dispatcher.dispatch()); - byte[] result2 = stream.toByteArray(); - assertEquals(9, result2.length); - assertEquals(1, result2[0]); - } - - @Test - public void testStreamResetBetweenDispatches() { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - ByteStreamTargetAdapter adapter = new ByteStreamTargetAdapter(stream); - DispatcherPolicy dispatcherPolicy = new DispatcherPolicy(); - dispatcherPolicy.setMaxMessagesPerTask(2); - dispatcherPolicy.setReceiveTimeout(0); - SimpleChannel channel = new SimpleChannel(dispatcherPolicy); - SimpleMessagingTaskScheduler scheduler = new SimpleMessagingTaskScheduler(1); - MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler); - dispatcher.addHandler(adapter); - channel.send(new GenericMessage(new byte[] {1,2,3}), 0); - channel.send(new GenericMessage(new byte[] {4,5,6}), 0); - channel.send(new GenericMessage(new byte[] {7,8,9}), 0); - assertEquals(2, dispatcher.dispatch()); - byte[] result1 = stream.toByteArray(); - assertEquals(6, result1.length); - stream.reset(); - assertEquals(1, dispatcher.dispatch()); - byte[] result2 = stream.toByteArray(); - assertEquals(3, result2.length); - assertEquals(7, result2[0]); - } - - @Test - public void testStreamWriteBetweenDispatches() throws IOException { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - ByteStreamTargetAdapter adapter = new ByteStreamTargetAdapter(stream); - DispatcherPolicy dispatcherPolicy = new DispatcherPolicy(); - dispatcherPolicy.setMaxMessagesPerTask(2); - dispatcherPolicy.setReceiveTimeout(0); - SimpleChannel channel = new SimpleChannel(dispatcherPolicy); - SimpleMessagingTaskScheduler scheduler = new SimpleMessagingTaskScheduler(1); - MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler); - dispatcher.addHandler(adapter); - channel.send(new GenericMessage(new byte[] {1,2,3}), 0); - channel.send(new GenericMessage(new byte[] {4,5,6}), 0); - channel.send(new GenericMessage(new byte[] {7,8,9}), 0); - assertEquals(2, dispatcher.dispatch()); - byte[] result1 = stream.toByteArray(); - assertEquals(6, result1.length); - stream.write(new byte[] {123}); - stream.flush(); - assertEquals(1, dispatcher.dispatch()); - byte[] result2 = stream.toByteArray(); - assertEquals(10, result2.length); - assertEquals(1, result2[0]); - assertEquals(123, result2[6]); - assertEquals(7, result2[7]); - } - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/stream/CharacterStreamSourceAdapterTests.java b/spring-integration-core/src/test/java/org/springframework/integration/adapter/stream/CharacterStreamSourceAdapterTests.java deleted file mode 100644 index 52d32815b5..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/stream/CharacterStreamSourceAdapterTests.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2002-2007 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.stream; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import java.io.ByteArrayInputStream; - -import org.junit.Test; - -import org.springframework.integration.channel.MessageChannel; -import org.springframework.integration.channel.SimpleChannel; -import org.springframework.integration.message.Message; - -/** - * @author Mark Fisher - */ -public class CharacterStreamSourceAdapterTests { - - @Test - public void testEndOfStream() { - byte[] bytes = "test".getBytes(); - ByteArrayInputStream stream = new ByteArrayInputStream(bytes); - MessageChannel channel = new SimpleChannel(); - CharacterStreamSourceAdapter adapter = new CharacterStreamSourceAdapter(stream); - adapter.setChannel(channel); - adapter.start(); - int count = adapter.processMessages(); - assertEquals(1, count); - Message message1 = channel.receive(0); - assertEquals("test", message1.getPayload()); - Message message2 = channel.receive(0); - assertNull(message2); - adapter.processMessages(); - Message message3 = channel.receive(0); - assertNull(message3); - } - - @Test - public void testEndOfStreamWithMaxMessagesPerTask() { - byte[] bytes = "test".getBytes(); - ByteArrayInputStream stream = new ByteArrayInputStream(bytes); - MessageChannel channel = new SimpleChannel(); - CharacterStreamSourceAdapter adapter = new CharacterStreamSourceAdapter(stream); - adapter.setChannel(channel); - adapter.setMaxMessagesPerTask(5); - adapter.start(); - int count = adapter.processMessages(); - assertEquals(1, count); - Message message1 = channel.receive(0); - assertEquals("test", message1.getPayload()); - Message message2 = channel.receive(0); - assertNull(message2); - } - - @Test - public void testMultipleLinesWithSingleMessagePerTask() { - String s = "test1" + System.getProperty("line.separator") + "test2"; - ByteArrayInputStream stream = new ByteArrayInputStream(s.getBytes()); - MessageChannel channel = new SimpleChannel(); - CharacterStreamSourceAdapter adapter = new CharacterStreamSourceAdapter(stream); - adapter.setInitialDelay(10000); - adapter.setMaxMessagesPerTask(1); - adapter.setChannel(channel); - adapter.start(); - int count = adapter.processMessages(); - assertEquals(1, count); - Message message1 = channel.receive(0); - assertEquals("test1", message1.getPayload()); - Message message2 = channel.receive(0); - assertNull(message2); - adapter.processMessages(); - Message message3 = channel.receive(0); - assertEquals("test2", message3.getPayload()); - } - - @Test - public void testLessThanMaxMessagesAvailable() { - String s = "test1" + System.getProperty("line.separator") + "test2"; - ByteArrayInputStream stream = new ByteArrayInputStream(s.getBytes()); - MessageChannel channel = new SimpleChannel(); - CharacterStreamSourceAdapter adapter = new CharacterStreamSourceAdapter(stream); - adapter.setChannel(channel); - adapter.setMaxMessagesPerTask(5); - adapter.start(); - int count = adapter.processMessages(); - assertEquals(2, count); - Message message1 = channel.receive(0); - assertEquals("test1", message1.getPayload()); - Message message2 = channel.receive(0); - assertEquals("test2", message2.getPayload()); - Message message3 = channel.receive(0); - assertNull(message3); - } - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/stream/CharacterStreamTargetAdapterTests.java b/spring-integration-core/src/test/java/org/springframework/integration/adapter/stream/CharacterStreamTargetAdapterTests.java deleted file mode 100644 index cbd9365956..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/adapter/stream/CharacterStreamTargetAdapterTests.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright 2002-2007 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.stream; - -import static org.junit.Assert.assertEquals; - -import java.io.ByteArrayOutputStream; - -import org.junit.Test; - -import org.springframework.integration.channel.DispatcherPolicy; -import org.springframework.integration.channel.MessageChannel; -import org.springframework.integration.channel.SimpleChannel; -import org.springframework.integration.dispatcher.DefaultMessageDispatcher; -import org.springframework.integration.dispatcher.MessageDispatcher; -import org.springframework.integration.message.GenericMessage; -import org.springframework.integration.message.StringMessage; -import org.springframework.integration.scheduling.SimpleMessagingTaskScheduler; - -/** - * @author Mark Fisher - */ -public class CharacterStreamTargetAdapterTests { - - private SimpleMessagingTaskScheduler scheduler = new SimpleMessagingTaskScheduler(1); - - - @Test - public void testSingleString() { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream); - adapter.handle(new StringMessage("foo")); - String result = new String(stream.toByteArray()); - assertEquals("foo", result); - } - - @Test - public void testTwoStringsAndNoNewLinesByDefault() { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - MessageChannel channel = new SimpleChannel(); - CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream); - MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler); - dispatcher.addHandler(adapter); - channel.send(new StringMessage("foo"), 0); - channel.send(new StringMessage("bar"), 0); - assertEquals(1, dispatcher.dispatch()); - String result1 = new String(stream.toByteArray()); - assertEquals("foo", result1); - assertEquals(1, dispatcher.dispatch()); - String result2 = new String(stream.toByteArray()); - assertEquals("foobar", result2); - } - - @Test - public void testTwoStringsWithNewLines() { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - MessageChannel channel = new SimpleChannel(); - CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream); - adapter.setShouldAppendNewLine(true); - MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler); - dispatcher.addHandler(adapter); - channel.send(new StringMessage("foo"), 0); - channel.send(new StringMessage("bar"), 0); - assertEquals(1, dispatcher.dispatch()); - String result1 = new String(stream.toByteArray()); - String newLine = System.getProperty("line.separator"); - assertEquals("foo" + newLine, result1); - assertEquals(1, dispatcher.dispatch()); - String result2 = new String(stream.toByteArray()); - assertEquals("foo" + newLine + "bar" + newLine, result2); - } - - @Test - public void testMaxMessagesPerTaskSameAsMessageCount() { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream); - DispatcherPolicy dispatcherPolicy = new DispatcherPolicy(); - dispatcherPolicy.setMaxMessagesPerTask(2); - SimpleChannel channel = new SimpleChannel(dispatcherPolicy); - MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler); - dispatcher.addHandler(adapter); - channel.send(new StringMessage("foo"), 0); - channel.send(new StringMessage("bar"), 0); - assertEquals(2, dispatcher.dispatch()); - String result = new String(stream.toByteArray()); - assertEquals("foobar", result); - } - - @Test - public void testMaxMessagesPerTaskExceedsMessageCountWithAppendedNewLines() { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream); - DispatcherPolicy dispatcherPolicy = new DispatcherPolicy(); - dispatcherPolicy.setMaxMessagesPerTask(10); - dispatcherPolicy.setReceiveTimeout(0); - SimpleChannel channel = new SimpleChannel(dispatcherPolicy); - MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler); - adapter.setShouldAppendNewLine(true); - dispatcher.addHandler(adapter); - channel.send(new StringMessage("foo"), 0); - channel.send(new StringMessage("bar"), 0); - assertEquals(2, dispatcher.dispatch()); - String result = new String(stream.toByteArray()); - String newLine = System.getProperty("line.separator"); - assertEquals("foo" + newLine + "bar" + newLine, result); - } - - @Test - public void testSingleNonStringObject() { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - MessageChannel channel = new SimpleChannel(); - CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream); - MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler); - dispatcher.addHandler(adapter); - TestObject testObject = new TestObject("foo"); - channel.send(new GenericMessage(testObject)); - int count = dispatcher.dispatch(); - assertEquals(1, count); - String result = new String(stream.toByteArray()); - assertEquals("foo", result); - } - - @Test - public void testTwoNonStringObjectWithOutNewLines() { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream); - DispatcherPolicy dispatcherPolicy = new DispatcherPolicy(); - dispatcherPolicy.setReceiveTimeout(0); - dispatcherPolicy.setMaxMessagesPerTask(2); - SimpleChannel channel = new SimpleChannel(dispatcherPolicy); - MessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler); - dispatcher.addHandler(adapter); - TestObject testObject1 = new TestObject("foo"); - TestObject testObject2 = new TestObject("bar"); - channel.send(new GenericMessage(testObject1), 0); - channel.send(new GenericMessage(testObject2), 0); - assertEquals(2, dispatcher.dispatch()); - String result = new String(stream.toByteArray()); - assertEquals("foobar", result); - } - - @Test - public void testTwoNonStringObjectWithNewLines() { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream); - DispatcherPolicy dispatcherPolicy = new DispatcherPolicy(); - dispatcherPolicy.setReceiveTimeout(0); - dispatcherPolicy.setMaxMessagesPerTask(2); - SimpleChannel channel = new SimpleChannel(dispatcherPolicy); - DefaultMessageDispatcher dispatcher = new DefaultMessageDispatcher(channel, scheduler); - adapter.setShouldAppendNewLine(true); - dispatcher.addHandler(adapter); - TestObject testObject1 = new TestObject("foo"); - TestObject testObject2 = new TestObject("bar"); - channel.send(new GenericMessage(testObject1), 0); - channel.send(new GenericMessage(testObject2), 0); - dispatcher.dispatch(); - String result = new String(stream.toByteArray()); - String newLine = System.getProperty("line.separator"); - assertEquals("foo" + newLine + "bar" + newLine, result); - } - - - private static class TestObject { - - private String text; - - TestObject(String text) { - this.text = text; - } - - public String toString() { - return this.text; - } - } - -}