From 563e0878c5da81f70e7ae162f05a6069d0040cfc Mon Sep 17 00:00:00 2001 From: Gunnar Hillert Date: Sat, 8 Dec 2012 15:24:27 -0500 Subject: [PATCH] INTSAMPLES-63 - Polish Tcp-Client-Server Sample For reference see: https://jira.springsource.org/browse/INTSAMPLES-63 * Update README.md * Code clean-up (E.g. convert spaces to tabs) * Make sample executable via Maven --- basic/tcp-client-server/README.md | 128 ++++++++++++--- basic/tcp-client-server/pom.xml | 9 ++ .../samples/tcpclientserver/CustomOrder.java | 49 +++--- .../CustomSerializerDeserializer.java | 151 +++++++++--------- .../samples/tcpclientserver/Main.java | 131 +++++++++++++++ .../samples/tcpclientserver/TelnetServer.java | 59 ------- .../TcpServerConnectionDeserializeTest.java | 2 +- .../TcpServerCustomSerializerTest.java | 2 +- .../support/CustomTestContextLoader.java | 4 +- 9 files changed, 351 insertions(+), 184 deletions(-) create mode 100644 basic/tcp-client-server/src/main/java/org/springframework/integration/samples/tcpclientserver/Main.java delete mode 100644 basic/tcp-client-server/src/main/java/org/springframework/integration/samples/tcpclientserver/TelnetServer.java diff --git a/basic/tcp-client-server/README.md b/basic/tcp-client-server/README.md index 5afb7439..dca9e14a 100644 --- a/basic/tcp-client-server/README.md +++ b/basic/tcp-client-server/README.md @@ -1,21 +1,68 @@ TCP Sample ========== -This is a place to get started with the [Transmission Control Protocol][] (TCP). It demonstrates a simple message flow represented by the diagram below: +This is the place to get started with the Samples for *Spring Integration's* support for the the [Transmission Control Protocol][] (TCP). The sample demonstrates a simple message flow represented by the diagram below: - Gateway -> Channel -> TcpOutboundGateway -> <===Socket===> -> TcpInboundGateway -> Channel -> ServiceActivator + Gateway (SimpleGateway) -> Channel -> TcpOutboundGateway -> <==Socket==> -> TcpInboundGateway -> Channel -> ServiceActivator (EchoService) -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. +The *EchoService* class 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. -## Running the Sample +Several variations of the sample are provided: -To run sample simply execute a test case in the **org.springframework.integration.samples.tcpclientserver** package. +* Client-Server Demo with explicit Transformers (Sample also provides [Telnet][] connectivity) +* Client-Server Demo with ConversionService +* Serializer Demo + * Using the Stx-Etx [Serializer][]/[Deserializer][] + * Using a Custom [Serializer][]/[Deserializer][] -Note that the test case includes an alternative configuration that uses the built-in *conversion service* and the channel *dataType* attribute, instead of explicit *Transformers*, to convert from byte arrays to Strings. +### Client-Server Demo -Simply change the *@ContextConfiguration* to switch between the two techniques. In addition, a simple telnet server is provided; see **TelnetServer** in *src/main/java*. Run this class as a Java application and then use `telnet` to connect to the service (**telnet localhost 11111**). +The Client-Server Demo illustrates 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 (Class *EchoService*) and the echoed response comes back over *TCP*. The demo uses explicit *Transformer*s to convert the *byte array* payloads to *Strings*. -Messages sent will be returned, preceded by 'echo:'. +You can execute this sample simply via Maven: + + $ mvn clean package exec:java + +Alternatively, you can also execute the **Main** method in class *org.springframework.integration.samples.tcpclientserver.Main*. In both cases you should see the following console output: + + ========================================================= + + Welcome to the Spring Integration + TCP-Client-Server Sample! + + For more information please visit: + http://www.springintegration.org/ + + ========================================================= + Detect open server socket...using port 5680 + Waiting for server to accept connections...running. + + + Please enter some text and press : + Note: + - Entering FAIL will create an exception + - Entering q will quit the application + + --> Please also check out the other samples, that are provided as JUnit tests. + --> You can also connect to the server on port '5680' using Telnet. + + + hello + echo:hello + q + Exiting application...bye. + +The respective open server socket it dynamically selected. Alternatively, you can also customize the port by providing an additional system property at startup e.g. + + $ mvn clean package exec:java -DavailableServerSocket=7777 + +#### Connect via Telnet + +The configured *Inbound Gateway* processes [CRLF][] (Carriage Return + Line Feed) delimited messages using the default [ByteArrayCrLfSerializer][]. This means that the *Inbound Gateway* works works fine as a very simple [Telnet][] server! Just start up the sample and connect to the used port: + + $ telnet localhost + +Each time you hit enter you should see your input echoed back, preceded by 'echo:' $ telnet localhost 11111 Trying 127.0.0.1... @@ -26,33 +73,74 @@ Messages sent will be returned, preceded by 'echo:'. Test echo:Test ^] - telnet> quit Connection closed. ->Note that the test case also demonstrates error handling on an inbound gateway using direct channels. If the payload is 'FAIL', the EchoService throws an exception. The gateway is configured >with an error-channel attribute. Messages sent to that channel are consumed by a transformer that concatenates the inbound message payload with the message text from the thrown exception, >returning **FAIL:Failure Demonstration** over the TCP socket. +> In order to quit the Telnet session, press `Ctrl+]` (Windows) or `Control+]` (Mac) followed by `q` or `quit`. -This can also be demonstrated with the telnet client thus... +The test case also demonstrates error handling on an *Inbound Gateway* using direct channels. If the payload is 'FAIL', the *EchoService* throws an exception. The *Gateway* is configured with an **error-channel** attribute. Messages sent to that channel are consumed by a *Transformer* that concatenates the inbound message payload with the message text from the thrown exception, returning **FAIL:Failure Demonstration** over the *TCP* socket. - $ telnet localhost 11111 +This can also be demonstrated with the Telnet client: + + telnet 127.0.0.1 5679 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. - Hello world! - echo:Hello world! + hello + echo:hello FAIL FAIL:Failure Demonstration - Hello - echo:Hello + Hello World + echo:Hello World ^] - telnet> quit Connection closed. -A third option exists for converting a stream of bytes to a domain object or message payload. You can hook up different serializers/deserializers at the connection factory which will apply the conversions right when the stream comes in to the *Gateway* and right when it goes out. +### Client-Server Demo with ConversionService -See **TcpServerConnectionDeserializeTest** for using a simple (comes with spring) Stx/Etx serializer. +This demo is similar to the previous demo. However, instead of using explicit *Transformers*, this version shows how Spring's [Conversion Service][] can be used to convert the *byte array* payloads to Strings. This demo also uses 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 return, the *Inbound Gateway* sends the message to the echo service and the echoed response comes back over *TCP* and is returned to the test case for verification. -See **TcpServerCustomSerializerTest** for creating and using your own serializers +> Please note the channel's *dataType* attribute. This attribute which will trigger the *conversion service*. + + +You can run the example by executing JUnit test **TcpClientServerDemoWithConversionServiceTest**. + +### Serializer Demo + +A third option exists for converting a stream of bytes to a domain object or message payload. You can hook up a different [Serializer][]/[Deserializer][] at the connection factory: + + + +This will apply the conversions right when the stream comes in to the *Gateway* and right when it goes out. Two examples (JUnit Tests) are provided: + +* **TcpServerConnectionDeserializeTest** for using a simple (comes with Spring) Stx/Etx [Serializer][]/[Deserializer][]. +* **TcpServerCustomSerializerTest** for creating and using your own serializers + +#### Stx-Etx Serializer Demo + +The Stx-Etx Serializer Demo shows an example of using the *Stx/Etx stream framing serializer* ([ByteArrayStxEtxSerializer][]) that is included with *Spring Integration*. This serializer reads data in an *InputStream* to a *byte array*. The data must be prefixed with the `` [control character][] and terminated by the `` [control character][]. + +We can be confident that the streams are properly handled because we explicitly send a stream with the Stx/Etx frame and the beginning and end of the actual content and the Server is configured to be able to handle the frame. In the asserts, we assert that the payload, once it reaches a component (in this case, the message listener we create and attach to the *incomingServerChannel*), does not have any of the Stx/Etx bytes. + +You can run the example by executing JUnit test **TcpServerConnectionDeserializeTest**. + +#### Using Custom Serializers + +Some use cases may dictate you needing to create your own stream handling serializers and deserializers. This sample shows a custom [Serializer][]/[Deserializer][] being used with the Java socket API on the front end (client) and the Spring Integration TCP inbound gateway with the custom serializer/deserializers. + +You can run the example by executing JUnit test **TcpServerCustomSerializerTest**. + + +[ByteArrayCrLfSerializer]: http://static.springsource.org/spring-integration/api/org/springframework/integration/ip/tcp/serializer/ByteArrayCrLfSerializer.html +[ByteArrayStxEtxSerializer]: http://static.springsource.org/spring-integration/api/org/springframework/integration/ip/tcp/serializer/ByteArrayStxEtxSerializer.html +[control character]: http://en.wikipedia.org/wiki/Control_character +[Conversion Service]: http://static.springsource.org/spring/docs/current/javadoc-api/org/springframework/core/convert/ConversionService.html +[CRLF]: http://en.wikipedia.org/wiki/Newline +[Deserializer]: http://static.springsource.org/spring/docs/current/javadoc-api/org/springframework/core/serializer/Deserializer.html +[Serializer]: http://static.springsource.org/spring/docs/current/javadoc-api/org/springframework/core/serializer/Serializer.html +[Telnet]: http://en.wikipedia.org/wiki/Telnet [Transmission Control Protocol]: http://en.wikipedia.org/wiki/Transmission_Control_Protocol \ No newline at end of file diff --git a/basic/tcp-client-server/pom.xml b/basic/tcp-client-server/pom.xml index d3ad7dea..2267a568 100644 --- a/basic/tcp-client-server/pom.xml +++ b/basic/tcp-client-server/pom.xml @@ -16,6 +16,7 @@ 2.2.0.RELEASE 1.2.17 4.10 + org.springframework.integration.samples.tcpclientserver.Main @@ -75,6 +76,14 @@ true + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + ${java.main.class} + + diff --git a/basic/tcp-client-server/src/main/java/org/springframework/integration/samples/tcpclientserver/CustomOrder.java b/basic/tcp-client-server/src/main/java/org/springframework/integration/samples/tcpclientserver/CustomOrder.java index 9ab1513f..caf442d1 100644 --- a/basic/tcp-client-server/src/main/java/org/springframework/integration/samples/tcpclientserver/CustomOrder.java +++ b/basic/tcp-client-server/src/main/java/org/springframework/integration/samples/tcpclientserver/CustomOrder.java @@ -19,36 +19,37 @@ import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; /** - * @author: ceposta + * @author Christian Posta + * @author Gunnar Hillert */ public class CustomOrder { - private int number; - private String sender; - private String message; + private int number; + private String sender; + private String message; - public CustomOrder(int number, String sender) { - this.number = number; - this.sender = sender; - } + public CustomOrder(int number, String sender) { + this.number = number; + this.sender = sender; + } - public int getNumber() { - return number; - } + public int getNumber() { + return number; + } - public String getSender() { - return sender; - } + public String getSender() { + return sender; + } - public String getMessage() { - return message; - } + public String getMessage() { + return message; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); - } + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); + } } diff --git a/basic/tcp-client-server/src/main/java/org/springframework/integration/samples/tcpclientserver/CustomSerializerDeserializer.java b/basic/tcp-client-server/src/main/java/org/springframework/integration/samples/tcpclientserver/CustomSerializerDeserializer.java index 9beaa8b4..f5592d01 100644 --- a/basic/tcp-client-server/src/main/java/org/springframework/integration/samples/tcpclientserver/CustomSerializerDeserializer.java +++ b/basic/tcp-client-server/src/main/java/org/springframework/integration/samples/tcpclientserver/CustomSerializerDeserializer.java @@ -42,104 +42,103 @@ import org.springframework.core.serializer.Serializer; * content is. After that message content is parsed from the stream, the stream is assumed * to not have anything after it. In your code you could have delimiters to mark the end * of the stream, or could agree with the client that a valid stream is only n characters, - * etc. Eitherway, since its custom, the client and server must have some predefined + * etc. Either way, since its custom, the client and server must have some predefined * assumptions in place for the communication to take place. * * - * @author: ceposta + * @author Christian Posta + * @author Gunnar Hillert */ public class CustomSerializerDeserializer implements Serializer, Deserializer{ - protected final Log logger = LogFactory.getLog(this.getClass()); + protected final Log logger = LogFactory.getLog(this.getClass()); - private static final int ORDER_NUMBER_LENGTH = 3; - private static final int SENDER_NAME_LENGTH = 10; - private static final int MESSAGE_LENGTH_LENGTH = 6; + private static final int ORDER_NUMBER_LENGTH = 3; + private static final int SENDER_NAME_LENGTH = 10; + private static final int MESSAGE_LENGTH_LENGTH = 6; + /** + * Convert a CustomOrder object into a byte-stream + * + * @param object + * @param outputStream + * @throws IOException + */ + public void serialize(CustomOrder object, OutputStream outputStream) throws IOException { + byte[] number = Integer.toString(object.getNumber()).getBytes(); + outputStream.write(number); - /** - * Convert a CustomOrder object into a byte-stream - * - * @param object - * @param outputStream - * @throws IOException - */ - public void serialize(CustomOrder object, OutputStream outputStream) throws IOException { - byte[] number = Integer.toString(object.getNumber()).getBytes(); - outputStream.write(number); + byte[] senderName = object.getSender().getBytes(); + outputStream.write(senderName); - byte[] senderName = object.getSender().getBytes(); - outputStream.write(senderName); + String lenghtPadded = pad(6, object.getMessage().length()); + byte[] length = lenghtPadded.getBytes(); + outputStream.write(length); - String lenghtPadded = pad(6, object.getMessage().length()); - byte[] length = lenghtPadded.getBytes(); - outputStream.write(length); + outputStream.write(object.getMessage().getBytes()); + outputStream.flush(); + } - outputStream.write(object.getMessage().getBytes()); - outputStream.flush(); - } + private String pad(int desiredLength, int length) { + return StringUtils.leftPad(Integer.toString(length), desiredLength, '0'); + } - private String pad(int desiredLength, int length) { - return StringUtils.leftPad(Integer.toString(length), desiredLength, '0'); - } + /** + * Convert a raw byte stream into a CustomOrder + * + * @param inputStream + * @return + * @throws IOException + */ + public CustomOrder deserialize(InputStream inputStream) throws IOException { + int orderNumber = parseOrderNumber(inputStream); + String senderName = parseSenderName(inputStream); - /** - * Convert a raw byte stream into a CustomOrder - * - * @param inputStream - * @return - * @throws IOException - */ - public CustomOrder deserialize(InputStream inputStream) throws IOException { - int orderNumber = parseOrderNumber(inputStream); - String senderName = parseSenderName(inputStream); + CustomOrder order = new CustomOrder(orderNumber, senderName); + String message = parseMessage(inputStream); + order.setMessage(message); + return order; + } - CustomOrder order = new CustomOrder(orderNumber, senderName); - String message = parseMessage(inputStream); - order.setMessage(message); - return order; - } + private String parseMessage(InputStream inputStream) throws IOException { + String lengthString = parseString(inputStream, MESSAGE_LENGTH_LENGTH); + int lengthOfMessage = Integer.valueOf(lengthString); - private String parseMessage(InputStream inputStream) throws IOException { - String lengthString = parseString(inputStream, MESSAGE_LENGTH_LENGTH); - int lengthOfMessage = Integer.valueOf(lengthString); + String message = parseString(inputStream, lengthOfMessage); + return message; + } - String message = parseString(inputStream, lengthOfMessage); - return message; - } + private String parseString(InputStream inputStream, int length) throws IOException { + StringBuilder builder = new StringBuilder(); - private String parseString(InputStream inputStream, int length) throws IOException { - StringBuilder builder = new StringBuilder(); + int c; + for (int i = 0; i < length; ++i) { + c = inputStream.read(); + checkClosure(c); + builder.append((char)c); + } - int c; - for (int i = 0; i < length; ++i) { - c = inputStream.read(); - checkClosure(c); - builder.append((char)c); - } + return builder.toString(); + } - return builder.toString(); - } + private String parseSenderName(InputStream inputStream) throws IOException { + return parseString(inputStream, SENDER_NAME_LENGTH); + } - private String parseSenderName(InputStream inputStream) throws IOException { - return parseString(inputStream, SENDER_NAME_LENGTH); - } + private int parseOrderNumber(InputStream inputStream) throws IOException { + String value = parseString(inputStream, ORDER_NUMBER_LENGTH); + return Integer.valueOf(value.toString()); + } - private int parseOrderNumber(InputStream inputStream) throws IOException { - String value = parseString(inputStream, ORDER_NUMBER_LENGTH); - return Integer.valueOf(value.toString()); - } - - - /** - * Check whether the byte passed in is the "closed socket" byte - * Note, I put this in here just as an example, but you could just extend the - * {@link org.springframework.integration.ip.tcp.serializer.AbstractByteArraySerializer} class - * which has this method - * - * @param bite - * @throws IOException - */ + /** + * Check whether the byte passed in is the "closed socket" byte + * Note, I put this in here just as an example, but you could just extend the + * {@link org.springframework.integration.ip.tcp.serializer.AbstractByteArraySerializer} class + * which has this method + * + * @param bite + * @throws IOException + */ protected void checkClosure(int bite) throws IOException { if (bite < 0) { logger.debug("Socket closed during message assembly"); diff --git a/basic/tcp-client-server/src/main/java/org/springframework/integration/samples/tcpclientserver/Main.java b/basic/tcp-client-server/src/main/java/org/springframework/integration/samples/tcpclientserver/Main.java new file mode 100644 index 00000000..960f69f1 --- /dev/null +++ b/basic/tcp-client-server/src/main/java/org/springframework/integration/samples/tcpclientserver/Main.java @@ -0,0 +1,131 @@ +/* + * 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.tcpclientserver; + +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +import org.springframework.context.support.GenericXmlApplicationContext; +import org.springframework.core.env.MapPropertySource; +import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory; +import org.springframework.integration.ip.util.TestingUtilities; +import org.springframework.integration.test.util.SocketUtils; + +/** + * 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. + * + * The test uses explicit transformers to convert the byte array payloads to + * Strings. + * + * Several other samples are provided as JUnit test-cases: + * + *
    + *
  • TcpClientServerDemoWithConversionServiceTest
  • + *
  • TcpServerConnectionDeserializeTest
  • + *
  • TcpServerCustomSerializerTest
  • + *
+ * + * @author Gunnar Hillert + * + */ +public final class Main { + + /** + * Prevent instantiation. + */ + private Main() {} + + /** + * Load the Spring Integration Application Context + * + * @param args - command line arguments + */ + public static void main(final String... args) { + + final Scanner scanner = new Scanner(System.in); + + System.out.println("\n=========================================================" + + "\n " + + "\n Welcome to the Spring Integration " + + "\n TCP-Client-Server Sample! " + + "\n " + + "\n For more information please visit: " + + "\n http://www.springintegration.org/ " + + "\n " + + "\n=========================================================" ); + + final GenericXmlApplicationContext context = Main.setupContext(); + final SimpleGateway gateway = context.getBean(SimpleGateway.class); + final AbstractServerConnectionFactory crLfServer = context.getBean(AbstractServerConnectionFactory.class); + + System.out.print("Waiting for server to accept connections..."); + TestingUtilities.waitListening(crLfServer, 10000L); + System.out.println("running.\n\n"); + + System.out.println("Please enter some text and press : "); + System.out.println("\tNote:"); + System.out.println("\t- Entering FAIL will create an exception"); + System.out.println("\t- Entering q will quit the application"); + System.out.print("\n"); + System.out.println("\t--> Please also check out the other samples, " + + "that are provided as JUnit tests."); + System.out.println("\t--> You can also connect to the server on port '" + crLfServer.getPort() + "' using Telnet.\n\n"); + + while (true) { + + final String input = scanner.nextLine(); + + if("q".equals(input.trim())) { + break; + } + else { + final String result = gateway.send(input); + System.out.println(result); + } + } + + System.out.println("Exiting application...bye."); + System.exit(0); + + } + + public static GenericXmlApplicationContext setupContext() { + final GenericXmlApplicationContext context = new GenericXmlApplicationContext(); + + System.out.print("Detect open server socket..."); + int availableServerSocket = SocketUtils.findAvailableServerSocket(5678); + + final Map sockets = new HashMap(); + sockets.put("availableServerSocket", availableServerSocket); + + final MapPropertySource propertySource = new MapPropertySource("sockets", sockets); + + context.getEnvironment().getPropertySources().addLast(propertySource); + + System.out.println("using port " + context.getEnvironment().getProperty("availableServerSocket")); + + context.load("classpath:META-INF/spring/integration/tcpClientServerDemo-context.xml"); + context.registerShutdownHook(); + context.refresh(); + + return context; + } +} diff --git a/basic/tcp-client-server/src/main/java/org/springframework/integration/samples/tcpclientserver/TelnetServer.java b/basic/tcp-client-server/src/main/java/org/springframework/integration/samples/tcpclientserver/TelnetServer.java deleted file mode 100644 index 3b7490a1..00000000 --- a/basic/tcp-client-server/src/main/java/org/springframework/integration/samples/tcpclientserver/TelnetServer.java +++ /dev/null @@ -1,59 +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.tcpclientserver; - -import java.util.HashMap; -import java.util.Map; - -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.core.env.MapPropertySource; - -/** - * The configured inbound gateway uses CRLF delimited messages which means - * it works fine as a very simple Telnet server - connect using - * telnet localhost 11111 - each time you hit enter you should see your input - * echoed back, preceded by 'echo:'. - * - * Alternatively, you can also customize the port by providing an additional system - * property at startup e.g. -DavailableServerSocket=7777 - * - * @author Gary Russell - * @author Gunnar Hillert - * - */ -public class TelnetServer { - - public static void main(String[] args) throws Exception { - - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"/META-INF/spring/integration/tcpClientServerDemo-context.xml"}, false); - - final Map sockets = new HashMap(); - sockets.put("availableServerSocket", 11111); - - final MapPropertySource propertySource = new MapPropertySource("sockets", sockets); - - context.getEnvironment().getPropertySources().addLast(propertySource); - context.refresh(); - - System.out.println("Use telnet and connect to port: " + context.getEnvironment().getProperty("availableServerSocket")); - System.out.println("Press Enter/Return in the console to exit"); - System.in.read(); - System.out.println("exiting application...bye.\n\n"); - System.exit(0); - } - -} diff --git a/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpServerConnectionDeserializeTest.java b/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpServerConnectionDeserializeTest.java index 6044fa28..a80c2c48 100644 --- a/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpServerConnectionDeserializeTest.java +++ b/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpServerConnectionDeserializeTest.java @@ -44,7 +44,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * assert that the payload, once it reaches a component (in this case, the message listener * we create and attach to the incomingServerChannel), does not have any of the Stx/Etx bytes. * - * @author: ceposta + * @author Christian Posta * @author Gunnar Hillert */ @RunWith(SpringJUnit4ClassRunner.class) diff --git a/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpServerCustomSerializerTest.java b/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpServerCustomSerializerTest.java index 970892a4..234e8d6a 100644 --- a/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpServerCustomSerializerTest.java +++ b/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpServerCustomSerializerTest.java @@ -50,7 +50,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * the Java socket API on the front end (client) and the Spring Integration TCP inbound * gateway with the custom serializer/deserializers. * - * @author ceposta + * @author Christian Posta * @author Gunnar Hillert * */ diff --git a/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/support/CustomTestContextLoader.java b/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/support/CustomTestContextLoader.java index e0d8793d..d5e3bd1f 100644 --- a/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/support/CustomTestContextLoader.java +++ b/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/support/CustomTestContextLoader.java @@ -26,9 +26,7 @@ import org.springframework.test.context.MergedContextConfiguration; import org.springframework.test.context.support.GenericXmlContextLoader; /** - * * @author Gunnar Hillert - * */ public class CustomTestContextLoader extends GenericXmlContextLoader { @@ -44,7 +42,7 @@ public class CustomTestContextLoader extends GenericXmlContextLoader { sockets.put("availableServerSocket", availableServerSocket); if (LOGGER.isInfoEnabled()) { - LOGGER.info("Available Server Socket 1: " + availableServerSocket); + LOGGER.info("Available server socket: " + availableServerSocket); } final MapPropertySource propertySource = new MapPropertySource("sockets", sockets);