Demo server uses JMX

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@176 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2009-04-22 05:18:40 +00:00
parent 39146e96a2
commit 9c56758fcc
2 changed files with 37 additions and 7 deletions

View File

@ -129,6 +129,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jmx</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>

View File

@ -1,9 +1,15 @@
package org.eclipse.jetty;
import java.lang.management.ManagementFactory;
import javax.management.MBeanServer;
import org.eclipse.jetty.http.security.Password;
import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.webapp.WebAppContext;
public class DemoServer
@ -11,22 +17,40 @@ public class DemoServer
public static void main(String[] args)
throws Exception
{
Server server = new Server(8080);
if (args.length!=1)
{
System.err.println("Usage - java "+DemoServer.class+" webappdir|war");
System.exit(1);
}
Server server = new Server();
WebAppContext context = new WebAppContext();
context.setWar("./target/jetty-test-webapp-"+Server.getVersion()); // TODO YUCK!
context.setDefaultsDescriptor("../jetty-webapp/src/main/config/etc/webdefault.xml");
server.setHandler(context);
// setup JMX
MBeanServer mbeanS = ManagementFactory.getPlatformMBeanServer();
MBeanContainer mbeanC = new MBeanContainer(mbeanS);
server.getContainer().addEventListener(mbeanC);
server.addBean(mbeanC);
// setup connector
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(8080);
server.addConnector(connector);
// setup Login service
HashLoginService login = new HashLoginService();
login.putUser("jetty",new Password("password"),new String[]{"user"});
login.putUser("admin",new Password("password"),new String[]{"user","admin"});
server.addBean(login);
server.start();
// setup webapp
WebAppContext context = new WebAppContext();
context.setWar(args[0]);
context.setDefaultsDescriptor("../jetty-webapp/src/main/config/etc/webdefault.xml");
server.setHandler(context);
// start the server
server.start();
System.err.println(server.dump());
server.join();
}
}