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();
}
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());
}
}
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();
}
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);
}
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);
}
Aggregations