Search in sources :

Example 1 with HotSwapHandler

use of org.eclipse.jetty.server.handler.HotSwapHandler in project jetty.project by eclipse.

the class HttpServerTestFixture method configureServer.

protected void configureServer(Handler handler) throws Exception {
    HotSwapHandler swapper = (HotSwapHandler) _server.getHandler();
    swapper.setHandler(handler);
    handler.start();
}
Also used : HotSwapHandler(org.eclipse.jetty.server.handler.HotSwapHandler)

Example 2 with HotSwapHandler

use of org.eclipse.jetty.server.handler.HotSwapHandler in project jetty.project by eclipse.

the class HttpOutputTest method init.

@Before
public void init() throws Exception {
    _server = new Server();
    HttpConnectionFactory http = new HttpConnectionFactory();
    http.getHttpConfiguration().setRequestHeaderSize(1024);
    http.getHttpConfiguration().setResponseHeaderSize(1024);
    http.getHttpConfiguration().setOutputBufferSize(4096);
    _connector = new LocalConnector(_server, http, null);
    _server.addConnector(_connector);
    _swap = new HotSwapHandler();
    _handler = new ContentHandler();
    _swap.setHandler(_handler);
    _server.setHandler(_swap);
    _server.start();
}
Also used : HotSwapHandler(org.eclipse.jetty.server.handler.HotSwapHandler) Before(org.junit.Before)

Example 3 with HotSwapHandler

use of org.eclipse.jetty.server.handler.HotSwapHandler in project jetty.project by eclipse.

the class WebAppContextTest method testServletContextListener.

@Test
public void testServletContextListener() throws Exception {
    Server server = new Server();
    HotSwapHandler swap = new HotSwapHandler();
    server.setHandler(swap);
    server.start();
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    context.setResourceBase(System.getProperty("java.io.tmpdir"));
    final List<String> history = new ArrayList<>();
    context.addEventListener(new ServletContextListener() {

        @Override
        public void contextInitialized(ServletContextEvent servletContextEvent) {
            history.add("I0");
        }

        @Override
        public void contextDestroyed(ServletContextEvent servletContextEvent) {
            history.add("D0");
        }
    });
    context.addEventListener(new ServletContextListener() {

        @Override
        public void contextInitialized(ServletContextEvent servletContextEvent) {
            history.add("I1");
        }

        @Override
        public void contextDestroyed(ServletContextEvent servletContextEvent) {
            history.add("D1");
            throw new RuntimeException("Listener1 destroy broken");
        }
    });
    context.addEventListener(new ServletContextListener() {

        @Override
        public void contextInitialized(ServletContextEvent servletContextEvent) {
            history.add("I2");
            throw new RuntimeException("Listener2 init broken");
        }

        @Override
        public void contextDestroyed(ServletContextEvent servletContextEvent) {
            history.add("D2");
        }
    });
    context.addEventListener(new ServletContextListener() {

        @Override
        public void contextInitialized(ServletContextEvent servletContextEvent) {
            history.add("I3");
        }

        @Override
        public void contextDestroyed(ServletContextEvent servletContextEvent) {
            history.add("D3");
        }
    });
    try {
        swap.setHandler(context);
        context.start();
    } catch (Exception e) {
        history.add(e.getMessage());
    } finally {
        try {
            swap.setHandler(null);
        } catch (Exception e) {
            while (e.getCause() instanceof Exception) e = (Exception) e.getCause();
            history.add(e.getMessage());
        } finally {
        }
    }
    Assert.assertThat(history, Matchers.contains("I0", "I1", "I2", "Listener2 init broken", "D1", "D0", "Listener1 destroy broken"));
    server.stop();
}
Also used : Server(org.eclipse.jetty.server.Server) HotSwapHandler(org.eclipse.jetty.server.handler.HotSwapHandler) ServletContextListener(javax.servlet.ServletContextListener) ArrayList(java.util.ArrayList) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ServletContextEvent(javax.servlet.ServletContextEvent) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

HotSwapHandler (org.eclipse.jetty.server.handler.HotSwapHandler)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ServletContextEvent (javax.servlet.ServletContextEvent)1 ServletContextListener (javax.servlet.ServletContextListener)1 ServletException (javax.servlet.ServletException)1 Server (org.eclipse.jetty.server.Server)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 Before (org.junit.Before)1 Test (org.junit.Test)1