Search in sources :

Example 1 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project jetty.project by eclipse.

the class JmxIT method connectToMBeanServer.

@BeforeClass
public static void connectToMBeanServer() throws Exception {
    startJetty();
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost:1099/jndi/rmi://localhost:1099/jmxrmi");
    __jmxc = JMXConnectorFactory.connect(url, null);
    __mbsc = __jmxc.getMBeanServerConnection();
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) BeforeClass(org.junit.BeforeClass)

Example 2 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project jetty.project by eclipse.

the class JmxIT method startJetty.

public static void startJetty() throws Exception {
    File target = MavenTestingUtils.getTargetDir();
    File jettyBase = new File(target, "test-base");
    File webapps = new File(jettyBase, "webapps");
    File war = new File(webapps, "jmx-webapp.war");
    //create server instance
    __server = new Server(0);
    //set up the webapp
    WebAppContext context = new WebAppContext();
    context.setWar(war.getCanonicalPath());
    context.setContextPath("/jmx-webapp");
    Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(__server);
    classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");
    context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/javax.servlet-[^/]*\\.jar$|.*/servlet-api-[^/]*\\.jar$");
    __server.setHandler(context);
    //set up jmx remote
    MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    __server.addBean(mbContainer);
    JMXServiceURL serviceUrl = new JMXServiceURL("rmi", "localhost", 1099, "/jndi/rmi://localhost:1099/jmxrmi");
    ConnectorServer jmxConnServer = new ConnectorServer(serviceUrl, "org.eclipse.jetty.jmx:name=rmiconnectorserver");
    __server.addBean(jmxConnServer);
    //start server
    __server.start();
    //remember chosen port
    __port = ((NetworkConnector) __server.getConnectors()[0]).getLocalPort();
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Server(org.eclipse.jetty.server.Server) ConnectorServer(org.eclipse.jetty.jmx.ConnectorServer) Configuration(org.eclipse.jetty.webapp.Configuration) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) ConnectorServer(org.eclipse.jetty.jmx.ConnectorServer) File(java.io.File)

Example 3 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project jetty.project by eclipse.

the class ConnectorServerTest method testIsLoopbackAddressWithWrongValue.

@Test
@Ignore
public void testIsLoopbackAddressWithWrongValue() throws Exception {
    // given
    JMXServiceURL serviceURLWithOutPort = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + InetAddress.getLocalHost() + ":1199/jmxrmi");
    // when
    connectorServer = new ConnectorServer(serviceURLWithOutPort, " domain: key5 = value5");
    // then
    assertNull("As loopback address returns false...registry must be null", connectorServer._registry);
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project jetty.project by eclipse.

the class ConnectorServerTest method testConnServerWithRmiDefaultPort.

@Test
// collides on ci server
@Ignore
public void testConnServerWithRmiDefaultPort() throws Exception {
    // given
    LocateRegistry.createRegistry(1099);
    JMXServiceURL serviceURLWithOutPort = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
    connectorServer = new ConnectorServer(serviceURLWithOutPort, " domain: key3 = value3");
    // when
    connectorServer.start();
    // then
    assertThat("Server status must be in started or starting", connectorServer.getState(), anyOf(is(ConnectorServer.STARTED), is(ConnectorServer.STARTING)));
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project jetty.project by eclipse.

the class ServerWithJMX method main.

public static void main(String[] args) throws Exception {
    // === jetty-jmx.xml ===
    MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    Server server = new Server(8080);
    server.addBean(mbContainer);
    ConnectorServer jmx = new ConnectorServer(new JMXServiceURL("rmi", null, 1999, "/jndi/rmi://localhost:1999/jmxrmi"), "org.eclipse.jetty.jmx:name=rmiconnectorserver");
    server.addBean(jmx);
    server.start();
    server.dumpStdErr();
    server.join();
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) ConnectorServer(org.eclipse.jetty.jmx.ConnectorServer) Server(org.eclipse.jetty.server.Server) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) ConnectorServer(org.eclipse.jetty.jmx.ConnectorServer)

Aggregations

JMXServiceURL (javax.management.remote.JMXServiceURL)280 JMXConnector (javax.management.remote.JMXConnector)150 MBeanServerConnection (javax.management.MBeanServerConnection)107 ObjectName (javax.management.ObjectName)90 IOException (java.io.IOException)78 HashMap (java.util.HashMap)75 MBeanServer (javax.management.MBeanServer)71 JMXConnectorServer (javax.management.remote.JMXConnectorServer)64 MalformedURLException (java.net.MalformedURLException)45 RemoteException (java.rmi.RemoteException)22 Test (org.junit.Test)22 Map (java.util.Map)16 UnknownHostException (java.net.UnknownHostException)14 Properties (java.util.Properties)14 Notification (javax.management.Notification)14 NotificationListener (javax.management.NotificationListener)14 MalformedObjectNameException (javax.management.MalformedObjectNameException)13 LocateRegistry (java.rmi.registry.LocateRegistry)12 Registry (java.rmi.registry.Registry)12 ArrayList (java.util.ArrayList)11