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();
}
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();
}
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();
}
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();
}
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);
}
Aggregations