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

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

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

HttpConnection.exceptionHandler介绍

[英]Set an handler called when a connection error happens
[中]设置在发生连接错误时调用的处理程序

代码示例

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

@Test
public void testClientConnectionExceptionHandler() throws Exception {
 server.requestHandler(req -> {
  NetSocket so = req.netSocket();
  so.write(Buffer.buffer(TestUtils.randomAlphaString(40) + "\r\n"));
 });
 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.connectionHandler(conn -> {
  conn.exceptionHandler(err -> {
   testComplete();
  });
 });
 req.sendHead();
 await();
}

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

@Test
public void testInvalidServerResponse() throws Exception {
 ServerBootstrap bootstrap = createH2Server((dec, enc) -> new Http2EventAdapter() {
  @Override
  public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception {
   enc.writeHeaders(ctx, streamId, new DefaultHttp2Headers().status("xyz"), 0, false, ctx.newPromise());
   ctx.flush();
  }
 });
 ChannelFuture s = bootstrap.bind(DEFAULT_HTTPS_HOST, DEFAULT_HTTPS_PORT).sync();
 try {
  Context ctx = vertx.getOrCreateContext();
  ctx.runOnContext(v -> {
   client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", onFailure(err -> {
    assertOnIOContext(ctx);
    if (err instanceof NumberFormatException) {
     testComplete();
    }
   }))
    .connectionHandler(conn -> conn.exceptionHandler(err -> fail()))
    .end();
  });
  await();
 } finally {
  s.channel().close().sync();
 }
}

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

@Test
public void testServerConnectionExceptionHandler() throws Exception {
 server.connectionHandler(conn -> {
  conn.exceptionHandler(err -> {
   assertTrue(err instanceof TooLongFrameException);
   testComplete();
  });
 });
 server.requestHandler(req -> {
  req.response().end();
 });
 CountDownLatch listenLatch = new CountDownLatch(1);
 server.listen(onSuccess(s -> listenLatch.countDown()));
 awaitLatch(listenLatch);
 client.close();
 client = vertx.createHttpClient(new HttpClientOptions().setMaxPoolSize(1));
 client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp1 -> {
  HttpClientRequest req = client.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp2 -> {
  });
  req.putHeader("the_header", TestUtils.randomAlphaString(10000));
  req.sendHead();
 });
 await();
}

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

@Test
public void testTooLongContentInHttpServerRequest() throws Exception {
 server.requestHandler(req -> {
  req.response().end();
 });
 server.connectionHandler(conn -> {
  conn.exceptionHandler(error -> {
   assertEquals(IllegalArgumentException.class, error.getClass());
   testComplete();
  });
 });
 startServer();
 NetClient client = vertx.createNetClient();
 try {
  client.connect(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, onSuccess(so -> {
   so.write("POST / HTTP/1.1\r\nContent-Length: 4\r\n\r\ntoolong\r\n");
  }));
  await();
 } finally {
  client.close();
 }
}
@Test

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

conn.exceptionHandler(err -> {
 assertOnIOContext(ctx);
 if (err instanceof Http2Exception) {

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

conn.exceptionHandler(err -> {
 assertSame(ctx, Vertx.currentContext());
 if (err instanceof Http2Exception) {

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

/**
 * Set an handler called when a connection error happens
 * @param handler the handler
 * @return a reference to this, so the API can be used fluently
 */
public io.vertx.rxjava.core.http.HttpConnection exceptionHandler(Handler<Throwable> handler) { 
 delegate.exceptionHandler(handler);
 return this;
}

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

/**
 * Set an handler called when a connection error happens
 * @param handler the handler
 * @return a reference to this, so the API can be used fluently
 */
public io.vertx.rxjava.core.http.HttpConnection exceptionHandler(Handler<Throwable> handler) { 
 delegate.exceptionHandler(handler);
 return this;
}

代码示例来源:origin: gravitee-io/gravitee-gateway

connection.exceptionHandler(ex -> {

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

@Test
public void testClientConnectionExceptionHandler() throws Exception {
 server.requestHandler(req -> {
  NetSocket so = req.netSocket();
  so.write(Buffer.buffer(TestUtils.randomAlphaString(40) + "\r\n"));
 });
 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.connectionHandler(conn -> {
  conn.exceptionHandler(err -> {
   testComplete();
  });
 });
 req.sendHead();
 await();
}

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

fail();
}).connectionHandler(conn -> {
 conn.exceptionHandler(err -> {
  fail();
 });

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

@Test
public void testTooLongContentInHttpServerRequest() throws Exception {
 server.requestHandler(req -> {
  req.response().end();
 });
 server.connectionHandler(conn -> {
  conn.exceptionHandler(error -> {
   assertEquals(IllegalArgumentException.class, error.getClass());
   testComplete();
  });
 });
 startServer();
 NetClient client = vertx.createNetClient();
 try {
  client.connect(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, onSuccess(so -> {
   so.write("POST / HTTP/1.1\r\nContent-Length: 4\r\n\r\ntoolong\r\n");
  }));
  await();
 } finally {
  client.close();
 }
}
@Test

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

@Test
public void testServerConnectionExceptionHandler() throws Exception {
 server.connectionHandler(conn -> {
  conn.exceptionHandler(err -> {
   assertTrue(err instanceof TooLongFrameException);
   testComplete();
  });
 });
 server.requestHandler(req -> {
  req.response().end();
 });
 CountDownLatch listenLatch = new CountDownLatch(1);
 server.listen(onSuccess(s -> listenLatch.countDown()));
 awaitLatch(listenLatch);
 client.close();
 client = vertx.createHttpClient(new HttpClientOptions().setMaxPoolSize(1));
 client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp1 -> {
  HttpClientRequest req = client.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp2 -> {
  });
  req.putHeader("the_header", TestUtils.randomAlphaString(10000));
  req.sendHead();
 });
 await();
}

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

connection.remoteAddress());
});
connection.exceptionHandler(e -> {
 LOGGER.info("http connection exception, local:{}, remote:{}.",
   connection.localAddress(),

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

conn.exceptionHandler(err -> {
 assertSame(ctx, Vertx.currentContext());
 if (err instanceof Http2Exception) {

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

conn.exceptionHandler(err -> {
 assertOnIOContext(ctx);
 if (err instanceof Http2Exception) {

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

@Override
public void handle(RoutingContext rc) {
 HttpServerResponse response = rc.response();
 response
  .setChunked(true)
  .putHeader(HttpHeaders.CONTENT_TYPE, "text/event-stream")
  .putHeader(HttpHeaders.CACHE_CONTROL, "no-cache")
  .putHeader(HttpHeaders.CONNECTION, HttpHeaders.KEEP_ALIVE);
 rc.request().connection()
  .closeHandler(v -> {
   connections.remove(response);
   endQuietly(response);
  })
  .exceptionHandler(t -> {
   connections.remove(response);
   rc.fail(t);
  });
 connections.add(response);
}

代码示例来源:origin: io.gravitee.gateway.http/gravitee-gateway-http-client-vertx

connection.exceptionHandler(ex -> {

代码示例来源:origin: io.gravitee.gateway/gravitee-gateway-http

connection.exceptionHandler(ex -> {

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

connection.remoteAddress());
});
connection.exceptionHandler(e -> {
 LOGGER.info("http connection exception, local:{}, remote:{}.",
   connection.localAddress(),

相关文章