mirror of https://github.com/apache/activemq.git
https://issues.apache.org/jira/browse/AMQ-3918 - transport connector urls exposed using JMX
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1359194 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b7dc057abd
commit
cb895f01b7
|
@ -2328,11 +2328,11 @@ public class BrokerService implements Service {
|
|||
if (policy != null) {
|
||||
connector.setMessageAuthorizationPolicy(policy);
|
||||
}
|
||||
connector.getStatistics().setEnabled(enableStatistics);
|
||||
connector.start();
|
||||
if (isUseJmx()) {
|
||||
connector = registerConnectorMBean(connector);
|
||||
}
|
||||
connector.getStatistics().setEnabled(enableStatistics);
|
||||
connector.start();
|
||||
return connector;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@ import java.lang.reflect.Method;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import javax.management.ObjectName;
|
||||
|
@ -364,21 +366,54 @@ public class BrokerView implements BrokerViewMBean {
|
|||
}
|
||||
}
|
||||
|
||||
public Map<String, String> getTransportConnectors() {
|
||||
Map<String, String> answer = new HashMap<String, String>();
|
||||
try {
|
||||
for (TransportConnector connector : brokerService.getTransportConnectors()) {
|
||||
answer.put(connector.getName(), connector.getConnectUri().toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.debug("Failed to read URI to build transport connectors map", e);
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTransportConnectorByType(String type) {
|
||||
return brokerService.getTransportConnectorURIsAsMap().get(type);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
/**
|
||||
* @deprecated use {@link #getTransportConnectors()} or {@link #getTransportConnectorByType(String)}
|
||||
*/
|
||||
public String getOpenWireURL() {
|
||||
String answer = brokerService.getTransportConnectorURIsAsMap().get("tcp");
|
||||
return answer != null ? answer : "";
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
/**
|
||||
* @deprecated use {@link #getTransportConnectors()} or {@link #getTransportConnectorByType(String)}
|
||||
*/
|
||||
public String getStompURL() {
|
||||
String answer = brokerService.getTransportConnectorURIsAsMap().get("stomp");
|
||||
return answer != null ? answer : "";
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
/**
|
||||
* @deprecated use {@link #getTransportConnectors()} or {@link #getTransportConnectorByType(String)}
|
||||
*/
|
||||
public String getSslURL() {
|
||||
String answer = brokerService.getTransportConnectorURIsAsMap().get("ssl");
|
||||
return answer != null ? answer : "";
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
/**
|
||||
* @deprecated use {@link #getTransportConnectors()} or {@link #getTransportConnectorByType(String)}
|
||||
*/
|
||||
public String getStompSslURL() {
|
||||
String answer = brokerService.getTransportConnectorURIsAsMap().get("stomp+ssl");
|
||||
return answer != null ? answer : "";
|
||||
|
|
|
@ -19,6 +19,8 @@ package org.apache.activemq.broker.jmx;
|
|||
import javax.management.ObjectName;
|
||||
import org.apache.activemq.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author David Martin Clavo david(dot)martin(dot)clavo(at)gmail.com (for the reloadLog4jProperties method)
|
||||
|
@ -249,21 +251,43 @@ public interface BrokerViewMBean extends Service {
|
|||
@MBeanInfo(value="Reloads log4j.properties from the classpath.")
|
||||
public void reloadLog4jProperties() throws Throwable;
|
||||
|
||||
@MBeanInfo("The url of the openwire connector")
|
||||
/**
|
||||
* @deprecated use {@link #getTransportConnectors()} or {@link #getTransportConnectorByType(String)}
|
||||
*/
|
||||
@Deprecated
|
||||
@MBeanInfo("The url of the openwire connector - deprecated, use getTransportConnectors or getTransportConnectorByType instead")
|
||||
String getOpenWireURL();
|
||||
|
||||
@MBeanInfo("The url of the stomp connector")
|
||||
/**
|
||||
* @deprecated use {@link #getTransportConnectors()} or {@link #getTransportConnectorByType(String)}
|
||||
*/
|
||||
@Deprecated
|
||||
@MBeanInfo("The url of the stomp connector - deprecated, use getTransportConnectors or getTransportConnectorByType instead")
|
||||
String getStompURL();
|
||||
|
||||
@MBeanInfo("The url of the SSL connector")
|
||||
/**
|
||||
* @deprecated use {@link #getTransportConnectors()} or {@link #getTransportConnectorByType(String)}
|
||||
*/
|
||||
@Deprecated
|
||||
@MBeanInfo("The url of the SSL connector - deprecated, use getTransportConnectors or getTransportConnectorByType instead")
|
||||
String getSslURL();
|
||||
|
||||
@MBeanInfo("The url of the Stomp SSL connector")
|
||||
/**
|
||||
* @deprecated use {@link #getTransportConnectors()} or {@link #getTransportConnectorByType(String)}
|
||||
*/
|
||||
@Deprecated
|
||||
@MBeanInfo("The url of the Stomp SSL connector - deprecated, use getTransportConnectors or getTransportConnectorByType instead")
|
||||
String getStompSslURL();
|
||||
|
||||
@MBeanInfo("The url of the VM connector")
|
||||
String getVMURL();
|
||||
|
||||
@MBeanInfo("The map of all defined transport connectors, with transport name as a key")
|
||||
Map<String, String> getTransportConnectors();
|
||||
|
||||
@MBeanInfo("The url of transport connector by it's type; e.g. tcp, stomp, ssl, etc.")
|
||||
String getTransportConnectorByType(String type);
|
||||
|
||||
@MBeanInfo("The location of the data directory")
|
||||
public String getDataDirectory();
|
||||
|
||||
|
|
|
@ -88,4 +88,6 @@ public abstract class TransportServerSupport extends ServiceSupport implements T
|
|||
public void setTransportOption(Map<String, Object> transportOptions) {
|
||||
this.transportOptions = transportOptions;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -90,8 +90,9 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
|
|||
public void testConnectors() throws Exception{
|
||||
ObjectName brokerName = assertRegisteredObjectName(domain + ":Type=Broker,BrokerName=localhost");
|
||||
BrokerViewMBean broker = (BrokerViewMBean)MBeanServerInvocationHandler.newProxyInstance(mbeanServer, brokerName, BrokerViewMBean.class, true);
|
||||
|
||||
assertEquals("openwire URL port doesn't equal bind Address",
|
||||
new URI(broker.getOpenWireURL()).getPort(),
|
||||
new URI(broker.getTransportConnectorByType("tcp")).getPort(),
|
||||
new URI(this.broker.getTransportConnectors().get(0).getPublishableConnectString()).getPort());
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
package org.apache.activemq.transport;
|
||||
|
||||
import org.apache.activemq.util.InetAddressUtil;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
|
||||
abstract public class WebTransportServerSupport extends TransportServerSupport {
|
||||
|
||||
protected URI bindAddress;
|
||||
protected Server server;
|
||||
protected Connector connector;
|
||||
protected SocketConnectorFactory socketConnectorFactory;
|
||||
protected String host;
|
||||
|
||||
public WebTransportServerSupport(URI location) {
|
||||
super(location);
|
||||
}
|
||||
|
||||
public void bind() throws Exception {
|
||||
|
||||
URI bind = getBindLocation();
|
||||
|
||||
String bindHost = bind.getHost();
|
||||
bindHost = (bindHost == null || bindHost.length() == 0) ? "localhost" : bindHost;
|
||||
InetAddress addr = InetAddress.getByName(bindHost);
|
||||
host = addr.getCanonicalHostName();
|
||||
if (addr.isAnyLocalAddress()) {
|
||||
host = InetAddressUtil.getLocalHostName();
|
||||
}
|
||||
|
||||
connector.setHost(host);
|
||||
connector.setPort(bindAddress.getPort());
|
||||
connector.setServer(server);
|
||||
server.addConnector(connector);
|
||||
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@ package org.apache.activemq.transport.http;
|
|||
import org.apache.activemq.command.BrokerInfo;
|
||||
import org.apache.activemq.transport.SocketConnectorFactory;
|
||||
import org.apache.activemq.transport.TransportServerSupport;
|
||||
import org.apache.activemq.transport.WebTransportServerSupport;
|
||||
import org.apache.activemq.transport.util.TextWireFormat;
|
||||
import org.apache.activemq.transport.xstream.XStreamWireFormat;
|
||||
import org.apache.activemq.util.ServiceStopper;
|
||||
|
@ -28,18 +29,15 @@ import org.eclipse.jetty.server.handler.GzipHandler;
|
|||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
public class HttpTransportServer extends TransportServerSupport {
|
||||
public class HttpTransportServer extends WebTransportServerSupport {
|
||||
|
||||
private URI bindAddress;
|
||||
private TextWireFormat wireFormat;
|
||||
private Server server;
|
||||
private Connector connector;
|
||||
private HttpTransportFactory transportFactory;
|
||||
protected SocketConnectorFactory socketConnectorFactory;
|
||||
|
||||
public HttpTransportServer(URI uri, HttpTransportFactory factory) {
|
||||
super(uri);
|
||||
|
@ -79,10 +77,9 @@ public class HttpTransportServer extends TransportServerSupport {
|
|||
if (connector == null) {
|
||||
connector = socketConnectorFactory.createConnector();
|
||||
}
|
||||
connector.setHost(bindAddress.getHost());
|
||||
connector.setPort(bindAddress.getPort());
|
||||
connector.setServer(server);
|
||||
server.addConnector(connector);
|
||||
|
||||
URI bind = getBindLocation();
|
||||
bind();
|
||||
|
||||
ServletContextHandler contextHandler =
|
||||
new ServletContextHandler(server, "/", ServletContextHandler.NO_SECURITY);
|
||||
|
@ -100,6 +97,7 @@ public class HttpTransportServer extends TransportServerSupport {
|
|||
contextHandler.setHandler(gzipHandler);
|
||||
|
||||
server.start();
|
||||
setConnectURI(new URI(bind.getScheme(), bind.getUserInfo(), host, connector.getLocalPort(), bind.getPath(), bind.getQuery(), bind.getFragment()));
|
||||
}
|
||||
|
||||
protected void doStop(ServiceStopper stopper) throws Exception {
|
||||
|
|
|
@ -20,6 +20,8 @@ package org.apache.activemq.transport.ws;
|
|||
import org.apache.activemq.command.BrokerInfo;
|
||||
import org.apache.activemq.transport.SocketConnectorFactory;
|
||||
import org.apache.activemq.transport.TransportServerSupport;
|
||||
import org.apache.activemq.transport.WebTransportServerSupport;
|
||||
import org.apache.activemq.util.InetAddressUtil;
|
||||
import org.apache.activemq.util.ServiceStopper;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
@ -27,6 +29,7 @@ import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
|||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
@ -35,12 +38,7 @@ import java.util.Map;
|
|||
* Creates a web server and registers web socket server
|
||||
*
|
||||
*/
|
||||
public class WSTransportServer extends TransportServerSupport {
|
||||
|
||||
private URI bindAddress;
|
||||
private Server server;
|
||||
private Connector connector;
|
||||
protected SocketConnectorFactory socketConnectorFactory;
|
||||
public class WSTransportServer extends WebTransportServerSupport {
|
||||
|
||||
public WSTransportServer(URI location) {
|
||||
super(location);
|
||||
|
@ -50,13 +48,14 @@ public class WSTransportServer extends TransportServerSupport {
|
|||
|
||||
protected void doStart() throws Exception {
|
||||
server = new Server();
|
||||
|
||||
if (connector == null) {
|
||||
connector = socketConnectorFactory.createConnector();
|
||||
}
|
||||
connector.setHost(bindAddress.getHost());
|
||||
connector.setPort(bindAddress.getPort());
|
||||
connector.setServer(server);
|
||||
server.addConnector(connector);
|
||||
|
||||
URI bind = getBindLocation();
|
||||
|
||||
bind();
|
||||
|
||||
ServletContextHandler contextHandler =
|
||||
new ServletContextHandler(server, "/", ServletContextHandler.NO_SECURITY);
|
||||
|
@ -68,6 +67,7 @@ public class WSTransportServer extends TransportServerSupport {
|
|||
contextHandler.setAttribute("acceptListener", getAcceptListener());
|
||||
|
||||
server.start();
|
||||
setConnectURI(new URI(bind.getScheme(), bind.getUserInfo(), host, connector.getLocalPort(), bind.getPath(), bind.getQuery(), bind.getFragment()));
|
||||
}
|
||||
|
||||
protected void doStop(ServiceStopper stopper) throws Exception {
|
||||
|
|
Loading…
Reference in New Issue