INTSAMPLES-13 Add error-channel to inbound channel adapter and tests

This commit is contained in:
Gary Russell
2010-11-17 21:46:09 -05:00
parent 3714a8a569
commit 12863155aa
5 changed files with 58 additions and 7 deletions

View File

@@ -24,8 +24,11 @@ package org.springframework.integration.samples.tcpclientserver;
*/
public class EchoService {
public String test(byte[] bytes) {
return "echo:" + new String(bytes);
public String test(String input) {
if ("FAIL".equals(input)) {
throw new RuntimeException("Failure Demonstration");
}
return "echo:" + input;
}
}

View File

@@ -21,6 +21,6 @@ package org.springframework.integration.samples.tcpclientserver;
*/
public interface SimpleGateway {
public byte[] send(String text);
public String send(String text);
}

View File

@@ -25,10 +25,15 @@
<ip:tcp-outbound-gateway id="outGateway"
request-channel="input"
reply-channel="clientBytes2StringChannel"
connection-factory="client"
request-timeout="10000"
reply-timeout="10000"
/>
<transformer id="clientBytes2String"
input-channel="clientBytes2StringChannel"
expression="new String(payload)"/>
<!-- Server side -->
@@ -38,7 +43,8 @@
<ip:tcp-inbound-gateway id="gatewayCrLf"
connection-factory="crLfServer"
request-channel="toSA" />
request-channel="serverBytes2StringChannel"
error-channel="errorChannel"/>
<channel id="toSA" />
@@ -50,4 +56,13 @@
<beans:bean id="echoService"
class="org.springframework.integration.samples.tcpclientserver.EchoService" />
<transformer id="serverBytes2String"
input-channel="serverBytes2StringChannel"
output-channel="toSA"
expression="new String(payload)"/>
<transformer id="errorHandler"
input-channel="errorChannel"
expression="payload.failedMessage.payload + ':' + payload.cause.message"/>
</beans:beans>

View File

@@ -42,10 +42,17 @@ public class TcpClientServerDemoTest {
SimpleGateway gw;
@Test
public void test() {
byte[] echo = gw.send("Hello world!");
String result = new String(echo);
public void testHappyDay() {
String result = gw.send("Hello world!");
System.out.println(result);
assertEquals("echo:Hello world!", result);
}
@Test
public void testFail() {
String result = gw.send("FAIL");
System.out.println(result);
assertEquals("FAIL:Failure Demonstration", result);
}
}