Fix MongoDb module for the latest Spring Data
The `MappingMongoConverter` now used different path when it iterates documents form conversion from a DB cursor * Fix `MongoDbMessageStore.MessageReadingMongoConverter` to override a `read(TypeInformation<S>, Bson)` method to convert a `MessageWrapper` properly * Upgrade to the latest MongoDb driver
This commit is contained in:
@@ -85,12 +85,12 @@ ext {
|
|||||||
mailVersion = '2.0.1'
|
mailVersion = '2.0.1'
|
||||||
micrometerVersion = '1.10.0-SNAPSHOT'
|
micrometerVersion = '1.10.0-SNAPSHOT'
|
||||||
mockitoVersion = '4.4.0'
|
mockitoVersion = '4.4.0'
|
||||||
mongoDriverVersion = '4.5.0'
|
mongoDriverVersion = '4.6.0'
|
||||||
mysqlVersion = '8.0.28'
|
mysqlVersion = '8.0.28'
|
||||||
pahoMqttClientVersion = '1.2.5'
|
pahoMqttClientVersion = '1.2.5'
|
||||||
postgresVersion = '42.3.3'
|
postgresVersion = '42.3.3'
|
||||||
r2dbch2Version = '0.9.1.RELEASE'
|
r2dbch2Version = '0.9.1.RELEASE'
|
||||||
reactorVersion = '2020.0.15'
|
reactorVersion = '2020.0.18'
|
||||||
resilience4jVersion = '1.7.1'
|
resilience4jVersion = '1.7.1'
|
||||||
romeToolsVersion = '1.18.0'
|
romeToolsVersion = '1.18.0'
|
||||||
rsocketVersion = '1.1.1'
|
rsocketVersion = '1.1.1'
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ import org.springframework.context.ApplicationContextAware;
|
|||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
import org.springframework.core.serializer.support.SerializingConverter;
|
import org.springframework.core.serializer.support.SerializingConverter;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.annotation.Transient;
|
|
||||||
import org.springframework.data.convert.ReadingConverter;
|
import org.springframework.data.convert.ReadingConverter;
|
||||||
import org.springframework.data.convert.WritingConverter;
|
import org.springframework.data.convert.WritingConverter;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
@@ -63,6 +62,7 @@ import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
|
|||||||
import org.springframework.data.mongodb.core.query.Criteria;
|
import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
import org.springframework.data.mongodb.core.query.Query;
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
import org.springframework.data.mongodb.core.query.Update;
|
import org.springframework.data.mongodb.core.query.Update;
|
||||||
|
import org.springframework.data.util.TypeInformation;
|
||||||
import org.springframework.integration.history.MessageHistory;
|
import org.springframework.integration.history.MessageHistory;
|
||||||
import org.springframework.integration.message.AdviceMessage;
|
import org.springframework.integration.message.AdviceMessage;
|
||||||
import org.springframework.integration.store.AbstractMessageGroupStore;
|
import org.springframework.integration.store.AbstractMessageGroupStore;
|
||||||
@@ -495,9 +495,9 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore
|
|||||||
Query query = Query.query(Criteria.where("_id").is(SEQUENCE_NAME));
|
Query query = Query.query(Criteria.where("_id").is(SEQUENCE_NAME));
|
||||||
query.fields().include(SEQUENCE);
|
query.fields().include(SEQUENCE);
|
||||||
return ((Number) this.template.findAndModify(query,
|
return ((Number) this.template.findAndModify(query,
|
||||||
new Update().inc(SEQUENCE, 1L),
|
new Update().inc(SEQUENCE, 1L),
|
||||||
FindAndModifyOptions.options().returnNew(true).upsert(true),
|
FindAndModifyOptions.options().returnNew(true).upsert(true),
|
||||||
Map.class, this.collectionName)
|
Map.class, this.collectionName)
|
||||||
.get(SEQUENCE)) // NOSONAR - never returns null
|
.get(SEQUENCE)) // NOSONAR - never returns null
|
||||||
.longValue();
|
.longValue();
|
||||||
}
|
}
|
||||||
@@ -589,9 +589,14 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore
|
|||||||
if (!MessageWrapper.class.equals(clazz)) {
|
if (!MessageWrapper.class.equals(clazz)) {
|
||||||
return super.read(clazz, source);
|
return super.read(clazz, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (S) readAsMessageWrapper(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
private MessageWrapper readAsMessageWrapper(Bson source) {
|
||||||
if (source != null) {
|
if (source != null) {
|
||||||
Map<String, Object> sourceMap = asMap(source);
|
Map<String, Object> sourceMap = asMap(source);
|
||||||
Message<?> message = null;
|
Message<?> message;
|
||||||
Object messageType = sourceMap.get("_messageType");
|
Object messageType = sourceMap.get("_messageType");
|
||||||
if (messageType == null) {
|
if (messageType == null) {
|
||||||
messageType = GenericMessage.class.getName();
|
messageType = GenericMessage.class.getName();
|
||||||
@@ -629,21 +634,30 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore
|
|||||||
}
|
}
|
||||||
wrapper.setCondition((String) sourceMap.get("_condition"));
|
wrapper.setCondition((String) sourceMap.get("_condition"));
|
||||||
|
|
||||||
return (S) wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings({ UNCHECKED })
|
||||||
|
protected <S> S read(TypeInformation<S> type, Bson source) {
|
||||||
|
if (!MessageWrapper.class.equals(type.getType())) {
|
||||||
|
return super.read(type, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (S) readAsMessageWrapper(source);
|
||||||
|
}
|
||||||
|
|
||||||
private Map<String, Object> normalizeHeaders(Map<String, Object> headers) {
|
private Map<String, Object> normalizeHeaders(Map<String, Object> headers) {
|
||||||
Map<String, Object> normalizedHeaders = new HashMap<>();
|
Map<String, Object> normalizedHeaders = new HashMap<>();
|
||||||
for (Entry<String, Object> entry : headers.entrySet()) {
|
for (Entry<String, Object> entry : headers.entrySet()) {
|
||||||
String headerName = entry.getKey();
|
String headerName = entry.getKey();
|
||||||
Object headerValue = entry.getValue();
|
Object headerValue = entry.getValue();
|
||||||
if (headerValue instanceof Bson) {
|
if (headerValue instanceof Bson source) {
|
||||||
Bson source = (Bson) headerValue;
|
|
||||||
Map<String, Object> document = asMap(source);
|
Map<String, Object> document = asMap(source);
|
||||||
try {
|
try {
|
||||||
Class<?> typeClass = null;
|
Class<?> typeClass;
|
||||||
if (document.containsKey(CLASS)) {
|
if (document.containsKey(CLASS)) {
|
||||||
Object type = document.get(CLASS);
|
Object type = document.get(CLASS);
|
||||||
typeClass = ClassUtils.forName(type.toString(), MongoDbMessageStore.this.classLoader);
|
typeClass = ClassUtils.forName(type.toString(), MongoDbMessageStore.this.classLoader);
|
||||||
@@ -670,8 +684,7 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore
|
|||||||
private Object extractPayload(Bson source) {
|
private Object extractPayload(Bson source) {
|
||||||
Object payload = asMap(source).get("payload");
|
Object payload = asMap(source).get("payload");
|
||||||
|
|
||||||
if (payload instanceof Bson) {
|
if (payload instanceof Bson payloadObject) {
|
||||||
Bson payloadObject = (Bson) payload;
|
|
||||||
Object payloadType = asMap(payloadObject).get(CLASS);
|
Object payloadType = asMap(payloadObject).get(CLASS);
|
||||||
try {
|
try {
|
||||||
Class<?> payloadClass =
|
Class<?> payloadClass =
|
||||||
@@ -845,7 +858,7 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore
|
|||||||
|
|
||||||
private volatile Object _groupId; // NOSONAR name
|
private volatile Object _groupId; // NOSONAR name
|
||||||
|
|
||||||
@Transient
|
// @Transient
|
||||||
private final Message<?> message; // NOSONAR name
|
private final Message<?> message; // NOSONAR name
|
||||||
|
|
||||||
@SuppressWarnings(UNUSED)
|
@SuppressWarnings(UNUSED)
|
||||||
|
|||||||
Reference in New Issue
Block a user