Search in sources :

Example 26 with ServerConnector

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

the class AbstractTest method prepareServer.

protected void prepareServer(ConnectionFactory connectionFactory) {
    QueuedThreadPool serverExecutor = new QueuedThreadPool();
    serverExecutor.setName("server");
    server = new Server(serverExecutor);
    connector = new ServerConnector(server, 1, 1, connectionFactory);
    server.addConnector(connector);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool)

Example 27 with ServerConnector

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

the class OverlayServer method main.

public static void main(String[] args) throws Exception {
    // NamingUtil.__log.setDebugEnabled(true);
    String jetty_home = System.getProperty("jetty.home", "target/test-classes/home");
    System.setProperty("jetty.home", jetty_home);
    Server server = new Server();
    server.setAttribute("org.eclipse.jetty.webapp.configuration", new String[] { org.eclipse.jetty.webapp.WebInfConfiguration.class.getCanonicalName(), org.eclipse.jetty.webapp.WebXmlConfiguration.class.getCanonicalName(), org.eclipse.jetty.webapp.MetaInfConfiguration.class.getCanonicalName(), org.eclipse.jetty.webapp.FragmentConfiguration.class.getCanonicalName(), org.eclipse.jetty.plus.webapp.EnvConfiguration.class.getCanonicalName(), org.eclipse.jetty.plus.webapp.PlusConfiguration.class.getCanonicalName(), org.eclipse.jetty.webapp.JettyWebXmlConfiguration.class.getCanonicalName() });
    // Setup Connectors
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(8080);
    server.addConnector(connector);
    HandlerCollection handlers = new HandlerCollection();
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    RequestLogHandler requestLogHandler = new RequestLogHandler();
    handlers.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
    StatisticsHandler stats = new StatisticsHandler();
    stats.setHandler(handlers);
    server.setHandler(stats);
    // Setup deployers
    DeploymentManager deployer = new DeploymentManager();
    deployer.setContexts(contexts);
    server.addBean(deployer);
    OverlayedAppProvider provider = new OverlayedAppProvider();
    provider.setNodeName("nodeA");
    provider.setScanDir(new File(jetty_home + "/overlays"));
    provider.setScanInterval(2);
    deployer.addAppProvider(provider);
    server.setStopAtShutdown(true);
    //server.setSendServerVersion(true);
    // Uncomment to work with JNDI examples
    // new org.eclipse.jetty.plus.jndi.Transaction(new com.atomikos.icatch.jta.UserTransactionImp());
    server.start();
    server.join();
}
Also used : Server(org.eclipse.jetty.server.Server) DeploymentManager(org.eclipse.jetty.deploy.DeploymentManager) OverlayedAppProvider(org.eclipse.jetty.overlays.OverlayedAppProvider) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) StatisticsHandler(org.eclipse.jetty.server.handler.StatisticsHandler) File(java.io.File)

Example 28 with ServerConnector

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

the class SSLAsyncIOServletTest method prepare.

public void prepare(HttpServlet servlet) throws Exception {
    server = new Server();
    connector = new ServerConnector(server, sslContextFactory);
    server.addConnector(connector);
    contextPath = "/context";
    ServletContextHandler context = new ServletContextHandler(server, contextPath, true, false);
    servletPath = "/servlet";
    context.addServlet(new ServletHolder(servlet), servletPath);
    server.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server)

Example 29 with ServerConnector

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

the class AsyncServletIOTest method setUp.

@Before
public void setUp() throws Exception {
    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setOutputBufferSize(4096);
    _connector = new ServerConnector(_server, new HttpConnectionFactory(http_config));
    _server.setConnectors(new Connector[] { _connector });
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/ctx");
    context.addEventListener(new DebugListener());
    _server.setHandler(context);
    _servletHandler = context.getServletHandler();
    ServletHolder holder = new ServletHolder(_servlet0);
    holder.setAsyncSupported(true);
    _servletHandler.addServletWithMapping(holder, "/path/*");
    ServletHolder holder2 = new ServletHolder(_servlet2);
    holder2.setAsyncSupported(true);
    _servletHandler.addServletWithMapping(holder2, "/path2/*");
    ServletHolder holder3 = new ServletHolder(_servlet3);
    holder3.setAsyncSupported(true);
    _servletHandler.addServletWithMapping(holder3, "/path3/*");
    ServletHolder holder4 = new ServletHolder(_servlet4);
    holder4.setAsyncSupported(true);
    _servletHandler.addServletWithMapping(holder4, "/path4/*");
    _server.start();
    _port = _connector.getLocalPort();
    _owp.set(0);
    _oda.set(0);
    _read.set(0);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) DebugListener(org.eclipse.jetty.server.DebugListener) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) Before(org.junit.Before)

Example 30 with ServerConnector

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

the class AsyncServletTest method setUp.

@Before
public void setUp() throws Exception {
    _connector = new ServerConnector(_server);
    _server.setConnectors(new Connector[] { _connector });
    _log = new ArrayList<>();
    RequestLog log = new Log();
    RequestLogHandler logHandler = new RequestLogHandler();
    logHandler.setRequestLog(log);
    _server.setHandler(logHandler);
    _expectedLogs = 1;
    _expectedCode = "200 ";
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
    context.setContextPath("/ctx");
    logHandler.setHandler(context);
    context.addEventListener(new DebugListener());
    _errorHandler = new ErrorPageErrorHandler();
    context.setErrorHandler(_errorHandler);
    _errorHandler.addErrorPage(300, 599, "/error/custom");
    _servletHandler = context.getServletHandler();
    ServletHolder holder = new ServletHolder(_servlet);
    holder.setAsyncSupported(true);
    _servletHandler.addServletWithMapping(holder, "/error/*");
    _servletHandler.addServletWithMapping(holder, "/path/*");
    _servletHandler.addServletWithMapping(holder, "/path1/*");
    _servletHandler.addServletWithMapping(holder, "/path2/*");
    _servletHandler.addServletWithMapping(holder, "/p th3/*");
    _servletHandler.addServletWithMapping(new ServletHolder(new FwdServlet()), "/fwd/*");
    ServletHolder holder2 = new ServletHolder("NoAsync", _servlet);
    holder2.setAsyncSupported(false);
    _servletHandler.addServletWithMapping(holder2, "/noasync/*");
    _server.start();
    _port = _connector.getLocalPort();
    __history.clear();
    __latch = new CountDownLatch(1);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) RequestLog(org.eclipse.jetty.server.RequestLog) RequestLog(org.eclipse.jetty.server.RequestLog) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) DebugListener(org.eclipse.jetty.server.DebugListener) CountDownLatch(java.util.concurrent.CountDownLatch) Before(org.junit.Before)

Aggregations

ServerConnector (org.eclipse.jetty.server.ServerConnector)272 Server (org.eclipse.jetty.server.Server)205 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)80 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)73 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)63 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)53 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)51 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)49 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)42 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)40 URI (java.net.URI)37 Test (org.junit.Test)31 File (java.io.File)28 BeforeClass (org.junit.BeforeClass)28 IOException (java.io.IOException)26 Before (org.junit.Before)25 BeforeClass (org.testng.annotations.BeforeClass)22 ServletException (javax.servlet.ServletException)21 HttpServletRequest (javax.servlet.http.HttpServletRequest)19 HttpServletResponse (javax.servlet.http.HttpServletResponse)18