@Override public void handle(RoutingContext context) { TracingHandler tracingHandler = context.get(TracingHandler.class.getName()); if (tracingHandler != null) { // then we already have a span if (!context.failed()) { // re-routed, so re-attach the end handler context.addHeadersEndHandler(tracingHandler); } context.next(); return; } Span span = serverHandler.handleReceive(extractor, context.request()); TracingHandler handler = new TracingHandler(context, span); context.put(TracingHandler.class.getName(), handler); context.addHeadersEndHandler(handler); try (Tracer.SpanInScope ws = tracer.withSpanInScope(span)) { context.next(); } }
@Override public boolean failed() { return decoratedContext.failed(); }
@Override public boolean failed() { return inner.failed(); }
/** * @return true if the context is being routed to failure handlers. */ public boolean failed() { boolean ret = delegate.failed(); return ret; }
/** * @return true if the context is being routed to failure handlers. */ public boolean failed() { boolean ret = delegate.failed(); return ret; }
@Override public boolean failed() { return decoratedContext.failed(); }
@Override public boolean failed() { return inner.failed(); }
@Override public boolean failed() { return rc.failed(); }
@Override public boolean failed() { return this.inner.failed(); }
@Override public boolean failed() { return delegate.failed(); }
@Override public boolean failed() { return delegate.failed(); }
@Override public void handle(final RoutingContext event) { if (event.failed()) { event.failure().printStackTrace(); } } }
@Override public void handle(final RoutingContext event) { if (event.failed()) { event.failure().printStackTrace(); } } }
private boolean oauth2Error(RoutingContext context) { return context.failed() && context.failure() instanceof OAuth2Exception; } }
private boolean oauth2Error(RoutingContext context) { return context.failed() && context.failure() instanceof OAuth2Exception; } }
/** * Verifies that the handler does not try to process a failed * context if the response is already ended. */ @Test public void testHandlerDetectsEndedResponse() { final HttpServerResponse response = mock(HttpServerResponse.class); when(response.ended()).thenReturn(true); final RoutingContext ctx = mock(RoutingContext.class); when(ctx.response()).thenReturn(response); when(ctx.failed()).thenReturn(true); final DefaultFailureHandler handler = new DefaultFailureHandler(); handler.handle(ctx); verify(response, never()).setStatusCode(anyInt()); verify(response, never()).write(any(Buffer.class)); verify(response, never()).end(); }
@Override public void handle(final RoutingContext event) { if (event.failed()) { final Throwable ex = event.failure(); if (ex instanceof WebException) { final WebException error = (WebException) ex; Answer.reply(event, Envelop.failure(error)); } else { // Other exception found event.fail(ex); } } else { // Success, do not throw, continue to request event.next(); } } }
/** * Verifies that the handler sets an empty response body for * a context that has failed with an exception that does not contain * a detail message. */ @Test public void testHandlerSucceedsForExceptionsWithoutMessage() { final HttpServerRequest request = mock(HttpServerRequest.class, Mockito.RETURNS_MOCKS); final HttpServerResponse response = mock(HttpServerResponse.class); when(response.ended()).thenReturn(false); final RoutingContext ctx = mock(RoutingContext.class); when(ctx.request()).thenReturn(request); when(ctx.response()).thenReturn(response); when(ctx.failed()).thenReturn(true); when(ctx.failure()).thenReturn(new IllegalStateException()); // no detail message final DefaultFailureHandler handler = new DefaultFailureHandler(); handler.handle(ctx); verify(response).setStatusCode(HttpURLConnection.HTTP_INTERNAL_ERROR); verify(response, never()).write(any(Buffer.class)); verify(response).end(); }
@Override public void handle(final RoutingContext event) { if (event.failed()) { final Throwable ex = event.failure(); if (ex instanceof WebException) { final WebException error = (WebException) ex; Answer.reply(event, Envelop.failure(error)); } else { // Other exception found event.fail(ex); } } else { // Success, do not throw, continue to request event.next(); } } }
/** * Verifies that the handler writes the status code and the status message to the response in case of failure and * ctx.failure() returns null. */ @Test public void testHandlerWithFailedContextAndEmptyFailure() { final RoutingContext ctx = mock(RoutingContext.class); final HttpServerRequest request = mock(HttpServerRequest.class, Mockito.RETURNS_MOCKS); final HttpServerResponse response = mock(HttpServerResponse.class, Mockito.RETURNS_MOCKS); when(response.ended()).thenReturn(false); when(ctx.request()).thenReturn(request); when(ctx.response()).thenReturn(response); when(ctx.failed()).thenReturn(true); when(ctx.failure()).thenReturn(null); when(ctx.statusCode()).thenReturn(HttpURLConnection.HTTP_UNAUTHORIZED); final DefaultFailureHandler handler = new DefaultFailureHandler(); handler.handle(ctx); verify(response).setStatusCode(HttpURLConnection.HTTP_UNAUTHORIZED); verify(response, never()).write(any(Buffer.class)); verify(response).end(); } }