INT-3869: Fix MBeanServer Detection
JIRA: https://jira.spring.io/browse/INT-3869 When using `@EnableIntegrationMBeanExport` with no `server` property, the `IntegrationMBeanExportConfiguration` incorrectly created a new `MBeanServer` instead of attempting to locate an existing one. Use the `SpecificPlatform` logic from `MBeanExportConfiguration` to locate a specific server on `WebSphere` and `WebLogic`; otherwise defer to `JmxUtils.locateMBeanServer()` in the exporter's initialization method. Add a test to verify the same server is used in multiple contexts. * Fix `ConnectionFactoryTests` regarding new `MessageProducerSupport` logic
This commit is contained in:
committed by
Artem Bilan
parent
996e6bb969
commit
d8ad38d8ea
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -53,6 +53,7 @@ import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.integration.channel.NullChannel;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.ip.event.IpIntegrationEvent;
|
||||
import org.springframework.integration.ip.tcp.TcpReceivingChannelAdapter;
|
||||
@@ -128,6 +129,7 @@ public class ConnectionFactoryTests extends LogAdjustingTestSupport {
|
||||
when(bf.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)).thenReturn(scheduler);
|
||||
serverFactory.setBeanFactory(bf);
|
||||
TcpReceivingChannelAdapter adapter = new TcpReceivingChannelAdapter();
|
||||
adapter.setOutputChannel(new NullChannel());
|
||||
adapter.setConnectionFactory(serverFactory);
|
||||
adapter.start();
|
||||
assertTrue("Listening event not received", serverListeningLatch.await(10, TimeUnit.SECONDS));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2016 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.
|
||||
@@ -22,7 +22,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.MBeanServerFactory;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
@@ -37,6 +36,7 @@ import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportAware;
|
||||
import org.springframework.context.annotation.MBeanExportConfiguration.SpecificPlatform;
|
||||
import org.springframework.context.annotation.Role;
|
||||
import org.springframework.context.expression.StandardBeanExpressionResolver;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
@@ -55,6 +55,7 @@ import org.springframework.util.StringUtils;
|
||||
* {@link EnableIntegrationMBeanExport} annotation. See its javadoc for complete usage details.
|
||||
*
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
* @since 4.0
|
||||
*/
|
||||
@Configuration
|
||||
@@ -143,7 +144,10 @@ public class IntegrationMBeanExportConfiguration implements ImportAware, Environ
|
||||
exporter.setServer(bean);
|
||||
}
|
||||
else {
|
||||
exporter.setServer(MBeanServerFactory.createMBeanServer());
|
||||
SpecificPlatform specificPlatform = SpecificPlatform.get();
|
||||
if (specificPlatform != null) {
|
||||
exporter.setServer(specificPlatform.getMBeanServer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ package org.springframework.integration.monitor;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@@ -33,14 +34,18 @@ import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.support.GenericXmlApplicationContext;
|
||||
import org.springframework.integration.channel.AbstractMessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.config.EnableIntegration;
|
||||
import org.springframework.integration.context.IntegrationObjectSupport;
|
||||
import org.springframework.integration.context.OrderlyShutdownCapable;
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.endpoint.MessageProducerSupport;
|
||||
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
|
||||
import org.springframework.integration.jmx.config.EnableIntegrationMBeanExport;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
@@ -224,6 +229,28 @@ public class MBeanExporterIntegrationTests {
|
||||
assertEquals(2, names.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleMBeanServer() {
|
||||
AnnotationConfigApplicationContext ctx1 = new AnnotationConfigApplicationContext(Config1.class);
|
||||
AnnotationConfigApplicationContext ctx2 = new AnnotationConfigApplicationContext(Config2.class);
|
||||
assertSame(TestUtils.getPropertyValue(ctx1.getBean(IntegrationMBeanExporter.class), "server"),
|
||||
TestUtils.getPropertyValue(ctx2.getBean(IntegrationMBeanExporter.class), "server"));
|
||||
ctx1.close();
|
||||
ctx2.close();
|
||||
}
|
||||
|
||||
@EnableIntegration
|
||||
@EnableIntegrationMBeanExport(defaultDomain = "config1")
|
||||
public static class Config1 {
|
||||
|
||||
}
|
||||
|
||||
@EnableIntegration
|
||||
@EnableIntegrationMBeanExport(defaultDomain = "config2")
|
||||
public static class Config2 {
|
||||
|
||||
}
|
||||
|
||||
public static class BogusEndpoint extends AbstractEndpoint {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
||||
Reference in New Issue
Block a user