@Override public InetSocketAddress getAddress() { return delegate.getAddress(); } };
public int getServerPort() { return httpServer.getAddress().getPort(); }
synchronized public int getPort() { return server.getAddress().getPort(); }
@Override public void start() { if (started.compareAndSet(false, true)) { LOGGER.log(Level.FINE, "Starting JdkHttpServerTestContainer..."); server.start(); if (baseUri.getPort() == 0) { baseUri = UriBuilder.fromUri(baseUri) .port(server.getAddress().getPort()) .build(); LOGGER.log(Level.INFO, "Started JdkHttpServerTestContainer at the base URI " + baseUri); } } else { LOGGER.log(Level.WARNING, "Ignoring start request - JdkHttpServerTestContainer is already started."); } }
/** * Returns base server url in the form <i>protocol://serverHostName:serverPort</i>. * * @return Base server url. */ public String getBaseUrl() { return proto + "://" + httpSrv.getAddress().getHostName() + ":" + httpSrv.getAddress().getPort(); }
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 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); } }
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(); } }
/** * 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); } } }
@SneakyThrows protected void assertResponse(GenericContainer container) { try { container.start(); String response = container.execInContainer("wget", "-O", "-", "http://host.testcontainers.internal:" + server.getAddress().getPort()).getStdout(); assertEquals("received response", "Hello World!", response); } finally { container.stop(); } } }
@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); // } }
server.start(); live.set(true); log("StanfordCoreNLPServer listening at " + server.getAddress()); } catch (IOException e) { e.printStackTrace();
/** * Gets the port number. */ public int getPort() { return server.getAddress().getPort(); } }
synchronized public int getPort() { return server.getAddress().getPort(); }
@Override public void start() { if (httpServer == null) { try { httpServer = HttpServer.create(new InetSocketAddress(configuredPort), 10); runtimePort = httpServer.getAddress().getPort(); } catch (IOException e) { throw new RuntimeException(e); } } context.bind(httpServer); httpServer.start(); }
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 String detectAgentUrl(HttpServer pServer, JolokiaServerConfig pConfig, String pContextPath) { serverAddress= pServer.getAddress(); InetAddress realAddress; int port; if (serverAddress != null) { realAddress = serverAddress.getAddress(); if (realAddress.isAnyLocalAddress()) { try { realAddress = NetworkUtil.getLocalAddress(); } catch (IOException e) { try { realAddress = InetAddress.getLocalHost(); } catch (UnknownHostException e1) { // Ok, ok. We take the original one realAddress = serverAddress.getAddress(); } } } port = serverAddress.getPort(); } else { realAddress = pConfig.getAddress(); port = pConfig.getPort(); } return String.format("%s://%s:%d%s", pConfig.getProtocol(),realAddress.getHostAddress(),port, pContextPath); }
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(); } }
@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(); }