INTSAMPLES-13 Add error-channel to inbound channel adapter and tests
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,6 +21,6 @@ package org.springframework.integration.samples.tcpclientserver;
|
||||
*/
|
||||
public interface SimpleGateway {
|
||||
|
||||
public byte[] send(String text);
|
||||
public String send(String text);
|
||||
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user