Skip to content

Commit 016f3e2

Browse files
AMQ-9162 Fix WS transport start via JMX after it was closed.
1 parent 98805bc commit 016f3e2

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

activemq-http/src/main/java/org/apache/activemq/transport/ws/WSTransportServer.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ protected void doStart() throws Exception {
9696

9797
contextHandler.setAttribute("acceptListener", getAcceptListener());
9898

99-
server.start();
99+
ClassLoader original = Thread.currentThread().getContextClassLoader();
100+
Thread.currentThread().setContextClassLoader(WSTransportServer.class.getClassLoader());
101+
try {
102+
server.start();
103+
} finally {
104+
Thread.currentThread().setContextClassLoader(original);
105+
}
100106

101107
// Update the Connect To URI with our actual location in case the configured port
102108
// was set to zero so that we report the actual port we are listening on.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.activemq.transport.ws;
18+
19+
import org.apache.activemq.broker.BrokerService;
20+
import org.apache.activemq.broker.jmx.ConnectorViewMBean;
21+
import org.apache.activemq.util.Wait;
22+
import org.junit.Before;
23+
import org.junit.Test;
24+
25+
import javax.management.ObjectName;
26+
import java.util.concurrent.TimeUnit;
27+
28+
import static org.junit.Assert.assertTrue;
29+
30+
public class WSConnectorJMXTest {
31+
32+
private BrokerService broker;
33+
34+
@Before
35+
public void setUp() throws Exception {
36+
broker = new BrokerService();
37+
broker.setDeleteAllMessagesOnStartup(true);
38+
broker.setPersistent(true);
39+
broker.setUseJmx(true);
40+
broker.addConnector("ws://localhost:0").setName("Default");
41+
broker.setBrokerName("localhost");
42+
broker.start();
43+
broker.waitUntilStarted(30_000);
44+
broker.deleteAllMessages();
45+
}
46+
47+
@Test
48+
public void testRestartConnection() throws Exception {
49+
Thread.currentThread().setContextClassLoader(new ClassLoader(null) {});
50+
51+
ConnectorViewMBean connectionView = getProxyToConnectionView();
52+
connectionView.stop();
53+
assertTrue("Connection should close", Wait.waitFor(() -> !connectionView.isStarted(),
54+
TimeUnit.SECONDS.toMillis(60), 500));
55+
connectionView.start();
56+
assertTrue("Connection should open", Wait.waitFor(connectionView::isStarted,
57+
TimeUnit.SECONDS.toMillis(60), 500));
58+
}
59+
60+
protected ConnectorViewMBean getProxyToConnectionView() throws Exception {
61+
ObjectName connectorQuery = new ObjectName(
62+
"org.apache.activemq:type=Broker,brokerName=localhost,connector=clientConnectors,connectorName=Default");
63+
64+
return (ConnectorViewMBean) broker.getManagementContext()
65+
.newProxyInstance(connectorQuery, ConnectorViewMBean.class, true);
66+
}
67+
}

0 commit comments

Comments
 (0)