CAMEL-6820: Improved support for Camel File Streams and JMS ByteMessages Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7f4952d4 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7f4952d4 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7f4952d4
Branch: refs/heads/master Commit: 7f4952d457051f40543d11cd29eee930b911a700 Parents: 8be6a77 Author: Scott England-Sullivan <sully6...@apache.org> Authored: Mon Mar 17 14:58:12 2014 -0500 Committer: Scott England-Sullivan <sully6...@apache.org> Committed: Mon Mar 17 14:58:12 2014 -0500 ---------------------------------------------------------------------- components/camel-sjms/pom.xml | 211 ++++++++++--------- .../component/sjms/jms/JmsMessageHelper.java | 16 ++ .../component/sjms/bugfixes/CAMEL_6820Test.java | 88 ++++++++ 3 files changed, 215 insertions(+), 100 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/7f4952d4/components/camel-sjms/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-sjms/pom.xml b/components/camel-sjms/pom.xml index a4c0083..f7fb95e 100644 --- a/components/camel-sjms/pom.xml +++ b/components/camel-sjms/pom.xml @@ -15,112 +15,123 @@ See the License for the specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> +<project + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.camel</groupId> - <artifactId>components</artifactId> - <version>2.13-SNAPSHOT</version> - </parent> + <parent> + <groupId>org.apache.camel</groupId> + <artifactId>components</artifactId> + <version>2.13-SNAPSHOT</version> + </parent> - <artifactId>camel-sjms</artifactId> - <packaging>bundle</packaging> - <name>Camel :: Simple JMS</name> - <description>A pure Java JMS Camel Component</description> + <artifactId>camel-sjms</artifactId> + <packaging>bundle</packaging> + <name>Camel :: Simple JMS</name> + <description>A pure Java JMS Camel Component</description> - <properties> - <camel.osgi.export.pkg> - org.apache.camel.component.sjms, - org.apache.camel.component.sjms.jms - </camel.osgi.export.pkg> - <camel.osgi.import.pkg> - !org.apache.camel.component.sjms.*, - org.apache.camel.*;${camel.osgi.import.camel.version}, - ${camel.osgi.import.defaults}, - * - </camel.osgi.import.pkg> - <camel.osgi.private.pkg> - org.apache.camel.component.sjms.consumer, - org.apache.camel.component.sjms.producer, - org.apache.camel.component.sjms.taskmanager, - org.apache.camel.component.sjms.tx - </camel.osgi.private.pkg> - <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=sjms</camel.osgi.export.service> - </properties> + <properties> + <camel.osgi.export.pkg> + org.apache.camel.component.sjms, + org.apache.camel.component.sjms.jms + </camel.osgi.export.pkg> + <camel.osgi.import.pkg> + !org.apache.camel.component.sjms.*, + org.apache.camel.*;${camel.osgi.import.camel.version}, + ${camel.osgi.import.defaults}, + * + </camel.osgi.import.pkg> + <camel.osgi.private.pkg> + org.apache.camel.component.sjms.consumer, + org.apache.camel.component.sjms.producer, + org.apache.camel.component.sjms.taskmanager, + org.apache.camel.component.sjms.tx + </camel.osgi.private.pkg> + <camel.osgi.export.service> + org.apache.camel.spi.ComponentResolver;component=sjms + </camel.osgi.export.service> + </properties> - <dependencies> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-core</artifactId> - </dependency> + <dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core</artifactId> + </dependency> - <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jms_1.1_spec</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-annotation_1.0_spec</artifactId> - <version>${geronimo-annotation-spec-version}</version> - <scope>provided</scope> - </dependency> + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-jms_1.1_spec</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-annotation_1.0_spec</artifactId> + <version>${geronimo-annotation-spec-version}</version> + <scope>provided</scope> + </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>activemq-broker</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>activemq-kahadb-store</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>activemq-pool</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>com.atomikos</groupId> - <artifactId>transactions-jta</artifactId> - <version>${atomikos-transactions-version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <scope>test</scope> - </dependency> - </dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.activemq</groupId> + <artifactId>activemq-broker</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.activemq</groupId> + <artifactId>activemq-kahadb-store</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.activemq</groupId> + <artifactId>activemq-pool</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.atomikos</groupId> + <artifactId>transactions-jta</artifactId> + <version>${atomikos-transactions-version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>${commons-io-version}</version> + <scope>test</scope> + </dependency> + </dependencies> - <build> - <plugins> - <plugin> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <forkMode>pertest</forkMode> - <forkedProcessTimeoutInSeconds>6000</forkedProcessTimeoutInSeconds> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-clean-plugin</artifactId> - <configuration> - <filesets> - <fileset> - <directory>${basedir}/activemq-data</directory> - </fileset> - </filesets> - </configuration> - </plugin> - </plugins> - </build> + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <forkMode>pertest</forkMode> + <forkedProcessTimeoutInSeconds>6000</forkedProcessTimeoutInSeconds> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-clean-plugin</artifactId> + <configuration> + <filesets> + <fileset> + <directory>${basedir}/activemq-data</directory> + </fileset> + </filesets> + </configuration> + </plugin> + </plugins> + </build> </project> http://git-wip-us.apache.org/repos/asf/camel/blob/7f4952d4/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/jms/JmsMessageHelper.java ---------------------------------------------------------------------- diff --git a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/jms/JmsMessageHelper.java b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/jms/JmsMessageHelper.java index 4482dec..89e7ba5 100644 --- a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/jms/JmsMessageHelper.java +++ b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/jms/JmsMessageHelper.java @@ -16,6 +16,7 @@ */ package org.apache.camel.component.sjms.jms; +import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.io.Serializable; import java.util.Collection; @@ -120,6 +121,21 @@ public final class JmsMessageHelper { textMessage.setText((String)payload); answer = textMessage; break; + case Stream: + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + InputStream is = (InputStream)payload; + int reads = is.read(); + while (reads != -1) { + baos.write(reads); + reads = is.read(); + } + + BytesMessage bytesStreamMessage = session.createBytesMessage(); + bytesStreamMessage.writeBytes(baos.toByteArray()); + baos.close(); + is.close(); + answer = bytesStreamMessage; + break; default: break; } http://git-wip-us.apache.org/repos/asf/camel/blob/7f4952d4/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/bugfixes/CAMEL_6820Test.java ---------------------------------------------------------------------- diff --git a/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/bugfixes/CAMEL_6820Test.java b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/bugfixes/CAMEL_6820Test.java new file mode 100644 index 0000000..e6e0ce4 --- /dev/null +++ b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/bugfixes/CAMEL_6820Test.java @@ -0,0 +1,88 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.camel.component.sjms.bugfixes; + +import java.io.File; +import java.io.InputStream; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.component.sjms.SjmsComponent; +import org.apache.camel.component.sjms.support.JmsTestSupport; +import org.apache.commons.io.FileUtils; +import org.junit.Test; + +/** + * Unit test for CAMEL_6820Test. This test is to verify the ability to + * support the Camel File Component more cleanly along with better support + * for ByteMessages. + */ +public class CAMEL_6820Test extends JmsTestSupport { + + private static final String TEST_DATA_DIR = "target/testdata"; + private static final String FILE_OUTPUT_URI = "file:" + TEST_DATA_DIR; + private static final String FILE_INPUT_URI = "file:" + TEST_DATA_DIR; + private static final String SJMS_QUEUE_URI = "sjms:queue:file.converter.queue"; + private static final String MOCK_RESULT_URI = "mock:result"; + + @Test + public void testCamelGenericFileConverterMessage() throws Exception { + File f = new File(TEST_DATA_DIR); + + // First make sure the directories are empty or purged so we don't get bad data on a + // test that is run against an uncleaned target directory + if (f.exists()) { + FileUtils.deleteDirectory(new File(TEST_DATA_DIR)); + + } + + // Then add the directory back + f.mkdirs(); + + // Make sure the SjmsComponent is available + SjmsComponent component = context.getComponent("sjms", SjmsComponent.class); + assertNotNull(component); + + // Create the test String + final String expectedBody = "Hello World"; + + // Create the Mock endpoint + MockEndpoint mock = getMockEndpoint(MOCK_RESULT_URI); + mock.expectedMessageCount(1); + mock.expectedBodiesReceived(expectedBody); + + // Send the message to a file to be read by the file component + template.sendBody(FILE_OUTPUT_URI, expectedBody); + + // Verify that it is working correctly + mock.assertIsSatisfied(); + } + + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from(FILE_INPUT_URI) + .convertBodyTo(InputStream.class) + .to(SJMS_QUEUE_URI); + + from(SJMS_QUEUE_URI) + .convertBodyTo(String.class) + .to(MOCK_RESULT_URI); + } + }; + } +}