INT-3402-3: Channels Late Resolution #3
JIRA: https://jira.spring.io/browse/INT-3402 * Add late resolution of channel names for the `MessagingGatewaySupport` * Implement delegate logic for internal implementations like `ContentEnricher.Gateway`
This commit is contained in:
committed by
Gary Russell
parent
1c051416ce
commit
7f74c571d4
@@ -44,7 +44,7 @@
|
||||
</enricher>
|
||||
|
||||
<enricher input-channel="input2" output-channel="output">
|
||||
<header name="foo" expression="new java.util.Date()" type="int"/>
|
||||
<header name="foo" expression="new java.util.Date()"/>
|
||||
</enricher>
|
||||
|
||||
<util:constant id="testBean" static-field="org.springframework.integration.config.xml.EnricherParserTests$Gender.MALE"/>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -34,6 +34,7 @@ import org.springframework.beans.TypeMismatchException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice;
|
||||
@@ -44,7 +45,6 @@ import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandlingException;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -82,7 +82,8 @@ public class EnricherParserTests {
|
||||
assertNull(accessor.getPropertyValue("requestPayloadExpression"));
|
||||
assertNotNull(TestUtils.getPropertyValue(enricher, "gateway.beanFactory"));
|
||||
|
||||
Map<Expression, Expression> propertyExpressions = (Map<Expression, Expression>) accessor.getPropertyValue("propertyExpressions");
|
||||
Map<Expression, Expression> propertyExpressions =
|
||||
(Map<Expression, Expression>) accessor.getPropertyValue("propertyExpressions");
|
||||
for (Map.Entry<Expression, Expression> e : propertyExpressions.entrySet()) {
|
||||
if ("name".equals(e.getKey().getExpressionString())) {
|
||||
assertEquals("payload.sourceName", e.getValue().getExpressionString());
|
||||
@@ -110,7 +111,7 @@ public class EnricherParserTests {
|
||||
Object endpoint = context.getBean("enricher");
|
||||
|
||||
Long requestTimeout = TestUtils.getPropertyValue(endpoint, "handler.requestTimeout", Long.class);
|
||||
Long replyTimeout = TestUtils.getPropertyValue(endpoint, "handler.replyTimeout", Long.class);
|
||||
Long replyTimeout = TestUtils.getPropertyValue(endpoint, "handler.replyTimeout", Long.class);
|
||||
|
||||
assertEquals(Long.valueOf(1234L), requestTimeout);
|
||||
assertEquals(Long.valueOf(9876L), replyTimeout);
|
||||
@@ -130,6 +131,9 @@ public class EnricherParserTests {
|
||||
|
||||
@Test
|
||||
public void integrationTest() {
|
||||
QueueChannel output = context.getBean("output", QueueChannel.class);
|
||||
output.purge(null);
|
||||
|
||||
SubscribableChannel requests = context.getBean("requests", SubscribableChannel.class);
|
||||
|
||||
class Foo extends AbstractReplyProducingMessageHandler {
|
||||
@@ -149,7 +153,8 @@ public class EnricherParserTests {
|
||||
.setHeader("notOverwrite", "test")
|
||||
.build();
|
||||
context.getBean("input", MessageChannel.class).send(request);
|
||||
Message<?> reply = context.getBean("output", PollableChannel.class).receive(0);
|
||||
|
||||
Message<?> reply = output.receive(0);
|
||||
Target enriched = (Target) reply.getPayload();
|
||||
assertEquals("foo", enriched.getName());
|
||||
assertEquals(42, enriched.getAge());
|
||||
@@ -193,6 +198,7 @@ public class EnricherParserTests {
|
||||
public String getSourceName() {
|
||||
return sourceName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Target implements Cloneable {
|
||||
@@ -246,10 +252,12 @@ public class EnricherParserTests {
|
||||
copy.setMarried(this.married);
|
||||
return copy;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static enum Gender {
|
||||
MALE, FEMALE
|
||||
|
||||
}
|
||||
|
||||
public static class FooAdvice extends AbstractRequestHandlerAdvice {
|
||||
@@ -261,4 +269,5 @@ public class EnricherParserTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -118,7 +118,8 @@ public class ContentEnricherTests {
|
||||
protected Object handleRequestMessage(Message<?> requestMessage) {
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
return new Target("child");
|
||||
@@ -144,7 +145,8 @@ public class ContentEnricherTests {
|
||||
|
||||
try {
|
||||
enricher.handleMessage(requestMessage);
|
||||
} catch (ReplyRequiredException e) {
|
||||
}
|
||||
catch (ReplyRequiredException e) {
|
||||
assertEquals("No reply produced by handler 'Enricher', and its 'requiresReply' property is set to true.", e.getMessage());
|
||||
return;
|
||||
}
|
||||
@@ -173,8 +175,9 @@ public class ContentEnricherTests {
|
||||
Message<?> requestMessage = MessageBuilder.withPayload(target).setReplyChannel(replyChannel).build();
|
||||
|
||||
try {
|
||||
enricher.handleMessage(requestMessage);
|
||||
} catch (MessageDeliveryException e) {
|
||||
enricher.handleMessage(requestMessage);
|
||||
}
|
||||
catch (MessageDeliveryException e) {
|
||||
assertEquals("failed to send message to channel '" + requestChannelName
|
||||
+ "' within timeout: " + requestTimeout, e.getMessage());
|
||||
return;
|
||||
@@ -220,8 +223,9 @@ public class ContentEnricherTests {
|
||||
enricher.setBeanFactory(mock(BeanFactory.class));
|
||||
|
||||
try {
|
||||
enricher.afterPropertiesSet();
|
||||
} catch (IllegalArgumentException e) {
|
||||
enricher.afterPropertiesSet();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
assertEquals("If the replyChannel is set, then the requestChannel must not be null", e.getMessage());
|
||||
return;
|
||||
}
|
||||
@@ -236,8 +240,9 @@ public class ContentEnricherTests {
|
||||
enricher.setBeanFactory(mock(BeanFactory.class));
|
||||
|
||||
try {
|
||||
enricher.setReplyTimeout(null);
|
||||
} catch (IllegalArgumentException e) {
|
||||
enricher.setReplyTimeout(null);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("replyTimeout must not be null", e.getMessage());
|
||||
return;
|
||||
}
|
||||
@@ -252,8 +257,9 @@ public class ContentEnricherTests {
|
||||
enricher.setBeanFactory(mock(BeanFactory.class));
|
||||
|
||||
try {
|
||||
enricher.setRequestTimeout(null);
|
||||
} catch (IllegalArgumentException e) {
|
||||
enricher.setRequestTimeout(null);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("requestTimeout must not be null", e.getMessage());
|
||||
return;
|
||||
}
|
||||
@@ -286,10 +292,11 @@ public class ContentEnricherTests {
|
||||
enricher.setBeanFactory(mock(BeanFactory.class));
|
||||
|
||||
try {
|
||||
enricher.afterPropertiesSet();
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("If the replyChannel is set, then the requestChannel must not be null", e.getMessage());
|
||||
return;
|
||||
enricher.afterPropertiesSet();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
assertEquals("If the replyChannel is set, then the requestChannel must not be null", e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
fail("Expected an IllegalArgumentException to be thrown.");
|
||||
@@ -414,10 +421,11 @@ public class ContentEnricherTests {
|
||||
Message<?> requestMessage = MessageBuilder.withPayload(target).setReplyChannel(replyChannel).build();
|
||||
|
||||
try {
|
||||
enricher.handleMessage(requestMessage);
|
||||
} catch (MessageHandlingException e) {
|
||||
enricher.handleMessage(requestMessage);
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
assertThat(e.getMessage(), containsString("Failed to clone payload object"));
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
fail("Expected a MessageHandlingException to be thrown.");
|
||||
@@ -478,6 +486,7 @@ public class ContentEnricherTests {
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -517,6 +526,7 @@ public class ContentEnricherTests {
|
||||
clone.setChild(this.child);
|
||||
return clone;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final class TargetUser {
|
||||
@@ -557,6 +567,7 @@ public class ContentEnricherTests {
|
||||
public Object clone() {
|
||||
throw new IllegalStateException("Cloning not possible");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user