Search in sources :

Example 81 with Server

use of org.eclipse.jetty.server.Server 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 82 with Server

use of org.eclipse.jetty.server.Server 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 83 with Server

use of org.eclipse.jetty.server.Server 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)

Example 84 with Server

use of org.eclipse.jetty.server.Server in project jetty.project by eclipse.

the class StreamTest method startServer.

@BeforeClass
public static void startServer() throws Exception {
    server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(0);
    server.addConnector(connector);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    server.setHandler(context);
    ServerContainer wsContainer = WebSocketServerContainerInitializer.configureContext(context);
    // Prepare Server Side Output directory for uploaded files
    outputDir = MavenTestingUtils.getTargetTestingDir(StreamTest.class.getName());
    FS.ensureEmpty(outputDir);
    // Create Server Endpoint with output directory configuration
    ServerEndpointConfig config = ServerEndpointConfig.Builder.create(UploadSocket.class, "/upload/{filename}").configurator(new ServerUploadConfigurator(outputDir)).build();
    wsContainer.addEndpoint(config);
    server.start();
    String host = connector.getHost();
    if (host == null) {
        host = "localhost";
    }
    int port = connector.getLocalPort();
    serverUri = new URI(String.format("ws://%s:%d/", host, port));
    if (LOG.isDebugEnabled())
        LOG.debug("Server started on {}", serverUri);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) URI(java.net.URI) ServerEndpoint(javax.websocket.server.ServerEndpoint) ClientEndpoint(javax.websocket.ClientEndpoint) BeforeClass(org.junit.BeforeClass)

Example 85 with Server

use of org.eclipse.jetty.server.Server in project jetty.project by eclipse.

the class TextStreamTest 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(ServerTextStreamer.class, PATH).build();
    container.addEndpoint(config);
    server.start();
    wsClient = ContainerProvider.getWebSocketContainer();
    server.addBean(wsClient, true);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Before(org.junit.Before)

Aggregations

Server (org.eclipse.jetty.server.Server)577 ServerConnector (org.eclipse.jetty.server.ServerConnector)217 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)143 Test (org.junit.Test)119 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)113 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)75 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)73 IOException (java.io.IOException)71 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)67 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)67 File (java.io.File)65 URI (java.net.URI)56 Before (org.junit.Before)50 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)49 BeforeClass (org.junit.BeforeClass)48 ServletException (javax.servlet.ServletException)45 Connector (org.eclipse.jetty.server.Connector)42 LocalConnector (org.eclipse.jetty.server.LocalConnector)42 URL (java.net.URL)39 HttpServletRequest (javax.servlet.http.HttpServletRequest)39