Initial Changes for SPR 4.0.0.RC1

- MessageConverter
This commit is contained in:
Gary Russell
2013-10-21 10:28:37 -04:00
parent b1f9aed694
commit b31018945d
16 changed files with 76 additions and 67 deletions

View File

@@ -121,7 +121,7 @@ public class AsyncMessagingTemplate extends GenericMessagingTemplate implements
public <R> Future<R> asyncReceiveAndConvert() {
return this.executor.submit(new Callable<R>() {
public R call() throws Exception {
return (R) receiveAndConvert();
return (R) receiveAndConvert(null);
}
});
}
@@ -130,7 +130,7 @@ public class AsyncMessagingTemplate extends GenericMessagingTemplate implements
public <R> Future<R> asyncReceiveAndConvert(final PollableChannel channel) {
return this.executor.submit(new Callable<R>() {
public R call() throws Exception {
return (R) receiveAndConvert(channel);
return (R) receiveAndConvert(channel, null);
}
});
}
@@ -139,7 +139,7 @@ public class AsyncMessagingTemplate extends GenericMessagingTemplate implements
public <R> Future<R> asyncReceiveAndConvert(final String channelName) {
return this.executor.submit(new Callable<R>() {
public R call() throws Exception {
return (R) receiveAndConvert(channelName);
return (R) receiveAndConvert(channelName, null);
}
});
}
@@ -172,7 +172,7 @@ public class AsyncMessagingTemplate extends GenericMessagingTemplate implements
public <R> Future<R> asyncConvertSendAndReceive(final Object request) {
return this.executor.submit(new Callable<R>() {
public R call() throws Exception {
return (R) convertSendAndReceive(request);
return (R) convertSendAndReceive(request, null);
}
});
}
@@ -181,7 +181,7 @@ public class AsyncMessagingTemplate extends GenericMessagingTemplate implements
public <R> Future<R> asyncConvertSendAndReceive(final MessageChannel channel, final Object request) {
return this.executor.submit(new Callable<R>() {
public R call() throws Exception {
return (R) convertSendAndReceive(channel, request);
return (R) convertSendAndReceive(channel, request, null);
}
});
}
@@ -190,7 +190,7 @@ public class AsyncMessagingTemplate extends GenericMessagingTemplate implements
public <R> Future<R> asyncConvertSendAndReceive(final String channelName, final Object request) {
return this.executor.submit(new Callable<R>() {
public R call() throws Exception {
return (R) convertSendAndReceive(channelName, request);
return (R) convertSendAndReceive(channelName, request, null);
}
});
}
@@ -199,7 +199,7 @@ public class AsyncMessagingTemplate extends GenericMessagingTemplate implements
public <R> Future<R> asyncConvertSendAndReceive(final Object request, final MessagePostProcessor requestPostProcessor) {
return this.executor.submit(new Callable<R>() {
public R call() throws Exception {
return (R) convertSendAndReceive(request, requestPostProcessor);
return (R) convertSendAndReceive(request, null, requestPostProcessor);
}
});
}
@@ -208,7 +208,7 @@ public class AsyncMessagingTemplate extends GenericMessagingTemplate implements
public <R> Future<R> asyncConvertSendAndReceive(final MessageChannel channel, final Object request, final MessagePostProcessor requestPostProcessor) {
return this.executor.submit(new Callable<R>() {
public R call() throws Exception {
return (R) convertSendAndReceive(channel, request, requestPostProcessor);
return (R) convertSendAndReceive(channel, request, null, requestPostProcessor);
}
});
}
@@ -217,7 +217,7 @@ public class AsyncMessagingTemplate extends GenericMessagingTemplate implements
public <R> Future<R> asyncConvertSendAndReceive(final String channelName, final Object request, final MessagePostProcessor requestPostProcessor) {
return this.executor.submit(new Callable<R>() {
public R call() throws Exception {
return (R) convertSendAndReceive(channelName, request, requestPostProcessor);
return (R) convertSendAndReceive(channelName, request, null, requestPostProcessor);
}
});
}

View File

@@ -196,7 +196,7 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint implement
this.initializeIfNecessary();
Assert.state(this.replyChannel != null && (this.replyChannel instanceof PollableChannel),
"receive is not supported, because no pollable reply channel has been configured");
return this.messagingTemplate.receiveAndConvert((PollableChannel) this.replyChannel);
return this.messagingTemplate.receiveAndConvert((PollableChannel) this.replyChannel, null);
}
protected Object sendAndReceive(Object object) {
@@ -221,7 +221,7 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint implement
Throwable error = null;
try {
if (shouldConvert) {
reply = this.messagingTemplate.convertSendAndReceive(this.requestChannel, object, this.historyWritingPostProcessor);
reply = this.messagingTemplate.convertSendAndReceive(this.requestChannel, object, null, this.historyWritingPostProcessor);
if (reply instanceof Throwable) {
error = (Throwable) reply;
}

View File

@@ -15,13 +15,13 @@
*/
package org.springframework.integration.support.converter;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.converter.MessageConverter;
import org.springframework.util.Assert;
@@ -31,7 +31,7 @@ import org.springframework.util.Assert;
* @since 3.0
*
*/
public class MapMessageConverter implements MessageConverter<Object> {
public class MapMessageConverter implements MessageConverter {
private volatile String[] headerNames;
@@ -58,7 +58,8 @@ public class MapMessageConverter implements MessageConverter<Object> {
this.filterHeadersInToMessage = filterHeadersInToMessage;
}
public <P> Message<P> toMessage(Object object) {
@Override
public Message<?> toMessage(Object object, MessageHeaders messageHeaders) {
Assert.isInstanceOf(Map.class, object, "This converter expects a Map");
@SuppressWarnings("unchecked")
Map<String, ?> map = (Map<String, ?>) object;
@@ -78,12 +79,12 @@ public class MapMessageConverter implements MessageConverter<Object> {
}
}*/
}
@SuppressWarnings("unchecked")
Message<P> convertedMessage = (Message<P>) messageBuilder.build();
Message<?> convertedMessage = messageBuilder.build();
return convertedMessage;
}
public Object fromMessage(Message<?> message, Type type) {
@Override
public Object fromMessage(Message<?> message, Class<?> clazz) {
Map<String,Object> map = new HashMap<String, Object>();
map.put("payload", message.getPayload());
Map<String, Object> headers = new HashMap<String, Object>();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* 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.
@@ -16,12 +16,11 @@
package org.springframework.integration.support.converter;
import java.lang.reflect.Type;
import org.springframework.integration.mapping.InboundMessageMapper;
import org.springframework.integration.mapping.OutboundMessageMapper;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.converter.MessageConversionException;
import org.springframework.messaging.support.converter.MessageConverter;
@@ -30,7 +29,7 @@ import org.springframework.messaging.support.converter.MessageConverter;
* @since 2.0
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public class SimpleMessageConverter implements MessageConverter<Object> {
public class SimpleMessageConverter implements MessageConverter {
private volatile InboundMessageMapper inboundMessageMapper;
@@ -65,7 +64,7 @@ public class SimpleMessageConverter implements MessageConverter<Object> {
this.outboundMessageMapper = (outboundMessageMapper != null) ? outboundMessageMapper : new DefaultOutboundMessageMapper();
}
public <P> Message<P> toMessage(Object object) {
public Message<?> toMessage(Object object, MessageHeaders headers) {
try {
return this.inboundMessageMapper.toMessage(object);
}
@@ -74,7 +73,7 @@ public class SimpleMessageConverter implements MessageConverter<Object> {
}
}
public Object fromMessage(Message<?> message, Type targetClass) {
public Object fromMessage(Message<?> message, Class<?> targetClass) {
try {
return this.outboundMessageMapper.fromMessage(message);
}

View File

@@ -22,14 +22,15 @@ import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.integration.annotation.Aggregator;
import org.springframework.integration.annotation.CorrelationStrategy;
import org.springframework.integration.annotation.ReleaseStrategy;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.PollableChannel;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -54,8 +55,8 @@ public class AnnotationAggregatorTests {
@SuppressWarnings("unchecked")
Message<String> result = (Message<String>) output.receive();
String payload = result.getPayload();
assertTrue("Wrong payload: "+payload, payload.contains("Payload=a"));
assertTrue("Wrong payload: "+payload, payload.contains("Payload=b"));
assertTrue("Wrong payload: "+payload, payload.contains("Payload String content=a"));
assertTrue("Wrong payload: "+payload, payload.contains("Payload String content=b"));
}
@SuppressWarnings("unused")
@@ -65,12 +66,12 @@ public class AnnotationAggregatorTests {
public Message<?> aggregate(final List<Message<?>> messages) {
return MessageBuilder.withPayload(messages.toString()).build();
}
@ReleaseStrategy
public boolean release(final List<Message<?>> messages) {
return messages.size()>1;
}
@CorrelationStrategy
public Object getKey(Message<?> message) {
return "1";

View File

@@ -22,6 +22,7 @@ import static org.junit.Assert.fail;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
@@ -203,7 +204,7 @@ public class ServiceActivatorParserTests {
GenericMessagingTemplate template = new GenericMessagingTemplate();
template.setDefaultDestination(channel);
return template.convertSendAndReceive(payload);
return template.convertSendAndReceive(payload, null);
}
@@ -232,9 +233,9 @@ public class ServiceActivatorParserTests {
@SuppressWarnings("unused")
private static class TestPerson {
private String firstName;
private final String firstName;
private String lastName;
private final String lastName;
public TestPerson(String firstName, String lastName) {
this.firstName = firstName;

View File

@@ -24,8 +24,9 @@ import static org.junit.Assert.fail;
import java.util.Map;
import org.junit.Test;
import org.springframework.messaging.Message;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
/**
* @author Gary Russell
@@ -56,17 +57,17 @@ public class MapMessageConverterTests {
assertNull(headers.get("baz"));
headers.put("baz", "qux");
message = converter.toMessage(map);
assertEquals("foo", message.getPayload());
assertEquals("baz", message.getHeaders().get("bar"));
assertEquals("qux", message.getHeaders().get("baz"));
Message<?> converted = converter.toMessage(map, null);
assertEquals("foo", converted.getPayload());
assertEquals("baz", converted.getHeaders().get("bar"));
assertEquals("qux", converted.getHeaders().get("baz"));
converter.setFilterHeadersInToMessage(true);
message = converter.toMessage(map);
assertEquals("foo", message.getPayload());
assertEquals("baz", message.getHeaders().get("bar"));
assertNull(message.getHeaders().get("baz"));
converted = converter.toMessage(map, null);
assertEquals("foo", converted.getPayload());
assertEquals("baz", converted.getHeaders().get("bar"));
assertNull(converted.getHeaders().get("baz"));
}
@Test
@@ -83,7 +84,7 @@ public class MapMessageConverterTests {
map.remove("payload");
try {
converter.toMessage(map);
converter.toMessage(map, null);
fail("Expected exception");
}
catch (IllegalArgumentException e) {
@@ -105,8 +106,8 @@ public class MapMessageConverterTests {
assertNotNull(headers);
assertEquals(0, headers.size());
map.remove("headers");
message = converter.toMessage(map);
assertEquals("foo", message.getPayload());
Message<?> converted = converter.toMessage(map, null);
assertEquals("foo", converted.getPayload());
}
@Test

View File

@@ -15,10 +15,10 @@
*/
package org.springframework.integration.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
@@ -54,14 +54,14 @@ import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.handler.MethodInvokingMessageProcessor;
import org.springframework.integration.handler.ServiceActivatingHandler;
import org.springframework.integration.history.MessageHistory;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.support.context.NamedComponent;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
/**
* @author Oleg Zhurakousky