当前位置: 首页>>代码示例>>Java>>正文


Java HttpServer.close方法代码示例

本文整理汇总了Java中io.vertx.core.http.HttpServer.close方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServer.close方法的具体用法?Java HttpServer.close怎么用?Java HttpServer.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.vertx.core.http.HttpServer的用法示例。


在下文中一共展示了HttpServer.close方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testValidJWT

import io.vertx.core.http.HttpServer; //导入方法依赖的package包/类
@Test
public void testValidJWT(TestContext context) throws URISyntaxException {
    HttpServer openIdMockServer = this.createOpenIdMockServer(CERTS_VALID);
    Async openIdStarted = context.async();
    openIdMockServer.listen(TestConfig.OPENID_PORT, context.asyncAssertSuccess(i -> openIdStarted.complete()));
    openIdStarted.awaitSuccess(5000);
    JsonObject config = TestConfig.getApiConfig();
    config.getJsonObject("auth").put("enable", true);
    deployApiVerticle(context, config);

    createSslRequest("/api/v1.0/pr/latest")
            .putHeader("Authorization", "Bearer " + JWT_TOKEN)
            .send(context.asyncAssertSuccess(res ->
                    context.assertEquals(200, res.statusCode())
            ));
    openIdMockServer.close(context.asyncAssertSuccess());
}
 
开发者ID:Deutsche-Boerse-Risk,项目名称:DAVe,代码行数:18,代码来源:AuthTest.java

示例2: testTLS

import io.vertx.core.http.HttpServer; //导入方法依赖的package包/类
private void testTLS(WebClientOptions clientOptions, HttpServerOptions serverOptions, Function<WebClient, HttpRequest<Buffer>> requestProvider, Consumer<HttpServerRequest> serverAssertions) throws Exception {
  WebClient sslClient = WebClient.create(vertx, clientOptions);
  HttpServer sslServer = vertx.createHttpServer(serverOptions);
  sslServer.requestHandler(req -> {
    assertEquals(serverOptions.isSsl(), req.isSSL());
    if (serverAssertions != null) {
      serverAssertions.accept(req);
    }
    req.response().end();
  });
  try {
    startServer(sslServer);
    HttpRequest<Buffer> builder = requestProvider.apply(sslClient);
    builder.send(onSuccess(resp -> testComplete()));
    await();
  } finally {
    sslClient.close();
    sslServer.close();
  }
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:21,代码来源:WebClientTest.java

示例3: testStreamHttpServerRequest

import io.vertx.core.http.HttpServer; //导入方法依赖的package包/类
@Test
public void testStreamHttpServerRequest() throws Exception {
  Buffer expected = TestUtils.randomBuffer(10000);
  HttpServer server2 = vertx.createHttpServer(new HttpServerOptions().setPort(8081)).requestHandler(req -> req.bodyHandler(body -> {
    assertEquals(body, expected);
    req.response().end();
  }));
  startServer(server2);
  WebClient webClient = WebClient.create(vertx);
  try {
    server.requestHandler(req -> webClient.postAbs("http://localhost:8081/")
      .sendStream(req, onSuccess(resp -> req.response().end("ok"))));
    startServer();
    webClient.post(8080, "localhost", "/").sendBuffer(expected, onSuccess(resp -> {
      assertEquals("ok", resp.bodyAsString());
      complete();
    }));
    await();
  } finally {
    server2.close();
  }
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:23,代码来源:WebClientTest.java

示例4: testFailingAuth

import io.vertx.core.http.HttpServer; //导入方法依赖的package包/类
private void testFailingAuth(TestContext context, HttpServer openIdServer, String jwtToken) {
    Async openIdStarted = context.async();
    openIdServer.listen(TestConfig.OPENID_PORT, context.asyncAssertSuccess(i -> openIdStarted.complete()));
    openIdStarted.awaitSuccess(5000);
    JsonObject config = TestConfig.getApiConfig();
    config.getJsonObject("auth").put("enable", true);
    deployApiVerticle(context, config);

    createSslRequest("/api/v1.0/am/latest")
            .putHeader("Authorization", "Bearer " + jwtToken)
            .send(context.asyncAssertSuccess(res ->
                    context.assertEquals(401, res.statusCode())
            ));
    openIdServer.close(context.asyncAssertSuccess());
}
 
开发者ID:Deutsche-Boerse-Risk,项目名称:DAVe,代码行数:16,代码来源:AuthTest.java

示例5: testFailingServer

import io.vertx.core.http.HttpServer; //导入方法依赖的package包/类
private void testFailingServer(TestContext context, HttpServer openIdServer) throws InterruptedException {
    Async openIdStarted = context.async();
    openIdServer.listen(TestConfig.OPENID_PORT, context.asyncAssertSuccess(i -> openIdStarted.complete()));
    openIdStarted.awaitSuccess(5000);
    JsonObject config = TestConfig.getApiConfig();
    config.getJsonObject("auth").put("enable", true);
    Async deployFailed = context.async();
    vertx.deployVerticle(ApiVerticle.class.getName(), new DeploymentOptions().setConfig(config),
            context.asyncAssertFailure(i -> deployFailed.complete()));
    deployFailed.awaitSuccess(5000);
    context.assertFalse(new HealthCheck(vertx).isComponentReady(HealthCheck.Component.API));
    openIdServer.close(context.asyncAssertSuccess());
}
 
开发者ID:Deutsche-Boerse-Risk,项目名称:DAVe,代码行数:14,代码来源:AuthTest.java

示例6: testCSRF

import io.vertx.core.http.HttpServer; //导入方法依赖的package包/类
@Test
public void testCSRF(TestContext context) throws InterruptedException, URISyntaxException {
    HttpServer openIdMockServer = this.createOpenIdMockServer(CERTS_VALID);
    Async openIdStarted = context.async();
    openIdMockServer.listen(TestConfig.OPENID_PORT, context.asyncAssertSuccess(i -> openIdStarted.complete()));
    openIdStarted.awaitSuccess(5000);
    JsonObject config = TestConfig.getApiConfig();
    config.getJsonObject("auth").put("enable", true);
    config.getJsonObject("csrf").put("enable", true);
    deployApiVerticle(context, config);

    createSslRequest("/api/v1.0/pr/latest")
            .putHeader("Authorization", "Bearer " + JWT_TOKEN)
            .send(context.asyncAssertSuccess(res -> {
                context.assertEquals(200, res.statusCode());

                final String csrfToken = getCsrfCookie(res.cookies())
                        .orElseThrow(() -> new RuntimeException("XSRF-TOKEN cookie not found"));

                createSslPostRequest("/api/v1.0/pr/delete")
                        .putHeader("Authorization", "Bearer " + JWT_TOKEN)
                        .putHeader("X-XSRF-TOKEN", csrfToken)
                        .send(context.asyncAssertSuccess(csrfRes -> {
                            // We expect "Not found (404)" error code instead of "Forbidden (403)"
                            context.assertEquals(404, csrfRes.statusCode());
                        }));
            }));
    openIdMockServer.close(context.asyncAssertSuccess());
}
 
开发者ID:Deutsche-Boerse-Risk,项目名称:DAVe,代码行数:30,代码来源:AuthTest.java

示例7: cleanup

import io.vertx.core.http.HttpServer; //导入方法依赖的package包/类
protected void cleanup(HttpServer server) throws Exception {
  CountDownLatch latch = new CountDownLatch(1);
  if (server != null) {
    server.close(ar -> {
      latch.countDown();
    });
  }
  awaitLatch(latch);
}
 
开发者ID:vert-x3,项目名称:vertx-dropwizard-metrics,代码行数:10,代码来源:MetricsTestBase.java

示例8: executeApp

import io.vertx.core.http.HttpServer; //导入方法依赖的package包/类
@Override
public void executeApp() throws Exception {
    int port = getAvailablePort();
    HttpServer httpServer = Vertx.vertx().createHttpServer()
            .requestHandler(req -> req.response().end("Hello World!"))
            .listen(port);
    CloseableHttpClient httpClient = HttpClients.createDefault();
    HttpGet httpGet = new HttpGet("http://localhost:" + port + "/abc?xyz=123");
    int statusCode = httpClient.execute(httpGet).getStatusLine().getStatusCode();
    if (statusCode != 200) {
        throw new IllegalStateException("Unexpected status code: " + statusCode);
    }
    httpServer.close();
}
 
开发者ID:glowroot,项目名称:glowroot,代码行数:15,代码来源:Vertx3xIT.java

示例9: testHttpMetricsOnClose

import io.vertx.core.http.HttpServer; //导入方法依赖的package包/类
@Test
public void testHttpMetricsOnClose() throws Exception {
  int requests = 6;
  CountDownLatch latch = new CountDownLatch(requests);

  HttpClient client = vertx.createHttpClient(new HttpClientOptions());
  HttpServer server = vertx.createHttpServer(new HttpServerOptions().setHost("localhost").setPort(8081)).requestHandler(req -> {
    req.response().end();
  }).listen(ar -> {
    assertTrue(ar.succeeded());
    for (int i = 0; i < requests; i++) {
      client.request(HttpMethod.GET, 8081, "localhost", "/some/uri", resp -> {
        latch.countDown();
      }).end();
    }
  });

  awaitLatch(latch);

  client.close();
  server.close(ar -> {
    assertTrue(ar.succeeded());
    vertx.runOnContext(v -> testComplete());
  });

  await();

  JsonObject metrics;
  long start = System.currentTimeMillis();
  // This allows http server metrics to be completely removed from the registry
  do {
    metrics = metricsService.getMetricsSnapshot(server);
    if (metrics != null && metrics.isEmpty()) {
      break;
    }
    MILLISECONDS.sleep(100);
  } while (System.currentTimeMillis() - start < 5000);
  assertNotNull(metrics);
  assertEquals(Collections.emptyMap(), metrics.getMap());

  metrics = metricsService.getMetricsSnapshot(client);
  assertNotNull(metrics);
  assertNull(metrics.getJsonObject("connections.max-pool-size"));
}
 
开发者ID:vert-x3,项目名称:vertx-dropwizard-metrics,代码行数:45,代码来源:MetricsTest.java

示例10: testAuthCodeFlow

import io.vertx.core.http.HttpServer; //导入方法依赖的package包/类
@Test
public void testAuthCodeFlow() throws Exception {

  // lets mock a oauth2 server using code auth code flow
  OAuth2Auth oauth2 = OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions()
      .setClientID("client-id")
      .setClientSecret("client-secret")
      .setSite("http://localhost:10000"));

  final CountDownLatch latch = new CountDownLatch(1);

  HttpServer server = vertx.createHttpServer().requestHandler(req -> {
    if (req.method() == HttpMethod.POST && "/oauth/token".equals(req.path())) {
      req.setExpectMultipart(true).bodyHandler(buffer -> req.response().putHeader("Content-Type", "application/json").end(fixture.encode()));
    } else if (req.method() == HttpMethod.POST && "/oauth/revoke".equals(req.path())) {
      req.setExpectMultipart(true).bodyHandler(buffer -> req.response().end());
    } else {
      req.response().setStatusCode(400).end();
    }
  }).listen(10000, ready -> {
    if (ready.failed()) {
      throw new RuntimeException(ready.cause());
    }
    // ready
    latch.countDown();
  });

  latch.await();

  // create a oauth2 handler on our domain to the callback: "http://localhost:8080/callback"
  OAuth2AuthHandler oauth2Handler = OAuth2AuthHandler.create(oauth2, "http://localhost:8080/callback");

  // setup the callback handler for receiving the callback
  oauth2Handler.setupCallback(router.route());

  // protect everything under /protected
  router.route("/protected/*").handler(oauth2Handler);
  // mount some handler under the protected zone
  router.route("/protected/somepage").handler(rc -> {
    assertNotNull(rc.user());
    rc.response().end("Welcome to the protected resource!");
  });


  testRequest(HttpMethod.GET, "/protected/somepage", null, resp -> {
    // in this case we should get a redirect
    redirectURL = resp.getHeader("Location");
    assertNotNull(redirectURL);
  }, 302, "Found", null);

  // fake the redirect
  testRequest(HttpMethod.GET, "/callback?state=/protected/somepage&code=1", null, resp -> {
  }, 200, "OK", "Welcome to the protected resource!");

  server.close();
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:57,代码来源:OAuth2AuthHandlerTest.java

示例11: testPasswordFlow

import io.vertx.core.http.HttpServer; //导入方法依赖的package包/类
@Test
public void testPasswordFlow() throws Exception {

  // lets mock a oauth2 server using code auth code flow
  OAuth2Auth oauth2 = OAuth2Auth.create(vertx, OAuth2FlowType.PASSWORD, new OAuth2ClientOptions()
    .setClientID("client-id")
    .setClientSecret("client-secret")
    .setSite("http://localhost:10000"));

  final CountDownLatch latch = new CountDownLatch(1);

  HttpServer server = vertx.createHttpServer().requestHandler(req -> {
    if (req.method() == HttpMethod.POST && "/oauth/token".equals(req.path())) {
      req.setExpectMultipart(true).bodyHandler(buffer -> {
        final String queryString = buffer.toString();
        assertTrue(queryString.contains("username=paulo"));
        assertTrue(queryString.contains("password=bananas"));
        assertTrue(queryString.contains("grant_type=password"));

        req.response().putHeader("Content-Type", "application/json").end(fixture.encode());
      });
    } else if (req.method() == HttpMethod.POST && "/oauth/revoke".equals(req.path())) {
      req.setExpectMultipart(true).bodyHandler(buffer -> req.response().end());
    } else {
      req.response().setStatusCode(400).end();
    }
  }).listen(10000, ready -> {
    if (ready.failed()) {
      throw new RuntimeException(ready.cause());
    }
    // ready
    latch.countDown();
  });

  latch.await();

  AuthHandler oauth2Handler = BasicAuthHandler.create(oauth2);

  // protect everything under /protected
  router.route("/protected/*").handler(oauth2Handler);
  // mount some handler under the protected zone
  router.route("/protected/somepage").handler(rc -> {
    assertNotNull(rc.user());
    rc.response().end("Welcome to the protected resource!");
  });


  testRequest(HttpMethod.GET, "/protected/somepage", req -> req.putHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString("paulo:bananas".getBytes())), res -> {
    // in this case we should get the resource
  }, 200, "OK", "Welcome to the protected resource!");

  testRequest(HttpMethod.GET, "/protected/somepage", 401, "Unauthorized");

  server.close();
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:56,代码来源:OAuth2AuthHandlerTest.java


注:本文中的io.vertx.core.http.HttpServer.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。