@Override public void afterPropertiesSet() throws Exception { if (this.server == null) { InetSocketAddress address = (this.hostname != null ? new InetSocketAddress(this.hostname, this.port) : new InetSocketAddress(this.port)); HttpServer server = HttpServer.create(address, this.backlog); if (logger.isInfoEnabled()) { logger.info("Starting HttpServer at address " + address); } server.start(); this.server = server; this.localServer = true; } super.afterPropertiesSet(); }
public SimpleEurekaHttpServer(EurekaHttpClient requestHandler, EurekaTransportEventListener eventListener) throws IOException { this.requestHandler = requestHandler; this.eventListener = eventListener; this.httpServer = HttpServer.create(new InetSocketAddress(0), 1); httpServer.createContext("/v2", createEurekaV2Handle()); httpServer.setExecutor(null); httpServer.start(); }
@Override public void afterPropertiesSet() throws IOException { InetSocketAddress address = (this.hostname != null ? new InetSocketAddress(this.hostname, this.port) : new InetSocketAddress(this.port)); this.server = HttpServer.create(address, this.backlog); if (this.executor != null) { this.server.setExecutor(this.executor); } if (this.contexts != null) { this.contexts.forEach((key, context) -> { HttpContext httpContext = this.server.createContext(key, context); if (this.filters != null) { httpContext.getFilters().addAll(this.filters); } if (this.authenticator != null) { httpContext.setAuthenticator(this.authenticator); } }); } if (logger.isInfoEnabled()) { logger.info("Starting HttpServer at address " + address); } this.server.start(); }
@Override public void afterPropertiesSet() throws Exception { if (this.server == null) { InetSocketAddress address = (this.hostname != null ? new InetSocketAddress(this.hostname, this.port) : new InetSocketAddress(this.port)); HttpServer server = HttpServer.create(address, this.backlog); if (logger.isInfoEnabled()) { logger.info("Starting HttpServer at address " + address); } server.start(); this.server = server; this.localServer = true; } super.afterPropertiesSet(); }
private LocalResourceManagerHelper() { try { server = HttpServer.create(new InetSocketAddress(0), 0); port = server.getAddress().getPort(); server.createContext(CONTEXT, new RequestHandler()); server.createContext(OPERATION_CONTEXT, new OperationRequestHandler()); } catch (IOException e) { throw new RuntimeException("Could not bind the mock Resource Manager server.", e); } }
HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0); server.createContext("/test", new MyHandler());
public void start() { int numHandler = 3; InetSocketAddress socketAddr = new InetSocketAddress(port); Executor executor = Executors.newFixedThreadPool(numHandler); try { hs = HttpServer.create(socketAddr, 0); hs.createContext(HttpserverUtils.HTTPSERVER_CONTEXT_PATH_LOGVIEW, new LogHandler(conf)); hs.setExecutor(executor); hs.start(); } catch (BindException e) { LOG.info("HttpServer has started already!"); hs = null; return; } catch (IOException e) { LOG.error("Failed to start HttpServer", e); hs = null; return; } LOG.info("Success started HttpServer at port:" + port); }
@Override public void afterPropertiesSet() throws IOException { InetSocketAddress address = (this.hostname != null ? new InetSocketAddress(this.hostname, this.port) : new InetSocketAddress(this.port)); this.server = HttpServer.create(address, this.backlog); if (this.executor != null) { this.server.setExecutor(this.executor); } if (this.contexts != null) { this.contexts.forEach((key, context) -> { HttpContext httpContext = this.server.createContext(key, context); if (this.filters != null) { httpContext.getFilters().addAll(this.filters); } if (this.authenticator != null) { httpContext.setAuthenticator(this.authenticator); } }); } if (logger.isInfoEnabled()) { logger.info("Starting HttpServer at address " + address); } this.server.start(); }
private HttpServer startServer(int port, HttpHandler handler) throws IOException { final HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); server.createContext(URI_PATH, handler); new Thread(new Runnable() { @Override public void run() { server.start(); } }).start(); return server; }
synchronized public void init(InetAddress bindAddress, Router router) throws InitializationException { try { InetSocketAddress socketAddress = new InetSocketAddress(bindAddress, configuration.getListenPort()); server = HttpServer.create(socketAddress, configuration.getTcpConnectionBacklog()); server.createContext("/", new RequestHttpHandler(router)); log.info("Created server (for receiving TCP streams) on: " + server.getAddress()); } catch (Exception ex) { throw new InitializationException("Could not initialize " + getClass().getSimpleName() + ": " + ex.toString(), ex); } }
private HttpServer startServer(int port, HttpHandler handler) throws IOException { final HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); server.createContext(URI_PATH, handler); new Thread(new Runnable() { @Override public void run() { server.start(); } }).start(); servers.add(server); return server; }
/** * Starts the lightweight HTTP server serving the JAX-RS application. * * @return new instance of the lightweight HTTP server * @throws IOException */ static HttpServer startServer() throws IOException { // create a new server listening at port 8080 final HttpServer server = HttpServer.create(new InetSocketAddress(getBaseURI().getPort()), 0); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { server.stop(0); } })); // create a handler wrapping the JAX-RS application HttpHandler handler = RuntimeDelegate.getInstance().createEndpoint(new JaxRsApplication(), HttpHandler.class); // map JAX-RS handler to the server root server.createContext(getBaseURI().getPath(), handler); // start the server server.start(); return server; }
private void start(String path, HttpHandler handler) throws IOException { httpServer = HttpServer.create(socket, 0); httpServer.createContext(path, handler); new Thread(new Runnable() { @Override public void run() { httpServer.start(); } }).start(); endpoint = "localhost:" + httpServer.getAddress().getPort(); } }
private static void initHttpServer() throws Exception { // Setup default endpoints final HttpServer server = HttpServer.create(); server.createContext("/echo", new EchoHandler()); // Hook to allow for graceful exit final Closeable c = () -> { PollScheduler.getInstance().stop(); server.stop(5); }; server.createContext("/exit", new ExitHandler(c)); // Bind and start server server.bind(new InetSocketAddress(Config.getPort()), 0); server.start(); }
/** * If we have a separate liveness port, start a server on a separate thread pool whose only * job is to watch for when the CoreNLP server becomes ready. * This will also immediately signal liveness. * * @param live The boolean to track when CoreNLP has initialized and the server is ready * to serve requests. */ private void livenessServer(AtomicBoolean live) { if (this.serverPort != this.statusPort) { try { // Create the server if (this.ssl) { server = addSSLContext(HttpsServer.create(new InetSocketAddress(statusPort), 0)); // 0 is the default 'backlog' } else { server = HttpServer.create(new InetSocketAddress(statusPort), 0); // 0 is the default 'backlog' } // Add the two status endpoints withAuth(server.createContext("/live", new LiveHandler()), Optional.empty()); withAuth(server.createContext("/ready", new ReadyHandler(live)), Optional.empty()); // Start the server server.start(); // Server started log("Liveness server started at " + server.getAddress()); } catch (IOException e) { err("Could not start liveness server. This will probably result in very bad things happening soon.", e); } } }
public static HttpServer startHttpServer(int port, HttpHandler handler) throws Exception { //some stack overflow goodness for testing only InetSocketAddress address = new InetSocketAddress(port); HttpServer httpServer = HttpServer.create(address, 0); httpServer.createContext("/", handler); httpServer.setExecutor(new ThreadPoolExecutor(1, 1, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<>())); httpServer.start(); return httpServer; }
@BeforeClass public void setUp() throws Exception { TEST_SERVER = HttpServer.create(new InetSocketAddress(TEST_PORT), 0); TEST_SERVER.createContext("/v2/segments", new testSegmentUploadHandler()); TEST_SERVER.setExecutor(null); // creates a default executor TEST_SERVER.start(); }
@BeforeClass public static void setUpClass() throws Exception { server = HttpServer.create(new InetSocketAddress(0), 0); server.createContext("/", exchange -> { byte[] content = "Hello World!".getBytes(); exchange.sendResponseHeaders(200, content.length); try (OutputStream responseBody = exchange.getResponseBody()) { responseBody.write(content); responseBody.flush(); } }); server.start(); Testcontainers.exposeHostPorts(server.getAddress().getPort()); }
@BeforeClass public static void setUp() throws Exception { server = HttpServer.create(new InetSocketAddress(0), 0); server.createContext("/", exchange -> { byte[] content = "Hello World!".getBytes(); exchange.sendResponseHeaders(200, content.length); try (OutputStream responseBody = exchange.getResponseBody()) { responseBody.write(content); responseBody.flush(); } }); server.start(); localServerPort = server.getAddress().getPort(); // exposePort { Testcontainers.exposeHostPorts(localServerPort); // } }
@Test public void simpleHessianServiceExporter() throws IOException { final int port = SocketUtils.findAvailableTcpPort(); TestBean tb = new TestBean("tb"); SimpleHessianServiceExporter exporter = new SimpleHessianServiceExporter(); exporter.setService(tb); exporter.setServiceInterface(ITestBean.class); exporter.setDebug(true); exporter.prepare(); HttpServer server = HttpServer.create(new InetSocketAddress(port), -1); server.createContext("/hessian", exporter); server.start(); try { HessianClientInterceptor client = new HessianClientInterceptor(); client.setServiceUrl("http://localhost:" + port + "/hessian"); client.setServiceInterface(ITestBean.class); //client.setHessian2(true); client.prepare(); ITestBean proxy = ProxyFactory.getProxy(ITestBean.class, client); assertEquals("tb", proxy.getName()); proxy.setName("test"); assertEquals("test", proxy.getName()); } finally { server.stop(Integer.MAX_VALUE); } }