Merge branch 'master' of git.springsource.org:spring-integration/spring-integration
Conflicts: spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageSplitter.java
This commit is contained in:
@@ -31,6 +31,7 @@ import org.springframework.util.StringUtils;
|
||||
public class SplitterFactoryBean extends AbstractMessageHandlerFactoryBean {
|
||||
|
||||
private volatile Long sendTimeout;
|
||||
private volatile boolean requiresReply;
|
||||
|
||||
public void setSendTimeout(Long sendTimeout) {
|
||||
this.sendTimeout = sendTimeout;
|
||||
@@ -64,7 +65,14 @@ public class SplitterFactoryBean extends AbstractMessageHandlerFactoryBean {
|
||||
if (this.sendTimeout != null) {
|
||||
splitter.setSendTimeout(sendTimeout);
|
||||
}
|
||||
splitter.setRequiresReply(requiresReply);
|
||||
return splitter;
|
||||
}
|
||||
public boolean isRequiresReply() {
|
||||
return requiresReply;
|
||||
}
|
||||
|
||||
public void setRequiresReply(boolean requiresReply) {
|
||||
this.requiresReply = requiresReply;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,18 @@ import org.springframework.integration.MessageChannel;
|
||||
*/
|
||||
public interface AsyncMessagingOperations {
|
||||
|
||||
Future<?> asyncSend(Message<?> message);
|
||||
|
||||
Future<?> asyncSend(MessageChannel channel, Message<?> message);
|
||||
|
||||
Future<?> asyncSend(String channelName, Message<?> message);
|
||||
|
||||
Future<?> asyncConvertAndSend(Object message);
|
||||
|
||||
Future<?> asyncConvertAndSend(MessageChannel channel, Object message);
|
||||
|
||||
Future<?> asyncConvertAndSend(String channelName, Object message);
|
||||
|
||||
Future<Message<?>> asyncReceive();
|
||||
|
||||
Future<Message<?>> asyncReceive(PollableChannel channel);
|
||||
|
||||
@@ -42,6 +42,54 @@ public class AsyncMessagingTemplate extends MessagingTemplate implements AsyncMe
|
||||
(AsyncTaskExecutor) executor : new TaskExecutorAdapter(executor);
|
||||
}
|
||||
|
||||
public Future<?> asyncSend(final Message<?> message) {
|
||||
return this.executor.submit(new Runnable() {
|
||||
public void run() {
|
||||
send(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Future<?> asyncSend(final MessageChannel channel, final Message<?> message) {
|
||||
return this.executor.submit(new Runnable() {
|
||||
public void run() {
|
||||
send(channel, message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Future<?> asyncSend(final String channelName, final Message<?> message) {
|
||||
return this.executor.submit(new Runnable() {
|
||||
public void run() {
|
||||
send(channelName, message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Future<?> asyncConvertAndSend(final Object object) {
|
||||
return this.executor.submit(new Runnable() {
|
||||
public void run() {
|
||||
convertAndSend(object);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Future<?> asyncConvertAndSend(final MessageChannel channel, final Object object) {
|
||||
return this.executor.submit(new Runnable() {
|
||||
public void run() {
|
||||
convertAndSend(channel, object);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Future<?> asyncConvertAndSend(final String channelName, final Object object) {
|
||||
return this.executor.submit(new Runnable() {
|
||||
public void run() {
|
||||
convertAndSend(channelName, object);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Future<Message<?>> asyncReceive() {
|
||||
return this.executor.submit(new Callable<Message<?>>() {
|
||||
public Message<?> call() throws Exception {
|
||||
|
||||
@@ -20,6 +20,8 @@ import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageHeaders;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -38,7 +40,10 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess
|
||||
@SuppressWarnings("unchecked")
|
||||
protected final Object handleRequestMessage(Message<?> message) {
|
||||
Object result = this.splitMessage(message);
|
||||
if (result == null) {
|
||||
// return null if 'null', empty Collection or empty Array
|
||||
if ( result == null ||
|
||||
(result instanceof Collection && CollectionUtils.isEmpty((Collection<?>)result)) ||
|
||||
(result.getClass().isArray() && ObjectUtils.isEmpty((Object[]) result)) ) {
|
||||
return null;
|
||||
}
|
||||
MessageHeaders headers = message.getHeaders();
|
||||
@@ -53,7 +58,7 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess
|
||||
} else {
|
||||
messageBuilders = Collections.singletonList(this.createBuilder(result, incomingSequenceDetails, correlationId, 1, 1));
|
||||
}
|
||||
return messageBuilders.isEmpty() ? null : messageBuilders;
|
||||
return messageBuilders;
|
||||
}
|
||||
|
||||
private List<MessageBuilder> messageBuildersForArray(Object result, List<Object[]> incomingSequenceDetails, Object correlationId) {
|
||||
|
||||
@@ -1948,6 +1948,15 @@ Name of the header whose value to use.
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="expressionOrInnerEndpointDefinitionAware">
|
||||
<xsd:attributeGroup ref="inputOutputChannelGroup" />
|
||||
<xsd:attribute name="requires-reply" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Specify whether the splitter method must return a non-null value. This value will be
|
||||
FALSE by default, but if set to TRUE, a MessageHandlingException will be thrown when
|
||||
the underlying service method (or expression) returns a NULL value.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.integration.core;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@@ -47,6 +48,97 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class AsyncMessagingTemplateTests {
|
||||
|
||||
@Test
|
||||
public void asyncSendWithDefaultChannel() throws Exception {
|
||||
QueueChannel channel = new QueueChannel();
|
||||
AsyncMessagingTemplate template = new AsyncMessagingTemplate();
|
||||
template.setDefaultChannel(channel);
|
||||
Message<?> message = MessageBuilder.withPayload("test").build();
|
||||
Future<?> future = template.asyncSend(message);
|
||||
assertNull(future.get(1000, TimeUnit.MILLISECONDS));
|
||||
Message<?> result = channel.receive(0);
|
||||
assertEquals(message, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asyncSendWithExplicitChannel() throws Exception {
|
||||
QueueChannel channel = new QueueChannel();
|
||||
AsyncMessagingTemplate template = new AsyncMessagingTemplate();
|
||||
Message<?> message = MessageBuilder.withPayload("test").build();
|
||||
Future<?> future = template.asyncSend(channel, message);
|
||||
assertNull(future.get(1000, TimeUnit.MILLISECONDS));
|
||||
Message<?> result = channel.receive(0);
|
||||
assertEquals(message, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asyncSendWithResolvedChannel() throws Exception {
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
context.registerSingleton("testChannel", QueueChannel.class);
|
||||
context.refresh();
|
||||
QueueChannel channel = context.getBean("testChannel", QueueChannel.class);
|
||||
AsyncMessagingTemplate template = new AsyncMessagingTemplate();
|
||||
template.setBeanFactory(context);
|
||||
Message<?> message = MessageBuilder.withPayload("test").build();
|
||||
Future<?> future = template.asyncSend("testChannel", message);
|
||||
assertNull(future.get(1000, TimeUnit.MILLISECONDS));
|
||||
Message<?> result = channel.receive(0);
|
||||
assertEquals(message, result);
|
||||
}
|
||||
|
||||
@Test(expected = TimeoutException.class)
|
||||
public void asyncSendWithTimeoutException() throws Exception {
|
||||
QueueChannel channel = new QueueChannel(1);
|
||||
channel.send(MessageBuilder.withPayload("blocker").build());
|
||||
AsyncMessagingTemplate template = new AsyncMessagingTemplate();
|
||||
Future<?> result = template.asyncSend(channel, MessageBuilder.withPayload("test").build());
|
||||
result.get(100, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asyncConvertAndSendWithDefaultChannel() throws Exception {
|
||||
QueueChannel channel = new QueueChannel();
|
||||
AsyncMessagingTemplate template = new AsyncMessagingTemplate();
|
||||
template.setDefaultChannel(channel);
|
||||
Future<?> future = template.asyncConvertAndSend("test");
|
||||
assertNull(future.get(1000, TimeUnit.MILLISECONDS));
|
||||
Message<?> result = channel.receive(0);
|
||||
assertEquals("test", result.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asyncConvertAndSendWithExplicitChannel() throws Exception {
|
||||
QueueChannel channel = new QueueChannel();
|
||||
AsyncMessagingTemplate template = new AsyncMessagingTemplate();
|
||||
Future<?> future = template.asyncConvertAndSend(channel, "test");
|
||||
assertNull(future.get(1000, TimeUnit.MILLISECONDS));
|
||||
Message<?> result = channel.receive(0);
|
||||
assertEquals("test", result.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asyncConvertAndSendWithResolvedChannel() throws Exception {
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
context.registerSingleton("testChannel", QueueChannel.class);
|
||||
context.refresh();
|
||||
QueueChannel channel = context.getBean("testChannel", QueueChannel.class);
|
||||
AsyncMessagingTemplate template = new AsyncMessagingTemplate();
|
||||
template.setBeanFactory(context);
|
||||
Future<?> future = template.asyncConvertAndSend("testChannel", "test");
|
||||
assertNull(future.get(1000, TimeUnit.MILLISECONDS));
|
||||
Message<?> result = channel.receive(0);
|
||||
assertEquals("test", result.getPayload());
|
||||
}
|
||||
|
||||
@Test(expected = TimeoutException.class)
|
||||
public void asyncConvertAndSendWithTimeoutException() throws Exception {
|
||||
QueueChannel channel = new QueueChannel(1);
|
||||
channel.send(MessageBuilder.withPayload("blocker").build());
|
||||
AsyncMessagingTemplate template = new AsyncMessagingTemplate();
|
||||
Future<?> result = template.asyncConvertAndSend(channel, "test");
|
||||
result.get(100, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asyncReceiveWithDefaultChannel() throws Exception {
|
||||
QueueChannel channel = new QueueChannel();
|
||||
|
||||
@@ -19,13 +19,19 @@ package org.springframework.integration.router.config;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.MessageHandlingException;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -88,5 +94,14 @@ public class SplitterParserTests {
|
||||
assertEquals("test", result4.getPayload());
|
||||
assertNull(output.receive(0));
|
||||
}
|
||||
|
||||
@Test(expected=MessageHandlingException.class)
|
||||
public void splitterParserTestWithRequiresReply() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"splitterParserTests.xml", this.getClass());
|
||||
context.start();
|
||||
DirectChannel inputChannel = context.getBean("requiresReplyInput", DirectChannel.class);
|
||||
inputChannel.send(MessageBuilder.withPayload(Collections.emptyList()).build());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,11 @@
|
||||
ref="splitterImpl"
|
||||
input-channel="splitterImplementationInput"
|
||||
output-channel="output"/>
|
||||
|
||||
<splitter id="splitterImplementationRequiresReply"
|
||||
input-channel="requiresReplyInput"
|
||||
output-channel="output"
|
||||
requires-reply="true"/>
|
||||
|
||||
<beans:bean id="splitterBean" class="org.springframework.integration.router.config.TestSplitterBean"/>
|
||||
|
||||
|
||||
@@ -16,6 +16,17 @@
|
||||
|
||||
package org.springframework.integration.splitter;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
@@ -23,15 +34,6 @@ import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Iwein Fuld
|
||||
@@ -104,5 +106,4 @@ public class DefaultSplitterTests {
|
||||
Message<?> output = replyChannel.receive(15);
|
||||
assertThat(output, is(nullValue()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -191,21 +191,13 @@ public abstract class AbstractJmsTemplateBasedAdapter extends IntegrationObjectS
|
||||
&& (this.destination != null || this.destinationName != null),
|
||||
"Either a 'jmsTemplate' or *both* 'connectionFactory' and"
|
||||
+ " 'destination' (or 'destination-name') are required.");
|
||||
this.jmsTemplate = this.createDefaultJmsTemplate();
|
||||
this.jmsTemplate = this.createJmsTemplate();
|
||||
}
|
||||
this.jmsTemplate.setExplicitQosEnabled(this.explicitQosEnabled);
|
||||
this.jmsTemplate.setTimeToLive(this.timeToLive);
|
||||
this.jmsTemplate.setPriority(this.priority);
|
||||
this.jmsTemplate.setDeliveryMode(this.deliveryMode);
|
||||
if (this.messageConverter != null) {
|
||||
this.jmsTemplate.setMessageConverter(this.messageConverter);
|
||||
}
|
||||
//this.configureMessageConverter(this.jmsTemplate);
|
||||
this.initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
private JmsTemplate createDefaultJmsTemplate() {
|
||||
private JmsTemplate createJmsTemplate() {
|
||||
JmsTemplate jmsTemplate = new JmsTemplate();
|
||||
jmsTemplate.setConnectionFactory(this.connectionFactory);
|
||||
if (this.destination != null) {
|
||||
@@ -218,16 +210,18 @@ public abstract class AbstractJmsTemplateBasedAdapter extends IntegrationObjectS
|
||||
if (this.destinationResolver != null) {
|
||||
jmsTemplate.setDestinationResolver(this.destinationResolver);
|
||||
}
|
||||
jmsTemplate.setExplicitQosEnabled(this.explicitQosEnabled);
|
||||
jmsTemplate.setTimeToLive(this.timeToLive);
|
||||
jmsTemplate.setPriority(this.priority);
|
||||
jmsTemplate.setDeliveryMode(this.deliveryMode);
|
||||
if (this.messageConverter != null) {
|
||||
jmsTemplate.setMessageConverter(this.messageConverter);
|
||||
}
|
||||
return jmsTemplate;
|
||||
}
|
||||
|
||||
// protected void configureMessageConverter(JmsTemplate jmsTemplate) {
|
||||
// MessageConverter converter = jmsTemplate.getMessageConverter();
|
||||
// if (converter == null) {
|
||||
// jmsTemplate.setMessageConverter(new SimpleMessageConverter());
|
||||
// }
|
||||
// }
|
||||
protected boolean shouldExtractPayload() {
|
||||
return extractPayload;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -52,6 +52,10 @@ abstract class JmsAdapterParserUtils {
|
||||
|
||||
static final String HEADER_MAPPER_PROPERTY = "headerMapper";
|
||||
|
||||
private static final String[] JMS_TEMPLATE_ATTRIBUTES = { "destination", "destination-name",
|
||||
"connection-factory", "message-converter", "time-to-live", "priority", "delivery-persistent", "explicit-qos-enabled" };
|
||||
|
||||
|
||||
/*
|
||||
* The following constants match those of javax.jms.Session.
|
||||
* They are duplicated here to avoid a dependency in tooling.
|
||||
@@ -102,4 +106,13 @@ abstract class JmsAdapterParserUtils {
|
||||
}
|
||||
}
|
||||
|
||||
static void verifyNoJmsTemplateAttributes(Element element, ParserContext parserContext) {
|
||||
for (String attributeName : JMS_TEMPLATE_ATTRIBUTES) {
|
||||
if (element.hasAttribute(attributeName)) {
|
||||
parserContext.getReaderContext().error("When providing a 'jms-template' reference, the '"
|
||||
+ attributeName + "' attribute is not allowed", parserContext.extractSource(element));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -60,15 +60,7 @@ public class JmsInboundChannelAdapterParser extends AbstractPollingInboundChanne
|
||||
boolean hasDestinationRef = StringUtils.hasText(destination);
|
||||
boolean hasDestinationName = StringUtils.hasText(destinationName);
|
||||
if (StringUtils.hasText(jmsTemplate)) {
|
||||
if (element.hasAttribute(JmsAdapterParserUtils.CONNECTION_FACTORY_ATTRIBUTE) ||
|
||||
hasDestinationRef || hasDestinationName) {
|
||||
parserContext.getReaderContext().error(
|
||||
"When providing '" + JmsAdapterParserUtils.JMS_TEMPLATE_ATTRIBUTE +
|
||||
"', none of '" + JmsAdapterParserUtils.CONNECTION_FACTORY_ATTRIBUTE +
|
||||
"', '" + JmsAdapterParserUtils.DESTINATION_ATTRIBUTE + "', or '" +
|
||||
JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE + "' are allowed.",
|
||||
source);
|
||||
}
|
||||
JmsAdapterParserUtils.verifyNoJmsTemplateAttributes(element, parserContext);
|
||||
builder.addConstructorArgReference(jmsTemplate);
|
||||
}
|
||||
else if (hasDestinationRef || hasDestinationName) {
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.integration.jms.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
@@ -44,11 +43,7 @@ public class JmsOutboundChannelAdapterParser extends AbstractOutboundChannelAdap
|
||||
boolean hasDestinationRef = StringUtils.hasText(destination);
|
||||
boolean hasDestinationName = StringUtils.hasText(destinationName);
|
||||
if (StringUtils.hasText(jmsTemplate)) {
|
||||
if (element.hasAttribute(JmsAdapterParserUtils.CONNECTION_FACTORY_ATTRIBUTE) ||
|
||||
hasDestinationRef || hasDestinationName) {
|
||||
throw new BeanCreationException("When providing a 'jms-template' reference, none of " +
|
||||
"'connection-factory', 'destination', or 'destination-name' should be provided.");
|
||||
}
|
||||
JmsAdapterParserUtils.verifyNoJmsTemplateAttributes(element, parserContext);
|
||||
builder.addConstructorArgReference(jmsTemplate);
|
||||
}
|
||||
else if (hasDestinationRef ^ hasDestinationName) {
|
||||
@@ -64,8 +59,8 @@ public class JmsOutboundChannelAdapterParser extends AbstractOutboundChannelAdap
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new BeanCreationException("Either a 'jms-template' reference " +
|
||||
"or one of 'destination' or 'destination-name' must be provided.");
|
||||
parserContext.getReaderContext().error("Either a 'jms-template' reference " +
|
||||
"or one of 'destination' or 'destination-name' must be provided.", parserContext.extractSource(element));
|
||||
}
|
||||
if (StringUtils.hasText(headerMapper)) {
|
||||
builder.addPropertyReference(JmsAdapterParserUtils.HEADER_MAPPER_PROPERTY, headerMapper);
|
||||
|
||||
@@ -13,8 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.jms.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
@@ -22,9 +26,8 @@ import javax.jms.Message;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.TextMessage;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.mapping.InboundMessageMapper;
|
||||
@@ -55,10 +58,10 @@ public class ExceptionHandlingSiConsumerTests {
|
||||
}
|
||||
});
|
||||
Message message = jmsTemplate.receive(reply);
|
||||
System.out.println(message);
|
||||
Assert.assertNotNull(message);
|
||||
assertNotNull(message);
|
||||
applicationContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonSiProducer_siConsumer_sync_withReturnNoException() throws Exception {
|
||||
ActiveMqTestUtils.prepare();
|
||||
@@ -76,7 +79,8 @@ public class ExceptionHandlingSiConsumerTests {
|
||||
}
|
||||
});
|
||||
Message message = jmsTemplate.receive(reply);
|
||||
Assert.assertNotNull(message);
|
||||
assertNotNull(message);
|
||||
assertEquals("echoWithException", ((TextMessage) message).getText());
|
||||
applicationContext.close();
|
||||
}
|
||||
|
||||
@@ -86,35 +90,40 @@ public class ExceptionHandlingSiConsumerTests {
|
||||
final ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("Exception-nonSiProducer-siConsumer.xml", ExceptionHandlingSiConsumerTests.class);
|
||||
SampleGateway gateway = applicationContext.getBean("sampleGateway", SampleGateway.class);
|
||||
String reply = gateway.echo("echoWithExceptionChannel");
|
||||
System.out.println("Reply: " + reply);
|
||||
assertEquals("echoWithException", reply);
|
||||
applicationContext.close();
|
||||
}
|
||||
//
|
||||
public static class SampleService{
|
||||
public String echoWithException(String value){
|
||||
|
||||
|
||||
public static class SampleService {
|
||||
|
||||
public String echoWithException(String value) {
|
||||
throw new SampleException("echoWithException");
|
||||
}
|
||||
|
||||
public String echo(String value){
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public static class SampleException extends RuntimeException{
|
||||
public static class SampleException extends RuntimeException {
|
||||
public SampleException(String message){
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static interface SampleGateway{
|
||||
|
||||
|
||||
public static interface SampleGateway {
|
||||
public String echo(String value);
|
||||
}
|
||||
|
||||
public static class SampleErrorMessageMapper implements InboundMessageMapper<Throwable>{
|
||||
public org.springframework.integration.Message<?> toMessage(
|
||||
Throwable t) throws Exception {
|
||||
|
||||
|
||||
public static class SampleErrorMessageMapper implements InboundMessageMapper<Throwable> {
|
||||
public org.springframework.integration.Message<?> toMessage(Throwable t) throws Exception {
|
||||
return MessageBuilder.withPayload(t.getCause().getMessage()).build();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -58,7 +58,6 @@ public class JmsMessageHistoryTests {
|
||||
assertEquals("jms:inbound-channel-adapter", event1.getProperty(MessageHistory.TYPE_PROPERTY));
|
||||
assertEquals("sampleJmsInboundAdapter", event1.getProperty(MessageHistory.NAME_PROPERTY));
|
||||
Properties event2 = historyIterator.next();
|
||||
System.out.println(event2);
|
||||
assertEquals("channel", event2.getProperty(MessageHistory.TYPE_PROPERTY));
|
||||
assertEquals("jmsInputChannel", event2.getProperty(MessageHistory.NAME_PROPERTY));
|
||||
}
|
||||
|
||||
@@ -101,6 +101,20 @@ public class JmsOutboundChannelAdapterParserTests {
|
||||
assertEquals(context.getBean("template"), jmsTemplate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void adapterWithJmsTemplateQos() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsOutboundWithJmsTemplateQos.xml", this.getClass());
|
||||
EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("adapter");
|
||||
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(new DirectFieldAccessor(endpoint).getPropertyValue("handler"));
|
||||
JmsTemplate jmsTemplate = (JmsTemplate) handlerAccessor.getPropertyValue("jmsTemplate");
|
||||
assertNotNull(jmsTemplate);
|
||||
assertEquals(context.getBean("template"), jmsTemplate);
|
||||
assertTrue(jmsTemplate.isExplicitQosEnabled());
|
||||
assertEquals(7, jmsTemplate.getPriority());
|
||||
assertEquals(12345, jmsTemplate.getTimeToLive());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void adapterWithMessageConverter() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:integration="http://www.springframework.org/schema/integration"
|
||||
xmlns:jms="http://www.springframework.org/schema/integration/jms"
|
||||
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/integration/jms
|
||||
http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd">
|
||||
|
||||
<integration:channel id="input"/>
|
||||
|
||||
<jms:outbound-channel-adapter id="adapter" channel="input" jms-template="template"/>
|
||||
|
||||
<bean id="template" class="org.springframework.jms.core.JmsTemplate" >
|
||||
<property name="connectionFactory">
|
||||
<bean class="org.springframework.jms.connection.SingleConnectionFactory">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.jms.StubConnection">
|
||||
<constructor-arg value="target-test"/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="explicitQosEnabled" value="true"/>
|
||||
<property name="priority" value="7"/>
|
||||
<property name="timeToLive" value="12345"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-parent</artifactId>
|
||||
@@ -23,7 +24,7 @@
|
||||
<org.hamcrest.version>1.1</org.hamcrest.version>
|
||||
<org.slf4j.version>1.5.10</org.slf4j.version>
|
||||
<org.springframework.version>3.0.3.RELEASE</org.springframework.version>
|
||||
<org.springframework.security.version>2.0.5.RELEASE</org.springframework.security.version>
|
||||
<org.springframework.security.version>3.0.3.RELEASE</org.springframework.security.version>
|
||||
<org.springframework.ws.version>1.5.9</org.springframework.ws.version>
|
||||
</properties>
|
||||
<profiles>
|
||||
@@ -101,7 +102,8 @@
|
||||
</profiles>
|
||||
<distributionManagement>
|
||||
<!-- see 'staging' profile for dry-run deployment settings -->
|
||||
<!-- see 'snapshot', 'milestone' and 'release' profiles for respective repository settings -->
|
||||
<!-- see 'snapshot', 'milestone' and 'release' profiles for respective
|
||||
repository settings -->
|
||||
<downloadUrl>http://static.springframework.org/spring-integration/site/downloads/releases.html</downloadUrl>
|
||||
<site>
|
||||
<id>static.springframework.org</id>
|
||||
@@ -109,14 +111,10 @@
|
||||
</site>
|
||||
</distributionManagement>
|
||||
<dependencyManagement>
|
||||
<!--
|
||||
inheritable <dependency> declarations for child poms. children still
|
||||
must explicitly declare the groupId/artifactId of these dependencies
|
||||
in order for them to show up on the classpath, but metadata like
|
||||
<version> and <scope> are inherited, which cuts down on verbosity.
|
||||
see
|
||||
http://www.sonatype.com/books/mvnref-book/reference/pom-relationships-sect-dep-manage.html
|
||||
-->
|
||||
<!-- inheritable <dependency> declarations for child poms. children still
|
||||
must explicitly declare the groupId/artifactId of these dependencies in order
|
||||
for them to show up on the classpath, but metadata like <version> and <scope>
|
||||
are inherited, which cuts down on verbosity. see http://www.sonatype.com/books/mvnref-book/reference/pom-relationships-sect-dep-manage.html -->
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
@@ -213,13 +211,21 @@
|
||||
<artifactId>spring-commons-serializer</artifactId>
|
||||
<version>1.0.0.M1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-core</artifactId>
|
||||
<version>${org.springframework.security.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-config</artifactId>
|
||||
<version>${org.springframework.security.version}</version>
|
||||
</dependency>
|
||||
<!-- test-scoped dependencies -->
|
||||
<dependency>
|
||||
<!--
|
||||
while cglib is not necessarily a 'test'-related dependency, it is
|
||||
only used for testing purposes by child modules thus it's scope has
|
||||
been generalized to 'test' here
|
||||
-->
|
||||
<!-- while cglib is not necessarily a 'test'-related dependency, it is
|
||||
only used for testing purposes by child modules thus it's scope has been
|
||||
generalized to 'test' here -->
|
||||
<groupId>cglib</groupId>
|
||||
<artifactId>cglib-nodep</artifactId>
|
||||
<version>${cglib.version}</version>
|
||||
@@ -276,12 +282,10 @@
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<dependencies>
|
||||
<!--
|
||||
dependency definitions to be inherited by child poms. any
|
||||
<dependency> declarations here will automatically show up on child
|
||||
project classpaths. only items that are truly common across all
|
||||
projects should go here. otherwise, consider <dependencyManagement />
|
||||
-->
|
||||
<!-- dependency definitions to be inherited by child poms. any <dependency>
|
||||
declarations here will automatically show up on child project classpaths.
|
||||
only items that are truly common across all projects should go here. otherwise,
|
||||
consider <dependencyManagement /> -->
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
@@ -292,10 +296,8 @@
|
||||
<build>
|
||||
<extensions>
|
||||
<extension>
|
||||
<!--
|
||||
available only in the springframework maven repository. see
|
||||
<repositories> section below
|
||||
-->
|
||||
<!-- available only in the springframework maven repository. see <repositories>
|
||||
section below -->
|
||||
<groupId>org.springframework.build.aws</groupId>
|
||||
<artifactId>org.springframework.build.aws.maven</artifactId>
|
||||
<version>3.0.0.RELEASE</version>
|
||||
@@ -376,12 +378,9 @@
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<!--
|
||||
configures the springsource bundlor plugin, which generates
|
||||
OSGI-compatible MANIFEST.MF files during the 'compile' phase of
|
||||
the maven build. For more information, see
|
||||
http://static.springsource.org/s2-bundlor/1.0.x/user-guide/html/ch04s03.html
|
||||
-->
|
||||
<!-- configures the springsource bundlor plugin, which generates OSGI-compatible
|
||||
MANIFEST.MF files during the 'compile' phase of the maven build. For more
|
||||
information, see http://static.springsource.org/s2-bundlor/1.0.x/user-guide/html/ch04s03.html -->
|
||||
<groupId>com.springsource.bundlor</groupId>
|
||||
<artifactId>com.springsource.bundlor.maven</artifactId>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
@@ -398,10 +397,8 @@
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<!--
|
||||
configures the jar plugin to pick up the manifest created by
|
||||
bundlor (see above)
|
||||
-->
|
||||
<!-- configures the jar plugin to pick up the manifest created by bundlor
|
||||
(see above) -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
@@ -416,11 +413,8 @@
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<!--
|
||||
significantly speeds up the 'Dependencies' report during site
|
||||
creation see
|
||||
http://old.nabble.com/Skipping-dependency-report-during-Maven2-site-generation-td20116761.html
|
||||
-->
|
||||
<!-- significantly speeds up the 'Dependencies' report during site creation
|
||||
see http://old.nabble.com/Skipping-dependency-report-during-Maven2-site-generation-td20116761.html -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<version>2.1</version>
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-core</artifactId>
|
||||
<version>3.0.3.RELEASE</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
@@ -38,7 +37,6 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-config</artifactId>
|
||||
<version>3.0.3.RELEASE</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
|
||||
Reference in New Issue
Block a user