mirror of https://github.com/apache/activemq.git
Fix issue where the registry lookup was a hardcoded name and didn't account for the connector path
This commit is contained in:
parent
5cc7394fe2
commit
4522061527
|
@ -70,6 +70,11 @@ public class ManagementContext implements Service {
|
|||
*/
|
||||
public static final String DEFAULT_DOMAIN = "org.apache.activemq";
|
||||
|
||||
/**
|
||||
* Default registry lookup name
|
||||
*/
|
||||
public static final String DEFAULT_LOOKUP_NAME = "jmxrmi";
|
||||
|
||||
static {
|
||||
String option = Boolean.FALSE.toString();
|
||||
try {
|
||||
|
@ -95,6 +100,7 @@ public class ManagementContext implements Service {
|
|||
private Map<String, ?> environment;
|
||||
private int rmiServerPort;
|
||||
private String connectorPath = "/jmxrmi";
|
||||
private String lookupName = DEFAULT_LOOKUP_NAME;
|
||||
private final AtomicBoolean started = new AtomicBoolean(false);
|
||||
private final CountDownLatch connectorStarted = new CountDownLatch(1);
|
||||
private JMXConnectorServer connectorServer;
|
||||
|
@ -597,6 +603,12 @@ public class ManagementContext implements Service {
|
|||
|
||||
public void setConnectorPath(String connectorPath) {
|
||||
this.connectorPath = connectorPath;
|
||||
|
||||
if (connectorPath == null || connectorPath.length() == 0) {
|
||||
this.lookupName = DEFAULT_LOOKUP_NAME;
|
||||
} else {
|
||||
this.lookupName = connectorPath.replaceAll("^/+", "").replaceAll("/+$", "");
|
||||
}
|
||||
}
|
||||
|
||||
public int getConnectorPort() {
|
||||
|
@ -684,16 +696,15 @@ public class ManagementContext implements Service {
|
|||
*/
|
||||
@SuppressWarnings("restriction")
|
||||
private class JmxRegistry extends sun.rmi.registry.RegistryImpl {
|
||||
public static final String LOOKUP_NAME = "jmxrmi";
|
||||
|
||||
|
||||
public JmxRegistry(int port) throws RemoteException {
|
||||
super(port);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public Remote lookup(String s) throws RemoteException, NotBoundException {
|
||||
return LOOKUP_NAME.equals(s) ? serverStub : null;
|
||||
return lookupName.equals(s) ? serverStub : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -710,7 +721,7 @@ public class ManagementContext implements Service {
|
|||
|
||||
@Override
|
||||
public String[] list() throws RemoteException {
|
||||
return new String[] {LOOKUP_NAME};
|
||||
return new String[] {lookupName};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,10 +42,18 @@ import org.slf4j.LoggerFactory;
|
|||
*/
|
||||
public class ManagementContextXBeanConfigTest extends TestCase {
|
||||
|
||||
protected BrokerService brokerService;
|
||||
private static final String MANAGEMENT_CONTEXT_TEST_XML = "org/apache/activemq/xbean/management-context-test.xml";
|
||||
private static final String MANAGEMENT_CONTEXT_TEST_XML_CONNECTOR_PATH =
|
||||
"org/apache/activemq/xbean/management-context-test-connector-path.xml";
|
||||
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(ManagementContextXBeanConfigTest.class);
|
||||
|
||||
protected BrokerService brokerService;
|
||||
|
||||
public void testManagmentContextConfiguredCorrectly() throws Exception {
|
||||
brokerService = getBrokerService(MANAGEMENT_CONTEXT_TEST_XML);
|
||||
brokerService.start();
|
||||
|
||||
assertEquals(2011, brokerService.getManagementContext().getConnectorPort());
|
||||
assertEquals("test.domain", brokerService.getManagementContext().getJmxDomainName());
|
||||
// Make sure the broker is registered in the right jmx domain.
|
||||
|
@ -58,6 +66,9 @@ public class ManagementContextXBeanConfigTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testSuccessAuthentication() throws Exception {
|
||||
brokerService = getBrokerService(MANAGEMENT_CONTEXT_TEST_XML);
|
||||
brokerService.start();
|
||||
|
||||
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:2011/jmxrmi");
|
||||
Map<String, Object> env = new HashMap<String, Object>();
|
||||
env.put(JMXConnector.CREDENTIALS, new String[]{"admin", "activemq"});
|
||||
|
@ -65,7 +76,21 @@ public class ManagementContextXBeanConfigTest extends TestCase {
|
|||
assertAuthentication(connector);
|
||||
}
|
||||
|
||||
public void testConnectorPath() throws Exception {
|
||||
brokerService = getBrokerService(MANAGEMENT_CONTEXT_TEST_XML_CONNECTOR_PATH);
|
||||
brokerService.start();
|
||||
|
||||
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:2011/activemq-jmx");
|
||||
Map<String, Object> env = new HashMap<String, Object>();
|
||||
env.put(JMXConnector.CREDENTIALS, new String[]{"admin", "activemq"});
|
||||
JMXConnector connector = JMXConnectorFactory.connect(url, env);
|
||||
assertAuthentication(connector);
|
||||
}
|
||||
|
||||
public void testFailAuthentication() throws Exception {
|
||||
brokerService = getBrokerService(MANAGEMENT_CONTEXT_TEST_XML);
|
||||
brokerService.start();
|
||||
|
||||
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:2011/jmxrmi");
|
||||
try {
|
||||
JMXConnector connector = JMXConnectorFactory.connect(url, null);
|
||||
|
@ -85,12 +110,6 @@ public class ManagementContextXBeanConfigTest extends TestCase {
|
|||
LOG.info("Broker " + mbean.getBrokerId() + " - " + mbean.getBrokerName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
brokerService = createBroker();
|
||||
brokerService.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if (brokerService != null) {
|
||||
|
@ -98,8 +117,7 @@ public class ManagementContextXBeanConfigTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
protected BrokerService createBroker() throws Exception {
|
||||
String uri = "org/apache/activemq/xbean/management-context-test.xml";
|
||||
private BrokerService getBrokerService(String uri) throws Exception {
|
||||
return BrokerFactory.createBroker(new URI("xbean:" + uri));
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<!-- this file can only be parsed using the xbean-spring library -->
|
||||
<!-- START SNIPPET: xbean -->
|
||||
<beans
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:amq="http://activemq.apache.org/schema/core"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
|
||||
|
||||
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
|
||||
|
||||
<broker useJmx="true" xmlns="http://activemq.apache.org/schema/core">
|
||||
<managementContext>
|
||||
<managementContext createConnector="true" connectorPort="2011" jmxDomainName="test.domain" connectorPath="/activemq-jmx">
|
||||
<property xmlns="http://www.springframework.org/schema/beans" name="environment">
|
||||
<map xmlns="http://www.springframework.org/schema/beans">
|
||||
<entry xmlns="http://www.springframework.org/schema/beans" key="jmx.remote.x.password.file" value="src/test/resources/jmx.password"/>
|
||||
<entry xmlns="http://www.springframework.org/schema/beans" key="jmx.remote.x.access.file" value="src/test/resources/jmx.access"/>
|
||||
</map>
|
||||
</property>
|
||||
</managementContext>
|
||||
</managementContext>
|
||||
</broker>
|
||||
|
||||
</beans>
|
||||
<!-- END SNIPPET: xbean -->
|
Loading…
Reference in New Issue