Search in sources :

Example 41 with Server

use of org.eclipse.jetty.server.Server 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 42 with Server

use of org.eclipse.jetty.server.Server in project jetty.project by eclipse.

the class ServerWithJNDI method main.

public static void main(String[] args) throws Exception {
    // Create the server
    Server server = new Server(8080);
    // Enable parsing of jndi-related parts of web.xml and jetty-env.xml
    Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(server);
    classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
    // Create a WebApp
    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    File warFile = new File("../../jetty-distribution/target/distribution/demo-base/webapps/test-jndi.war");
    webapp.setWar(warFile.getAbsolutePath());
    server.setHandler(webapp);
    // Register new transaction manager in JNDI
    // At runtime, the webapp accesses this as java:comp/UserTransaction
    new org.eclipse.jetty.plus.jndi.Transaction(new com.acme.MockUserTransaction());
    // Define an env entry with Server scope.
    // At runtime, the webapp accesses this as java:comp/env/woggle
    // This is equivalent to putting an env-entry in web.xml:
    // <env-entry>
    // <env-entry-name>woggle</env-entry-name>
    // <env-entry-type>java.lang.Integer</env-entry-type>
    // <env-entry-value>4000</env-entry-value>
    // </env-entry>
    new org.eclipse.jetty.plus.jndi.EnvEntry(server, "woggle", new Integer(4000), false);
    // Define an env entry with webapp scope.
    // At runtime, the webapp accesses this as java:comp/env/wiggle
    // This is equivalent to putting a web.xml entry in web.xml:
    // <env-entry>
    // <env-entry-name>wiggle</env-entry-name>
    // <env-entry-value>100</env-entry-value>
    // <env-entry-type>java.lang.Double</env-entry-type>
    // </env-entry>
    // Note that the last arg of "true" means that this definition for
    // "wiggle" would override an entry of the
    // same name in web.xml
    new org.eclipse.jetty.plus.jndi.EnvEntry(webapp, "wiggle", new Double(100), true);
    // Register a reference to a mail service scoped to the webapp.
    // This must be linked to the webapp by an entry in web.xml:
    // <resource-ref>
    // <res-ref-name>mail/Session</res-ref-name>
    // <res-type>javax.mail.Session</res-type>
    // <res-auth>Container</res-auth>
    // </resource-ref>
    // At runtime the webapp accesses this as java:comp/env/mail/Session
    org.eclipse.jetty.jndi.factories.MailSessionReference mailref = new org.eclipse.jetty.jndi.factories.MailSessionReference();
    mailref.setUser("CHANGE-ME");
    mailref.setPassword("CHANGE-ME");
    Properties props = new Properties();
    props.put("mail.smtp.auth", "false");
    props.put("mail.smtp.host", "CHANGE-ME");
    props.put("mail.from", "CHANGE-ME");
    props.put("mail.debug", "false");
    mailref.setProperties(props);
    new org.eclipse.jetty.plus.jndi.Resource(webapp, "mail/Session", mailref);
    // Register a mock DataSource scoped to the webapp
    // This must be linked to the webapp via an entry in web.xml:
    // <resource-ref>
    // <res-ref-name>jdbc/mydatasource</res-ref-name>
    // <res-type>javax.sql.DataSource</res-type>
    // <res-auth>Container</res-auth>
    // </resource-ref>
    // At runtime the webapp accesses this as
    // java:comp/env/jdbc/mydatasource
    new org.eclipse.jetty.plus.jndi.Resource(webapp, "jdbc/mydatasource", new com.acme.MockDataSource());
    server.start();
    server.join();
}
Also used : Server(org.eclipse.jetty.server.Server) Configuration(org.eclipse.jetty.webapp.Configuration) Properties(java.util.Properties) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) File(java.io.File)

Example 43 with Server

use of org.eclipse.jetty.server.Server in project jetty.project by eclipse.

the class SimplestServer method main.

public static void main(String[] args) throws Exception {
    Server server = new Server(8080);
    server.start();
    server.dumpStdErr();
    server.join();
}
Also used : Server(org.eclipse.jetty.server.Server)

Example 44 with Server

use of org.eclipse.jetty.server.Server in project jetty.project by eclipse.

the class WebSocketServer method main.

public static void main(String[] args) throws Exception {
    Server server = new Server(8080);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    server.setHandler(context);
    // Add the echo socket servlet to the /echo path map
    context.addServlet(new ServletHolder(EchoServlet.class), "/echo");
    server.start();
    context.dumpStdErr();
    server.join();
}
Also used : Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 45 with Server

use of org.eclipse.jetty.server.Server in project jetty.project by eclipse.

the class JarServer method main.

public static void main(String[] args) throws Exception {
    Server server = new Server(8080);
    ServletContextHandler context = new ServletContextHandler();
    Resource.setDefaultUseCaches(true);
    Resource base = Resource.newResource("jar:file:src/main/resources/content.jar!/");
    context.setBaseResource(base);
    context.addServlet(new ServletHolder(new DefaultServlet()), "/");
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { context, new DefaultHandler() });
    server.setHandler(handlers);
    server.start();
    server.join();
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) Resource(org.eclipse.jetty.util.resource.Resource) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Aggregations

Server (org.eclipse.jetty.server.Server)521 ServerConnector (org.eclipse.jetty.server.ServerConnector)209 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)129 Test (org.junit.Test)103 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)99 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)68 IOException (java.io.IOException)66 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)65 File (java.io.File)62 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)61 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)58 URI (java.net.URI)52 Before (org.junit.Before)50 BeforeClass (org.junit.BeforeClass)47 ServletException (javax.servlet.ServletException)44 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)43 LocalConnector (org.eclipse.jetty.server.LocalConnector)42 URL (java.net.URL)37 HttpServletRequest (javax.servlet.http.HttpServletRequest)33 HttpServletResponse (javax.servlet.http.HttpServletResponse)31