@Override public void handle(Void aVoid) { // Resume the vert.x request if we haven't already read the body if (inputStream == null) { vertxRequest.resume(); } applicationHandlerDelegate.handle(jerseyRequest); } });
/** * Get the Jersey server-side application handler associated with the container. * * @return Jersey server-side application handler associated with the container. */ @Override public ApplicationHandler getApplicationHandler() { return getApplicationHandlerDelegate().getApplicationHandler(); }
/** * Releases resources */ @Override public void close() { // Destroy the jersey service locator if (jerseyHandler != null && jerseyHandler.getDelegate() != null) { ServiceLocatorFactory.getInstance().destroy(jerseyHandler.getDelegate().getServiceLocator()); jerseyHandler = null; } if (server != null) { server.close(); server = null; } } }
@Before public void setUp() { when(container.getOptions()).thenReturn(options); when(container.getVertx()).thenReturn(vertx); when(container.getApplicationHandlerDelegate()).thenReturn(applicationHandlerDelegate); when(applicationHandlerDelegate.getServiceLocator()).thenReturn(serviceLocator); when(options.getMaxBodySize()).thenReturn(1024); when(options.getBaseUri()).thenReturn(URI.create("/test")); when(request.absoluteURI()).thenReturn(URI.create("http://test.englishtown.com/test").toString()); when(request.response()).thenReturn(response); when(request.headers()).thenReturn(headers); JsonArray resources = new JsonArray().add("com.englishtown.vertx.jersey.resources"); config.put(DefaultJerseyOptions.CONFIG_RESOURCES, resources); ContainerResponseWriterProvider provider = mock(ContainerResponseWriterProvider.class); when(provider.get(any(HttpServerRequest.class), any(ContainerRequest.class))).thenReturn(mock(ContainerResponseWriter.class)); when(serviceLocator.<Ref<Vertx>>getService((new TypeLiteral<Ref<Vertx>>() { }).getType())).thenReturn(vertxRef); when(serviceLocator.<Ref<Container>>getService((new TypeLiteral<Ref<Container>>() { }).getType())).thenReturn(containerRef); jerseyHandler = new DefaultJerseyHandler(() -> container, provider, requestProcessors); }
@Test public void testHandle() throws Exception { when(request.method()).thenReturn(HttpMethod.GET); when(request.headers()).thenReturn(mock(MultiMap.class)); jerseyHandler.handle(request); verify(applicationHandlerDelegate).handle(any(ContainerRequest.class)); }
/** * Shutdown jersey server and release resources */ @Override public void stop() { // Run jersey shutdown lifecycle if (container != null) { container.stop(); container = null; } // Destroy the jersey service locator if (jerseyHandler != null && jerseyHandler.getDelegate() != null) { ServiceLocatorFactory.getInstance().destroy(jerseyHandler.getDelegate().getServiceLocator()); jerseyHandler = null; } if (server != null) { server.close(); server = null; } } }
/** * Get the Jersey server-side application handler associated with the container. * * @return Jersey server-side application handler associated with the container. */ @Override public ApplicationHandler getApplicationHandler() { return getApplicationHandlerDelegate().getApplicationHandler(); }
@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)); }
/** * Shutdown jersey server and release resources */ @Override public void stop() { // Run jersey shutdown lifecycle if (container != null) { container.stop(); container = null; } // Destroy the jersey service locator if (jerseyHandler != null && jerseyHandler.getDelegate() != null) { ServiceLocatorFactory.getInstance().destroy(jerseyHandler.getDelegate().getServiceLocator()); jerseyHandler = null; } if (server != null) { server.close(); server = null; } } }
@Test public void testHandle_JSON_POST() throws Exception { DefaultHttpHeaders headers = new DefaultHttpHeaders(); headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); when(request.method()).thenReturn(HttpMethod.POST); when(request.headers()).thenReturn(new HeadersAdaptor(headers)); jerseyHandler.handle(request); verify(request).handler(dataHandlerCaptor.capture()); verify(request).endHandler(endHandlerCaptor.capture()); Buffer data = Buffer.buffer("{}"); dataHandlerCaptor.getValue().handle(data); endHandlerCaptor.getValue().handle(null); verify(applicationHandlerDelegate).handle(any(ContainerRequest.class)); }
applicationHandlerDelegate.handle(jerseyRequest);