Skip to content

Commit

Permalink
Initial commit that removes @context and @suspended. All examples hav…
Browse files Browse the repository at this point in the history
…e been updated.
  • Loading branch information
spericas committed May 23, 2023
1 parent 57216fe commit ae1f6ef
Show file tree
Hide file tree
Showing 92 changed files with 602 additions and 2,523 deletions.
6 changes: 3 additions & 3 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>jakarta.ws.rs</groupId>
<artifactId>all</artifactId>
<version>3.1.0</version>
<version>4.0.0-SNAPSHOT</version>
</parent>

<url>https://github.com/jax-rs/api</url>
Expand Down Expand Up @@ -231,9 +231,9 @@
<plugin>
<artifactId>maven-jxr-plugin</artifactId>
</plugin>
<plugin>
<!-- plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugin -->
<plugin>
<groupId>org.glassfish.copyright</groupId>
<artifactId>glassfish-copyright-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.container.AsyncResponse;
import jakarta.ws.rs.container.CompletionCallback;
import jakarta.ws.rs.container.Suspended;
import jakarta.ws.rs.core.MediaType;

/**
Expand All @@ -38,7 +37,7 @@ public class AsyncEventResource implements CompletionCallback {
private static final BlockingQueue<String> MESSAGES = new ArrayBlockingQueue<String>(5);

@GET
public void readMessage(@Suspended final AsyncResponse ar) {
public void readMessage(AsyncResponse ar) {
ar.register(AsyncEventResource.class);
Executors.newSingleThreadExecutor().submit(() -> {
try {
Expand All @@ -51,7 +50,7 @@ public void readMessage(@Suspended final AsyncResponse ar) {
}

@POST
public void postMessage(final String message, @Suspended final AsyncResponse asyncResponse) {
public void postMessage(final String message, AsyncResponse asyncResponse) {
Executors.newSingleThreadExecutor().submit(() -> {
try {
MESSAGES.put(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import static java.util.concurrent.TimeUnit.SECONDS;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.container.AsyncResponse;
import jakarta.ws.rs.container.Suspended;

import static java.util.concurrent.TimeUnit.SECONDS;

/**
* Long-running asynchronous processing examples.
Expand All @@ -46,8 +46,7 @@ public String basicSyncExample() {

@GET
@Path("async")
public void asyncExample(
@Suspended final AsyncResponse ar) {
public void asyncExample(AsyncResponse ar) {
ar.setTimeout(15, SECONDS);
Executors.newSingleThreadExecutor().submit(() -> {
try {
Expand All @@ -61,7 +60,7 @@ public void asyncExample(

@GET
@Path("asyncSelective")
public void selectiveSuspend(@QueryParam("query") final String query, @Suspended final AsyncResponse ar) {
public void selectiveSuspend(@QueryParam("query") final String query, AsyncResponse ar) {
if (!isComplex(query)) {
// process simple queries synchronously
ar.resume("Simple result for " + query);
Expand All @@ -85,7 +84,7 @@ private boolean isComplex(String query) {
@GET
@Path("asyncTimeoutOverride")
public void overriddenTimeoutAsync(@QueryParam("timeOut") Long timeOut, @QueryParam("timeUnit") TimeUnit timeUnit,
@Suspended final AsyncResponse ar) {
AsyncResponse ar) {
if (timeOut != null && timeUnit != null) {
ar.setTimeout(timeOut, timeUnit);
} else {
Expand All @@ -105,7 +104,7 @@ public void overriddenTimeoutAsync(@QueryParam("timeOut") Long timeOut, @QueryPa

@GET
@Path("asyncHandleUsage")
public void suspendHandleUsageExample(@Suspended final AsyncResponse ar) {
public void suspendHandleUsageExample(AsyncResponse ar) {
ar.setTimeout(15, SECONDS);
Executors.newSingleThreadExecutor().submit(() -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.container.AsyncResponse;
import jakarta.ws.rs.container.Suspended;

/**
* Example of a long running EJB resource.
Expand All @@ -27,7 +26,7 @@
public class LongRunningEjbResource {
@GET
@Asynchronous
public void longRunningOperation(@Suspended AsyncResponse ar) {
public void longRunningOperation(AsyncResponse ar) {
final String result = executeLongRunningOperation();
ar.resume(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.container.AsyncResponse;
import jakarta.ws.rs.container.Suspended;
import jakarta.ws.rs.core.MediaType;

/**
Expand All @@ -34,7 +33,7 @@ public class SimpleAsyncEventResource {
private static final BlockingQueue<AsyncResponse> SUSPENDED = new ArrayBlockingQueue<AsyncResponse>(5);

@GET
public void readMessage(@Suspended final AsyncResponse ar) throws InterruptedException {
public void readMessage(AsyncResponse ar) throws InterruptedException {
SUSPENDED.put(ar);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import java.net.URI;

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

/**
* Basic Java SE bootstrap example.
Expand All @@ -43,12 +46,21 @@ private BasicJavaSeBootstrapExample() {
* @param args unused command line arguments
* @throws InterruptedException when process is killed
*/
public static void main(final String[] args) throws InterruptedException {
SeBootstrap.start(HelloWorld.class).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();
public static final void main(final String[] args) throws InterruptedException {
final Application application = new HelloWorld();

final SeBootstrap.Configuration requestedConfiguration = SeBootstrap.Configuration.builder().build();

SeBootstrap.start(application, requestedConfiguration).thenAccept(instance -> {
Runtime.getRuntime()
.addShutdownHook(new Thread(() -> instance.stop()
.thenAccept(stopResult -> System.out.printf("Stop result: %s [Native stop result: %s].%n",
stopResult, stopResult.unwrap(Object.class)))));

final Configuration actualConfigurarion = instance.configuration();
final URI uri = UriBuilder.newInstance().scheme(actualConfigurarion.protocol().toLowerCase())
.host(actualConfigurarion.host()).port(actualConfigurarion.port())
.path(actualConfigurarion.rootPath()).build();
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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import java.net.URI;

import jakarta.ws.rs.SeBootstrap;
import jakarta.ws.rs.SeBootstrap.Configuration;
import jakarta.ws.rs.SeBootstrap.Configuration.SSLClientAuthentication;
import jakarta.ws.rs.core.Application;
import jakarta.ws.rs.core.UriBuilder;

/**
* Java SE Bootstrap Example using TLS Client Authentication.
Expand All @@ -31,15 +34,19 @@
* (e. g. 443, 8443, or someting completely different). The actual configuration needs to be queried after
* bootstrapping, otherwise callers would be unaware of the actual chosen port. If the client's certificate is invalid
* or cannot be validated, the server will reject the connection.
* </p>
* <p>
* This example uses some basic <em>external</em> JSSE configuration:
* </p>
* <p>
* <ul>
* <li>{@code javax.net.ssl.keyStore=~/.keystore} - HTTPS: Path to a keystore holding an X.509 certificate for
* {@code CN=localhost}</li>
* <li>{@code javax.net.ssl.keyStorePassword=...} - HTTPS: Password of that keystore</li>
* <li>Client Authentication: The default truststore ({@code $JAVA_HOME/lib/security/cacerts}) must hold the root
* certificate of the CA and all intermediate certificates used for signing the client's certificate.</li>
* </ul>
* </p>
*
* @author Markus KARG (markus@headcrashing.eu)
* @since 3.1
Expand All @@ -55,15 +62,22 @@ private ClientAuthenticationJavaSeBootstrapExample() {
* @param args unused command line arguments
* @throws InterruptedException when process is killed
*/
public static void main(final String[] args) throws InterruptedException {
public static final void main(final String[] args) throws InterruptedException {
final Application application = new HelloWorld();

final SeBootstrap.Configuration requestedConfiguration = SeBootstrap.Configuration.builder().protocol("HTTPS")
.sslClientAuthentication(SSLClientAuthentication.MANDATORY).build();

SeBootstrap.start(HelloWorld.class, 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();
SeBootstrap.start(application, requestedConfiguration).thenAccept(instance -> {
Runtime.getRuntime()
.addShutdownHook(new Thread(() -> instance.stop()
.thenAccept(stopResult -> System.out.printf("Stop result: %s [Native stop result: %s].%n",
stopResult, stopResult.unwrap(Object.class)))));

final Configuration actualConfigurarion = instance.configuration();
final URI uri = UriBuilder.newInstance().scheme(actualConfigurarion.protocol().toLowerCase())
.host(actualConfigurarion.host()).port(actualConfigurarion.port())
.path(actualConfigurarion.rootPath()).build();
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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import java.net.URI;

import jakarta.ws.rs.SeBootstrap;
import jakarta.ws.rs.SeBootstrap.Configuration;
import jakarta.ws.rs.SeBootstrap.Configuration.SSLClientAuthentication;
import jakarta.ws.rs.core.Application;
import jakarta.ws.rs.core.UriBuilder;

/**
* Java SE bootstrap example with explicit configuration.
Expand Down Expand Up @@ -54,7 +56,7 @@ private ExplicitJavaSeBootstrapExample() {
* {@code NONE, OPTIONAL, MANDATORY}.
* @throws InterruptedException when process is killed
*/
public static void main(final String[] args) throws InterruptedException {
public static final void main(final String[] args) throws InterruptedException {
final Application application = new HelloWorld();

final String protocol = args[0];
Expand All @@ -67,10 +69,15 @@ public static void main(final String[] args) throws InterruptedException {
.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();
Runtime.getRuntime()
.addShutdownHook(new Thread(() -> instance.stop()
.thenAccept(stopResult -> System.out.printf("Stop result: %s [Native stop result: %s].%n",
stopResult, stopResult.unwrap(Object.class)))));

final Configuration actualConfigurarion = instance.configuration();
final URI uri = UriBuilder.newInstance().scheme(actualConfigurarion.protocol().toLowerCase())
.host(actualConfigurarion.host()).port(actualConfigurarion.port())
.path(actualConfigurarion.rootPath()).build();
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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@

import java.net.URI;

import jakarta.ws.rs.SeBootstrap;
import jakarta.ws.rs.core.Application;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;

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

/**
* Java SE bootstrap example utilizing an external configuration system.
* <p>
Expand Down Expand Up @@ -68,7 +71,7 @@ private ExternalConfigJavaSeBootstrapExample() {
* @param args unused command line arguments
* @throws InterruptedException when process is killed
*/
public static void main(final String[] args) throws InterruptedException {
public static final void main(final String[] args) throws InterruptedException {
final Application application = new HelloWorld();

final Config config = ConfigProvider.getConfig();
Expand All @@ -77,10 +80,15 @@ public static void main(final String[] args) throws InterruptedException {
.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();
Runtime.getRuntime()
.addShutdownHook(new Thread(() -> instance.stop()
.thenAccept(stopResult -> System.out.printf("Stop result: %s [Native stop result: %s].%n",
stopResult, stopResult.unwrap(Object.class)))));

final Configuration actualConfigurarion = instance.configuration();
final URI uri = UriBuilder.newInstance().scheme(actualConfigurarion.protocol().toLowerCase())
.host(actualConfigurarion.host()).port(actualConfigurarion.port())
.path(actualConfigurarion.rootPath()).build();
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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import java.net.URI;

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

/**
* Java SE bootstrap example using HTTPS.
Expand All @@ -29,13 +31,17 @@
* {@code https://localhost/} on an implementation-specific default IP port (e. g. 443, 8443, or someting completely
* different). The actual configuration needs to be queried after bootstrapping, otherwise callers would be unaware of
* the actual chosen port.
* </p>
* <p>
* This example uses some basic <em>external</em> JSSE configuration:
* </p>
* <p>
* <ul>
* <li>{@code javax.net.ssl.keyStore=~/.keystore} - HTTPS: Path to a keystore holding an X.509 certificate for
* {@code CN=localhost}</li>
* <li>{@code javax.net.ssl.keyStorePassword=...} - HTTPS: Password of that keystore</li>
* </ul>
* </p>
*
* @author Markus KARG (markus@headcrashing.eu)
* @since 3.1
Expand All @@ -51,16 +57,21 @@ private HttpsJavaSeBootstrapExample() {
* @param args unused command line arguments
* @throws InterruptedException when process is killed
*/
public static void main(final String[] args) throws InterruptedException {
public static final 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();
Runtime.getRuntime()
.addShutdownHook(new Thread(() -> instance.stop()
.thenAccept(stopResult -> System.out.printf("Stop result: %s [Native stop result: %s].%n",
stopResult, stopResult.unwrap(Object.class)))));

final Configuration actualConfigurarion = instance.configuration();
final URI uri = UriBuilder.newInstance().scheme(actualConfigurarion.protocol().toLowerCase())
.host(actualConfigurarion.host()).port(actualConfigurarion.port())
.path(actualConfigurarion.rootPath()).build();
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.");
Expand Down
Loading

0 comments on commit ae1f6ef

Please sign in to comment.