Search in sources :

Example 6 with Application

use of jakarta.ws.rs.core.Application in project jaxrs-api by eclipse-ee4j.

the class ExplicitJavaSeBootstrapExample method main.

/**
 * Runs this example.
 *
 * @param args configuration to be used in exact this order: {@code PROTOCOL HOST PORT ROOT_PATH CLIENT_AUTH} where the
 * protocol can be either {@code HTTP} or {@code HTTPS} and the client authentication is one of
 * {@code NONE, OPTIONAL, MANDATORY}.
 * @throws InterruptedException when process is killed
 */
public static void main(final String[] args) throws InterruptedException {
    final Application application = new HelloWorld();
    final String protocol = args[0];
    final String host = args[1];
    final int port = Integer.parseInt(args[2]);
    final String rootPath = args[3];
    final SSLClientAuthentication clientAuth = SSLClientAuthentication.valueOf(args[4]);
    final SeBootstrap.Configuration requestedConfiguration = SeBootstrap.Configuration.builder().protocol(protocol).host(host).port(port).rootPath(rootPath).sslClientAuthentication(clientAuth).build();
    SeBootstrap.start(application, requestedConfiguration).thenAccept(instance -> {
        instance.stopOnShutdown(stopResult -> System.out.printf("Stop result: %s [Native stop result: %s].%n", stopResult, stopResult.unwrap(Object.class)));
        final URI uri = instance.configuration().baseUri();
        System.out.printf("Instance %s running at %s [Native handle: %s].%n", instance, uri, instance.unwrap(Object.class));
        System.out.println("Send SIGKILL to shutdown.");
    });
    Thread.currentThread().join();
}
Also used : SSLClientAuthentication(jakarta.ws.rs.SeBootstrap.Configuration.SSLClientAuthentication) SeBootstrap(jakarta.ws.rs.SeBootstrap) Application(jakarta.ws.rs.core.Application) URI(java.net.URI)

Example 7 with Application

use of jakarta.ws.rs.core.Application in project jaxrs-api by eclipse-ee4j.

the class NativeJavaSeBootstrapExample method main.

/**
 * Runs this example.
 *
 * @param args unused command line arguments
 * @throws InterruptedException when process is killed
 * @throws ClassNotFoundException when Jersey's Grizzly backend is not on the classpath
 */
public static void main(final String[] args) throws InterruptedException, ClassNotFoundException {
    final Application application = new HelloWorld();
    final SeBootstrap.Configuration requestedConfiguration = SeBootstrap.Configuration.builder().property("jersey.config.server.httpServerClass", Class.forName("org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServer")).build();
    SeBootstrap.start(application, requestedConfiguration).thenAccept(instance -> {
        instance.stopOnShutdown(stopResult -> System.out.printf("Stop result: %s [Native stop result: %s].%n", stopResult, stopResult.unwrap(Object.class)));
        final URI uri = instance.configuration().baseUri();
        System.out.printf("Instance %s running at %s [Native handle: %s].%n", instance, uri, instance.unwrap(Object.class));
        System.out.println("Send SIGKILL to shutdown.");
    });
    Thread.currentThread().join();
}
Also used : SeBootstrap(jakarta.ws.rs.SeBootstrap) Application(jakarta.ws.rs.core.Application) URI(java.net.URI)

Example 8 with Application

use of jakarta.ws.rs.core.Application in project jaxrs-api by eclipse-ee4j.

the class TlsJavaSeBootstrapExample method main.

/**
 * Runs this example.
 *
 * @param args KEYSTORE_PATH KEYSTORE_PASSWORD
 * @throws GeneralSecurityException in case JSSE fails
 * @throws IOException in case file access fails
 * @throws InterruptedException when process is killed
 */
public static void main(final String[] args) throws GeneralSecurityException, IOException, InterruptedException {
    final Application application = new HelloWorld();
    final Path keyStorePath = Paths.get(args[0]);
    final char[] passphrase = args[1].toCharArray();
    final KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
    keyStore.load(Files.newInputStream(keyStorePath), passphrase);
    final KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    keyManagerFactory.init(keyStore, passphrase);
    final SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
    sslContext.init(keyManagerFactory.getKeyManagers(), null, null);
    final SeBootstrap.Configuration requestedConfiguration = SeBootstrap.Configuration.builder().protocol("HTTPS").sslContext(sslContext).build();
    SeBootstrap.start(application, requestedConfiguration).thenAccept(instance -> {
        instance.stopOnShutdown(stopResult -> System.out.printf("Stop result: %s [Native stop result: %s].%n", stopResult, stopResult.unwrap(Object.class)));
        final URI uri = instance.configuration().baseUri();
        System.out.printf("Instance %s running at %s [Native handle: %s].%n", instance, uri, instance.unwrap(Object.class));
        System.out.println("Send SIGKILL to shutdown.");
    });
    Thread.currentThread().join();
}
Also used : Path(java.nio.file.Path) SSLContext(javax.net.ssl.SSLContext) SeBootstrap(jakarta.ws.rs.SeBootstrap) Application(jakarta.ws.rs.core.Application) KeyStore(java.security.KeyStore) URI(java.net.URI) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 9 with Application

use of jakarta.ws.rs.core.Application in project jaxrs-api by eclipse-ee4j.

the class HttpsJavaSeBootstrapExample method main.

/**
 * Runs this example.
 *
 * @param args unused command line arguments
 * @throws InterruptedException when process is killed
 */
public static void main(final String[] args) throws InterruptedException {
    final Application application = new HelloWorld();
    final SeBootstrap.Configuration requestedConfiguration = SeBootstrap.Configuration.builder().protocol("HTTPS").build();
    SeBootstrap.start(application, requestedConfiguration).thenAccept(instance -> {
        instance.stopOnShutdown(stopResult -> System.out.printf("Stop result: %s [Native stop result: %s].%n", stopResult, stopResult.unwrap(Object.class)));
        final URI uri = instance.configuration().baseUri();
        System.out.printf("Instance %s running at %s [Native handle: %s].%n", instance, uri, instance.unwrap(Object.class));
        System.out.println("Send SIGKILL to shutdown.");
    });
    Thread.currentThread().join();
}
Also used : SeBootstrap(jakarta.ws.rs.SeBootstrap) Application(jakarta.ws.rs.core.Application) URI(java.net.URI)

Example 10 with Application

use of jakarta.ws.rs.core.Application in project jaxrs-api by eclipse-ee4j.

the class SeBootstrapTest method shouldUseDefaultConfigurationIfOmitted.

/**
 * Assert that a default {@code Configuration} is used when not passed to the
 * {@code SeBootstrap.start} method.
 *
 * @since 3.1
 */
@Test
public void shouldUseDefaultConfigurationIfOmitted() {
    // given
    final Application application = mock(Application.class);
    final Configuration configuration = mock(Configuration.class);
    SeBootstrap.Configuration.Builder builder = mock(SeBootstrap.Configuration.Builder.class);
    given(SeBootstrap.Configuration.builder()).willReturn(builder);
    given(builder.build()).willReturn(configuration);
    // when
    SeBootstrap.start(application);
    // then
    verify(RuntimeDelegate.getInstance()).bootstrap(application, configuration);
}
Also used : Configuration(jakarta.ws.rs.SeBootstrap.Configuration) Application(jakarta.ws.rs.core.Application) Test(org.junit.jupiter.api.Test)

Aggregations

Application (jakarta.ws.rs.core.Application)18 SeBootstrap (jakarta.ws.rs.SeBootstrap)13 Test (org.junit.jupiter.api.Test)12 URI (java.net.URI)6 Configuration (jakarta.ws.rs.SeBootstrap.Configuration)3 JaxrsUtil.unprivilegedPort (ee.jakarta.tck.ws.rs.common.util.JaxrsUtil.unprivilegedPort)2 ApplicationPath (jakarta.ws.rs.ApplicationPath)2 GET (jakarta.ws.rs.GET)2 Path (jakarta.ws.rs.Path)2 Client (jakarta.ws.rs.client.Client)2 ClientBuilder (jakarta.ws.rs.client.ClientBuilder)2 UriBuilder (jakarta.ws.rs.core.UriBuilder)2 IOException (java.io.IOException)2 Collections (java.util.Collections)2 Optional (java.util.Optional)2 Set (java.util.Set)2 CompletionStage (java.util.concurrent.CompletionStage)2 ExecutionException (java.util.concurrent.ExecutionException)2 HOURS (java.util.concurrent.TimeUnit.HOURS)2 Config (org.eclipse.microprofile.config.Config)2