@Override public synchronized void start() { try { if (!isRunning) { server.start().get(); if (port == 0) { // Replace the specified port number with the primary port number. // Server#activePort doesn't return the first added port, so we need to find that. final Optional<ServerPort> port = server.activePorts().values().stream() .filter(p -> p.protocols().contains(protocol)) .filter(p -> address == null || Arrays.equals(address.getAddress(), p.localAddress().getAddress().getAddress())) .findFirst(); assert port.isPresent() : "the primary port doest not exist."; this.port = port.get().localAddress().getPort(); } isRunning = true; } } catch (Exception cause) { throw new WebServerException("Failed to start " + ArmeriaWebServer.class.getSimpleName(), Exceptions.peel(cause)); } }
/** * Starts the {@link Server} configured by {@link #configure(ServerBuilder)}. * If the {@link Server} has been started up already, the existing {@link Server} is returned. * Note that this operation blocks until the {@link Server} finished the start-up. * * @return the started {@link Server} */ public Server start() { final Server oldServer = server.get(); if (!isStopped(oldServer)) { return oldServer; } final ServerBuilder sb = new ServerBuilder(); try { configure(sb); } catch (Exception e) { throw new IllegalStateException("failed to configure a Server", e); } final Server server = sb.build(); server.start().join(); this.server.set(server); return server; }
public static void main(String[] args) throws Exception { final SamlServiceProvider ssp = samlServiceProvider(); final Server server = new ServerBuilder() .https(8443) // You can add this certificate to your trust store in order to make your web browser happy. .tls(new File(ClassLoader.getSystemResource("localhost.crt").toURI()), new File(ClassLoader.getSystemResource("localhost.key").toURI())) // Decorate you service with SAML decorator. .annotatedService("/", new MyService(), ssp.newSamlDecorator()) // Add SAML service to your server which handles a SAML response and a metadata request. .service(ssp.newSamlService()) .build(); Runtime.getRuntime().addShutdownHook(new Thread(() -> { server.stop().join(); logger.info("Server has been stopped."); })); server.start().join(); logger.info("Server has been started."); } }
@BeforeClass public static void init() throws Exception { server.start().get(); httpPort = server.activePorts().values().stream() .filter(ServerPort::hasHttp).findAny().get() .localAddress().getPort(); httpsPort = server.activePorts().values().stream() .filter(ServerPort::hasHttps).findAny().get() .localAddress().getPort(); }
s.start().handle((result, t) -> { if (t != null) { throw new IllegalStateException("Armeria server failed to start", t);
@BeforeClass public static void beforeClass() { server = ServerFactory.of(0); server.start().join(); client = HttpClient.of("http://127.0.0.1:" + server.activePort().get().localAddress().getPort()); }
@BeforeClass public static void init() throws Exception { server.start().get();
@Before public void startServers() { servers = new ArrayList<>(); for (Endpoint endpoint : sampleEndpoints) { final Server server = new ServerBuilder().http(endpoint.port()) .service("/", new EchoService()) .build(); final ServerListener listener = new ZooKeeperUpdatingListenerBuilder( instance().connectString().get(), zNode) .sessionTimeoutMillis(sessionTimeoutMillis) .endpoint(endpoint) .build(); server.addListener(listener); server.start().join(); servers.add(server); } }
s.start().join(); logger.info("Armeria server started at ports: {}", s.activePorts()); return s;
s.start().join(); logger.info("Armeria server started at ports: {}", s.activePorts()); return s;
s.start().handle((result, t) -> { if (t != null) { throw new IllegalStateException("Armeria server failed to start", t);
s.start().handle((result, t) -> { if (t != null) { throw new IllegalStateException("Armeria server failed to start", t);
s.start().join(); return s;
s.start().join(); return s;
s.start().join(); return s;