INT-1380 added ws-outbound-gateway sample

This commit is contained in:
Oleg Zhurakousky
2010-09-16 19:02:35 -04:00
parent 822741859c
commit 3090298704
13 changed files with 78 additions and 109 deletions

View File

@@ -21,6 +21,7 @@ import static org.junit.Assert.assertThat;
import javax.xml.transform.Source;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.springframework.ws.client.core.WebServiceTemplate;
@@ -38,6 +39,7 @@ import org.springframework.xml.transform.StringSource;
*/
public class InContainerTests {
private static Logger logger = Logger.getLogger(InContainerTests.class);
private static final String WS_URI = "http://localhost:8080/ws-inbound-gateway/echoservice";
private final WebServiceTemplate template = new WebServiceTemplate();
@@ -49,7 +51,7 @@ public class InContainerTests {
"<echoRequest xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">hello</echoRequest>");
template.sendSourceAndReceiveToResult(WS_URI, payload, result);
System.out.println("RESULT: " + result.toString());
logger.info("RESULT: " + result.toString());
assertThat(result.toString(), equalTo(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<echoResponse xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">hello</echoResponse>"));

View File

@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" path="src/main/reources"/>
<classpathentry kind="src" path="src.test/resources"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>

View File

@@ -0,0 +1 @@
/target

View File

@@ -2,48 +2,64 @@
<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.springframework.integration.samples</groupId>
<artifactId>spring-integration-samples</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<groupId>org.springframework.integration.samples</groupId>
<artifactId>ws-outbound-gateway</artifactId>
<name>Spring Integration WS Outbound Gateway Sample</name>
<version>2.0.0</version>
<packaging>jar</packaging>
<properties>
<spring.integration.version>2.0.0.M7</spring.integration.version>
<log4j.version>1.2.15</log4j.version>
<junit.version>4.7</junit.version>
<saaj.version>1.3</saaj.version>
<javax-activation.version>1.1.1</javax-activation.version>
</properties>
<dependencies>
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-stream</artifactId>
<version>${spring.integration.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-ws</artifactId>
<version>${spring.integration.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>${saaj.version}</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>${javax-activation.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- test-scoped dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>repository.springframework.maven.release</id>
<name>Spring Framework Maven Release Repository</name>
<url>http://maven.springframework.org/release</url>
</repository>
<repository>
<id>repository.springframework.maven.milestone</id>
<name>Spring Framework Maven Milestone Repository</name>
<url>http://maven.springframework.org/milestone</url>
</repository>
<repository>
<id>repository.springframework.maven.snapshot</id>
<name>Spring Framework Maven Snapshot Repository</name>
<url>http://maven.springframework.org/snapshot</url>
</repository>
</repositories>
</project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>false</showDeprecation>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,15 @@
This example demonstrates the following aspects of the WS support available with Spring Integration:
1. WS Outbound Gateway
as well as:
2. Content Enricher
3. Composed Message Processor
A very simple example that show you how easy it is to invoke a SOAP based service using Spring Integration
Message is simply sent to a channel where it is retrieved by a Chain which consists of Header Enricher and WS Outbound Gateway
Header Enricher enriches Message with the SOAP action header
WS Outbound Gateway converts Message to a SOAP request and sends it to a remote service which converts temperature from
Fahrenheit to Celsius and sent back where the result is printed to a console.
To run sample simply execute WebServicesDemoTest

View File

@@ -14,8 +14,9 @@
* limitations under the License.
*/
package org.springframework.integration.samples.ws;
package rg.springframework.integration.samples.ws;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
@@ -30,10 +31,12 @@ import org.springframework.integration.support.channel.ChannelResolver;
*
* @author Marius Bogoevici
*/
public class WebServiceDemo {
public class WebServiceDemoTest {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("temperatureConversion.xml", WebServiceDemo.class);
@Test
public void testWsOutboundGateway() {
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("/META-INF/spring/integration/temperatureConversion.xml", WebServiceDemoTest.class);
ChannelResolver channelResolver = new BeanFactoryChannelResolver(context);
// Compose the XML message according to the server's schema
@@ -49,5 +52,4 @@ public class WebServiceDemo {
MessageChannel channel = channelResolver.resolveChannelName("fahrenheitChannel");
channel.send(message);
}
}

View File

@@ -1,36 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p: %c - %m%n" />
</layout>
</appender>
<!-- Loggers -->
<logger name="org.springframework">
<level value="warn" />
</logger>
<logger name="org.springframework.ws">
<level value="warn" />
</logger>
<logger name="org.springframework.integration">
<level value="warn" />
</logger>
<logger name="org.springframework.integration.ws">
<level value="warn" />
</logger>
<!-- Root Logger -->
<root>
<priority value="warn" />
<appender-ref ref="console" />
</root>
</log4j:configuration>

View File

@@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:stream="http://www.springframework.org/schema/integration/stream"
xmlns:ws="http://www.springframework.org/schema/integration/ws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/stream
http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd
http://www.springframework.org/schema/integration/ws
http://www.springframework.org/schema/integration/ws/spring-integration-ws.xsd">
<!-- This chain receives from the 'fahrenheitChannel' and enriches the request Message by adding
the "soap-action" header value. Then, the Web Service outbound Messaging Gateway invokes the
Web Service for the given URI, and the reply Message is sent to the 'celsiusChannel'. -->
<chain input-channel="fahrenheitChannel" output-channel="celsiusChannel">
<ws:header-enricher>
<ws:soap-action value="http://tempuri.org/FahrenheitToCelsius"/>
</ws:header-enricher>
<ws:outbound-gateway uri="http://www.w3schools.com/webservices/tempconvert.asmx"/>
</chain>
<!-- The response from the service is logged to the console. -->
<stream:stdout-channel-adapter id="celsiusChannel"/>
</beans:beans>

View File

@@ -1,5 +0,0 @@
#Generated by Maven
#Sat Sep 04 08:22:37 EDT 2010
version=2.0.0.BUILD-SNAPSHOT
groupId=org.springframework.integration.samples
artifactId=ws-outbound-gateway