protected void callVertxRequestProcessor( int index, final HttpServerRequest vertxRequest, final ContainerRequest jerseyRequest, final Handler<Void> done ) { if (index >= requestProcessors.size()) { done.handle(null); } VertxRequestProcessor processor = requestProcessors.get(index); final int next = index + 1; processor.process(vertxRequest, jerseyRequest, new Handler<Void>() { @Override public void handle(Void aVoid) { if (next >= requestProcessors.size()) { done.handle(null); } else { callVertxRequestProcessor(next, vertxRequest, jerseyRequest, done); } } }); }
protected void callVertxRequestProcessor( int index, final HttpServerRequest vertxRequest, final ContainerRequest jerseyRequest, final Handler<Void> done ) { if (index >= requestProcessors.size()) { done.handle(null); } VertxRequestProcessor processor = requestProcessors.get(index); final int next = index + 1; try { processor.process(vertxRequest, jerseyRequest, aVoid -> { if (next >= requestProcessors.size()) { done.handle(null); } else { callVertxRequestProcessor(next, vertxRequest, jerseyRequest, done); } }); } catch (Throwable t) { logger.error("VertxRequestProcessor " + processor.getClass().getSimpleName() + " threw exception: " + t.getMessage(), t); vertxRequest.response() .setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code()) .end(); } }
protected void callVertxRequestProcessor( int index, final HttpServerRequest vertxRequest, final ContainerRequest jerseyRequest, final Handler<Void> done ) { if (index >= requestProcessors.size()) { done.handle(null); } VertxRequestProcessor processor = requestProcessors.get(index); final int next = index + 1; try { processor.process(vertxRequest, jerseyRequest, aVoid -> { if (next >= requestProcessors.size()) { done.handle(null); } else { callVertxRequestProcessor(next, vertxRequest, jerseyRequest, done); } }); } catch (Throwable t) { logger.error("VertxRequestProcessor " + processor.getClass().getSimpleName() + " threw exception: " + t.getMessage(), t); vertxRequest.response() .setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code()) .end(); } }
@Test public void testHandle_RequestProcessors() throws Exception { when(request.headers()).thenReturn(mock(MultiMap.class)); when(request.method()).thenReturn(HttpMethod.GET); InputStream inputStream = null; VertxRequestProcessor rp1 = mock(VertxRequestProcessor.class); VertxRequestProcessor rp2 = mock(VertxRequestProcessor.class); requestProcessors.add(rp1); requestProcessors.add(rp2); jerseyHandler.handle(request, inputStream); verify(rp1).process(any(HttpServerRequest.class), any(ContainerRequest.class), endHandlerCaptor.capture()); endHandlerCaptor.getValue().handle(null); verify(rp2).process(any(HttpServerRequest.class), any(ContainerRequest.class), endHandlerCaptor.capture()); endHandlerCaptor.getValue().handle(null); verify(applicationHandlerDelegate).handle(any(ContainerRequest.class)); }
@Test public void testHandle_RequestProcessors_Throw() throws Exception { when(request.headers()).thenReturn(mock(MultiMap.class)); when(request.method()).thenReturn(HttpMethod.GET); InputStream inputStream = null; VertxRequestProcessor rp1 = mock(VertxRequestProcessor.class); VertxRequestProcessor rp2 = mock(VertxRequestProcessor.class); when(response.setStatusCode(anyInt())).thenReturn(response); doThrow(RuntimeException.class).when(rp2).process(any(), any(), any()); requestProcessors.add(rp1); requestProcessors.add(rp2); jerseyHandler.handle(request, inputStream); verify(rp1).process(any(), any(), endHandlerCaptor.capture()); endHandlerCaptor.getValue().handle(null); verify(rp2).process(any(), any(), any()); verify(response).setStatusCode(eq(HttpResponseStatus.INTERNAL_SERVER_ERROR.code())); verify(response).end(); }