INTSAMPLES-4 Add Simple TCP Client/Server Sample
This commit is contained in:
10
basic/tcp-client-server/.classpath
Normal file
10
basic/tcp-client-server/.classpath
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
||||
<classpathentry kind="src" path="src/main/resources"/>
|
||||
<classpathentry kind="src" path="src/test/java"/>
|
||||
<classpathentry kind="src" path="src/test/resources"/>
|
||||
<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"/>
|
||||
</classpath>
|
||||
1
basic/tcp-client-server/.gitignore
vendored
Normal file
1
basic/tcp-client-server/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
35
basic/tcp-client-server/.project
Normal file
35
basic/tcp-client-server/.project
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>tcp-client-server</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.springframework.ide.eclipse.core.springbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.maven.ide.eclipse.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.springframework.ide.eclipse.core.springnature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,4 @@
|
||||
#Fri Oct 01 16:39:52 EDT 2010
|
||||
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/tcp-client-server/src/main/resources/META-INF/spring/integration/tcpClientServerDemo-context.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="GatewayModelElement" type\="gateway">\n<structure end\="859" endstart\="859" start\="702" startend\="859"/>\n<bounds height\="124" width\="124" x\="19" y\="17"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="1028" endstart\="1028" start\="1006" startend\="1028"/>\n<bounds height\="124" width\="124" x\="163" y\="17"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="1421" endstart\="1421" start\="1400" startend\="1421"/>\n<bounds height\="124" width\="124" x\="19" y\="161"/>\n</element>\n<element clazz\="ServiceActivatorModelElement" type\="service-activator">\n<structure end\="1515" endstart\="1515" start\="1424" startend\="1515"/>\n<bounds height\="124" width\="124" x\="163" y\="161"/>\n</element>\n</graph>
|
||||
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/tcp-client-server/src/main/resources/META-INF/spring/integration/tcpClientServerDemo.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="GatewayModelElement" type\="gateway">\n<structure end\="863" endstart\="863" start\="698" startend\="863"/>\n<bounds height\="124" width\="124" x\="163" y\="17"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="1065" endstart\="1065" start\="1039" startend\="1065"/>\n<bounds height\="124" width\="124" x\="307" y\="17"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="1097" endstart\="1097" start\="1069" startend\="1097"/>\n<bounds height\="124" width\="124" x\="19" y\="17"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="1531" endstart\="1531" start\="1506" startend\="1531"/>\n<bounds height\="124" width\="124" x\="19" y\="161"/>\n</element>\n<element clazz\="ServiceActivatorModelElement" type\="service-activator">\n<structure end\="1628" endstart\="1628" start\="1534" startend\="1628"/>\n<bounds height\="124" width\="124" x\="163" y\="161"/>\n</element>\n</graph>
|
||||
eclipse.preferences.version=1
|
||||
@@ -0,0 +1,23 @@
|
||||
#Fri Oct 01 15:50:57 EDT 2010
|
||||
//org.springframework.ide.eclipse.beans.core.default.version.http\://www.springframework.org/schema/aop=
|
||||
//org.springframework.ide.eclipse.beans.core.default.version.http\://www.springframework.org/schema/beans=
|
||||
//org.springframework.ide.eclipse.beans.core.default.version.http\://www.springframework.org/schema/context=
|
||||
//org.springframework.ide.eclipse.beans.core.default.version.http\://www.springframework.org/schema/integration=
|
||||
//org.springframework.ide.eclipse.beans.core.default.version.http\://www.springframework.org/schema/jee=
|
||||
//org.springframework.ide.eclipse.beans.core.default.version.http\://www.springframework.org/schema/lang=
|
||||
//org.springframework.ide.eclipse.beans.core.default.version.http\://www.springframework.org/schema/task=
|
||||
//org.springframework.ide.eclipse.beans.core.default.version.http\://www.springframework.org/schema/tx=
|
||||
//org.springframework.ide.eclipse.beans.core.default.version.http\://www.springframework.org/schema/util=
|
||||
//org.springframework.ide.eclipse.beans.core.prefix.http\://www.springframework.org/schema/aop=aop
|
||||
//org.springframework.ide.eclipse.beans.core.prefix.http\://www.springframework.org/schema/beans=beans
|
||||
//org.springframework.ide.eclipse.beans.core.prefix.http\://www.springframework.org/schema/context=context
|
||||
//org.springframework.ide.eclipse.beans.core.prefix.http\://www.springframework.org/schema/integration=int
|
||||
//org.springframework.ide.eclipse.beans.core.prefix.http\://www.springframework.org/schema/jee=jee
|
||||
//org.springframework.ide.eclipse.beans.core.prefix.http\://www.springframework.org/schema/lang=lang
|
||||
//org.springframework.ide.eclipse.beans.core.prefix.http\://www.springframework.org/schema/task=task
|
||||
//org.springframework.ide.eclipse.beans.core.prefix.http\://www.springframework.org/schema/tx=tx
|
||||
//org.springframework.ide.eclipse.beans.core.prefix.http\://www.springframework.org/schema/util=util
|
||||
eclipse.preferences.version=1
|
||||
org.springframework.ide.eclipse.beans.core.default.version.check.classpath=true
|
||||
org.springframework.ide.eclipse.beans.core.enable.project.preferences=true
|
||||
org.springframework.ide.eclipse.beans.core.loadNamespaceHandlerFromClasspath=true
|
||||
14
basic/tcp-client-server/.springBeans
Normal file
14
basic/tcp-client-server/.springBeans
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beansProjectDescription>
|
||||
<version>1</version>
|
||||
<pluginVersion><![CDATA[2.5.0.201008251000-M3]]></pluginVersion>
|
||||
<configSuffixes>
|
||||
<configSuffix><![CDATA[xml]]></configSuffix>
|
||||
</configSuffixes>
|
||||
<enableImports><![CDATA[false]]></enableImports>
|
||||
<configs>
|
||||
<config>src/main/resources/META-INF/spring/integration/tcpClientServerDemo-context.xml</config>
|
||||
</configs>
|
||||
<configSets>
|
||||
</configSets>
|
||||
</beansProjectDescription>
|
||||
72
basic/tcp-client-server/pom.xml
Normal file
72
basic/tcp-client-server/pom.xml
Normal file
@@ -0,0 +1,72 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>
|
||||
<groupId>org.springframework.integration.samples</groupId>
|
||||
<artifactId>tcp-client-server</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<name>Spring Integration TCP Client Server Sample</name>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<spring.version>3.0.3.RELEASE</spring.version>
|
||||
<spring.integration.version>2.0.0.M7</spring.integration.version>
|
||||
<log4j.version>1.2.16</log4j.version>
|
||||
<junit.version>4.7</junit.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-ip</artifactId>
|
||||
<version>${spring.integration.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>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<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>
|
||||
<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>
|
||||
8
basic/tcp-client-server/readme.txt
Normal file
8
basic/tcp-client-server/readme.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
This is a place to get started with tcp. It demonstrates a simple message flow represented by the diagram below:
|
||||
|
||||
Gateway -> Channel -> TcpOutboundGateway -> <===Socket===> -> TcpInboundGateway -> Channel -> ServiceActivator
|
||||
|
||||
The service returns a response which the inbound gateway sends back over the socket to the outbound gateway
|
||||
and the result is returned to the client that invoked the original SimpleGateway method.
|
||||
|
||||
To run sample simply execute a test case in org.springframework.integration.samples.tcpclientservice package
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.tcpclientserver;
|
||||
|
||||
/**
|
||||
* Simple service that receives data in a byte array,
|
||||
* converts it to a String and appends it to 'echo:'.
|
||||
*
|
||||
* @author Gary Russell
|
||||
*
|
||||
*/
|
||||
public class EchoService {
|
||||
|
||||
public String test(byte[] bytes) {
|
||||
return "echo:" + new String(bytes);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.tcpclientserver;
|
||||
|
||||
/**
|
||||
* @author Gary Russell
|
||||
*
|
||||
*/
|
||||
public interface SimpleGateway {
|
||||
|
||||
public byte[] send(String text);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:ip="http://www.springframework.org/schema/integration/ip"
|
||||
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/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd">
|
||||
|
||||
<!-- Client side -->
|
||||
|
||||
<gateway id="gw"
|
||||
service-interface="org.springframework.integration.samples.tcpclientserver.SimpleGateway"
|
||||
default-request-channel="input"/>
|
||||
|
||||
<ip:tcp-connection-factory id="client"
|
||||
type="client"
|
||||
host="localhost"
|
||||
port="11111"
|
||||
single-use="true"
|
||||
so-timeout="10000"
|
||||
/>
|
||||
|
||||
<channel id="input" />
|
||||
|
||||
<ip:tcp-outbound-gateway id="outGateway"
|
||||
request-channel="input"
|
||||
connection-factory="client"
|
||||
request-timeout="10000"
|
||||
reply-timeout="10000"
|
||||
/>
|
||||
|
||||
<!-- Server side -->
|
||||
|
||||
<ip:tcp-connection-factory id="crLfServer"
|
||||
type="server"
|
||||
port="11111"/>
|
||||
|
||||
<ip:tcp-inbound-gateway id="gatewayCrLf"
|
||||
connection-factory="crLfServer"
|
||||
request-channel="toSA" />
|
||||
|
||||
<channel id="toSA" />
|
||||
|
||||
<service-activator input-channel="toSA"
|
||||
ref="echoService"
|
||||
method="test"
|
||||
/>
|
||||
|
||||
<beans:bean id="echoService"
|
||||
class="org.springframework.integration.samples.tcpclientserver.EchoService" />
|
||||
|
||||
</beans:beans>
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.tcpclientserver;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
|
||||
/**
|
||||
* Demonstrates the use of a gateway as an entry point into the integration flow.
|
||||
* The message generated by the gateway is sent over tcp by the outbound gateway
|
||||
* to the inbound gateway. In turn the inbound gateway sends the message to an
|
||||
* echo service and the echoed response comes back over tcp and is returned to
|
||||
* the test case for verification.
|
||||
*
|
||||
* @author Gary Russell
|
||||
*
|
||||
*/
|
||||
@ContextConfiguration("/META-INF/spring/integration/tcpClientServerDemo-context.xml")
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class TcpClientServerDemoTest {
|
||||
|
||||
@Autowired
|
||||
SimpleGateway gw;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
byte[] echo = gw.send("Hello world!");
|
||||
String result = new String(echo);
|
||||
System.out.println(result);
|
||||
assertEquals("echo:Hello world!", result);
|
||||
}
|
||||
}
|
||||
28
basic/tcp-client-server/src/test/resources/log4j.xml
Normal file
28
basic/tcp-client-server/src/test/resources/log4j.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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.integration.samples">
|
||||
<level value="debug" />
|
||||
</logger>
|
||||
|
||||
<!-- Root Logger -->
|
||||
<root>
|
||||
<priority value="warn" />
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
||||
Reference in New Issue
Block a user