Fix possible NPE when generate correlationData

**Cherry-pick to 4.3.x**

Related to https://github.com/spring-projects/spring-integration/pull/2761
This commit is contained in:
Artem Bilan
2019-02-22 11:02:16 -05:00
parent f33f0575cb
commit 8f1a1c1777

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 the original author or authors.
* Copyright 2016-2019 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.
@@ -18,6 +18,7 @@ package org.springframework.integration.amqp.outbound;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.rabbit.connection.Connection;
@@ -54,6 +55,8 @@ import org.springframework.util.StringUtils;
public abstract class AbstractAmqpOutboundEndpoint extends AbstractReplyProducingMessageHandler
implements Lifecycle {
private static final UUID NO_ID = new UUID(0L, 0L);
private String exchangeName;
private String routingKey;
@@ -472,8 +475,18 @@ public abstract class AbstractAmqpOutboundEndpoint extends AbstractReplyProducin
protected CorrelationData generateCorrelationData(Message<?> requestMessage) {
CorrelationData correlationData = null;
if (this.correlationDataGenerator != null) {
correlationData = new CorrelationDataWrapper(requestMessage.getHeaders().getId().toString(),
this.correlationDataGenerator.processMessage(requestMessage), requestMessage);
UUID messageId = requestMessage.getHeaders().getId();
if (messageId == null) {
messageId = NO_ID;
}
Object userData = this.correlationDataGenerator.processMessage(requestMessage);
if (userData != null) {
correlationData = new CorrelationDataWrapper(messageId.toString(), userData, requestMessage);
}
else {
this.logger.debug("'confirmCorrelationExpression' resolved to 'null'; "
+ "no publisher confirm will be sent to the ack or nack channel");
}
}
return correlationData;
}