private void addSSL(HttpServer httpServer) { try { SSLProperties sslProperties = serverData.getRootContext().getBean(SSLProperties.class); if (sslProperties != null) { httpServer.addListener(this.createSSLListener(serverData.getPort(), sslProperties)); } }catch(BeanNotOfRequiredTypeException e){ } }
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."); broker.run(); // run queue broker task pump in this thread 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(); }
public static HttpServer startServer(String webRootPath) { final HttpServer server = new HttpServer(); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { server.shutdownNow(); } })); final NetworkListener listener = new NetworkListener("grizzly", "localhost", PORT); server.addListener(listener); final ServerConfiguration config = server.getServerConfiguration(); // add handler for serving static content config.addHttpHandler(new CLStaticHttpHandler(Main.class.getClassLoader(), WEB_ROOT), APP_PATH); // add handler for serving JAX-RS resources config.addHttpHandler(RuntimeDelegate.getInstance().createEndpoint(createResourceConfig(), GrizzlyHttpContainer.class), APP_PATH); try { // Start the server. server.start(); } catch (Exception ex) { throw new ProcessingException("Exception thrown when trying to start grizzly server", ex); } return server; }
public static HttpServer startServer(String webRootPath) { final HttpServer server = new HttpServer(); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { server.shutdownNow(); } })); final NetworkListener listener = new NetworkListener("grizzly", "localhost", PORT); server.addListener(listener); final ServerConfiguration config = server.getServerConfiguration(); // add handler for serving static content config.addHttpHandler(new CLStaticHttpHandler(Main.class.getClassLoader(), WEB_ROOT), APP_PATH); // add handler for serving JAX-RS resources config.addHttpHandler(RuntimeDelegate.getInstance().createEndpoint(createResourceConfig(), GrizzlyHttpContainer.class), APP_PATH); try { // Start the server. server.start(); } catch (Exception ex) { throw new ProcessingException("Exception thrown when trying to start grizzly server", ex); } return server; }
/** * Starts Grizzly HTTP server exposing static content, JAX-RS resources * and web sockets defined in this application. * * @param webRootPath static content root path. */ private static void startServer(String webRootPath) { final HttpServer server = new HttpServer(); Runtime.getRuntime().addShutdownHook(new Thread(server::shutdownNow)); final NetworkListener listener = new NetworkListener("grizzly", "localhost", PORT); server.addListener(listener); final ServerConfiguration config = server.getServerConfiguration(); // add handler for serving static content config.addHttpHandler(new StaticContentHandler(webRootPath), APP_PATH); // add handler for serving JAX-RS resources config.addHttpHandler(RuntimeDelegate.getInstance().createEndpoint(createResourceConfig(), GrizzlyHttpContainer.class), API_PATH); try { // Start the server. server.start(); } catch (Exception ex) { throw new ProcessingException("Exception thrown when trying to start grizzly server", ex); } }
server.addListener(listener);
cc.setCompressableMimeTypes("application/json", "text/json"); // the mime types to compress listener.getTransport().setWorkerThreadPoolConfig(threadPoolConfig); httpServer.addListener(listener);
/** * This is done at most once. And only if at least one service gets published. */ private synchronized void addNetworkListener() { if (!isNetworkListenerAdded) { httpServer.addListener(networkListener); isNetworkListenerAdded = true; } }
HttpServer httpServer = new HttpServer(); NetworkListener networkListener1 = new NetworkListener("sample-listener1", "localhost", 8888); NetworkListener networkListener2 = new NetworkListener("sample-listener2", "localhost", 8889); httpServer.addListener(networkListener1); httpServer.addListener(networkListener2);
private void addSSL(HttpServer httpServer) { try { SSLProperties sslProperties = serverData.getRootContext().getBean(SSLProperties.class); if (sslProperties != null) { httpServer.addListener(this.createSSLListener(serverData.getPort(), sslProperties)); } }catch(BeanNotOfRequiredTypeException e){ } }
private void addSSL(HttpServer httpServer) { SSLProperties sslProperties = serverData.getRootContext().getBean(SSLProperties.class); if (sslProperties != null) { httpServer.addListener(this.createSSLListener(serverData.getPort(), sslProperties)); } }
public void startOn(HttpServer httpServer) { if (this.sslDefEngineConfig == null || httpServer == null) { return; } this.listenerSSL = new NetworkListener(SNI_LISTENER_NAME, NetworkListener.DEFAULT_NETWORK_HOST, new PortRange(this.port)); this.listenerSSL.setSSLEngineConfig(this.sslDefEngineConfig); this.listenerSSL.setSecure(true); httpServer.addListener(this.listenerSSL); log.info("[HTTPS Service](SNI) start on port= " + port); }
public static void main(String[] args) throws IOException { // Create jax-ws HttpHandler and passing web service instance. final HttpHandler jaxwsHandler = new JaxwsHandler(new AddService()); // Standard Grizzly HttpServer initialization final HttpServer httpServer = new HttpServer(); NetworkListener networkListener = new NetworkListener("jaxws-listener", "0.0.0.0", PORT); httpServer.getServerConfiguration().addHttpHandler(jaxwsHandler, WEB_SERVICE_CONTEXT_ROOT); httpServer.addListener(networkListener); // Start server httpServer.start(); try { System.out.println("WSDL is available at http://localhost:" + PORT + WEB_SERVICE_CONTEXT_ROOT + "?wsdl"); System.out.println("Press enter to stop the server..."); System.in.read(); } finally { httpServer.shutdownNow(); } } }
/** * @param docRoot the document root, * can be <code>null</code> when no static pages are needed * @param host the network port to which this listener will bind * @param range port range to attempt to bind to * * @return a <code>HttpServer</code> configured to listen to requests * on <code>host</code>:<code>[port-range]</code>, * using the specified <code>docRoot</code> as the server's document root */ public static HttpServer createSimpleServer(final String docRoot, final String host, final PortRange range) { final HttpServer server = new HttpServer(); final ServerConfiguration config = server.getServerConfiguration(); if (docRoot != null) { config.addHttpHandler(new StaticHttpHandler(docRoot), "/"); } final NetworkListener listener = new NetworkListener("grizzly", host, range); server.addListener(listener); return server; }
/** * @param docRoot the document root, * can be <code>null</code> when no static pages are needed * @param host the network port to which this listener will bind * @param range port range to attempt to bind to * * @return a <code>HttpServer</code> configured to listen to requests * on <code>host</code>:<code>[port-range]</code>, * using the specified <code>docRoot</code> as the server's document root */ public static HttpServer createSimpleServer(final String docRoot, final String host, final PortRange range) { final HttpServer server = new HttpServer(); final ServerConfiguration config = server.getServerConfiguration(); if (docRoot != null) { config.addHttpHandler(new StaticHttpHandler(docRoot), "/"); } final NetworkListener listener = new NetworkListener("grizzly", host, range); server.addListener(listener); return server; }
/** * @param docRoot the document root, * can be <code>null</code> when no static pages are needed * @param host the network port to which this listener will bind * @param range port range to attempt to bind to * * @return a <code>HttpServer</code> configured to listen to requests * on <code>host</code>:<code>[port-range]</code>, * using the specified <code>docRoot</code> as the server's document root */ public static HttpServer createSimpleServer(final String docRoot, final String host, final PortRange range) { final HttpServer server = new HttpServer(); final ServerConfiguration config = server.getServerConfiguration(); if (docRoot != null) { config.addHttpHandler(new StaticHttpHandler(docRoot), "/"); } final NetworkListener listener = new NetworkListener("grizzly", host, range); server.addListener(listener); return server; }
/** * @param docRoot the document root, * can be <code>null</code> when no static pages are needed * @param host the network port to which this listener will bind * @param range port range to attempt to bind to * * @return a <code>HttpServer</code> configured to listen to requests * on <code>host</code>:<code>[port-range]</code>, * using the specified <code>docRoot</code> as the server's document root */ public static HttpServer createSimpleServer(final String docRoot, final String host, final PortRange range) { final HttpServer server = new HttpServer(); final ServerConfiguration config = server.getServerConfiguration(); if (docRoot != null) { config.addHttpHandler(new StaticHttpHandler(docRoot), "/"); } final NetworkListener listener = new NetworkListener("grizzly", host, range); server.addListener(listener); return server; }
/** * Starts the {@link HttpServer}. * * @param port Port to listen on. * @param cometEnabled If comet should be enabled. * @param cometEnabled If websockets should be enabled. * @throws IOException Couldn't start the {@link HttpServer}. */ private void startGrizzly(int port, boolean cometEnabled, boolean websocketsEnabled) throws IOException { httpServer = new HttpServer(); NetworkListener networkListener = new NetworkListener("osgi-listener", "0.0.0.0", port); System.out.println("PORT=" + port); if (cometEnabled) { logger.info("Enabling Comet."); networkListener.registerAddOn(new CometAddOn()); } if (websocketsEnabled) { logger.info("Enabling WebSockets."); networkListener.registerAddOn(new WebSocketAddOn()); } httpServer.addListener(networkListener); httpServer.start(); }
@BeforeMethod public void setup() throws Exception { generateTempFile(); server = new HttpServer(); NetworkListener nonSecure = new NetworkListener("nonsecure", DEFAULT_NETWORK_HOST, NON_SECURE_PORT); NetworkListener secure = new NetworkListener("secure", DEFAULT_NETWORK_HOST, SECURE_PORT); secure.setSecure(true); secure.setSSLEngineConfig(createSSLConfig()); server.addListener(nonSecure); server.addListener(secure); server.getServerConfiguration().addHttpHandler(new ConsumingHandler(), "/test"); server.start(); }
private void startServer(HttpHandler httpHandler) throws IOException { httpServer = new HttpServer(); NetworkListener networkListener = new NetworkListener("jaxws-listener", "0.0.0.0", PORT); httpServer.getServerConfiguration().addHttpHandler(new StaticHttpHandler(), "/add"); // make sure JAX-WS Handler is not default httpServer.getServerConfiguration().addHttpHandler(httpHandler, HttpHandlerRegistration.bulder() .contextPath("/add/a/b") .urlPattern("/") .build()); httpServer.addListener(networkListener); httpServer.start(); }