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 end() { // End the vertx response vertxRequest.response().end(); // Call any post response processors if (!postResponseProcessors.isEmpty()) { for (VertxPostResponseProcessor processor : postResponseProcessors) { processor.process(vertxRequest.response(), jerseyResponse); } } }
/** * Implement to provide binding definitions using the exposed binding * methods. */ @Override protected void configure() { // Bind the vertx and container instances bind(vertx).to(Vertx.class); bind(container).to(Container.class); // Request and read stream bindFactory(VertxRequestReferencingFactory.class).to(HttpServerRequest.class).in(PerLookup.class); bindFactory(VertxRequestReferencingFactory.class).to(new TypeLiteral<ReadStream<HttpServerRequest>>() { }).in(PerLookup.class); bindFactory(ReferencingFactory.<HttpServerRequest>referenceFactory()).to(new TypeLiteral<Ref<HttpServerRequest>>() { }).in(RequestScoped.class); // Response bindFactory(VertxResponseReferencingFactory.class).to(HttpServerResponse.class).in(PerLookup.class); bindFactory(ReferencingFactory.<HttpServerResponse>referenceFactory()).to(new TypeLiteral<Ref<HttpServerResponse>>() { }).in(RequestScoped.class); } }
@Test public void testConfigure() throws Exception { InternalVertxJerseyBinder binder = new InternalVertxJerseyBinder(mock(Vertx.class)); DynamicConfiguration dynamicConfiguration = mock(DynamicConfiguration.class); binder.bind(dynamicConfiguration); }
rc.register(new InternalVertxJerseyBinder(vertx));
/** * Implement to provide binding definitions using the exposed binding * methods. */ @Override protected void configure() { // Bind the vertx and container instances bind(vertx).to(Vertx.class); // Request and read stream bindFactory(VertxRequestReferencingFactory.class).to(HttpServerRequest.class).in(PerLookup.class); bindFactory(VertxRequestReferencingFactory.class).to(new TypeLiteral<ReadStream<HttpServerRequest>>() { }).in(PerLookup.class); bindFactory(ReferencingFactory.<HttpServerRequest>referenceFactory()).to(new TypeLiteral<Ref<HttpServerRequest>>() { }).in(RequestScoped.class); // Response bindFactory(VertxResponseReferencingFactory.class).to(HttpServerResponse.class).in(PerLookup.class); bindFactory(ReferencingFactory.<HttpServerResponse>referenceFactory()).to(new TypeLiteral<Ref<HttpServerResponse>>() { }).in(RequestScoped.class); } }
protected void end() { // End the vertx response vertxRequest.response().end(); // Call any post response processors if (!postResponseProcessors.isEmpty()) { for (VertxPostResponseProcessor processor : postResponseProcessors) { processor.process(vertxRequest.response(), jerseyResponse); } } }
@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)); }
rc.register(new InternalVertxJerseyBinder(vertx));
/** * Implement to provide binding definitions using the exposed binding * methods. */ @Override protected void configure() { // Bind the vertx and container instances bind(vertx).to(Vertx.class); // Request and read stream bindFactory(VertxRequestReferencingFactory.class).to(HttpServerRequest.class).in(PerLookup.class); bindFactory(VertxRequestReferencingFactory.class).to(new TypeLiteral<ReadStream<HttpServerRequest>>() { }).in(PerLookup.class); bindFactory(ReferencingFactory.<HttpServerRequest>referenceFactory()).to(new TypeLiteral<Ref<HttpServerRequest>>() { }).in(RequestScoped.class); // Response bindFactory(VertxResponseReferencingFactory.class).to(HttpServerResponse.class).in(PerLookup.class); bindFactory(ReferencingFactory.<HttpServerResponse>referenceFactory()).to(new TypeLiteral<Ref<HttpServerResponse>>() { }).in(RequestScoped.class); } }
protected void end() { // End the vertx response vertxRequest.response().end(); // Call any post response processors if (!postResponseProcessors.isEmpty()) { for (VertxPostResponseProcessor processor : postResponseProcessors) { processor.process(vertxRequest.response(), jerseyResponse); } } }
/** * Creates a vert.x {@link HttpServer} with a jersey handler * * @param doneHandler the optional callback for when initialization has completed */ default void start(@Nullable Handler<AsyncResult<HttpServer>> doneHandler) { start(null, null, doneHandler); }
@Test public void testCommit() throws Exception { VertxPostResponseProcessor processor1 = mock(VertxPostResponseProcessor.class); VertxPostResponseProcessor processor2 = mock(VertxPostResponseProcessor.class); postResponseProcessors.add(processor1); postResponseProcessors.add(processor2); writer.commit(); verify(response).end(); verify(processor1).process(eq(response), any(ContainerResponse.class)); verify(processor2).process(eq(response), any(ContainerResponse.class)); }
/** * Creates a vert.x {@link HttpServer} with a jersey handler * * @param doneHandler the optional callback for when initialization has completed */ default void start(@Nullable Handler<AsyncResult<HttpServer>> doneHandler) { start(null, null, doneHandler); }
/** * Returns a promise for asynchronously creating a {@link JerseyServer} * * @param options * @param jerseyOptions * @return a promise for the server */ @Override public Promise<JerseyServer> createServer(@Nullable JerseyServerOptions options, @Nullable JerseyOptions jerseyOptions) { final Deferred<JerseyServer> d = when.defer(); try { JerseyServer jerseyServer = jerseyServerProvider.get(); jerseyServer.start(options, jerseyOptions, result -> { if (result.succeeded()) { d.resolve(jerseyServer); } else { d.reject(result.cause()); } }); } catch (RuntimeException e) { d.reject(e); } return d.getPromise(); }
/** * Returns a promise for asynchronously creating a {@link JerseyServer} * * @param options * @param jerseyOptions * @return a promise for the server */ @Override public Promise<JerseyServer> createServer(@Nullable JerseyServerOptions options, @Nullable JerseyOptions jerseyOptions) { final Deferred<JerseyServer> d = when.defer(); try { JerseyServer jerseyServer = jerseyServerProvider.get(); jerseyServer.start(options, jerseyOptions, result -> { if (result.succeeded()) { d.resolve(jerseyServer); } else { d.reject(result.cause()); } }); } catch (RuntimeException e) { d.reject(e); } return d.getPromise(); }