Search in sources :

Example 6 with NetworkListener

use of org.glassfish.grizzly.http.server.NetworkListener in project ddf by codice.

the class SecureStubServer method run.

/**
     * Starts the server
     */
public SecureStubServer run() {
    simpleServer.getServerConfiguration().addHttpHandler(stubsToHandler(), "/");
    try {
        if (secured) {
            for (NetworkListener networkListener : simpleServer.getListeners()) {
                networkListener.setSecure(true);
                SSLEngineConfigurator sslEngineConfig = new SSLEngineConfigurator(getSslConfig(), false, false, false);
                networkListener.setSSLEngineConfig(sslEngineConfig);
            }
        }
        simpleServer.start();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return this;
}
Also used : SSLEngineConfigurator(org.glassfish.grizzly.ssl.SSLEngineConfigurator) IOException(java.io.IOException) NetworkListener(org.glassfish.grizzly.http.server.NetworkListener)

Example 7 with NetworkListener

use of org.glassfish.grizzly.http.server.NetworkListener in project dukescript-presenters by dukescript.

the class Browser method pageURL.

private static URI pageURL(String protocol, HttpServer server, final String page) {
    NetworkListener listener = server.getListeners().iterator().next();
    int port = listener.getPort();
    try {
        return new URI(protocol + "://localhost:" + port + page);
    } catch (URISyntaxException ex) {
        throw new IllegalStateException(ex);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) NetworkListener(org.glassfish.grizzly.http.server.NetworkListener)

Example 8 with NetworkListener

use of org.glassfish.grizzly.http.server.NetworkListener in project ff4j by ff4j.

the class AbstractEmbeddedGrizzlyIntegrationTest method initOnce.

@BeforeClass
public static void initOnce() throws IOException {
    // WebContext for testing
    webappContext = new WebappContext("Test Context");
    ServletRegistration servletRegistration = webappContext.addServlet("jersey-servlet", ServletContainer.class);
    servletRegistration.setInitParameter("com.sun.jersey.spi.container.ContainerResponseFilters", "com.sun.jersey.api.container.filter.LoggingFilter");
    servletRegistration.setInitParameter("com.sun.jersey.spi.container.ContainerRequestFilters", "com.sun.jersey.api.container.filter.LoggingFilter");
    servletRegistration.setInitParameter("javax.ws.rs.Application", SampleFF4jJersey2Application.class.getCanonicalName());
    servletRegistration.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
    servletRegistration.addMapping("/*");
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.register(JacksonJsonProvider.class);
    clientConfig.register(FF4jJacksonMapper.class);
    client = ClientBuilder.newClient(clientConfig);
    server = new HttpServer();
    NetworkListener listener = new NetworkListener("grizzly2", HOST, PORT);
    server.addListener(listener);
    webappContext.deploy(server);
}
Also used : ServletRegistration(org.glassfish.grizzly.servlet.ServletRegistration) WebappContext(org.glassfish.grizzly.servlet.WebappContext) HttpServer(org.glassfish.grizzly.http.server.HttpServer) SampleFF4jJersey2Application(org.ff4j.web.api.test.SampleFF4jJersey2Application) ClientConfig(org.glassfish.jersey.client.ClientConfig) NetworkListener(org.glassfish.grizzly.http.server.NetworkListener) BeforeClass(org.junit.BeforeClass)

Example 9 with NetworkListener

use of org.glassfish.grizzly.http.server.NetworkListener in project narayana by jbosstm.

the class SpdyEnabledHttpServer method addSpdy.

private static void addSpdy(HttpServer server) {
    NetworkListener listener = server.getListener("grizzly");
    SpdyAddOn spdyAddOn = new SpdyAddOn(SpdyMode.NPN);
    listener.registerAddOn(spdyAddOn);
}
Also used : SpdyAddOn(org.glassfish.grizzly.spdy.SpdyAddOn) NetworkListener(org.glassfish.grizzly.http.server.NetworkListener)

Example 10 with NetworkListener

use of org.glassfish.grizzly.http.server.NetworkListener in project OpenTripPlanner by opentripplanner.

the class BrokerMain method run.

public void run() {
    int port = config.getProperty("port") != null ? Integer.parseInt(config.getProperty("port")) : DEFAULT_PORT;
    String addr = config.getProperty("bind-address") != null ? config.getProperty("bind-address") : DEFAULT_BIND_ADDRESS;
    LOG.info("Starting analyst broker on port {} of interface {}", port, addr);
    HttpServer httpServer = new HttpServer();
    NetworkListener networkListener = new NetworkListener("broker", addr, port);
    // We avoid blocking IO, and the following line allows us to see closed connections.
    networkListener.getTransport().setIOStrategy(SameThreadIOStrategy.getInstance());
    httpServer.addListener(networkListener);
    // Bypass Jersey etc. and add a low-level Grizzly handler.
    // As in servlets, * is needed in base path to identify the "rest" of the path.
    broker = new Broker(config, addr, port);
    httpServer.getServerConfiguration().addHttpHandler(new BrokerHttpHandler(broker), "/*");
    try {
        httpServer.start();
        LOG.info("Broker running.");
        // run queue broker task pump in this thread
        broker.run();
        Thread.currentThread().join();
    } catch (BindException be) {
        LOG.error("Cannot bind to port {}. Is it already in use?", port);
    } catch (IOException ioe) {
        LOG.error("IO exception while starting server.");
    } catch (InterruptedException ie) {
        LOG.info("Interrupted, shutting down.");
    }
    httpServer.shutdown();
}
Also used : HttpServer(org.glassfish.grizzly.http.server.HttpServer) BindException(java.net.BindException) IOException(java.io.IOException) NetworkListener(org.glassfish.grizzly.http.server.NetworkListener)

Aggregations

NetworkListener (org.glassfish.grizzly.http.server.NetworkListener)20 HttpServer (org.glassfish.grizzly.http.server.HttpServer)11 IOException (java.io.IOException)7 ProcessingException (javax.ws.rs.ProcessingException)5 ServerConfiguration (org.glassfish.grizzly.http.server.ServerConfiguration)5 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 CompressionConfig (org.glassfish.grizzly.http.CompressionConfig)3 CLStaticHttpHandler (org.glassfish.grizzly.http.server.CLStaticHttpHandler)3 SSLEngineConfigurator (org.glassfish.grizzly.ssl.SSLEngineConfigurator)3 GrizzlyHttpContainer (org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer)3 InstrumentedExecutorService (com.codahale.metrics.InstrumentedExecutorService)2 BindException (java.net.BindException)2 ExecutorService (java.util.concurrent.ExecutorService)2 PortRange (org.glassfish.grizzly.PortRange)2 TCPNIOTransport (org.glassfish.grizzly.nio.transport.TCPNIOTransport)2 SpdyAddOn (org.glassfish.grizzly.spdy.SpdyAddOn)2 ThreadPoolConfig (org.glassfish.grizzly.threadpool.ThreadPoolConfig)2 WebSocketAddOn (org.glassfish.grizzly.websockets.WebSocketAddOn)2 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)2