@Inject private void setup(Injector injector, HttpServer server) { final ServerConfiguration configuration = server.getServerConfiguration(); configuration.setDefaultErrorPageGenerator( generator != null ? generator : injector.getInstance(key)); log.info("Configured default error page generator on server \"%s\"", configuration.getName()); }
@Inject private void setup(HttpServer server) { final ServerConfiguration configuration = server.getServerConfiguration(); configuration.getMonitoringConfig().getWebServerConfig().addProbes(probe); log.info( "Configured access log writing to \"%s\" on server \"%s\"", accessLog, configuration.getName()); }
private HttpServer createHttpServer() { final HttpServer server = new HttpServer(); final int requestSize = (int) currentConfig.getMaxRequestSize(); final ServerConfiguration serverConfig = server.getServerConfiguration(); serverConfig.setMaxBufferedPostSize(requestSize); serverConfig.setMaxFormPostSize(requestSize); serverConfig.setDefaultQueryEncoding(Charsets.UTF8_CHARSET); if (keepStats()) { setHttpStatsProbe(server); } // Configure the network listener final NetworkListener listener = new NetworkListener( "Rest2LDAP", NetworkListener.DEFAULT_NETWORK_HOST, initConfig.getListenPort()); server.addListener(listener); // Configure the network transport final TCPNIOTransport transport = listener.getTransport(); transport.setReuseAddress(currentConfig.isAllowTCPReuseAddress()); transport.setKeepAlive(currentConfig.isUseTCPKeepAlive()); transport.setTcpNoDelay(currentConfig.isUseTCPNoDelay()); transport.setWriteTimeout(currentConfig.getMaxBlockedWriteTimeLimit(), TimeUnit.MILLISECONDS); final int bufferSize = (int) currentConfig.getBufferSize(); transport.setReadBufferSize(bufferSize); transport.setWriteBufferSize(bufferSize); transport.setIOStrategy(SameThreadIOStrategy.getInstance()); final int numRequestHandlers = getNumRequestHandlers(currentConfig.getNumRequestHandlers(), friendlyName); transport.setSelectorRunnersCount(numRequestHandlers); transport.setServerConnectionBackLog(currentConfig.getAcceptBacklog()); // Configure SSL if (sslEngineConfigurator != null) { listener.setSecure(true); listener.setSSLEngineConfig(sslEngineConfigurator); } return server; }
public static void main(String[] args) throws Exception { final Server server = new DefaultServer(); server.socketAction( new Action<ServerSocket>() { @Override public void on(final ServerSocket socket) { System.out.println("on socket: " + socket.uri()); socket.on( "echo", new Action<Object>() { @Override public void on(Object data) { System.out.println("on echo event: " + data); socket.send("echo", data); } }); socket.on( "chat", new Action<Object>() { @Override public void on(Object data) { System.out.println("on chat event: " + data); server.all().send("chat", data); } }); } }); HttpTransportServer httpTransportServer = new HttpTransportServer().transportAction(server); WebSocketTransportServer wsTransportServer = new WebSocketTransportServer().transportAction(server); HttpServer httpServer = HttpServer.createSimpleServer(); ServerConfiguration config = httpServer.getServerConfiguration(); config.addHttpHandler(new VibeHttpHandler().httpAction(httpTransportServer), "/vibe"); NetworkListener listener = httpServer.getListener("grizzly"); listener.registerAddOn(new WebSocketAddOn()); WebSocketEngine.getEngine() .register("", "/vibe", new VibeWebSocketApplication().wsAction(wsTransportServer)); httpServer.start(); System.in.read(); }
public static void main(String[] args) { // create a basic server that listens on port 8080. final HttpServer server = HttpServer.createSimpleServer(); final ServerConfiguration config = server.getServerConfiguration(); // Map the path, /echo, to the NonBlockingEchoHandler config.addHttpHandler(new NonBlockingEchoHandler(), "/echo"); try { server.start(); Client client = new Client(); client.run(); } catch (IOException ioe) { LOGGER.log(Level.SEVERE, ioe.toString(), ioe); } finally { server.shutdownNow(); } }