Search in sources :

Example 1 with MBeanContainer

use of org.eclipse.jetty.jmx.MBeanContainer 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 2 with MBeanContainer

use of org.eclipse.jetty.jmx.MBeanContainer in project jetty.project by eclipse.

the class AttrEventTriggerTest method setUp.

@Before
public void setUp() throws Exception {
    File docRoot = new File("target/test-output/docroot/");
    docRoot.mkdirs();
    docRoot.deleteOnExit();
    System.setProperty("org.eclipse.jetty.util.log.DEBUG", "");
    _server = new Server();
    ServerConnector connector = new ServerConnector(_server);
    connector.setPort(0);
    _server.setConnectors(new Connector[] { connector });
    _handler = new TestHandler();
    _server.setHandler(_handler);
    MBeanContainer.resetUnique();
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    _mBeanContainer = new MBeanContainer(mBeanServer);
    _server.addBean(_mBeanContainer, true);
    _server.addBean(Log.getLog());
    _counter = _handler.getRequestCounter();
    _server.addBean(_counter);
    _server.start();
    startClient();
    _monitor = new JMXMonitor();
    int port = connector.getLocalPort();
    _requestUrl = "http://localhost:" + port + "/";
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) MBeanServer(javax.management.MBeanServer) Server(org.eclipse.jetty.server.Server) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) File(java.io.File) MBeanServer(javax.management.MBeanServer) Before(org.junit.Before)

Example 3 with MBeanContainer

use of org.eclipse.jetty.jmx.MBeanContainer 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)

Example 4 with MBeanContainer

use of org.eclipse.jetty.jmx.MBeanContainer in project jetty.project by eclipse.

the class OneWebAppWithJsp method main.

public static void main(String[] args) throws Exception {
    // Create a basic jetty server object that will listen on port 8080.
    // Note that if you set this to port 0 then
    // a randomly available port will be assigned that you can either look
    // in the logs for the port,
    // or programmatically obtain it for use in test cases.
    Server server = new Server(8080);
    // Setup JMX
    MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    server.addBean(mbContainer);
    // The WebAppContext is the entity that controls the environment in
    // which a web application lives and
    // breathes. In this example the context path is being set to "/" so it
    // is suitable for serving root context
    // requests and then we see it setting the location of the war. A whole
    // host of other configurations are
    // available, ranging from configuring to support annotation scanning in
    // the webapp (through
    // PlusConfiguration) to choosing where the webapp will unpack itself.
    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    File warFile = new File("../../jetty-distribution/target/distribution/demo-base/webapps/test.war");
    if (!warFile.exists()) {
        throw new RuntimeException("Unable to find WAR File: " + warFile.getAbsolutePath());
    }
    webapp.setWar(warFile.getAbsolutePath());
    webapp.setExtractWAR(true);
    // This webapp will use jsps and jstl. We need to enable the
    // AnnotationConfiguration in order to correctly
    // set up the jsp container
    Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(server);
    classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");
    // Set the ContainerIncludeJarPattern so that jetty examines these
    // container-path jars for tlds, web-fragments etc.
    // If you omit the jar that contains the jstl .tlds, the jsp engine will
    // scan for them instead.
    webapp.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/[^/]*taglibs.*\\.jar$");
    // A WebAppContext is a ContextHandler as well so it needs to be set to
    // the server so it is aware of where to
    // send the appropriate requests.
    server.setHandler(webapp);
    // Configure a LoginService.
    // Since this example is for our test webapp, we need to setup a
    // LoginService so this shows how to create a very simple hashmap based
    // one. The name of the LoginService needs to correspond to what is
    // configured in the webapp's web.xml and since it has a lifecycle of
    // its own we register it as a bean with the Jetty server object so it
    // can be started and stopped according to the lifecycle of the server
    // itself.
    HashLoginService loginService = new HashLoginService();
    loginService.setName("Test Realm");
    loginService.setConfig("src/test/resources/realm.properties");
    server.addBean(loginService);
    // Start things up! 
    server.start();
    server.dumpStdErr();
    // The use of server.join() the will make the current thread join and
    // wait until the server is done executing.
    // See http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#join()
    server.join();
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) HashLoginService(org.eclipse.jetty.security.HashLoginService) Server(org.eclipse.jetty.server.Server) Configuration(org.eclipse.jetty.webapp.Configuration) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) File(java.io.File)

Example 5 with MBeanContainer

use of org.eclipse.jetty.jmx.MBeanContainer in project camel by apache.

the class WebsocketComponent method enableJmx.

private void enableJmx(Server server) {
    MBeanContainer containerToRegister = getMbContainer();
    if (containerToRegister != null) {
        LOG.info("Jetty JMX Extensions is enabled");
        server.addEventListener(containerToRegister);
    // Since we may have many Servers running, don't tie the MBeanContainer
    // to a Server lifecycle or we end up closing it while it is still in use.
    //server.addBean(mbContainer);
    }
}
Also used : MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer)

Aggregations

MBeanContainer (org.eclipse.jetty.jmx.MBeanContainer)34 Server (org.eclipse.jetty.server.Server)21 ServerConnector (org.eclipse.jetty.server.ServerConnector)11 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)11 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)10 File (java.io.File)9 MBeanServer (javax.management.MBeanServer)9 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)9 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)9 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)8 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)8 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)7 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)6 ConnectorServer (org.eclipse.jetty.jmx.ConnectorServer)5 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)5 JMXServiceURL (javax.management.remote.JMXServiceURL)4 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)4 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)4 Connector (org.eclipse.jetty.server.Connector)3 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)3