Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibly use jersey WebServer with SeBootstrap.Configurator #5075

Merged
merged 1 commit into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018 Markus KARG. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -17,6 +17,7 @@

package org.glassfish.jersey.grizzly2.httpserver;

import jakarta.ws.rs.SeBootstrap;
import jakarta.ws.rs.core.Application;

import org.glassfish.grizzly.http.server.HttpServer;
Expand All @@ -33,18 +34,18 @@
public final class GrizzlyHttpServerProvider implements WebServerProvider {

@Override
public final <T extends WebServer> T createServer(final Class<T> type, final Application application,
final JerseySeBootstrapConfiguration configuration) {
return GrizzlyHttpServer.class == type || WebServer.class == type
? type.cast(new GrizzlyHttpServer(application, configuration))
public <T extends WebServer> T createServer(final Class<T> type, final Application application,
final SeBootstrap.Configuration configuration) {
return WebServerProvider.isSupportedWebServer(GrizzlyHttpServer.class, type, configuration)
? type.cast(new GrizzlyHttpServer(application, JerseySeBootstrapConfiguration.from(configuration)))
: null;
}

@Override
public <T extends WebServer> T createServer(Class<T> type, Class<? extends Application> applicationClass,
JerseySeBootstrapConfiguration configuration) {
return GrizzlyHttpServer.class == type || WebServer.class == type
? type.cast(new GrizzlyHttpServer(applicationClass, configuration))
SeBootstrap.Configuration configuration) {
return WebServerProvider.isSupportedWebServer(GrizzlyHttpServer.class, type, configuration)
? type.cast(new GrizzlyHttpServer(applicationClass, JerseySeBootstrapConfiguration.from(configuration)))
: null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018 Markus KARG. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -17,7 +17,6 @@

package org.glassfish.jersey.grizzly2.httpserver;

import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
Expand Down Expand Up @@ -45,7 +44,6 @@

import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.internal.util.PropertiesHelper;
import org.glassfish.jersey.server.JerseySeBootstrapConfiguration;
import org.glassfish.jersey.server.ServerProperties;
import org.glassfish.jersey.server.spi.Container;
import org.glassfish.jersey.server.spi.WebServer;
Expand Down Expand Up @@ -82,10 +80,9 @@ private void shouldProvideServer(final Object application, final Resource resour
final SeBootstrap.Configuration configuration = configuration(getPort());

// when
final JerseySeBootstrapConfiguration jerseySeConfig = JerseySeBootstrapConfiguration.from(configuration);
final WebServer webServer = Application.class.isInstance(application)
? webServerProvider.createServer(WebServer.class, (Application) application, jerseySeConfig)
: webServerProvider.createServer(WebServer.class, (Class<Application>) application, jerseySeConfig);
? webServerProvider.createServer(WebServer.class, (Application) application, configuration)
: webServerProvider.createServer(WebServer.class, (Class<Application>) application, configuration);
final Object nativeHandle = webServer.unwrap(Object.class);
final CompletionStage<?> start = webServer.start();
final Object startResult = start.toCompletableFuture().get();
Expand Down Expand Up @@ -157,8 +154,7 @@ public void shouldScanFreePort() {
final SeBootstrap.Configuration configuration = configuration(SeBootstrap.Configuration.FREE_PORT);

// when
final JerseySeBootstrapConfiguration jerseySeConfig = JerseySeBootstrapConfiguration.from(configuration);
final WebServer webServer = webServerProvider.createServer(WebServer.class, application, jerseySeConfig);
final WebServer webServer = webServerProvider.createServer(WebServer.class, application, configuration);

// then
assertThat(webServer.port(), is(greaterThan(0)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018 Markus KARG. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -17,6 +17,7 @@

package org.glassfish.jersey.jdkhttp;

import jakarta.ws.rs.SeBootstrap;
import jakarta.ws.rs.core.Application;

import org.glassfish.jersey.server.JerseySeBootstrapConfiguration;
Expand All @@ -35,17 +36,17 @@ public final class JdkHttpServerProvider implements WebServerProvider {

@Override
public <T extends WebServer> T createServer(final Class<T> type, final Application application,
final JerseySeBootstrapConfiguration configuration) {
return JdkHttpServer.class == type || WebServer.class == type
? type.cast(new JdkHttpServer(application, configuration))
final SeBootstrap.Configuration configuration) {
return WebServerProvider.isSupportedWebServer(JdkHttpServer.class, type, configuration)
? type.cast(new JdkHttpServer(application, JerseySeBootstrapConfiguration.from(configuration)))
: null;
}

@Override
public <T extends WebServer> T createServer(final Class<T> type, final Class<? extends Application> applicationClass,
final JerseySeBootstrapConfiguration configuration) {
return JdkHttpServer.class == type || WebServer.class == type
? type.cast(new JdkHttpServer(applicationClass, configuration))
final SeBootstrap.Configuration configuration) {
return WebServerProvider.isSupportedWebServer(JdkHttpServer.class, type, configuration)
? type.cast(new JdkHttpServer(applicationClass, JerseySeBootstrapConfiguration.from(configuration)))
: null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018 Markus KARG. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -18,7 +18,6 @@
package org.glassfish.jersey.jdkhttp;

import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.greaterThan;
Expand All @@ -44,7 +43,6 @@
import jakarta.ws.rs.core.UriBuilder;

import org.glassfish.jersey.internal.util.PropertiesHelper;
import org.glassfish.jersey.server.JerseySeBootstrapConfiguration;
import org.glassfish.jersey.server.ServerProperties;
import org.glassfish.jersey.server.spi.Container;
import org.glassfish.jersey.server.spi.WebServer;
Expand Down Expand Up @@ -83,10 +81,9 @@ private void shouldProvideServer(final Object application, final Resource resour
final SeBootstrap.Configuration configuration = configuration(getPort());

// when
final JerseySeBootstrapConfiguration jerseySeConfig = JerseySeBootstrapConfiguration.from(configuration);
final WebServer webServer = Application.class.isInstance(application)
? webServerProvider.createServer(WebServer.class, (Application) application, jerseySeConfig)
: webServerProvider.createServer(WebServer.class, (Class<Application>) application, jerseySeConfig);
? webServerProvider.createServer(WebServer.class, (Application) application, configuration)
: webServerProvider.createServer(WebServer.class, (Class<Application>) application, configuration);
final Object nativeHandle = webServer.unwrap(Object.class);
final CompletionStage<?> start = webServer.start();
final Object startResult = start.toCompletableFuture().get();
Expand Down Expand Up @@ -158,8 +155,7 @@ public final void shouldScanFreePort() throws InterruptedException, ExecutionExc
final SeBootstrap.Configuration configuration = configuration(SeBootstrap.Configuration.FREE_PORT);

// when
final JerseySeBootstrapConfiguration jerseySeConfig = JerseySeBootstrapConfiguration.from(configuration);
final WebServer webServer = webServerProvider.createServer(WebServer.class, application, jerseySeConfig);
final WebServer webServer = webServerProvider.createServer(WebServer.class, application, configuration);

// then
assertThat(webServer.port(), is(greaterThan(0)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018 Markus KARG. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -17,6 +17,7 @@

package org.glassfish.jersey.jetty;

import jakarta.ws.rs.SeBootstrap;
import jakarta.ws.rs.core.Application;

import org.glassfish.jersey.server.JerseySeBootstrapConfiguration;
Expand All @@ -33,18 +34,18 @@
public final class JettyHttpServerProvider implements WebServerProvider {

@Override
public final <T extends WebServer> T createServer(final Class<T> type, final Application application,
final JerseySeBootstrapConfiguration configuration) {
return JettyHttpServer.class == type || WebServer.class == type
? type.cast(new JettyHttpServer(application, configuration))
public <T extends WebServer> T createServer(final Class<T> type, final Application application,
final SeBootstrap.Configuration configuration) {
return WebServerProvider.isSupportedWebServer(JettyHttpServer.class, type, configuration)
? type.cast(new JettyHttpServer(application, JerseySeBootstrapConfiguration.from(configuration)))
: null;
}

@Override
public <T extends WebServer> T createServer(final Class<T> type, final Class<? extends Application> applicationClass,
final JerseySeBootstrapConfiguration configuration) {
return JettyHttpServer.class == type || WebServer.class == type
? type.cast(new JettyHttpServer(applicationClass, configuration))
final SeBootstrap.Configuration configuration) {
return WebServerProvider.isSupportedWebServer(JettyHttpServer.class, type, configuration)
? type.cast(new JettyHttpServer(applicationClass, JerseySeBootstrapConfiguration.from(configuration)))
: null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018 Markus KARG. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -45,7 +45,6 @@
import jakarta.ws.rs.core.UriBuilder;

import org.glassfish.jersey.internal.util.PropertiesHelper;
import org.glassfish.jersey.server.JerseySeBootstrapConfiguration;
import org.glassfish.jersey.server.ServerProperties;
import org.glassfish.jersey.server.spi.Container;
import org.glassfish.jersey.server.spi.WebServer;
Expand Down Expand Up @@ -82,10 +81,9 @@ private void shouldProvideServer(final Object application, final Resource resour
final SeBootstrap.Configuration configuration = configuration(getPort(), FALSE);

// when
final JerseySeBootstrapConfiguration jerseySeConfig = JerseySeBootstrapConfiguration.from(configuration);
final WebServer webServer = Application.class.isInstance(application)
? webServerProvider.createServer(WebServer.class, (Application) application, jerseySeConfig)
: webServerProvider.createServer(WebServer.class, (Class<Application>) application, jerseySeConfig);
? webServerProvider.createServer(WebServer.class, (Application) application, configuration)
: webServerProvider.createServer(WebServer.class, (Class<Application>) application, configuration);
final Object nativeHandle = webServer.unwrap(Object.class);
final CompletionStage<?> start = webServer.start();
final Object startResult = start.toCompletableFuture().get();
Expand Down Expand Up @@ -157,8 +155,7 @@ public final void shouldScanFreePort() throws InterruptedException, ExecutionExc
final SeBootstrap.Configuration configuration = configuration(SeBootstrap.Configuration.FREE_PORT, TRUE);

// when
final JerseySeBootstrapConfiguration jerseySeConfig = JerseySeBootstrapConfiguration.from(configuration);
final WebServer webServer = webServerProvider.createServer(WebServer.class, application, jerseySeConfig);
final WebServer webServer = webServerProvider.createServer(WebServer.class, application, configuration);

// then
assertThat(webServer.port(), is(greaterThan(0)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018 Markus KARG. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -17,6 +17,7 @@

package org.glassfish.jersey.netty.httpserver;

import jakarta.ws.rs.SeBootstrap;
import jakarta.ws.rs.core.Application;

import org.glassfish.jersey.server.JerseySeBootstrapConfiguration;
Expand All @@ -35,17 +36,17 @@ public final class NettyHttpServerProvider implements WebServerProvider {

@Override
public <T extends WebServer> T createServer(final Class<T> type, final Application application,
final JerseySeBootstrapConfiguration configuration) {
return NettyHttpServer.class == type || WebServer.class == type
? type.cast(new NettyHttpServer(application, configuration))
final SeBootstrap.Configuration configuration) {
return WebServerProvider.isSupportedWebServer(NettyHttpServer.class, type, configuration)
? type.cast(new NettyHttpServer(application, JerseySeBootstrapConfiguration.from(configuration)))
: null;
}

@Override
public <T extends WebServer> T createServer(final Class<T> type, final Class<? extends Application> applicationClass,
final JerseySeBootstrapConfiguration configuration) {
return NettyHttpServer.class == type || WebServer.class == type
? type.cast(new NettyHttpServer(applicationClass, configuration))
final SeBootstrap.Configuration configuration) {
return WebServerProvider.isSupportedWebServer(NettyHttpServer.class, type, configuration)
? type.cast(new NettyHttpServer(applicationClass, JerseySeBootstrapConfiguration.from(configuration)))
: null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018 Markus KARG. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -44,7 +44,6 @@
import jakarta.ws.rs.core.UriBuilder;

import org.glassfish.jersey.internal.util.PropertiesHelper;
import org.glassfish.jersey.server.JerseySeBootstrapConfiguration;
import org.glassfish.jersey.server.ServerProperties;
import org.glassfish.jersey.server.spi.Container;
import org.glassfish.jersey.server.spi.WebServer;
Expand Down Expand Up @@ -84,10 +83,9 @@ private void shouldProvideServer(final Object application, final Resource resour
final SeBootstrap.Configuration configuration = configuration(getPort(), FALSE);

// when
final JerseySeBootstrapConfiguration jerseySeConfig = JerseySeBootstrapConfiguration.from(configuration);
final WebServer webServer = Application.class.isInstance(application)
? webServerProvider.createServer(WebServer.class, (Application) application, jerseySeConfig)
: webServerProvider.createServer(WebServer.class, (Class<Application>) application, jerseySeConfig);
? webServerProvider.createServer(WebServer.class, (Application) application, configuration)
: webServerProvider.createServer(WebServer.class, (Class<Application>) application, configuration);
final Object nativeHandle = webServer.unwrap(Object.class);
final CompletionStage<?> start = webServer.start();
final Object startResult = start.toCompletableFuture().get();
Expand Down Expand Up @@ -160,8 +158,7 @@ public final void shouldScanFreePort() throws InterruptedException, ExecutionExc
final SeBootstrap.Configuration configuration = configuration(SeBootstrap.Configuration.FREE_PORT, TRUE);

// when
final JerseySeBootstrapConfiguration jerseySeConfig = JerseySeBootstrapConfiguration.from(configuration);
final WebServer webServer = webServerProvider.createServer(WebServer.class, application, jerseySeConfig);
final WebServer webServer = webServerProvider.createServer(WebServer.class, application, configuration);

// then
assertThat(webServer.port(), is(greaterThan(0)));
Expand Down
Loading