Updated service-activator to use new SimpleEndpoint and DefaultMessageHandler. Modified EndpointInterceptor for preHandle/aroundHandle/postHandle with access-to and return-values-for the request/reply Messages.
This commit is contained in:
@@ -19,8 +19,8 @@ package org.springframework.integration.config;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.springframework.integration.endpoint.interceptor.EndpointInterceptorAdapter;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageTarget;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -35,11 +35,11 @@ public class TestAroundSendEndpointInterceptor extends EndpointInterceptorAdapte
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean aroundSend(Message<?> message, MessageTarget endpoint) {
|
||||
public Message<?> aroundHandle(Message<?> message, MessageHandler handler) {
|
||||
this.counter.incrementAndGet();
|
||||
boolean result = endpoint.send(message);
|
||||
Message<?> reply = handler.handle(message);
|
||||
this.counter.incrementAndGet();
|
||||
return result;
|
||||
return reply;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,9 +34,9 @@ public class TestPreSendInterceptor extends EndpointInterceptorAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preSend(Message<?> message) {
|
||||
public Message<?> preHandle(Message<?> message) {
|
||||
this.counter.incrementAndGet();
|
||||
return true;
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.integration.endpoint;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -34,17 +35,19 @@ import org.springframework.integration.message.StringMessage;
|
||||
public class ReturnAddressTests {
|
||||
|
||||
@Test
|
||||
public void testReturnAddressOverrides() {
|
||||
public void testNextTargetOverrides() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"returnAddressTests.xml", this.getClass());
|
||||
MessageChannel channel1 = (MessageChannel) context.getBean("channel1WithOverride");
|
||||
PollableChannel replyChannel = (PollableChannel) context.getBean("replyChannel");
|
||||
context.start();
|
||||
Message<String> message = MessageBuilder.fromPayload("*")
|
||||
.setReturnAddress("replyChannel").build();
|
||||
.setNextTarget("replyChannel").build();
|
||||
channel1.send(message);
|
||||
Message<?> response = replyChannel.receive(3000);
|
||||
assertNotNull(response);
|
||||
PollableChannel outputChannel = (PollableChannel) context.getBean("channel2");
|
||||
assertNull(outputChannel.receive(0));
|
||||
assertEquals("**", response.getPayload());
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.endpoint.MessageEndpoint;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.transaction.IllegalTransactionStateException;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
@@ -156,11 +157,16 @@ public class TransactionInterceptorTests {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalTransactionStateException.class)
|
||||
public void testPropagationMandatoryCalledWithoutTransaction() {
|
||||
public void testPropagationMandatoryCalledWithoutTransaction() throws Throwable {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"transactionInterceptorPropagationTests.xml", this.getClass());
|
||||
final MessageEndpoint endpoint = (MessageEndpoint) context.getBean("mandatory");
|
||||
endpoint.send(new StringMessage("test"));
|
||||
try {
|
||||
endpoint.send(new StringMessage("test"));
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
throw e.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user