Search in sources :

Example 31 with ServletContextHandler

use of org.eclipse.jetty.servlet.ServletContextHandler in project jetty.project by eclipse.

the class EventSourceServletTest method startServer.

@Before
public void startServer() throws Exception {
    server = new Server(0);
    connector = (NetworkConnector) server.getConnectors()[0];
    String contextPath = "/test";
    context = new ServletContextHandler(server, contextPath, ServletContextHandler.SESSIONS);
    server.start();
}
Also used : Server(org.eclipse.jetty.server.Server) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Before(org.junit.Before)

Example 32 with ServletContextHandler

use of org.eclipse.jetty.servlet.ServletContextHandler in project jetty.project by eclipse.

the class ConcatServletTest method testConcatenation.

@Test
public void testConcatenation() throws Exception {
    String contextPath = "";
    ServletContextHandler context = new ServletContextHandler(server, contextPath);
    server.setHandler(context);
    String concatPath = "/concat";
    context.addServlet(ConcatServlet.class, concatPath);
    ServletHolder resourceServletHolder = new ServletHolder(new HttpServlet() {

        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            String includedURI = (String) request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI);
            response.getOutputStream().println(includedURI);
        }
    });
    context.addServlet(resourceServletHolder, "/resource/*");
    server.start();
    String resource1 = "/resource/one.js";
    String resource2 = "/resource/two.js";
    String uri = contextPath + concatPath + "?" + resource1 + "&" + resource2;
    String request = "" + "GET " + uri + " HTTP/1.1\r\n" + "Host: localhost\r\n" + "Connection: close\r\n" + "\r\n";
    String response = connector.getResponses(request);
    try (BufferedReader reader = new BufferedReader(new StringReader(response))) {
        while (true) {
            String line = reader.readLine();
            if (line == null)
                Assert.fail();
            if (line.trim().isEmpty())
                break;
        }
        Assert.assertEquals(resource1, reader.readLine());
        Assert.assertEquals(resource2, reader.readLine());
        Assert.assertNull(reader.readLine());
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpServlet(javax.servlet.http.HttpServlet) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Test(org.junit.Test)

Example 33 with ServletContextHandler

use of org.eclipse.jetty.servlet.ServletContextHandler in project jetty.project by eclipse.

the class DataRateLimitedServletTest method init.

@Before
public void init() throws Exception {
    server = new Server();
    connector = new LocalConnector(server);
    connector.getConnectionFactory(HttpConfiguration.ConnectionFactory.class).getHttpConfiguration().setSendServerVersion(false);
    context = new ServletContextHandler();
    context.setContextPath("/context");
    context.setWelcomeFiles(new String[] { "index.html", "index.jsp", "index.htm" });
    File baseResourceDir = testdir.getEmptyPathDir().toFile();
    // Use resolved real path for Windows and OSX
    Path baseResourcePath = baseResourceDir.toPath().toRealPath();
    context.setBaseResource(Resource.newResource(baseResourcePath.toFile()));
    ServletHolder holder = context.addServlet(DataRateLimitedServlet.class, "/stream/*");
    holder.setInitParameter("buffersize", "" + BUFFER);
    holder.setInitParameter("pause", "" + PAUSE);
    server.setHandler(context);
    server.addConnector(connector);
    server.start();
}
Also used : Path(java.nio.file.Path) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) LocalConnector(org.eclipse.jetty.server.LocalConnector) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) File(java.io.File) Before(org.junit.Before)

Example 34 with ServletContextHandler

use of org.eclipse.jetty.servlet.ServletContextHandler in project jetty.project by eclipse.

the class MemoryUsageTest method prepare.

@Before
public void prepare() throws Exception {
    server = new Server();
    connector = new ServerConnector(server);
    server.addConnector(connector);
    ServletContextHandler context = new ServletContextHandler(server, "/", true, false);
    ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
    ServerEndpointConfig config = ServerEndpointConfig.Builder.create(BasicEchoEndpoint.class, "/").build();
    container.addEndpoint(config);
    server.start();
    client = ContainerProvider.getWebSocketContainer();
    server.addBean(client, true);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) BasicEchoEndpoint(org.eclipse.jetty.websocket.jsr356.server.samples.echo.BasicEchoEndpoint) Server(org.eclipse.jetty.server.Server) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Before(org.junit.Before)

Example 35 with ServletContextHandler

use of org.eclipse.jetty.servlet.ServletContextHandler in project jetty.project by eclipse.

the class JsrBatchModeTest method prepare.

@Before
public void prepare() throws Exception {
    server = new Server();
    connector = new ServerConnector(server);
    server.addConnector(connector);
    ServletContextHandler context = new ServletContextHandler(server, "/", true, false);
    ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
    ServerEndpointConfig config = ServerEndpointConfig.Builder.create(BasicEchoEndpoint.class, "/").build();
    container.addEndpoint(config);
    server.start();
    client = ContainerProvider.getWebSocketContainer();
    server.addBean(client, true);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) BasicEchoEndpoint(org.eclipse.jetty.websocket.jsr356.server.samples.echo.BasicEchoEndpoint) Server(org.eclipse.jetty.server.Server) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Before(org.junit.Before)

Aggregations

ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)385 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)249 Server (org.eclipse.jetty.server.Server)216 ServerConnector (org.eclipse.jetty.server.ServerConnector)98 Test (org.junit.Test)70 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)55 IOException (java.io.IOException)42 HttpClient (org.eclipse.jetty.client.HttpClient)39 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)39 HttpServletRequest (javax.servlet.http.HttpServletRequest)38 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)37 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)37 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)32 Connector (org.eclipse.jetty.server.Connector)29 Request (org.eclipse.jetty.client.api.Request)27 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)25 ServletContainer (org.glassfish.jersey.servlet.ServletContainer)24 ServletException (javax.servlet.ServletException)22 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)22 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)22