io.vertx.core.http.HttpServer.exceptionHandler()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(202)

本文整理了Java中io.vertx.core.http.HttpServer.exceptionHandler()方法的一些代码示例,展示了HttpServer.exceptionHandler()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpServer.exceptionHandler()方法的具体详情如下:
包路径:io.vertx.core.http.HttpServer
类名称:HttpServer
方法名:exceptionHandler

HttpServer.exceptionHandler介绍

[英]Set an exception handler called for socket errors happening before the HTTP connection is established, e.g during the TLS handshake.
[中]为HTTP连接建立之前发生的套接字错误(例如在TLS握手期间)设置调用的异常处理程序。

代码示例

代码示例来源:origin: eclipse-vertx/vert.x

@Override
public void setUp() throws Exception {
 super.setUp();
 CountDownLatch listenLatch = new CountDownLatch(1);
 httpServer = vertx.createHttpServer()
  .requestHandler(request -> {})
  .exceptionHandler(t -> {
   caught.set(t);
   resetLatch.countDown();
  })
  .listen(8080, onSuccess(server -> listenLatch.countDown()));
 awaitLatch(listenLatch);
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testServerExceptionHandler() throws Exception {
 server.exceptionHandler(err -> {
  assertTrue(err instanceof TooLongFrameException);
  testComplete();
 });
 server.requestHandler(req -> {
  fail();
 });
 CountDownLatch listenLatch = new CountDownLatch(1);
 server.listen(onSuccess(s -> listenLatch.countDown()));
 awaitLatch(listenLatch);
 HttpClientRequest req = client.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp -> {
 });
 req.putHeader("the_header", TestUtils.randomAlphaString(10000));
 req.sendHead();
 await();
}

代码示例来源:origin: eclipse-vertx/vert.x

server.connectionHandler(conn -> complete());
AtomicInteger count = new AtomicInteger();
server.exceptionHandler(err -> {
 if (shouldPass) {
  HttpTLSTest.this.fail(err);

代码示例来源:origin: io.vertx/vertx-core

@Override
public void setUp() throws Exception {
 super.setUp();
 CountDownLatch listenLatch = new CountDownLatch(1);
 httpServer = vertx.createHttpServer()
  .requestHandler(request -> {})
  .exceptionHandler(t -> {
   caught.set(t);
   resetLatch.countDown();
  })
  .listen(8080, onSuccess(server -> listenLatch.countDown()));
 awaitLatch(listenLatch);
}

代码示例来源:origin: apache/servicecomb-java-chassis

httpServer.exceptionHandler(e -> {
 if(e instanceof ClosedChannelException) {

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Set an exception handler called for socket errors happening before the HTTP connection
 * is established, e.g during the TLS handshake.
 * @param handler the handler to set
 * @return a reference to this, so the API can be used fluently
 */
public io.vertx.rxjava.core.http.HttpServer exceptionHandler(Handler<Throwable> handler) { 
 delegate.exceptionHandler(handler);
 return this;
}

代码示例来源:origin: vert-x3/vertx-rx

/**
 * Set an exception handler called for socket errors happening before the HTTP connection
 * is established, e.g during the TLS handshake.
 * @param handler the handler to set
 * @return a reference to this, so the API can be used fluently
 */
public io.vertx.rxjava.core.http.HttpServer exceptionHandler(Handler<Throwable> handler) { 
 delegate.exceptionHandler(handler);
 return this;
}

代码示例来源:origin: io.vertx/vertx-core

@Test
public void testServerExceptionHandler() throws Exception {
 server.exceptionHandler(err -> {
  assertTrue(err instanceof TooLongFrameException);
  testComplete();
 });
 server.requestHandler(req -> {
  fail();
 });
 CountDownLatch listenLatch = new CountDownLatch(1);
 server.listen(onSuccess(s -> listenLatch.countDown()));
 awaitLatch(listenLatch);
 HttpClientRequest req = client.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp -> {
 });
 req.putHeader("the_header", TestUtils.randomAlphaString(10000));
 req.sendHead();
 await();
}

代码示例来源:origin: io.vertx/vertx-micrometer-metrics

@Override
public void init() {
 if (options.isStartEmbeddedServer()) {
  this.vertx = Vertx.vertx();
  // Start dedicated server
  HttpServerOptions serverOptions = options.getEmbeddedServerOptions();
  if (serverOptions == null) {
   serverOptions = new HttpServerOptions();
  }
  vertx.createHttpServer(serverOptions)
   .requestHandler(this::handleRequest)
   .exceptionHandler(t -> LOGGER.error("Error in Prometheus registry embedded server", t))
   .listen(serverOptions.getPort(), serverOptions.getHost());
 }
}

代码示例来源:origin: io.vertx/vertx-core

server.connectionHandler(conn -> complete());
AtomicInteger count = new AtomicInteger();
server.exceptionHandler(err -> {
 if (shouldPass) {
  HttpTLSTest.this.fail(err);

代码示例来源:origin: org.apache.servicecomb/transport-rest-vertx

httpServer.exceptionHandler(e -> {
 LOGGER.error("Unexpected error in server.{}", ExceptionUtils.getExceptionMessageWithoutTrace(e));
});

代码示例来源:origin: quarantyne/quarantyne

proxiedRequestHandler(frontReq, null);
}).exceptionHandler(ex -> {
 log.error("HTTP server error", ex);
}).listen(configArgs.getIngress().getPort(), configArgs.getIngress().getIp(), h -> {

代码示例来源:origin: io.vertx/vertx-micrometer-metrics

.exceptionHandler(System.err::println)
.listen(port, "localhost", res -> {
 if (res.succeeded()) {

代码示例来源:origin: io.vertx/vertx-micrometer-metrics

@Test
public void shouldBindExistingServer(TestContext context) {
 vertx = Vertx.vertx(new VertxOptions()
  .setMetricsOptions(new MicrometerMetricsOptions()
   .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true))
   .setEnabled(true)));
 Router router = Router.router(vertx);
 router.route("/custom").handler(routingContext -> {
  PrometheusMeterRegistry prometheusRegistry = (PrometheusMeterRegistry) BackendRegistries.getDefaultNow();
  String response = prometheusRegistry.scrape();
  routingContext.response().end(response);
 });
 vertx.createHttpServer().requestHandler(router).exceptionHandler(context.exceptionHandler()).listen(8081);
 Async async = context.async();
 PrometheusTestHelper.tryConnect(vertx, context, 8081, "localhost", "/custom", body -> {
  context.verify(v -> assertThat(body.toString())
     .contains("vertx_http_"));
  async.complete();
 });
 async.awaitSuccess(10000);
}

相关文章