Search in sources :

Example 56 with HandlerCollection

use of org.eclipse.jetty.server.handler.HandlerCollection in project gocd by gocd.

the class Jetty9ServerTest method shouldAddResourceHandlerForAssets.

@Test
public void shouldAddResourceHandlerForAssets() throws Exception {
    ArgumentCaptor<HandlerCollection> captor = ArgumentCaptor.forClass(HandlerCollection.class);
    jetty9Server.configure();
    verify(server, times(1)).setHandler(captor.capture());
    HandlerCollection handlerCollection = captor.getValue();
    assertThat(handlerCollection.getHandlers().length, is(3));
    Handler handler = handlerCollection.getHandlers()[1];
    assertThat(handler instanceof AssetsContextHandler, is(true));
    AssetsContextHandler assetsContextHandler = (AssetsContextHandler) handler;
    assertThat(assetsContextHandler.getContextPath(), is("context/assets"));
}
Also used : GzipHandler(org.eclipse.jetty.servlets.gzip.GzipHandler) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) Test(org.junit.Test)

Example 57 with HandlerCollection

use of org.eclipse.jetty.server.handler.HandlerCollection in project gocd by gocd.

the class Jetty9ServerTest method shouldAddDefaultHeadersForRootContext.

@Test
public void shouldAddDefaultHeadersForRootContext() throws Exception {
    ArgumentCaptor<HandlerCollection> captor = ArgumentCaptor.forClass(HandlerCollection.class);
    jetty9Server.configure();
    verify(server, times(1)).setHandler(captor.capture());
    HandlerCollection handlerCollection = captor.getValue();
    Jetty9Server.GoServerWelcomeFileHandler handler = (Jetty9Server.GoServerWelcomeFileHandler) handlerCollection.getHandlers()[0];
    Handler rootPathHandler = handler.getHandler();
    HttpServletResponse response = mock(HttpServletResponse.class);
    when(response.getWriter()).thenReturn(mock(PrintWriter.class));
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getPathInfo()).thenReturn("/");
    rootPathHandler.handle("/", mock(Request.class), request, response);
    verify(response).setHeader("X-XSS-Protection", "1; mode=block");
    verify(response).setHeader("X-Content-Type-Options", "nosniff");
    verify(response).setHeader("X-Frame-Options", "SAMEORIGIN");
    verify(response).setHeader("X-UA-Compatible", "chrome=1");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) GzipHandler(org.eclipse.jetty.servlets.gzip.GzipHandler) HttpServletResponse(javax.servlet.http.HttpServletResponse) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 58 with HandlerCollection

use of org.eclipse.jetty.server.handler.HandlerCollection in project gocd by gocd.

the class Jetty9ServerTest method shouldAddWelcomeRequestHandler.

@Test
public void shouldAddWelcomeRequestHandler() throws Exception {
    ArgumentCaptor<HandlerCollection> captor = ArgumentCaptor.forClass(HandlerCollection.class);
    jetty9Server.configure();
    verify(server, times(1)).setHandler(captor.capture());
    HandlerCollection handlerCollection = captor.getValue();
    assertThat(handlerCollection.getHandlers().length, is(3));
    Handler handler = handlerCollection.getHandlers()[0];
    assertThat(handler instanceof Jetty9Server.GoServerWelcomeFileHandler, is(true));
    Jetty9Server.GoServerWelcomeFileHandler welcomeFileHandler = (Jetty9Server.GoServerWelcomeFileHandler) handler;
    assertThat(welcomeFileHandler.getContextPath(), is("/"));
}
Also used : GzipHandler(org.eclipse.jetty.servlets.gzip.GzipHandler) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) Test(org.junit.Test)

Example 59 with HandlerCollection

use of org.eclipse.jetty.server.handler.HandlerCollection in project gocd by gocd.

the class Jetty9ServerTest method shouldAddWebAppContextHandler.

@Test
public void shouldAddWebAppContextHandler() throws Exception {
    ArgumentCaptor<HandlerCollection> captor = ArgumentCaptor.forClass(HandlerCollection.class);
    jetty9Server.configure();
    verify(server, times(1)).setHandler(captor.capture());
    HandlerCollection handlerCollection = captor.getValue();
    assertThat(handlerCollection.getHandlers().length, is(3));
    Handler handler = handlerCollection.getHandlers()[2];
    assertThat(handler, instanceOf(GzipHandler.class));
    WebAppContext webAppContext = (WebAppContext) ((GzipHandler) handler).getHandler();
    assertThat(webAppContext, instanceOf(WebAppContext.class));
    List<String> configClasses = new ArrayList<>(Arrays.asList(webAppContext.getConfigurationClasses()));
    assertThat(configClasses.contains(WebInfConfiguration.class.getCanonicalName()), is(true));
    assertThat(configClasses.contains(WebXmlConfiguration.class.getCanonicalName()), is(true));
    assertThat(configClasses.contains(JettyWebXmlConfiguration.class.getCanonicalName()), is(true));
    assertThat(webAppContext.getContextPath(), is("context"));
    assertThat(webAppContext.getWar(), is("cruise.war"));
    assertThat(webAppContext.isParentLoaderPriority(), is(true));
    assertThat(webAppContext.getDefaultsDescriptor(), is("jar:file:cruise.war!/WEB-INF/webdefault.xml"));
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) GzipHandler(org.eclipse.jetty.servlets.gzip.GzipHandler) ArrayList(java.util.ArrayList) GzipHandler(org.eclipse.jetty.servlets.gzip.GzipHandler) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) Test(org.junit.Test)

Example 60 with HandlerCollection

use of org.eclipse.jetty.server.handler.HandlerCollection in project gocd by gocd.

the class Jetty9ServerTest method shouldSetErrorHandlerForWebAppContext.

@Test
public void shouldSetErrorHandlerForWebAppContext() throws Exception {
    ArgumentCaptor<HandlerCollection> captor = ArgumentCaptor.forClass(HandlerCollection.class);
    jetty9Server.configure();
    verify(server, times(1)).setHandler(captor.capture());
    HandlerCollection handlerCollection = captor.getValue();
    assertThat(handlerCollection.getHandlers().length, is(3));
    Handler handler = handlerCollection.getHandlers()[2];
    assertThat(handler, instanceOf(GzipHandler.class));
    WebAppContext webAppContext = (WebAppContext) ((GzipHandler) handler).getHandler();
    assertThat(webAppContext, instanceOf(WebAppContext.class));
    assertThat(webAppContext.getErrorHandler() instanceof JettyCustomErrorPageHandler, is(true));
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) GzipHandler(org.eclipse.jetty.servlets.gzip.GzipHandler) GzipHandler(org.eclipse.jetty.servlets.gzip.GzipHandler) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) Test(org.junit.Test)

Aggregations

HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)76 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)44 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)30 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)27 Server (org.eclipse.jetty.server.Server)26 URISyntaxException (java.net.URISyntaxException)18 ServerConnector (org.eclipse.jetty.server.ServerConnector)18 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)18 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)16 Handler (org.eclipse.jetty.server.Handler)15 Test (org.junit.Test)13 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)9 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)9 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)8 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)7 GzipHandler (org.eclipse.jetty.servlets.gzip.GzipHandler)6 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)6 File (java.io.File)5 URI (java.net.URI)5 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)5