本文整理汇总了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());
}
示例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();
}
}
示例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();
}
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
示例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();
}
示例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"));
}
示例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();
}
示例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();
}