Java Code Examples for io.vertx.core.Vertx#createHttpServer()
The following examples show how to use
io.vertx.core.Vertx#createHttpServer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VertTest.java From jdk-source-analysis with Apache License 2.0 | 8 votes |
@Test public void test() { Vertx vertx = Vertx.vertx(); // request.response().putHeader("Content-Type", "text/plain").write("some text").end(); vertx.setPeriodic(1000, id -> { System.out.println(id); }); vertx.executeBlocking(promise -> { }, asyncResult -> { }); HttpServer server = vertx.createHttpServer(); Handler<HttpServerRequest> requestHandler = server.requestHandler(); }
Example 2
Source File: ServerTofaTest.java From incubator-tuweni with Apache License 2.0 | 6 votes |
@BeforeEach void startServer(@TempDirectory Path tempDir, @VertxInstance Vertx vertx) throws Exception { knownClientsFile = tempDir.resolve("known-clients.txt"); Files.write(knownClientsFile, Arrays.asList("#First line", "foobar.com " + DUMMY_FINGERPRINT)); SelfSignedCertificate serverCert = SelfSignedCertificate.create(); HttpServerOptions options = new HttpServerOptions(); options .setSsl(true) .setClientAuth(ClientAuth.REQUIRED) .setPemKeyCertOptions(serverCert.keyCertOptions()) .setTrustOptions(VertxTrustOptions.trustClientOnFirstAccess(knownClientsFile, false)) .setIdleTimeout(1500) .setReuseAddress(true) .setReusePort(true); httpServer = vertx.createHttpServer(options); SecurityTestUtils.configureAndStartTestServer(httpServer); }
Example 3
Source File: WebsiteMain.java From examples with Apache License 2.0 | 6 votes |
public static void main(String[] args) { System.out.println("done waiting"); Vertx vertx = Vertx.vertx(); // Deploy DeploymentOptions options = new DeploymentOptions().setWorker(true); ZookeeperVerticle zkv = new ZookeeperVerticle(); vertx.deployVerticle(zkv, options); HttpServer server = vertx.createHttpServer(); server.requestHandler(request -> { HttpServerResponse response = request.response(); response.putHeader("content-type", "application/json"); JsonObject responseJson; synchronized (WebsiteMain.jsonObject) { responseJson = WebsiteMain.jsonObject.copy(); } response.end(responseJson.encodePrettily()); }); server.listen(8080); }
Example 4
Source File: ApiControllerTest.java From exonum-java-binding with Apache License 2.0 | 6 votes |
@BeforeEach void setup(Vertx vertx, VertxTestContext context) { httpServer = vertx.createHttpServer(); webClient = WebClient.create(vertx); Router router = Router.router(vertx); new ApiController(qaService).mountApi(router); httpServer.requestHandler(router) .listen(0, context.succeeding(result -> { // Set the actual server port. port = result.actualPort(); context.completeNow(); })); }
Example 5
Source File: ServerCaOrTofaTest.java From cava with Apache License 2.0 | 6 votes |
@BeforeEach void startServer(@TempDirectory Path tempDir, @VertxInstance Vertx vertx) throws Exception { knownClientsFile = tempDir.resolve("known-clients.txt"); Files.write(knownClientsFile, Arrays.asList("#First line", "foobar.com " + DUMMY_FINGERPRINT)); SelfSignedCertificate serverCert = SelfSignedCertificate.create(); HttpServerOptions options = new HttpServerOptions(); options .setSsl(true) .setClientAuth(ClientAuth.REQUIRED) .setPemKeyCertOptions(serverCert.keyCertOptions()) .setTrustOptions(VertxTrustOptions.trustClientOnFirstAccess(knownClientsFile)) .setIdleTimeout(1500) .setReuseAddress(true) .setReusePort(true); httpServer = vertx.createHttpServer(options); SecurityTestUtils.configureAndStartTestServer(httpServer); }
Example 6
Source File: ServerWhitelistTest.java From cava with Apache License 2.0 | 6 votes |
@BeforeEach void startServer(@TempDirectory Path tempDir, @VertxInstance Vertx vertx) throws Exception { knownClientsFile = tempDir.resolve("known-clients.txt"); Files.write(knownClientsFile, Arrays.asList("#First line", "foo.com " + fooFingerprint)); SelfSignedCertificate serverCert = SelfSignedCertificate.create(); HttpServerOptions options = new HttpServerOptions(); options .setSsl(true) .setClientAuth(ClientAuth.REQUIRED) .setPemKeyCertOptions(serverCert.keyCertOptions()) .setTrustOptions(VertxTrustOptions.whitelistClients(knownClientsFile, false)) .setIdleTimeout(1500) .setReuseAddress(true) .setReusePort(true); httpServer = vertx.createHttpServer(options); SecurityTestUtils.configureAndStartTestServer(httpServer); }
Example 7
Source File: Examples.java From vertx-unit with Apache License 2.0 | 6 votes |
public static void async_05(TestContext context, Vertx vertx, Handler<HttpServerRequest> requestHandler) { Async async = context.async(2); HttpServer server = vertx.createHttpServer(); server.requestHandler(requestHandler); server.listen(8080, ar -> { context.assertTrue(ar.succeeded()); async.countDown(); }); vertx.setTimer(1000, id -> { async.complete(); }); // Wait until completion of the timer and the http request async.awaitSuccess(); // Do something else }
Example 8
Source File: ServerTofaTest.java From cava with Apache License 2.0 | 6 votes |
@BeforeEach void startServer(@TempDirectory Path tempDir, @VertxInstance Vertx vertx) throws Exception { knownClientsFile = tempDir.resolve("known-clients.txt"); Files.write(knownClientsFile, Arrays.asList("#First line", "foobar.com " + DUMMY_FINGERPRINT)); SelfSignedCertificate serverCert = SelfSignedCertificate.create(); HttpServerOptions options = new HttpServerOptions(); options .setSsl(true) .setClientAuth(ClientAuth.REQUIRED) .setPemKeyCertOptions(serverCert.keyCertOptions()) .setTrustOptions(VertxTrustOptions.trustClientOnFirstAccess(knownClientsFile, false)) .setIdleTimeout(1500) .setReuseAddress(true) .setReusePort(true); httpServer = vertx.createHttpServer(options); SecurityTestUtils.configureAndStartTestServer(httpServer); }
Example 9
Source File: ServerCaOrRecordTest.java From incubator-tuweni with Apache License 2.0 | 6 votes |
@BeforeEach void startServer(@TempDirectory Path tempDir, @VertxInstance Vertx vertx) throws Exception { knownClientsFile = tempDir.resolve("known-clients.txt"); Files.write(knownClientsFile, Arrays.asList("#First line", "foobar.com " + DUMMY_FINGERPRINT)); SelfSignedCertificate serverCert = SelfSignedCertificate.create(); HttpServerOptions options = new HttpServerOptions(); options .setSsl(true) .setClientAuth(ClientAuth.REQUIRED) .setPemKeyCertOptions(serverCert.keyCertOptions()) .setTrustOptions(VertxTrustOptions.recordClientFingerprints(knownClientsFile)) .setIdleTimeout(1500) .setReuseAddress(true) .setReusePort(true); httpServer = vertx.createHttpServer(options); SecurityTestUtils.configureAndStartTestServer(httpServer); }
Example 10
Source File: ServerCaOrWhitelistTest.java From incubator-tuweni with Apache License 2.0 | 6 votes |
@BeforeEach void startServer(@TempDirectory Path tempDir, @VertxInstance Vertx vertx) throws Exception { knownClientsFile = tempDir.resolve("known-clients.txt"); Files.write(knownClientsFile, Arrays.asList("#First line", "foo.com " + fooFingerprint)); SelfSignedCertificate serverCert = SelfSignedCertificate.create(); HttpServerOptions options = new HttpServerOptions(); options .setSsl(true) .setClientAuth(ClientAuth.REQUIRED) .setPemKeyCertOptions(serverCert.keyCertOptions()) .setTrustOptions(VertxTrustOptions.whitelistClients(knownClientsFile)) .setIdleTimeout(1500) .setReuseAddress(true) .setReusePort(true); httpServer = vertx.createHttpServer(options); SecurityTestUtils.configureAndStartTestServer(httpServer); }
Example 11
Source File: ServerRecordTest.java From incubator-tuweni with Apache License 2.0 | 6 votes |
@BeforeEach void startServer(@TempDirectory Path tempDir, @VertxInstance Vertx vertx) throws Exception { knownClientsFile = tempDir.resolve("known-clients.txt"); Files.write(knownClientsFile, Arrays.asList("#First line", "foobar.com " + DUMMY_FINGERPRINT)); SelfSignedCertificate serverCert = SelfSignedCertificate.create(); HttpServerOptions options = new HttpServerOptions(); options .setSsl(true) .setClientAuth(ClientAuth.REQUIRED) .setPemKeyCertOptions(serverCert.keyCertOptions()) .setTrustOptions(VertxTrustOptions.recordClientFingerprints(knownClientsFile, false)) .setIdleTimeout(1500) .setReuseAddress(true) .setReusePort(true); httpServer = vertx.createHttpServer(options); SecurityTestUtils.configureAndStartTestServer(httpServer); }
Example 12
Source File: VertTest.java From joyqueue with Apache License 2.0 | 5 votes |
public static void main(String[] args) { Vertx vertx = Vertx.vertx(); HttpServer server = vertx.createHttpServer(); Router router = Router.router(vertx); router.get("/hello").handler(routingContext -> { HttpServerRequest request = routingContext.request(); System.out.println(request.params().toString()); routingContext.response().end("helloworld"); }); server.requestHandler(request -> router.accept(request)).listen(8080); server.close(); }
Example 13
Source File: Examples.java From vertx-unit with Apache License 2.0 | 5 votes |
public static void async_04(TestContext context, Vertx vertx, Handler<HttpServerRequest> requestHandler) { Async async = context.async(); HttpServer server = vertx.createHttpServer(); server.requestHandler(requestHandler); server.listen(8080, ar -> { context.assertTrue(ar.succeeded()); async.complete(); }); // Wait until completion async.awaitSuccess(); // Do something else }
Example 14
Source File: Main.java From microservices-comparison with Apache License 2.0 | 5 votes |
public static void main(String[] args) { // TODO start a vertx instance // deploy verticles / one per resource in this case Json.mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); Vertx vertx = Vertx.vertx(); HttpClientOptions clientOptions = new HttpClientOptions() .setSsl(true) .setTrustStoreOptions(new JksOptions() .setPath(System.getProperty("javax.net.ssl.trustStore")) .setPassword(System.getProperty("javax.net.ssl.trustStorePassword"))); HttpClient httpClient = vertx.createHttpClient(clientOptions); Router router = Router.router(vertx); AuthHandler auth = new BearerAuthHandler(new FacebookOauthTokenVerifier(httpClient)); router.route("/*").handler(auth); HelloResource helloResource = new HelloResource(httpClient); router.get("/hello").produces("text/plain").handler(helloResource::hello); CarRepository carRepository = new InMemoryCarRepository(); CarsResource carsResource = new CarsResource(carRepository); router.route("/cars*").handler(BodyHandler.create()); router.get("/cars").produces("application/json").handler(carsResource::all); router.post("/cars").consumes("application/json").handler(carsResource::create); CarResource carResource = new CarResource(carRepository); router.get("/cars/:id").produces("application/json").handler(carResource::byId); HttpServerOptions serverOptions = new HttpServerOptions() .setSsl(true) .setKeyStoreOptions(new JksOptions() .setPath(System.getProperty("javax.net.ssl.keyStorePath")) .setPassword(System.getProperty("javax.net.ssl.keyStorePassword"))) .setPort(8090); HttpServer server = vertx.createHttpServer(serverOptions); server.requestHandler(router::accept).listen(); }
Example 15
Source File: SimpleWebsiteMain.java From examples with Apache License 2.0 | 5 votes |
public static void main(String[] args) { Vertx vertx = Vertx.vertx(); HttpServer server = vertx.createHttpServer(); server.requestHandler(request -> { HttpServerResponse response = request.response(); response.putHeader("content-type", "application/json"); JsonObject responseJson = SimpleWebsiteMain.jsonObject.copy(); response.end(responseJson.encodePrettily()); }); server.listen(8080); }
Example 16
Source File: VertxRestServiceAdapter.java From mewbase with MIT License | 5 votes |
public VertxRestServiceAdapter(Config cfg) { // Get the Vertx rest end point configuration final String host = cfg.getString("mewbase.api.rest.vertx.host"); final int port = cfg.getInt("mewbase.api.rest.vertx.port"); final Duration timeout = cfg.getDuration("mewbase.api.rest.vertx.timeout"); final HttpServerOptions opts = new HttpServerOptions().setHost(host).setPort(port); // Set up the rest server using the config. final Vertx vertx = Vertx.vertx(); httpServer = vertx.createHttpServer(opts); router = Router.router(vertx); router.route().handler(BodyHandler.create()); httpServer.requestHandler(router::accept); logger.info("Created Rest Adapter on "+ opts.getHost() + ":" + opts.getPort() ); }
Example 17
Source File: OpenAPI3Examples.java From vertx-web with Apache License 2.0 | 4 votes |
public void generateRouter(Vertx vertx, OpenAPI3RouterFactory routerFactory) { Router router = routerFactory.getRouter(); HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080).setHost("localhost")); server.requestHandler(router).listen(); }
Example 18
Source File: AllExamplesServer.java From vertxui with GNU General Public License v3.0 | 4 votes |
public static void start(Class<?> classs, Router router) { Vertx vertx = Vertx.currentContext().owner(); HttpServer httpServer = vertx.createHttpServer(new HttpServerOptions().setCompressionSupported(true)); start(classs, router, httpServer); }
Example 19
Source File: OpenAPI3Examples.java From vertx-web with Apache License 2.0 | 4 votes |
public void generateRouter(Vertx vertx, RouterFactory routerFactory) { Router router = routerFactory.createRouter(); HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080).setHost("localhost")); server.requestHandler(router).listen(); }
Example 20
Source File: MetricsExamples.java From vertx-dropwizard-metrics with Apache License 2.0 | 4 votes |
public void example2(Vertx vertx) { MetricsService metricsService = MetricsService.create(vertx); HttpServer server = vertx.createHttpServer(); // set up server JsonObject metrics = metricsService.getMetricsSnapshot(server); }