Merge pull request #76 from ghillert/INTSAMPLES-49
INTSAMPLES-49 - Move main demo class to src/main/java + add tests
This commit is contained in:
@@ -67,14 +67,14 @@
|
||||
<showDeprecation>true</showDeprecation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<configuration>
|
||||
<mainClass>${java.main.class}</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<configuration>
|
||||
<mainClass>${java.main.class}</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
JMS Sample
|
||||
==========
|
||||
|
||||
This example demonstrates the following aspects of the JMS support available with Spring Integration:
|
||||
This example demonstrates the following aspects of the Java Message Service (JMS) support available with *Spring Integration*:
|
||||
|
||||
1. JMS Message-driven Channel Adapter
|
||||
2. JMS Inbound Gateway
|
||||
@@ -11,15 +11,40 @@ It also uses the following components:
|
||||
|
||||
1. Poller
|
||||
2. Stdout Channel Adapter (from Stream support Module)
|
||||
3. Stdin Channel Adapter (from Stream support Module)
|
||||
3. Stdin Channel Adapter (from Stream support Module)
|
||||
|
||||
The Stdout and Stdin Channel Adapters will allow you to interact with JMS via the console. It uses an embedded ActiveMQ broker.
|
||||
|
||||
To run the samples, simply execute the **GatewayDemo** and **ChannelAdapterDemo** classes located in the *org.springframework.integration.samples.jms* package.
|
||||
To run the sample, simply execute the **Main** class located in the the *org.springframework.integration.samples.jms* package either from your favorite IDE or by using Maven. When using Maven you can start the sample by executing:
|
||||
|
||||
When running demos you will see the following prompt:
|
||||
$ mvn clean package exec:java
|
||||
|
||||
> Please type something and hit return
|
||||
You will then be prompted to run one of two demos:
|
||||
|
||||
* **GatewayDemo**
|
||||
* **ChannelAdapterDemo**
|
||||
|
||||
The console output should look like:
|
||||
|
||||
=========================================================
|
||||
|
||||
Welcome to the Spring Integration JMS Sample!
|
||||
|
||||
For more information please visit:
|
||||
http://www.springintegration.org/
|
||||
|
||||
=========================================================
|
||||
16:48:21.158 INFO [org.springframework.integration.samples.jms.Main.main()][org.springframework.integration.samples.jms.ActiveMqTestUtils] Refreshing ActiveMQ data directory.
|
||||
|
||||
Which Demo would you like to run? <enter>:
|
||||
|
||||
1. Channel Adapter Demo
|
||||
2. Gateway Demo
|
||||
|
||||
When running either one of the demos you will see the following prompt:
|
||||
|
||||
> Please type something and hit <enter>
|
||||
|
||||
* **GatewayDemo** uses the *DemoBean* service, which will echo the response and upper-casing it.
|
||||
* **ChannelAdapterDemo** will simply echo the response
|
||||
|
||||
* **GatewayDemo** uses *DemoBean* service, which will echo the response, upper-casing it.
|
||||
* **ChannelAdapterDemo** will simply echo the response
|
||||
@@ -16,9 +16,11 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<spring.integration.version>2.2.0.RELEASE</spring.integration.version>
|
||||
<activemq.version>5.7.0</activemq.version>
|
||||
<slf4j.version>1.7.2</slf4j.version>
|
||||
<log4j.version>1.2.17</log4j.version>
|
||||
<junit.version>4.10</junit.version>
|
||||
<java.main.class>org.springframework.integration.samples.jms.Main</java.main.class>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
@@ -37,10 +39,6 @@
|
||||
<artifactId>spring-context</artifactId>
|
||||
<groupId>org.springframework</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<groupId>org.slf4j</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -53,23 +51,33 @@
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-core</artifactId>
|
||||
<version>${spring.integration.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-jms</artifactId>
|
||||
<version>${spring.integration.version}</version>
|
||||
</dependency>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-jms</artifactId>
|
||||
<version>${spring.integration.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-stream</artifactId>
|
||||
<version>${spring.integration.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-test</artifactId>
|
||||
<version>${spring.integration.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.6.6</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
@@ -86,6 +94,14 @@
|
||||
<showDeprecation>true</showDeprecation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<configuration>
|
||||
<mainClass>${java.main.class}</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,28 +17,30 @@ package org.springframework.integration.samples.jms;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gunnar Hillert
|
||||
*
|
||||
*/
|
||||
public class ActiveMqTestUtils {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(ActiveMqTestUtils.class);
|
||||
|
||||
public static void prepare() {
|
||||
System.out.println("####### Refreshing ActiveMq ########");
|
||||
LOGGER.info("Refreshing ActiveMQ data directory.");
|
||||
File activeMqTempDir = new File("activemq-data");
|
||||
deleteDir(activeMqTempDir);
|
||||
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
private static void deleteDir(File directory){
|
||||
if (directory.exists()){
|
||||
String[] children = directory.list();
|
||||
if (children != null){
|
||||
for (int i=0; i < children.length; i++) {
|
||||
deleteDir(new File(directory, children[i]));
|
||||
}
|
||||
for (int i=0; i < children.length; i++) {
|
||||
deleteDir(new File(directory, children[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
directory.delete();
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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.samples.jms;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* A simple bootstrap main() method for starting a pair of JMS Channel
|
||||
* Adapters. Text entered in the console will go through an outbound
|
||||
* JMS Channel Adapter from which it is sent to a JMS Destination.
|
||||
* An inbound JMS Channel Adapter is listening to that same JMS
|
||||
* Destination and will echo the result in the console.
|
||||
* <p>
|
||||
* See the configuration in the three XML files that are referenced below.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Gunnar Hillert
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
private final static String[] configFilesGatewayDemo = {
|
||||
"/META-INF/spring/integration/common.xml",
|
||||
"/META-INF/spring/integration/inboundGateway.xml",
|
||||
"/META-INF/spring/integration/outboundGateway.xml"
|
||||
};
|
||||
|
||||
private final static String[] configFilesChannelAdapterDemo = {
|
||||
"/META-INF/spring/integration/common.xml",
|
||||
"/META-INF/spring/integration/inboundChannelAdapter.xml",
|
||||
"/META-INF/spring/integration/outboundChannelAdapter.xml"
|
||||
};
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
final Scanner scanner = new Scanner(System.in);
|
||||
|
||||
System.out.println("\n========================================================="
|
||||
+ "\n "
|
||||
+ "\n Welcome to the Spring Integration JMS Sample! "
|
||||
+ "\n "
|
||||
+ "\n For more information please visit: "
|
||||
+ "\n http://www.springintegration.org/ "
|
||||
+ "\n "
|
||||
+ "\n=========================================================" );
|
||||
|
||||
ActiveMqTestUtils.prepare();
|
||||
|
||||
System.out.println("\n Which Demo would you like to run? <enter>:\n");
|
||||
System.out.println("\t1. Channel Adapter Demo");
|
||||
System.out.println("\t2. Gateway Demo");
|
||||
|
||||
while (true) {
|
||||
final String input = scanner.nextLine();
|
||||
|
||||
if("1".equals(input.trim())) {
|
||||
System.out.println(" Loading Channel Adapter Demo...");
|
||||
new ClassPathXmlApplicationContext(configFilesChannelAdapterDemo, Main.class);
|
||||
break;
|
||||
} else if("2".equals(input.trim())) {
|
||||
System.out.println(" Loading Gateway Demo...");
|
||||
new ClassPathXmlApplicationContext(configFilesGatewayDemo, Main.class);
|
||||
break;
|
||||
} else {
|
||||
System.out.println("Invalid choice\n\n");
|
||||
System.out.print("Enter you choice: ");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
System.out.println(" Please type something and hit <enter>\n");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
|
||||
<property name="targetConnectionFactory">
|
||||
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
|
||||
<property name="brokerURL" value="vm://localhost"/>
|
||||
<property name="brokerURL" value="vm://localhost"/>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="sessionCacheSize" value="10"/>
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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.samples.jms;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* A simple bootstrap main() method for starting a pair of JMS Channel
|
||||
* Adapters. Text entered in the console will go through an outbound
|
||||
* JMS Channel Adapter from which it is sent to a JMS Destination.
|
||||
* An inbound JMS Channel Adapter is listening to that same JMS
|
||||
* Destination and will echo the result in the console.
|
||||
* <p>
|
||||
* See the configuration in the three XML files that are referenced below.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Gunnar Hillert
|
||||
*/
|
||||
public class ChannelAdapterDemo {
|
||||
|
||||
private final static String[] configFiles = {
|
||||
"/META-INF/spring/integration/common.xml",
|
||||
"/META-INF/spring/integration/inboundChannelAdapter.xml",
|
||||
"/META-INF/spring/integration/outboundChannelAdapter.xml"
|
||||
};
|
||||
|
||||
public static void main(String[] args) {
|
||||
ActiveMqTestUtils.prepare();
|
||||
new ClassPathXmlApplicationContext(configFiles, ChannelAdapterDemo.class);
|
||||
System.out.println("Please type something and hit return");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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.samples.jms;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.GenericXmlApplicationContext;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
|
||||
/**
|
||||
* @author Gunnar Hillert
|
||||
*/
|
||||
public class ChannelAdapterDemoTest {
|
||||
|
||||
private final static String[] configFilesChannelAdapterDemo = {
|
||||
"/META-INF/spring/integration/common.xml",
|
||||
"/META-INF/spring/integration/inboundChannelAdapter.xml",
|
||||
"/META-INF/spring/integration/outboundChannelAdapter.xml"
|
||||
};
|
||||
|
||||
private final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
|
||||
@Before
|
||||
public void setupStreams() {
|
||||
System.setOut(new PrintStream(this.out));
|
||||
}
|
||||
|
||||
private void resetStreams() {
|
||||
this.out.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChannelAdapterDemo() throws InterruptedException {
|
||||
|
||||
final GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(configFilesChannelAdapterDemo);
|
||||
|
||||
final MessageChannel stdinToJmsoutChannel = applicationContext.getBean("stdinToJmsoutChannel", MessageChannel.class);
|
||||
|
||||
resetStreams();
|
||||
stdinToJmsoutChannel.send(MessageBuilder.withPayload("jms test").build());
|
||||
|
||||
Thread.sleep(1000);
|
||||
Assert.assertEquals("jms test\n", out.toString());
|
||||
|
||||
applicationContext.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.samples.jms;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* A simple bootstrap main() method for starting a pair of JMS Gateways.
|
||||
* Text entered in the console will go through an outbound JMS Gateway from
|
||||
* which it is sent to a JMS Destination. An inbound JMS Gateway is listening
|
||||
* to that same JMS Destination and will send the text to another Spring
|
||||
* Integration channel where it is handled by a service that simply converts
|
||||
* the text to upper case. The upper-case result is then sent in a response
|
||||
* message over JMS so that the outbound Gateway receives it as the reply to
|
||||
* its original request. At that point, the text is logged to the console.
|
||||
* <p>
|
||||
* See the configuration in the three XML files that are referenced below.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class GatewayDemo {
|
||||
|
||||
private final static String[] configFiles = {
|
||||
"/META-INF/spring/integration/common.xml",
|
||||
"/META-INF/spring/integration/inboundGateway.xml",
|
||||
"/META-INF/spring/integration/outboundGateway.xml"
|
||||
};
|
||||
|
||||
public static void main(String[] args) {
|
||||
ActiveMqTestUtils.prepare();
|
||||
new ClassPathXmlApplicationContext(configFiles, GatewayDemo.class);
|
||||
System.out.println("Please type something and hit return");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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.samples.jms;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.GenericXmlApplicationContext;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
|
||||
/**
|
||||
* @author Gunnar Hillert
|
||||
*/
|
||||
public class GatewayDemoTest {
|
||||
|
||||
private final static String[] configFilesGatewayDemo = {
|
||||
"/META-INF/spring/integration/common.xml",
|
||||
"/META-INF/spring/integration/inboundGateway.xml",
|
||||
"/META-INF/spring/integration/outboundGateway.xml"
|
||||
};
|
||||
|
||||
private final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
|
||||
@Before
|
||||
public void setupStreams() {
|
||||
System.setOut(new PrintStream(this.out));
|
||||
}
|
||||
|
||||
private void resetStreams() {
|
||||
this.out.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGatewayDemo() throws InterruptedException {
|
||||
|
||||
final GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(configFilesGatewayDemo);
|
||||
|
||||
final MessageChannel stdinToJmsoutChannel = applicationContext.getBean("stdinToJmsoutChannel", MessageChannel.class);
|
||||
|
||||
resetStreams();
|
||||
stdinToJmsoutChannel.send(MessageBuilder.withPayload("jms test").build());
|
||||
|
||||
Thread.sleep(1000);
|
||||
Assert.assertEquals("JMS response: JMS TEST\n", out.toString());
|
||||
|
||||
applicationContext.close();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user