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();
}
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);
}
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;
}
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;
}
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);
}
}
Aggregations