/** * Stops the container */ @Override public void stop() { if (!started) { return; } getApplicationHandler().onShutdown(this); applicationHandlerDelegate = null; started = false; }
/** * 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(); }
/** * Reload the hosted Jersey application using the current {@link ResourceConfig * configuration}. */ @Override public void reload() { reload(getConfiguration()); }
@Test public void testStart() throws Exception { packages.add("com.englishtown.vertx.jersey.resources"); container = new DefaultVertxContainer(vertx, options, locator, null); container.start(); assertEquals(options, container.getOptions()); assertNotNull(container.getConfiguration()); assertNotNull(container.getApplicationHandler()); assertNotNull(container.getApplicationHandlerDelegate()); // Can't mock applicationHandler so can't verify onStartup() was called }
@Test public void testStop() throws Exception { packages.add("com.englishtown.vertx.jersey.resources"); container = new DefaultVertxContainer(vertx, options, locator, null); container.start(); container.stop(); // Can't mock applicationHandler so can't verify onShutdown() was called }
@Test public void testResourceConfigModifier() throws Exception { boolean[] b = {false}; ApplicationConfigurator configurator = rc -> { b[0] = true; return rc; }; packages.add("com.englishtown.vertx.jersey.resources"); container = new DefaultVertxContainer(vertx, options, locator, configurator); container.start(); assertTrue(b[0]); }
@Override public ApplicationHandlerDelegate getApplicationHandlerDelegate() { if (applicationHandlerDelegate == null) { ResourceConfig rc = createConfiguration(); ApplicationHandler applicationHandler = new ApplicationHandler(rc, null, locator); applicationHandlerDelegate = new DefaultApplicationHandlerDelegate(applicationHandler); } return applicationHandlerDelegate; }
@Override protected WhenJerseyServer getWhenJerseyServer() { ContainerResponseWriterProvider provider = new VertxResponseWriterProvider( vertx, new ArrayList<>(), new ArrayList<>()); DefaultJerseyOptions options = new DefaultJerseyOptions(vertx); VertxContainer container = new DefaultVertxContainer(vertx, options, null, null); JerseyHandler handler = new DefaultJerseyHandler(() -> container, provider, new ArrayList<>()); JerseyServer server = new DefaultJerseyServer(handler, container, () -> options); When when = WhenFactory.createSync(); return new DefaultWhenJerseyServer(vertx, () -> server, when); }
@Test public void testInit_Missing_Resources() throws Exception { try { container = new DefaultVertxContainer(vertx, options, locator, null); container.start(); fail(); } catch (IllegalStateException e) { assertEquals("At least one resource package name or component must be specified", e.getMessage()); } }
@Override public ApplicationHandlerDelegate getApplicationHandlerDelegate() { if (applicationHandlerDelegate == null) { ResourceConfig rc = createConfiguration(); ApplicationHandler applicationHandler = new ApplicationHandler(rc, null, locator); applicationHandlerDelegate = new DefaultApplicationHandlerDelegate(applicationHandler); } return applicationHandlerDelegate; }
/** * Return an immutable representation of the current {@link ResourceConfig * configuration}. * * @return current configuration of the hosted Jersey application. */ @Override public ResourceConfig getConfiguration() { ApplicationHandler handler = getApplicationHandler(); return handler == null ? null : handler.getConfiguration(); }
/** * Reload the hosted Jersey application using the current {@link ResourceConfig * configuration}. */ @Override public void reload() { reload(getConfiguration()); }
/** * 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(); }
/** * Stops the container */ @Override public void stop() { if (!started) { return; } getApplicationHandler().onShutdown(this); applicationHandlerDelegate = null; started = false; }
/** * Return an immutable representation of the current {@link ResourceConfig * configuration}. * * @return current configuration of the hosted Jersey application. */ @Override public ResourceConfig getConfiguration() { ApplicationHandler handler = getApplicationHandler(); return handler == null ? null : handler.getConfiguration(); }
/** * Starts the container */ @Override public void start() { if (started) { return; } ApplicationHandler handler = getApplicationHandler(); if (handler == null) { throw new IllegalStateException("ApplicationHandler cannot be null"); } handler.onStartup(this); started = true; }
/** * Starts the container */ @Override public void start() { if (started) { return; } ApplicationHandler handler = getApplicationHandler(); if (handler == null) { throw new IllegalStateException("ApplicationHandler cannot be null"); } handler.onStartup(this); started = true; }
/** * Reload the hosted Jersey application using a new {@link ResourceConfig * configuration}. * * @param configuration new configuration used for the reload. */ @Override public void reload(ResourceConfig configuration) { ApplicationHandler applicationHandler = new ApplicationHandler(configuration, null, locator); applicationHandlerDelegate = new DefaultApplicationHandlerDelegate(applicationHandler); getApplicationHandler().onReload(this); applicationHandler.onStartup(this); }
/** * Reload the hosted Jersey application using a new {@link ResourceConfig * configuration}. * * @param configuration new configuration used for the reload. */ @Override public void reload(ResourceConfig configuration) { ApplicationHandler applicationHandler = new ApplicationHandler(configuration, null, locator); applicationHandlerDelegate = new DefaultApplicationHandlerDelegate(applicationHandler); getApplicationHandler().onReload(this); applicationHandler.onStartup(this); }