INT-1903 polishing
This commit is contained in:
@@ -21,6 +21,7 @@ import java.lang.reflect.Field;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -28,7 +29,6 @@ import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.integration.MessageHeaders;
|
||||
import org.springframework.integration.MessageHeaders.IdGenerator;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
@@ -56,21 +56,27 @@ public final class IdGeneratorConfigurer implements ApplicationListener<ContextR
|
||||
}
|
||||
Field idGeneratorField = ReflectionUtils.findField(MessageHeaders.class, "idGenerator");
|
||||
ReflectionUtils.makeAccessible(idGeneratorField);
|
||||
IdGenerator existingIdGenerator = (IdGenerator) idGeneratorField.get(null);
|
||||
Assert.state(existingIdGenerator == null, "'MessageHeaders.idGenerator' " +
|
||||
"has already been set and can not be set again");
|
||||
IdGenerator existingIdGenerator = (IdGenerator) ReflectionUtils.getField(idGeneratorField, null);
|
||||
if (existingIdGenerator != null) {
|
||||
throw new BeanDefinitionStoreException(
|
||||
"'MessageHeaders.idGenerator' has already been set and can not be set again");
|
||||
}
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Message IDs will be generated using custom IdGenerator [" + idGeneratorBean.getClass() + "]");
|
||||
}
|
||||
ReflectionUtils.setField(idGeneratorField, null, idGeneratorBean);
|
||||
}
|
||||
catch (BeanDefinitionStoreException e) {
|
||||
// let this one propagate
|
||||
throw e;
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException e) {
|
||||
// We will use the default.
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Unable to locate MessageHeaders.IdGenerator. Will use default: UUID.randomUUID()");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (IllegalStateException e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Unexpected exception occurred while accessing idGenerator of MessageHeaders." +
|
||||
" Will use default: UUID.randomUUID()", e);
|
||||
|
||||
Reference in New Issue
Block a user