/** * Gets the {@link HttpServerOptions} used to set up the vert.x http server * * @return */ @Override public HttpServerOptions getServerOptions() { if (serverOptions == null) { serverOptions = createServerOptions(); } return serverOptions; }
@Inject public DefaultJerseyOptions(Vertx vertx) { this(getConfig(vertx)); }
protected HttpServerOptions createServerOptions() { // Setup the http server options HttpServerOptions serverOptions = new HttpServerOptions() .setHost(getHost()) .setPort(getPort()) .setAcceptBacklog(getAcceptBacklog()) // Performance tweak .setCompressionSupported(getCompressionSupported()); // Enable https if (getSSL()) { serverOptions.setSsl(true); } if (getKeyStoreOptions() != null) { serverOptions.setKeyStoreOptions(getKeyStoreOptions()); } Integer receiveBufferSize = getReceiveBufferSize(); if (receiveBufferSize != null && receiveBufferSize > 0) { // TODO: This doesn't seem to actually affect buffer size for dataHandler. Is this being used correctly or is it a Vertx bug? serverOptions.setReceiveBufferSize(receiveBufferSize); } return serverOptions; }
@Test public void testGetInstances() throws Exception { config.put(DefaultJerseyOptions.CONFIG_INSTANCES, new JsonArray().add(MyObj.class.getName())); config.put(DefaultJerseyOptions.CONFIG_BINDERS, new JsonArray().add(MyBinder.class.getName())); Set<Object> instances = options.getInstances(); assertNotNull(instances); assertEquals(2, instances.size()); List<Object> list = new ArrayList<>(instances); assertThat(list.get(0), instanceOf(MyObj.class)); assertThat(list.get(1), instanceOf(MyBinder.class)); }
@Test(expected = RuntimeException.class) public void testGetComponents_Fail() throws Exception { config.put(DefaultJerseyOptions.CONFIG_COMPONENTS, new JsonArray().add(MyObj.class.getName() + ".invalid")); options.getComponents(); fail(); }
@Before public void setUp() throws Exception { when(vertx.getOrCreateContext()).thenReturn(context); when(context.config()).thenReturn(config); options = new DefaultJerseyOptions(vertx); }
@Test public void testGetBaseUri() throws Exception { URI uri; String expected = "/"; uri = options.getBaseUri(); assertEquals(expected, uri.getPath()); expected = "test/base/path"; config.put(DefaultJerseyOptions.CONFIG_BASE_PATH, expected); expected += "/"; uri = options.getBaseUri(); assertEquals(expected, uri.getPath()); }
protected HttpServerOptions createServerOptions() { // Setup the http server options HttpServerOptions serverOptions = new HttpServerOptions() .setHost(getHost()) .setPort(getPort()) .setAcceptBacklog(getAcceptBacklog()) // Performance tweak .setCompressionSupported(getCompressionSupported()); // Enable https if (getSSL()) { serverOptions.setSsl(true); } if (getKeyStoreOptions() != null) { serverOptions.setKeyStoreOptions(getKeyStoreOptions()); } Integer receiveBufferSize = getReceiveBufferSize(); if (receiveBufferSize != null && receiveBufferSize > 0) { // TODO: This doesn't seem to actually affect buffer size for dataHandler. Is this being used correctly or is it a Vertx bug? serverOptions.setReceiveBufferSize(receiveBufferSize); } return serverOptions; }
@Test(expected = RuntimeException.class) public void testGetInstances_Fail() throws Exception { config.put(DefaultJerseyOptions.CONFIG_INSTANCES, new JsonArray().add(MyObj.class.getName() + ".invalid")); options.getInstances(); fail(); }
@Test public void testGetComponents() throws Exception { config.put(DefaultJerseyOptions.CONFIG_COMPONENTS, new JsonArray().add(MyObj.class.getName())); config.put(DefaultJerseyOptions.CONFIG_FEATURES, new JsonArray().add(MyBinder.class.getName())); Set<Class<?>> instances = options.getComponents(); assertNotNull(instances); assertEquals(2, instances.size()); assertTrue(instances.contains(MyObj.class)); assertTrue(instances.contains(MyBinder.class)); }
@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); }
/** * Gets the {@link HttpServerOptions} used to set up the vert.x http server * * @return */ @Override public HttpServerOptions getServerOptions() { if (serverOptions == null) { serverOptions = createServerOptions(); } return serverOptions; }
@Inject public DefaultJerseyOptions(Vertx vertx) { this(getConfig(vertx)); }