@Override public void setExecutor(final Executor executor) { delegate.setExecutor(executor); }
@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(); }
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(); }
HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0); server.createContext("/test", new MyHandler()); server.setExecutor(null); // creates a default executor server.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(); }
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); }
HttpsServer.create(new InetSocketAddress(port), 0); server.setExecutor(Executors.newCachedThreadPool()); server.createContext(path, handler); return server;
public static void main(String[] args) throws Exception { HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0); server.createContext("/simple", new HttpHandler() { @Override public void handle(HttpExchange t) throws IOException { try { TimeUnit.MILLISECONDS.sleep(100); } catch (InterruptedException e) { // ignore } String response = "This is the response"; t.sendResponseHeaders(200, response.length()); OutputStream os = t.getResponseBody(); os.write(response.getBytes()); os.close(); } }); server.setExecutor(null); // creates a default executor server.start(); }
server.setExecutor(Executors.newCachedThreadPool()); server.start(); System.out.println("Server is listening on port 8080" );
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(); }
server.setExecutor(Executors.newCachedThreadPool(new ThreadFactoryBuilder() .setNameFormat("jdk-http-server-%d") .setUncaughtExceptionHandler(new JerseyProcessingUncaughtExceptionHandler())
server.setExecutor(serverExecutor); server.start(); live.set(true);
/** * Starts the http server. * * @return {@code this} */ public SimpleHttpServer start() { try { server = HttpServer.create(new InetSocketAddress(port), 0); server.createContext("/", new TestHandler()); server.setExecutor(null); server.start(); return this; } catch (IOException e) { throw new RuntimeException(e); } }
public static void main(String[] args) { try { HttpServer hs = HttpServer.create(new InetSocketAddress(8080), 0); hs.createContext("/", new MyHandler()); hs.createContext("/java", new MyHandler()); hs.setExecutor(null); hs.start(); System.out.println("---begin---"); System.out.println("Listening on " + hs.getAddress()); } catch (IOException ioe) { ioe.printStackTrace(); } }
private static void startupHttpCmdPort() { try { s_logger.info("Listening for HTTP CMDs on port " + httpCmdListenPort); HttpServer cmdServer = HttpServer.create(new InetSocketAddress(httpCmdListenPort), 2); cmdServer.createContext("/cmd", new ConsoleProxyCmdHandler()); cmdServer.setExecutor(new ThreadExecutor()); // creates a default executor cmdServer.start(); } catch (Exception e) { s_logger.error(e.getMessage(), e); System.exit(1); } }
/** * Create the HttpServer to use. Can be overridden if a custom or already existing HttpServer should be * used * * @return HttpServer to use * @throws IOException if something fails during the initialisation */ private HttpServer createHttpServer(JolokiaServerConfig pConfig) throws IOException { int port = pConfig.getPort(); InetAddress address = pConfig.getAddress(); InetSocketAddress socketAddress = new InetSocketAddress(address,port); HttpServer server = pConfig.useHttps() ? createHttpsServer(socketAddress, pConfig) : HttpServer.create(socketAddress, pConfig.getBacklog()); // Thread factory which creates only daemon threads ThreadFactory daemonThreadFactory = new DaemonThreadFactory(pConfig.getThreadNamePrefix()); // Prepare executor pool Executor executor; String mode = pConfig.getExecutor(); if ("fixed".equalsIgnoreCase(mode)) { executor = Executors.newFixedThreadPool(pConfig.getThreadNr(), daemonThreadFactory); } else if ("cached".equalsIgnoreCase(mode)) { executor = Executors.newCachedThreadPool(daemonThreadFactory); } else { executor = Executors.newSingleThreadExecutor(daemonThreadFactory); } server.setExecutor(executor); return server; }
/** * Start a HTTP server serving Prometheus metrics from the given registry. */ public HTTPServer(InetSocketAddress addr, CollectorRegistry registry, boolean daemon) throws IOException { server = HttpServer.create(); server.bind(addr, 3); HttpHandler mHandler = new HTTPMetricHandler(registry); server.createContext("/", mHandler); server.createContext("/metrics", mHandler); executorService = Executors.newFixedThreadPool(5, NamedDaemonThreadFactory.defaultThreadFactory(daemon)); server.setExecutor(executorService); start(daemon); }
private static void startupHttpMain() { try { ConsoleProxyServerFactory factory = getHttpServerFactory(); if (factory == null) { s_logger.error("Unable to load HTTP server factory"); System.exit(1); } HttpServer server = factory.createHttpServerInstance(httpListenPort); server.createContext("/getscreen", new ConsoleProxyThumbnailHandler()); server.createContext("/resource/", new ConsoleProxyResourceHandler()); server.createContext("/ajax", new ConsoleProxyAjaxHandler()); server.createContext("/ajaximg", new ConsoleProxyAjaxImageHandler()); server.setExecutor(new ThreadExecutor()); // creates a default executor server.start(); } catch (Exception e) { s_logger.error(e.getMessage(), e); System.exit(1); } }
@Before public void startHttpServer() throws IOException { httpServer = HttpServer.create(new InetSocketAddress(0), 0); httpServer.createContext("/", new TestHandler()); httpServer.setExecutor(null); httpServer.start(); serverPort = httpServer.getAddress().getPort(); }