@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(); }
@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(); } }
@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(); }
@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
conn.exceptionHandler(err -> { assertOnIOContext(ctx); if (err instanceof Http2Exception) {
conn.exceptionHandler(err -> { assertSame(ctx, Vertx.currentContext()); if (err instanceof Http2Exception) {
/** * 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; }
/** * 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; }
connection.exceptionHandler(ex -> {
@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(); }
fail(); }).connectionHandler(conn -> { conn.exceptionHandler(err -> { fail(); });
@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
@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(); }
connection.remoteAddress()); }); connection.exceptionHandler(e -> { LOGGER.info("http connection exception, local:{}, remote:{}.", connection.localAddress(),
conn.exceptionHandler(err -> { assertSame(ctx, Vertx.currentContext()); if (err instanceof Http2Exception) {
conn.exceptionHandler(err -> { assertOnIOContext(ctx); if (err instanceof Http2Exception) {
@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); }
connection.exceptionHandler(ex -> {
connection.exceptionHandler(ex -> {
connection.remoteAddress()); }); connection.exceptionHandler(e -> { LOGGER.info("http connection exception, local:{}, remote:{}.", connection.localAddress(),