HelloWebServer.java 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package hello;
  2. import org.eclipse.jetty.server.HttpConfiguration;
  3. import org.eclipse.jetty.server.HttpConnectionFactory;
  4. import org.eclipse.jetty.server.Server;
  5. import org.eclipse.jetty.server.ServerConnector;
  6. import org.eclipse.jetty.servlet.ServletContextHandler;
  7. /**
  8. * An implementation of the TechEmpower benchmark tests using the Jetty web
  9. * server.
  10. */
  11. public final class HelloWebServer
  12. {
  13. public static void main(String[] args) throws Exception
  14. {
  15. Server server = new Server(8080);
  16. ServerConnector connector = server.getBean(ServerConnector.class);
  17. HttpConfiguration config = connector.getBean(HttpConnectionFactory.class).getHttpConfiguration();
  18. config.setSendDateHeader(true);
  19. config.setSendServerVersion(true);
  20. ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SECURITY|ServletContextHandler.NO_SESSIONS);
  21. context.setContextPath("/");
  22. server.setHandler(context);
  23. context.addServlet(org.eclipse.jetty.servlet.DefaultServlet.class,"/");
  24. context.addServlet(JsonServlet.class,"/json");
  25. context.addServlet(PlaintextServlet.class,"/plaintext");
  26. server.start();
  27. server.join();
  28. }
  29. }