INT-3465:Content Enricher Improvements
JIRA: https://jira.spring.io/browse/INT-3465 Add support for adding/removing individual recipients to the RecipientListRouter Modify documentation in what's new and spring-integration-4.1.xsd Polishing `AbstractRemoteFileOutboundGateway`: close `outputStream` before `file.delete()` to release exclusive file-lock
This commit is contained in:
@@ -34,19 +34,19 @@ 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.messaging.MessageHandlingException;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.transformer.ContentEnricher;
|
||||
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;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -163,6 +163,8 @@ public class EnricherParserTests {
|
||||
assertEquals(Gender.MALE, headers.get("testBean"));
|
||||
assertEquals("foo", headers.get("sourceName"));
|
||||
assertEquals("test", headers.get("notOverwrite"));
|
||||
requests.unsubscribe(foo);
|
||||
adviceCalled--;
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?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"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/util
|
||||
http://www.springframework.org/schema/util/spring-util.xsd">
|
||||
|
||||
<channel id="input"/>
|
||||
|
||||
<channel id="output">
|
||||
<queue />
|
||||
</channel>
|
||||
|
||||
<header-enricher input-channel="requests1" output-channel="requests">
|
||||
<header-channels-to-string />
|
||||
</header-enricher>
|
||||
|
||||
<channel id="requests"/>
|
||||
|
||||
<channel id="replies"/>
|
||||
|
||||
<enricher id="enricher" input-channel="input"
|
||||
request-channel="requests1" request-timeout="1234"
|
||||
reply-timeout="9876" reply-channel="replies"
|
||||
order="99" should-clone-payload="true" output-channel="output">
|
||||
<property name="name" expression="payload.sourceName" null-result-expression="'Could not determine the name'"/>
|
||||
<property name="age" value="42" null-result-expression="'11'"/>
|
||||
<property name="gender" value="#{testBean}"/>
|
||||
<property name="married" null-result-expression="'1'"/>
|
||||
|
||||
<header name="foo" value="bar" null-result-expression="'Could not determine the foo'"/>
|
||||
<header name="testBean" expression="@testBean" null-result-expression="'Could not determine the testBean'"/>
|
||||
<header name="sourceName" null-result-expression="'Could not determine the sourceName'"/>
|
||||
<header name="notOverwrite" expression="payload.sourceName" overwrite="false"
|
||||
null-result-expression="'Could not determine the notOverwrite'"/>
|
||||
|
||||
<request-handler-advice-chain>
|
||||
<beans:bean class="org.springframework.integration.config.xml.EnricherParserTests4$FooAdvice" />
|
||||
</request-handler-advice-chain>
|
||||
</enricher>
|
||||
|
||||
<util:constant id="testBean" static-field="org.springframework.integration.config.xml.EnricherParserTests4$Gender.MALE"/>
|
||||
|
||||
</beans:beans>
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright 2002-2013 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.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Liujiong
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class EnricherParserTests4 {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
private static volatile int adviceCalled;
|
||||
|
||||
@Test
|
||||
public void nullResultIntegrationTest() {
|
||||
SubscribableChannel requests = context.getBean("requests", SubscribableChannel.class);
|
||||
|
||||
class NullFoo extends AbstractReplyProducingMessageHandler {
|
||||
|
||||
@Override
|
||||
protected Object handleRequestMessage(Message<?> requestMessage) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
NullFoo foo = new NullFoo();
|
||||
foo.setOutputChannel(context.getBean("replies", MessageChannel.class));
|
||||
requests.subscribe(foo);
|
||||
Target original = new Target();
|
||||
Message<?> request = MessageBuilder.withPayload(original).setHeader("sourceName", "test")
|
||||
.setHeader("notOverwrite", "test").build();
|
||||
context.getBean("input", MessageChannel.class).send(request);
|
||||
Message<?> reply = context.getBean("output", PollableChannel.class).receive(0);
|
||||
Target enriched = (Target) reply.getPayload();
|
||||
assertEquals("Could not determine the name", enriched.getName());
|
||||
assertEquals(11, enriched.getAge());
|
||||
assertEquals(null, enriched.getGender());
|
||||
assertTrue(enriched.isMarried());
|
||||
assertNotSame(original, enriched);
|
||||
assertEquals(1, adviceCalled);
|
||||
|
||||
MessageHeaders headers = reply.getHeaders();
|
||||
assertEquals("Could not determine the foo", headers.get("foo"));
|
||||
assertEquals("Could not determine the testBean", headers.get("testBean"));
|
||||
assertEquals("Could not determine the sourceName", headers.get("sourceName"));
|
||||
assertEquals("test", headers.get("notOverwrite"));
|
||||
adviceCalled--;
|
||||
requests.unsubscribe(foo);
|
||||
}
|
||||
|
||||
|
||||
public static class Target implements Cloneable {
|
||||
|
||||
private volatile String name;
|
||||
|
||||
private volatile int age;
|
||||
|
||||
private volatile Gender gender;
|
||||
|
||||
private volatile boolean married;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public Gender getGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public void setGender(Gender gender) {
|
||||
this.gender = gender;
|
||||
}
|
||||
|
||||
public boolean isMarried() {
|
||||
return married;
|
||||
}
|
||||
|
||||
public void setMarried(boolean married) {
|
||||
this.married = married;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
Target copy = new Target();
|
||||
copy.setName(this.name);
|
||||
copy.setAge(this.age);
|
||||
copy.setGender(this.gender);
|
||||
copy.setMarried(this.married);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum Gender {
|
||||
MALE, FEMALE
|
||||
}
|
||||
|
||||
public static class FooAdvice extends AbstractRequestHandlerAdvice {
|
||||
|
||||
@Override
|
||||
protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message) throws Exception {
|
||||
adviceCalled++;
|
||||
return callback.execute();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user