INT-3358: Make MutableMessage package protected
JIRA: https://jira.spring.io/browse/INT-3358
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.message;
|
||||
package org.springframework.integration.support;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
@@ -39,7 +39,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* @since 4.0
|
||||
*
|
||||
*/
|
||||
public class MutableMessage<T> implements Message<T>, Serializable {
|
||||
class MutableMessage<T> implements Message<T>, Serializable {
|
||||
|
||||
private static final long serialVersionUID = -636635024258737500L;
|
||||
|
||||
@@ -49,12 +49,12 @@ public class MutableMessage<T> implements Message<T>, Serializable {
|
||||
|
||||
private final Map<String, Object> rawHeaders;
|
||||
|
||||
public MutableMessage(T payload) {
|
||||
MutableMessage(T payload) {
|
||||
this(payload, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public MutableMessage(T payload, Map<String, Object> headers) {
|
||||
MutableMessage(T payload, Map<String, Object> headers) {
|
||||
Assert.notNull(payload, "payload must not be null");
|
||||
this.headers = new MessageHeaders(headers);
|
||||
this.payload = payload;
|
||||
@@ -21,7 +21,6 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.springframework.integration.IntegrationMessageHeaderAccessor;
|
||||
import org.springframework.integration.message.MutableMessage;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.PatternMatchUtils;
|
||||
|
||||
@@ -55,7 +55,6 @@ import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.integration.annotation.Transformer;
|
||||
import org.springframework.integration.channel.AbstractMessageChannel;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.FixedSubscriberChannel;
|
||||
import org.springframework.integration.channel.NullChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.channel.interceptor.WireTap;
|
||||
@@ -66,8 +65,8 @@ import org.springframework.integration.config.GlobalChannelInterceptor;
|
||||
import org.springframework.integration.config.IntegrationConverter;
|
||||
import org.springframework.integration.history.MessageHistory;
|
||||
import org.springframework.integration.history.MessageHistoryConfigurer;
|
||||
import org.springframework.integration.message.MutableMessage;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.support.MutableMessageBuilder;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
@@ -214,7 +213,7 @@ public class EnableIntegrationTests {
|
||||
assertThat(this.testConverter.getInvoked(), Matchers.greaterThan(0));
|
||||
|
||||
assertTrue(this.bytesChannel.send(new GenericMessage<byte[]>("foo".getBytes())));
|
||||
assertTrue(this.bytesChannel.send(new GenericMessage<Message<?>>(new MutableMessage<Object>(""))));
|
||||
assertTrue(this.bytesChannel.send(new GenericMessage<Message<?>>(MutableMessageBuilder.withPayload("").build())));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.config.IntegrationEvaluationContextFactoryBean;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.json.JsonPathUtils;
|
||||
import org.springframework.integration.message.MutableMessage;
|
||||
import org.springframework.integration.support.MutableMessageBuilder;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
@@ -138,7 +138,7 @@ public class ParentContextTests {
|
||||
Message<?> out = child.getBean("output", QueueChannel.class).receive(0);
|
||||
assertNotNull(out);
|
||||
assertEquals("foobar", out.getPayload());
|
||||
child.getBean("parentIn", MessageChannel.class).send(new MutableMessage<String>("bar"));
|
||||
child.getBean("parentIn", MessageChannel.class).send(MutableMessageBuilder.withPayload("bar").build());
|
||||
out = child.getBean("parentOut", QueueChannel.class).receive(0);
|
||||
assertNotNull(out);
|
||||
assertThat(out, instanceOf(GenericMessage.class));
|
||||
@@ -158,7 +158,7 @@ public class ParentContextTests {
|
||||
parent.getBean("fromParentToChild", MessageChannel.class).send(new GenericMessage<String>("foo"));
|
||||
out = child.getBean("output", QueueChannel.class).receive(0);
|
||||
assertNotNull(out);
|
||||
assertThat(out, instanceOf(MutableMessage.class));
|
||||
assertEquals("org.springframework.integration.support.MutableMessage", out.getClass().getName());
|
||||
assertEquals("FOO", out.getPayload());
|
||||
|
||||
child.close();
|
||||
|
||||
@@ -16,10 +16,9 @@
|
||||
|
||||
package org.springframework.integration.message;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -64,7 +63,7 @@ public class MessageBuilderAtConfigTests {
|
||||
in.send(new GenericMessage<String>("foo"));
|
||||
Message<?> m1 = out.receive(0);
|
||||
Message<?> m2 = out.receive(0);
|
||||
assertThat(m1, Matchers.instanceOf(MutableMessage.class));
|
||||
assertEquals("org.springframework.integration.support.MutableMessage", m1.getClass().getName());
|
||||
assertTrue(m1 == m2);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Date;
|
||||
@@ -28,7 +27,6 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -151,7 +149,7 @@ public class MessageBuilderTests {
|
||||
in.send(new GenericMessage<String>("foo"));
|
||||
Message<?> m1 = out.receive(0);
|
||||
Message<?> m2 = out.receive(0);
|
||||
assertThat(m1, Matchers.instanceOf(MutableMessage.class));
|
||||
assertEquals("org.springframework.integration.support.MutableMessage", m1.getClass().getName());
|
||||
assertTrue(m1 == m2);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,10 +23,12 @@ import static org.springframework.integration.history.MessageHistory.TYPE_PROPER
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
@@ -35,7 +37,9 @@ import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.converter.GenericConverter;
|
||||
import org.springframework.core.serializer.support.DeserializingConverter;
|
||||
import org.springframework.core.serializer.support.SerializingConverter;
|
||||
import org.springframework.data.annotation.Id;
|
||||
@@ -55,12 +59,12 @@ import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.core.query.Update;
|
||||
import org.springframework.integration.history.MessageHistory;
|
||||
import org.springframework.integration.message.AdviceMessage;
|
||||
import org.springframework.integration.message.MutableMessage;
|
||||
import org.springframework.integration.store.AbstractMessageGroupStore;
|
||||
import org.springframework.integration.store.MessageGroup;
|
||||
import org.springframework.integration.store.MessageGroupStore;
|
||||
import org.springframework.integration.store.MessageStore;
|
||||
import org.springframework.integration.store.SimpleMessageGroup;
|
||||
import org.springframework.integration.support.MutableMessageBuilder;
|
||||
import org.springframework.jmx.export.annotation.ManagedAttribute;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
@@ -357,7 +361,7 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
List<Converter<?, ?>> customConverters = new ArrayList<Converter<?,?>>();
|
||||
List<Object> customConverters = new ArrayList<Object>();
|
||||
customConverters.add(new UuidToDBObjectConverter());
|
||||
customConverters.add(new DBObjectToUUIDConverter());
|
||||
customConverters.add(new MessageHistoryToDBObjectConverter());
|
||||
@@ -537,16 +541,35 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore
|
||||
|
||||
}
|
||||
|
||||
private class DBObjectToMutableMessageConverter implements Converter<DBObject, MutableMessage<?>> {
|
||||
private class DBObjectToMutableMessageConverter implements GenericConverter {
|
||||
|
||||
@Override
|
||||
public MutableMessage<?> convert(DBObject source) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> headers = MongoDbMessageStore.this.converter.normalizeHeaders((Map<String, Object>) source.get("headers"));
|
||||
private final Class<?> mutableMessageClass;
|
||||
|
||||
return new MutableMessage<Object>(MongoDbMessageStore.this.converter.extractPayload(source), headers);
|
||||
private DBObjectToMutableMessageConverter() {
|
||||
try {
|
||||
this.mutableMessageClass = ClassUtils.forName("org.springframework.integration.support.MutableMessage",
|
||||
MongoDbMessageStore.this.classLoader);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ConvertiblePair> getConvertibleTypes() {
|
||||
Set<ConvertiblePair> convertiblePairs = new HashSet<ConvertiblePair>();
|
||||
convertiblePairs.add(new ConvertiblePair(DBObject.class, this.mutableMessageClass));
|
||||
return convertiblePairs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
DBObject dbObject = (DBObject) source;
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> headers = MongoDbMessageStore.this.converter.normalizeHeaders((Map<String, Object>) dbObject.get("headers"));
|
||||
|
||||
return MutableMessageBuilder.withPayload(MongoDbMessageStore.this.converter.extractPayload(dbObject)).copyHeaders(headers).build();
|
||||
}
|
||||
}
|
||||
|
||||
private class DBObjectToAdviceMessageConverter implements Converter<DBObject, AdviceMessage> {
|
||||
|
||||
@@ -32,11 +32,11 @@ import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.history.MessageHistory;
|
||||
import org.springframework.integration.message.AdviceMessage;
|
||||
import org.springframework.integration.message.MutableMessage;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailable;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailableTests;
|
||||
import org.springframework.integration.store.MessageStore;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.support.MutableMessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.support.ErrorMessage;
|
||||
@@ -222,11 +222,11 @@ public abstract class AbstractMongoDbMessageStoreTests extends MongoDbAvailableT
|
||||
Person p = new Person();
|
||||
p.setFname("John");
|
||||
p.setLname("Doe");
|
||||
Message<?> messageToStore = new GenericMessage<Message<?>>(new MutableMessage<Object>(p));
|
||||
Message<?> messageToStore = new GenericMessage<Message<?>>(MutableMessageBuilder.withPayload(p).build());
|
||||
store.addMessage(messageToStore);
|
||||
Message<?> retrievedMessage = store.getMessage(messageToStore.getHeaders().getId());
|
||||
assertNotNull(retrievedMessage);
|
||||
assertTrue(retrievedMessage.getPayload() instanceof MutableMessage);
|
||||
assertEquals("org.springframework.integration.support.MutableMessage", retrievedMessage.getPayload().getClass().getName());
|
||||
assertEquals(messageToStore.getPayload(), retrievedMessage.getPayload());
|
||||
assertEquals(messageToStore.getHeaders(), retrievedMessage.getHeaders());
|
||||
assertEquals(((Message<?>) messageToStore.getPayload()).getPayload(), p);
|
||||
|
||||
@@ -27,10 +27,10 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.IntegrationMessageHeaderAccessor;
|
||||
import org.springframework.integration.message.MutableMessage;
|
||||
import org.springframework.integration.redis.rules.RedisAvailable;
|
||||
import org.springframework.integration.redis.rules.RedisAvailableTests;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.support.MutableMessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
@@ -82,7 +82,7 @@ public class RedisChannelMessageStoreTests extends RedisAvailableTests {
|
||||
assertEquals(10, this.cms.messageGroupSize("cms:testChannel1"));
|
||||
assertEquals(10, this.cms.getMessageGroup("cms:testChannel1").size());
|
||||
for (int i = 0; i < 10; i++) {
|
||||
this.testChannel2.send(new MutableMessage<Integer>(i));
|
||||
this.testChannel2.send(MutableMessageBuilder.withPayload(i).build());
|
||||
}
|
||||
assertEquals(2, this.cms.getMessageGroupCount());
|
||||
assertEquals(10, this.cms.messageGroupSize("cms:testChannel2"));
|
||||
@@ -91,13 +91,13 @@ public class RedisChannelMessageStoreTests extends RedisAvailableTests {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Message<?> out = this.testChannel1.receive(0);
|
||||
assertThat(out, Matchers.instanceOf(GenericMessage.class));
|
||||
assertEquals(Integer.valueOf(i), out.getPayload());
|
||||
assertEquals(i, out.getPayload());
|
||||
}
|
||||
assertNull(this.testChannel1.receive(0));
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Message<?> out = this.testChannel2.receive(0);
|
||||
assertThat(out, Matchers.instanceOf(MutableMessage.class));
|
||||
assertEquals(Integer.valueOf(i), out.getPayload());
|
||||
assertEquals("org.springframework.integration.support.MutableMessage", out.getClass().getName());
|
||||
assertEquals(i, out.getPayload());
|
||||
}
|
||||
assertNull(this.testChannel2.receive(0));
|
||||
assertEquals(0, this.cms.getMessageGroupCount());
|
||||
@@ -143,11 +143,11 @@ public class RedisChannelMessageStoreTests extends RedisAvailableTests {
|
||||
Message<?> m = this.testChannel3.receive(0);
|
||||
assertNotNull(m);
|
||||
assertEquals(Integer.valueOf(199), new IntegrationMessageHeaderAccessor(m).getPriority());
|
||||
assertEquals(Integer.valueOf(99), m.getPayload());
|
||||
assertEquals(99, m.getPayload());
|
||||
m = this.testChannel3.receive(0);
|
||||
assertNotNull(m);
|
||||
assertNull(new IntegrationMessageHeaderAccessor(m).getPriority());
|
||||
assertEquals(Integer.valueOf(98), m.getPayload());
|
||||
assertEquals(98, m.getPayload());
|
||||
assertEquals(0, this.priorityCms.messageGroupSize("priorityCms:testChannel3"));
|
||||
|
||||
m = this.testChannel4.receive(0);
|
||||
|
||||
Reference in New Issue
Block a user