Search in sources :

Example 1 with ServerContainer

use of org.eclipse.jetty.websocket.jsr356.server.ServerContainer 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 2 with ServerContainer

use of org.eclipse.jetty.websocket.jsr356.server.ServerContainer 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 3 with ServerContainer

use of org.eclipse.jetty.websocket.jsr356.server.ServerContainer in project jetty.project by eclipse.

the class JsrBrowserDebugTool method setupServer.

private void setupServer(int port) throws DeploymentException, ServletException, URISyntaxException, MalformedURLException, IOException {
    server = new Server();
    HttpConfiguration httpConf = new HttpConfiguration();
    httpConf.setSendServerVersion(true);
    ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(httpConf));
    connector.setPort(port);
    server.addConnector(connector);
    String resourcePath = "/jsr-browser-debug-tool/index.html";
    URL urlStatics = JsrBrowserDebugTool.class.getResource(resourcePath);
    Objects.requireNonNull(urlStatics, "Unable to find " + resourcePath + " in classpath");
    String urlBase = urlStatics.toURI().toASCIIString().replaceFirst("/[^/]*$", "/");
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    context.setBaseResource(Resource.newResource(urlBase));
    ServletHolder holder = context.addServlet(DefaultServlet.class, "/");
    holder.setInitParameter("dirAllowed", "true");
    server.setHandler(context);
    ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
    container.addEndpoint(JsrBrowserSocket.class);
    LOG.info("{} setup on port {}", this.getClass().getName(), port);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) URL(java.net.URL) ServerContainer(org.eclipse.jetty.websocket.jsr356.server.ServerContainer)

Example 4 with ServerContainer

use of org.eclipse.jetty.websocket.jsr356.server.ServerContainer in project wicket by apache.

the class StartExamples method main.

/**
 * Main function, starts the jetty server.
 *
 * @param args
 */
public static void main(String[] args) throws Exception {
    System.setProperty("wicket.configuration", "development");
    Server server = new Server();
    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    http_config.setSecurePort(8443);
    http_config.setOutputBufferSize(32768);
    ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config));
    http.setPort(8080);
    http.setIdleTimeout(1000 * 60 * 60);
    server.addConnector(http);
    Resource keystore = Resource.newClassPathResource("/keystore");
    if (keystore != null && keystore.exists()) {
        // if a keystore for a SSL certificate is available, start a SSL
        // connector on port 8443.
        // By default, the quickstart comes with a Apache Wicket Quickstart
        // Certificate that expires about half way september 2021. Do not
        // use this certificate anywhere important as the passwords are
        // available in the source.
        SslContextFactory sslContextFactory = new SslContextFactory();
        sslContextFactory.setKeyStoreResource(keystore);
        sslContextFactory.setKeyStorePassword("wicket");
        sslContextFactory.setKeyManagerPassword("wicket");
        HttpConfiguration https_config = new HttpConfiguration(http_config);
        https_config.addCustomizer(new SecureRequestCustomizer());
        ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https_config));
        https.setPort(8443);
        https.setIdleTimeout(500000);
        server.addConnector(https);
        System.out.println("SSL access to the examples has been enabled on port 8443");
        System.out.println("You can access the application using SSL on https://localhost:8443");
        System.out.println();
    }
    WebAppContext bb = new WebAppContext();
    bb.setServer(server);
    bb.setContextPath("/");
    bb.setWar("src/main/webapp");
    ServerContainer serverContainer = WebSocketServerContainerInitializer.configureContext(bb);
    serverContainer.addEndpoint(new WicketServerEndpointConfig());
    // uncomment next line if you want to test with JSESSIONID encoded in the urls
    // ((AbstractSessionManager)
    // bb.getSessionHandler().getSessionManager()).setUsingCookies(false);
    server.setHandler(bb);
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    server.addEventListener(mBeanContainer);
    server.addBean(mBeanContainer);
    try {
        server.start();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(100);
    }
}
Also used : SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) MBeanServer(javax.management.MBeanServer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) Resource(org.eclipse.jetty.util.resource.Resource) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ServerConnector(org.eclipse.jetty.server.ServerConnector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) WicketServerEndpointConfig(org.apache.wicket.protocol.ws.javax.WicketServerEndpointConfig) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) ServerContainer(org.eclipse.jetty.websocket.jsr356.server.ServerContainer) MBeanServer(javax.management.MBeanServer)

Example 5 with ServerContainer

use of org.eclipse.jetty.websocket.jsr356.server.ServerContainer in project jetty.project by eclipse.

the class WebSocketJsrServer method main.

public static void main(String[] args) throws Exception {
    Server server = new Server(8080);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    server.setHandler(context);
    // Enable javax.websocket configuration for the context
    ServerContainer wsContainer = WebSocketServerContainerInitializer.configureContext(context);
    // Add your websockets to the container
    wsContainer.addEndpoint(EchoJsrSocket.class);
    server.start();
    context.dumpStdErr();
    server.join();
}
Also used : Server(org.eclipse.jetty.server.Server) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ServerContainer(org.eclipse.jetty.websocket.jsr356.server.ServerContainer)

Aggregations

Server (org.eclipse.jetty.server.Server)6 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)6 ServerConnector (org.eclipse.jetty.server.ServerConnector)5 ServerContainer (org.eclipse.jetty.websocket.jsr356.server.ServerContainer)5 ServerEndpointConfig (javax.websocket.server.ServerEndpointConfig)4 BasicEchoEndpoint (org.eclipse.jetty.websocket.jsr356.server.samples.echo.BasicEchoEndpoint)3 Before (org.junit.Before)3 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)2 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)2 URL (java.net.URL)1 HashSet (java.util.HashSet)1 MBeanServer (javax.management.MBeanServer)1 ServletException (javax.servlet.ServletException)1 DeploymentException (javax.websocket.DeploymentException)1 Endpoint (javax.websocket.Endpoint)1 ServerApplicationConfig (javax.websocket.server.ServerApplicationConfig)1 ServerEndpoint (javax.websocket.server.ServerEndpoint)1 WicketServerEndpointConfig (org.apache.wicket.protocol.ws.javax.WicketServerEndpointConfig)1 MBeanContainer (org.eclipse.jetty.jmx.MBeanContainer)1 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)1