Search in sources :

Example 6 with HandlerWrapper

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

the class HandlerTest method testInsertWrapper.

@Test
public void testInsertWrapper() {
    HandlerWrapper a = new HandlerWrapper();
    HandlerWrapper b = new HandlerWrapper();
    HandlerWrapper c = new HandlerWrapper();
    a.insertHandler(c);
    a.insertHandler(b);
    assertThat(a.getHandler(), equalTo(b));
    assertThat(b.getHandler(), equalTo(c));
    assertThat(c.getHandler(), nullValue());
}
Also used : HandlerWrapper(org.eclipse.jetty.server.handler.HandlerWrapper) Test(org.junit.Test)

Example 7 with HandlerWrapper

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

the class HandlerTest method testInsertWrapperBadChain.

@Test
public void testInsertWrapperBadChain() {
    HandlerWrapper a = new HandlerWrapper();
    HandlerWrapper b = new HandlerWrapper();
    HandlerWrapper c = new HandlerWrapper();
    HandlerWrapper d = new HandlerWrapper();
    a.insertHandler(d);
    b.insertHandler(c);
    c.setHandler(new AbstractHandler() {

        @Override
        public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        }
    });
    try {
        a.insertHandler(b);
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString("bad tail"));
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) HandlerWrapper(org.eclipse.jetty.server.handler.HandlerWrapper) Test(org.junit.Test)

Example 8 with HandlerWrapper

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

the class HandlerTest method testWrapperDeepLoop.

@Test
public void testWrapperDeepLoop() {
    HandlerWrapper a = new HandlerWrapper();
    HandlerWrapper b = new HandlerWrapper();
    HandlerWrapper c = new HandlerWrapper();
    a.setHandler(b);
    b.setHandler(c);
    try {
        c.setHandler(a);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e.getMessage(), containsString("loop"));
    }
}
Also used : HandlerWrapper(org.eclipse.jetty.server.handler.HandlerWrapper) Test(org.junit.Test)

Example 9 with HandlerWrapper

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

the class HandlerTest method testInsertWrapperTail.

@Test
public void testInsertWrapperTail() {
    HandlerWrapper a = new HandlerWrapper();
    HandlerWrapper b = new HandlerWrapper();
    a.insertHandler(b);
    assertThat(a.getHandler(), equalTo(b));
    assertThat(b.getHandler(), nullValue());
}
Also used : HandlerWrapper(org.eclipse.jetty.server.handler.HandlerWrapper) Test(org.junit.Test)

Example 10 with HandlerWrapper

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

the class Invoker method init.

/* ------------------------------------------------------------ */
public void init() {
    ServletContext config = getServletContext();
    _contextHandler = ((ContextHandler.Context) config).getContextHandler();
    Handler handler = _contextHandler.getHandler();
    while (handler != null && !(handler instanceof ServletHandler) && (handler instanceof HandlerWrapper)) handler = ((HandlerWrapper) handler).getHandler();
    _servletHandler = (ServletHandler) handler;
    Enumeration<String> e = getInitParameterNames();
    while (e.hasMoreElements()) {
        String param = e.nextElement();
        String value = getInitParameter(param);
        String lvalue = value.toLowerCase(Locale.ENGLISH);
        if ("nonContextServlets".equals(param)) {
            _nonContextServlets = value.length() > 0 && lvalue.startsWith("t");
        }
        if ("verbose".equals(param)) {
            _verbose = value.length() > 0 && lvalue.startsWith("t");
        } else {
            if (_parameters == null)
                _parameters = new HashMap<String, String>();
            _parameters.put(param, value);
        }
    }
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) HashMap(java.util.HashMap) ServletContext(javax.servlet.ServletContext) Handler(org.eclipse.jetty.server.Handler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) HandlerWrapper(org.eclipse.jetty.server.handler.HandlerWrapper)

Aggregations

HandlerWrapper (org.eclipse.jetty.server.handler.HandlerWrapper)19 Test (org.junit.Test)14 Handler (org.eclipse.jetty.server.Handler)5 Server (org.eclipse.jetty.server.Server)5 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)4 IOException (java.io.IOException)3 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)3 File (java.io.File)2 ServletException (javax.servlet.ServletException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 UnknownHostException (java.net.UnknownHostException)1 HashMap (java.util.HashMap)1 ServletContext (javax.servlet.ServletContext)1 HttpServlet (javax.servlet.http.HttpServlet)1 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)1