Search in sources :

Example 26 with MBeanContainer

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

the class DoSFilterJMXTest method testDoSFilterJMX.

@Test
public void testDoSFilterJMX() throws Exception {
    Server server = new Server();
    Connector connector = new ServerConnector(server);
    server.addConnector(connector);
    ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
    DoSFilter filter = new DoSFilter();
    FilterHolder holder = new FilterHolder(filter);
    String name = "dos";
    holder.setName(name);
    holder.setInitParameter(DoSFilter.MANAGED_ATTR_INIT_PARAM, "true");
    context.addFilter(holder, "/*", EnumSet.of(DispatcherType.REQUEST));
    context.setInitParameter(ServletContextHandler.MANAGED_ATTRIBUTES, name);
    MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
    MBeanContainer mbeanContainer = new MBeanContainer(mbeanServer);
    server.addBean(mbeanContainer);
    server.start();
    String domain = DoSFilter.class.getPackage().getName();
    Set<ObjectName> mbeanNames = mbeanServer.queryNames(ObjectName.getInstance(domain + ":*"), null);
    Assert.assertEquals(1, mbeanNames.size());
    ObjectName objectName = mbeanNames.iterator().next();
    boolean value = (Boolean) mbeanServer.getAttribute(objectName, "enabled");
    mbeanServer.setAttribute(objectName, new Attribute("enabled", !value));
    Assert.assertEquals(!value, filter.isEnabled());
    String whitelist = (String) mbeanServer.getAttribute(objectName, "whitelist");
    String address = "127.0.0.1";
    Assert.assertFalse(whitelist.contains(address));
    boolean result = (Boolean) mbeanServer.invoke(objectName, "addWhitelistAddress", new Object[] { address }, new String[] { String.class.getName() });
    Assert.assertTrue(result);
    whitelist = (String) mbeanServer.getAttribute(objectName, "whitelist");
    Assert.assertTrue(whitelist.contains(address));
    result = (Boolean) mbeanServer.invoke(objectName, "removeWhitelistAddress", new Object[] { address }, new String[] { String.class.getName() });
    Assert.assertTrue(result);
    whitelist = (String) mbeanServer.getAttribute(objectName, "whitelist");
    Assert.assertFalse(whitelist.contains(address));
    server.stop();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) MBeanServer(javax.management.MBeanServer) Server(org.eclipse.jetty.server.Server) Attribute(javax.management.Attribute) ObjectName(javax.management.ObjectName) ServerConnector(org.eclipse.jetty.server.ServerConnector) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 27 with MBeanContainer

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

the class DeploymentManagerLifeCyclePathTest method testStateTransition_DeployedToUndeployed.

@Test
public void testStateTransition_DeployedToUndeployed() throws Exception {
    DeploymentManager depman = new DeploymentManager();
    // no default
    depman.setDefaultLifeCycleGoal(null);
    AppLifeCyclePathCollector pathtracker = new AppLifeCyclePathCollector();
    MockAppProvider mockProvider = new MockAppProvider();
    // Setup JMX
    MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    depman.addBean(mbContainer);
    depman.addLifeCycleBinding(pathtracker);
    depman.addAppProvider(mockProvider);
    depman.setContexts(new ContextHandlerCollection());
    // Start DepMan
    depman.start();
    // Trigger new App
    mockProvider.findWebapp("foo-webapp-1.war");
    App app = depman.getAppByOriginId("mock-foo-webapp-1.war");
    // Request Deploy of App
    depman.requestAppGoal(app, "deployed");
    JmxServiceConnection jmxConnection = new JmxServiceConnection();
    jmxConnection.connect();
    MBeanServerConnection mbsConnection = jmxConnection.getConnection();
    ObjectName dmObjName = new ObjectName("org.eclipse.jetty.deploy:type=deploymentmanager,id=0");
    String[] params = new String[] { "mock-foo-webapp-1.war", "undeployed" };
    String[] signature = new String[] { "java.lang.String", "java.lang.String" };
    mbsConnection.invoke(dmObjName, "requestAppGoal", params, signature);
    // Setup Expectations.
    List<String> expected = new ArrayList<String>();
    // SHOULD NOT SEE THIS NODE VISITED - expected.add("undeployed");
    expected.add("deploying");
    expected.add("deployed");
    expected.add("undeploying");
    expected.add("undeployed");
    pathtracker.assertExpected("Test JMX StateTransition / Deployed -> Undeployed", expected);
}
Also used : ArrayList(java.util.ArrayList) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) ObjectName(javax.management.ObjectName) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) MBeanServerConnection(javax.management.MBeanServerConnection) Test(org.junit.Test)

Example 28 with MBeanContainer

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

the class Jetty9Server method mbeans.

private MBeanContainer mbeans() {
    MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
    MBeanContainer mbeans = new MBeanContainer(platformMBeanServer);
    return mbeans;
}
Also used : MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) MBeanServer(javax.management.MBeanServer)

Example 29 with MBeanContainer

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

the class JettyHttpComponent method getMbContainer.

public synchronized MBeanContainer getMbContainer() {
    // If null, provide the default implementation.
    if (mbContainer == null) {
        MBeanServer mbs = null;
        final ManagementStrategy mStrategy = this.getCamelContext().getManagementStrategy();
        final ManagementAgent mAgent = mStrategy.getManagementAgent();
        if (mAgent != null) {
            mbs = mAgent.getMBeanServer();
        }
        if (mbs != null) {
            mbContainer = new MBeanContainer(mbs);
            startMbContainer();
        } else {
            LOG.warn("JMX disabled in CamelContext. Jetty JMX extensions will remain disabled.");
        }
    }
    return this.mbContainer;
}
Also used : ManagementAgent(org.apache.camel.spi.ManagementAgent) ManagementStrategy(org.apache.camel.spi.ManagementStrategy) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) MBeanServer(javax.management.MBeanServer)

Example 30 with MBeanContainer

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

the class StartJavaScriptTests method main.

/**
 * Main function, starts the jetty server.
 *
 * @param args
 */
public static void main(String[] args) {
    System.setProperty("wicket.configuration", "development");
    Server server = new Server();
    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    http_config.setSecurePort(8443);
    http_config.setOutputBufferSize(32768);
    ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config));
    http.setPort(8080);
    http.setIdleTimeout(1000 * 60 * 60);
    server.addConnector(http);
    Resource keystore = Resource.newClassPathResource("/keystore");
    if (keystore != null && keystore.exists()) {
        // if a keystore for a SSL certificate is available, start a SSL
        // connector on port 8443.
        // By default, the quickstart comes with a Apache Wicket Quickstart
        // Certificate that expires about half way september 2021. Do not
        // use this certificate anywhere important as the passwords are
        // available in the source.
        SslContextFactory sslContextFactory = new SslContextFactory();
        sslContextFactory.setKeyStoreResource(keystore);
        sslContextFactory.setKeyStorePassword("wicket");
        sslContextFactory.setKeyManagerPassword("wicket");
        HttpConfiguration https_config = new HttpConfiguration(http_config);
        https_config.addCustomizer(new SecureRequestCustomizer());
        ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https_config));
        https.setPort(8443);
        https.setIdleTimeout(500000);
        server.addConnector(https);
        System.out.println("SSL access to the examples has been enabled on port 8443");
        System.out.println("You can access the application using SSL on https://localhost:8443");
        System.out.println();
    }
    WebAppContext bb = new WebAppContext();
    bb.setServer(server);
    bb.setContextPath("/ajax-tests");
    bb.setWar("../../wicket-core/src");
    // uncomment next line if you want to test with JSESSIONID encoded in the urls
    // ((AbstractSessionManager)
    // bb.getSessionHandler().getSessionManager()).setUsingCookies(false);
    server.setHandler(bb);
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    server.addEventListener(mBeanContainer);
    server.addBean(mBeanContainer);
    try {
        server.start();
        browse();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(100);
    }
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) MBeanServer(javax.management.MBeanServer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) Resource(org.eclipse.jetty.util.resource.Resource) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) MBeanServer(javax.management.MBeanServer)

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 MBeanServer (javax.management.MBeanServer)9 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)9 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)9 File (java.io.File)8 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