ReplyHandler is now configurable on the DefaultMessageEndpoint. The <endpoint/> element also accepts a 'reply-handler' attribute (INT-129).

This commit is contained in:
Mark Fisher
2008-02-26 02:35:09 +00:00
parent abedfb0b3d
commit 51d02ee8ad
7 changed files with 94 additions and 1 deletions

View File

@@ -157,4 +157,18 @@ public class EndpointParserTests {
assertEquals(message, exception.getFailedMessage());
}
@Test
public void testCustomReplyHandler() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"endpointWithReplyHandler.xml", this.getClass());
MessageHandler endpoint = (MessageHandler) context.getBean("endpoint");
TestReplyHandler replyHandler = (TestReplyHandler) context.getBean("replyHandler");
assertNull(replyHandler.getLastMessage());
Message<?> message = new StringMessage("test");
endpoint.handle(message);
Message<?> reply = replyHandler.getLastMessage();
assertNotNull(reply);
assertEquals("foo", reply.getPayload());
}
}

View File

@@ -34,6 +34,10 @@ public class TestHandler implements MessageHandler {
private String replyMessageText = null;
public TestHandler() {
this(1);
}
public TestHandler(int countdown) {
this.latch = new CountDownLatch(countdown);
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright 2002-2007 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.config;
import org.springframework.integration.handler.ReplyHandler;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.MessageHeader;
/**
* @author Mark Fisher
*/
public class TestReplyHandler implements ReplyHandler {
private volatile Message<?> lastMessage;
public void handle(Message<?> replyMessage, MessageHeader originalMessageHeader) {
this.lastMessage = replyMessage;
}
public Message<?> getLastMessage() {
return this.lastMessage;
}
}

View File

@@ -0,0 +1,22 @@
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
<message-bus/>
<channel id="testChannel"/>
<endpoint id="endpoint" input-channel="testChannel" handler-ref="testHandler" reply-handler="replyHandler"/>
<beans:bean id="testHandler" class="org.springframework.integration.config.TestHandler">
<beans:property name="replyMessageText" value="foo"/>
</beans:bean>
<beans:bean id="replyHandler" class="org.springframework.integration.config.TestReplyHandler"/>
</beans:beans>