@Test public void testResetPushPromiseNoHandler() throws Exception { server.requestHandler(req -> { req.response().push(HttpMethod.GET, "/wibble", ar -> { assertTrue(ar.succeeded()); HttpServerResponse resp = ar.result(); resp.setChunked(true).write("content"); AtomicLong reset = new AtomicLong(); resp.exceptionHandler(err -> { if (err instanceof StreamResetException) { reset.set(((StreamResetException)err).getCode()); } }); resp.closeHandler(v -> { assertEquals(Http2Error.CANCEL.code(), reset.get()); testComplete(); }); }); }); startServer(); HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> { }); req.end(); await(); }
resp.exceptionHandler(err -> { assertEquals(0, reqExceptionHandlerCount.get()); assertEquals(1, respExceptionHandlerCount.incrementAndGet());
req.response().exceptionHandler(err -> { if (err instanceof StreamResetException) { reset.set(((StreamResetException) err).getCode());
@Test public void testNoExceptionHandlerCalledWhenResponseEnded() throws Exception { server.requestHandler(req -> { HttpServerResponse resp = req.response(); req.exceptionHandler(this::fail); resp.exceptionHandler(err -> { err.printStackTrace(); }); resp.end(); }).listen(DEFAULT_HTTP_PORT, onSuccess(s -> { client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp -> { resp.endHandler(v -> { vertx.setTimer(100, tid -> testComplete()); }); resp.exceptionHandler(t -> { fail("Should not be called"); }); })).exceptionHandler(t -> { fail("Should not be called"); }).end(); })); await(); }
@Test public void testClientResetServerStreamDuringResponse() throws Exception { server.requestHandler(req -> { req.exceptionHandler(err -> { assertEquals(err.getClass(), StreamResetException.class); }); AtomicLong reset = new AtomicLong(); req.response().exceptionHandler(err -> { if (err instanceof StreamResetException) { reset.set(((StreamResetException) err).getCode()); } }); req.response().closeHandler(v -> { assertEquals(10L, reset.get()); testComplete(); }); req.response().setChunked(true).write(Buffer.buffer("some-data")); }); startServer(); client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", onSuccess(resp -> { resp.exceptionHandler(this::fail); resp.request().reset(10); assertIllegalStateException(() -> resp.request().write(Buffer.buffer())); assertIllegalStateException(resp.request()::end); })).end(Buffer.buffer("hello")); await(); }
private void checkHttpServerResponse(HttpServerResponse resp) { Buffer buff = Buffer.buffer(); assertIllegalStateException(() -> resp.drainHandler(noOpHandler())); assertIllegalStateException(() -> resp.end()); assertIllegalStateException(() -> resp.end("foo")); assertIllegalStateException(() -> resp.end(buff)); assertIllegalStateException(() -> resp.end("foo", "UTF-8")); assertIllegalStateException(() -> resp.exceptionHandler(noOpHandler())); assertIllegalStateException(() -> resp.setChunked(false)); assertIllegalStateException(() -> resp.setWriteQueueMaxSize(123)); assertIllegalStateException(() -> resp.write(buff)); assertIllegalStateException(() -> resp.write("foo")); assertIllegalStateException(() -> resp.write("foo", "UTF-8")); assertIllegalStateException(() -> resp.write(buff)); assertIllegalStateException(() -> resp.writeQueueFull()); assertIllegalStateException(() -> resp.sendFile("asokdasokd")); }
@Test public void testResetActivePushPromise() throws Exception { server.requestHandler(req -> { req.response().push(HttpMethod.GET, "/wibble", ar -> { assertTrue(ar.succeeded()); HttpServerResponse response = ar.result(); response.exceptionHandler(err -> { if (err instanceof StreamResetException) { assertEquals(Http2Error.CANCEL.code(), ((StreamResetException) err).getCode()); testComplete(); } }); response.setChunked(true).write("some_content"); }); }); startServer(); HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", onFailure(resp -> { })); req.pushHandler(pushedReq -> { pushedReq.handler(onSuccess(pushedResp -> { pushedResp.handler(buff -> { pushedReq.reset(Http2Error.CANCEL.code()); }); })); }); req.end(); await(); }
}); HttpServerResponse resp = req.response(); resp.exceptionHandler(err -> { assertFalse(Thread.holdsLock(conn)); complete();
public VertxHttpResponse(final HttpServerResponse response, final ResteasyProviderFactory providerFactory, final HttpMethod method) { outputHeaders = new MultivaluedMapImpl<String, Object>(); this.method = method; os = (method == null || !method.equals(HttpMethod.HEAD)) ? new ChunkOutputStream(this, 1000) : null; this.response = response; this.providerFactory = providerFactory; response.exceptionHandler(t -> vertxException = t); response.closeHandler(v -> vertxException = new IOException("Connection closed")); }
@Override public HttpServerResponse exceptionHandler(Handler<Throwable> handler) { wrapped.exceptionHandler(handler); return this; }
@Test public void testResetPushPromiseNoHandler() throws Exception { server.requestHandler(req -> { req.response().push(HttpMethod.GET, "/wibble", ar -> { assertTrue(ar.succeeded()); HttpServerResponse resp = ar.result(); resp.setChunked(true).write("content"); AtomicLong reset = new AtomicLong(); resp.exceptionHandler(err -> { if (err instanceof StreamResetException) { reset.set(((StreamResetException)err).getCode()); } }); resp.closeHandler(v -> { assertEquals(Http2Error.CANCEL.code(), reset.get()); testComplete(); }); }); }); startServer(); HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> { }); req.end(); await(); }
req.response().exceptionHandler(err -> { if (err instanceof StreamResetException) { reset.set(((StreamResetException) err).getCode());
resp.exceptionHandler(err -> { assertEquals(0, reqExceptionHandlerCount.get()); assertEquals(1, respExceptionHandlerCount.incrementAndGet());
@Test public void testNoExceptionHandlerCalledWhenResponseEnded() throws Exception { server.requestHandler(req -> { HttpServerResponse resp = req.response(); req.exceptionHandler(this::fail); resp.exceptionHandler(err -> { err.printStackTrace(); }); resp.end(); }).listen(DEFAULT_HTTP_PORT, onSuccess(s -> { client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> { resp.endHandler(v -> { vertx.setTimer(100, tid -> testComplete()); }); resp.exceptionHandler(t -> { fail("Should not be called"); }); }).exceptionHandler(t -> { fail("Should not be called"); }).end(); })); await(); }
@Test public void testClientResetServerStreamDuringResponse() throws Exception { server.requestHandler(req -> { req.exceptionHandler(err -> { assertEquals(err.getClass(), StreamResetException.class); }); AtomicLong reset = new AtomicLong(); req.response().exceptionHandler(err -> { if (err instanceof StreamResetException) { reset.set(((StreamResetException) err).getCode()); } }); req.response().closeHandler(v -> { assertEquals(10L, reset.get()); testComplete(); }); req.response().setChunked(true).write(Buffer.buffer("some-data")); }); startServer(); HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath"); req.handler(resp -> { resp.exceptionHandler(this::fail); req.reset(10); assertIllegalStateException(() -> req.write(Buffer.buffer())); assertIllegalStateException(req::end); }).end(Buffer.buffer("hello")); await(); }
private void checkHttpServerResponse(HttpServerResponse resp) { Buffer buff = Buffer.buffer(); assertIllegalStateException(() -> resp.drainHandler(noOpHandler())); assertIllegalStateException(() -> resp.end()); assertIllegalStateException(() -> resp.end("foo")); assertIllegalStateException(() -> resp.end(buff)); assertIllegalStateException(() -> resp.end("foo", "UTF-8")); assertIllegalStateException(() -> resp.exceptionHandler(noOpHandler())); assertIllegalStateException(() -> resp.setChunked(false)); assertIllegalStateException(() -> resp.setWriteQueueMaxSize(123)); assertIllegalStateException(() -> resp.write(buff)); assertIllegalStateException(() -> resp.write("foo")); assertIllegalStateException(() -> resp.write("foo", "UTF-8")); assertIllegalStateException(() -> resp.write(buff)); assertIllegalStateException(() -> resp.writeQueueFull()); assertIllegalStateException(() -> resp.sendFile("asokdasokd")); }
@Test public void testResetActivePushPromise() throws Exception { server.requestHandler(req -> { req.response().push(HttpMethod.GET, "/wibble", ar -> { assertTrue(ar.succeeded()); HttpServerResponse response = ar.result(); response.exceptionHandler(err -> { if (err instanceof StreamResetException) { assertEquals(Http2Error.CANCEL.code(), ((StreamResetException) err).getCode()); testComplete(); } }); response.setChunked(true).write("some_content"); }); }); startServer(); HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> { fail(); }); req.pushHandler(pushedReq -> { pushedReq.handler(pushedResp -> { pushedResp.handler(buff -> { pushedReq.reset(Http2Error.CANCEL.code()); }); }); }); req.end(); await(); }
}); HttpServerResponse resp = req.response(); resp.exceptionHandler(err -> { assertFalse(Thread.holdsLock(conn)); complete();
try { resp.endHandler(null); resp.exceptionHandler(null); resp.drainHandler(null); resp.bodyEndHandler(null);
public VertxHttpResponse(HttpServerResponse response, ResteasyProviderFactory providerFactory, HttpMethod method) { outputHeaders = new MultivaluedMapImpl<String, Object>(); this.method = method; os = (method == null || !method.equals(HttpMethod.HEAD)) ? new ChunkOutputStream(this, 1000) : null; this.response = response; this.providerFactory = providerFactory; response.exceptionHandler(t -> vertxException = t); response.closeHandler(v -> vertxException = new IOException("Connection closed")); }