-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from jamezp/migration
Add the bootstrap-cdi example.
- Loading branch information
Showing
10 changed files
with
506 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
= Bootstrap with CDI | ||
|
||
In https://jakarta.ee/specifications/restful-ws/3.1/[Jakarta RESTful Web Services 3.1] the `SeBootstrap` API was | ||
introduced. This quickstart shows how to use the API with RESTEasy. | ||
|
||
== Building | ||
|
||
To build the `bootstrap-cdi` quickstart you must have https://maven.apache.org/[Maven] installed and at least Java 11. | ||
Then you simply need to run the following: | ||
|
||
---- | ||
mvn clean verify | ||
---- | ||
|
||
This will create a `bootstrap-cdi.jar` which can be executed from the command line. A test is also executed as part of | ||
the build. | ||
|
||
== Running the Quickstart | ||
|
||
The `bootstrap-cdi.jar` created can be executed from the command. | ||
|
||
---- | ||
java -jar target/bootstrap-cdi.jar | ||
---- | ||
|
||
This will start an Undertow container with RESTEasy and CDI support. To exit the application you need to send a `SIGKILL` | ||
, for example `CTRL+C`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ JBoss, Home of Professional Open Source. | ||
~ | ||
~ Copyright 2022 Red Hat, Inc., and individual contributors | ||
~ as indicated by the @author tags. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>dev.resteasy.tools</groupId> | ||
<artifactId>resteasy-parent</artifactId> | ||
<version>2.0.1.Final</version> | ||
<relativePath/> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>dev.resteasy.quickstarts</groupId> | ||
<artifactId>bootstrap-cdi</artifactId> | ||
<version>6.1.0.Final-SNAPSHOT</version> | ||
<name>RESTEasy Quick Start: Bootstrap API</name> | ||
|
||
<properties> | ||
<!-- Dependency versions --> | ||
<version.jakarta.enterprise.cdi-api>4.0.1</version.jakarta.enterprise.cdi-api> | ||
<version.jakarta.ws.rs.api>3.1.0</version.jakarta.ws.rs.api> | ||
<version.org.jboss.logmanager>2.1.19.Final</version.org.jboss.logmanager> | ||
<version.org.jboss.resteasy>6.2.0.Final</version.org.jboss.resteasy> | ||
<version.org.junit>5.9.1</version.org.junit> | ||
|
||
<!-- Plugin Versions --> | ||
<version.jandex.maven.plugin>1.2.3</version.jandex.maven.plugin> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-bom</artifactId> | ||
<version>${version.org.jboss.resteasy}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit</groupId> | ||
<artifactId>junit-bom</artifactId> | ||
<version>${version.org.junit}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>jakarta.ws.rs</groupId> | ||
<artifactId>jakarta.ws.rs-api</artifactId> | ||
<version>${version.jakarta.ws.rs.api}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.logmanager</groupId> | ||
<artifactId>jboss-logmanager</artifactId> | ||
<version>${version.org.jboss.logmanager}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-undertow-cdi</artifactId> | ||
</dependency> | ||
|
||
<!-- Test Dependencies --> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-client</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>${project.artifactId}</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>net.revelc.code.formatter</groupId> | ||
<artifactId>formatter-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>net.revelc.code</groupId> | ||
<artifactId>impsort-maven-plugin</artifactId> | ||
</plugin> | ||
<!-- Use Jandex to --> | ||
<plugin> | ||
<groupId>org.jboss.jandex</groupId> | ||
<artifactId>jandex-maven-plugin</artifactId> | ||
<version>${version.jandex.maven.plugin}</version> | ||
<executions> | ||
<execution> | ||
<id>make-index</id> | ||
<goals> | ||
<goal>jandex</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<mainClass>dev.resteasy.quickstart.bootstrap.Main</mainClass> | ||
<packageName>dev.resteasy.quickstart.bootstrap</packageName> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<configuration> | ||
<transformers> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer"> | ||
<resource>module-info.class</resource> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
42 changes: 42 additions & 0 deletions
42
bootstrap-cdi/src/main/java/dev/resteasy/quickstart/bootstrap/Greeter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* | ||
* Copyright 2022 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.resteasy.quickstart.bootstrap; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
/** | ||
* A simple greeter CDI bean. | ||
* | ||
* @author <a href="mailto:[email protected]">James R. Perkins</a> | ||
*/ | ||
@ApplicationScoped | ||
public class Greeter { | ||
|
||
/** | ||
* Returns a greeting for the name provided. | ||
* | ||
* @param name the name to add to the greeting | ||
* @return a greeting | ||
*/ | ||
public String greet(@NotNull final String name) { | ||
return "Hello " + name + "!"; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
bootstrap-cdi/src/main/java/dev/resteasy/quickstart/bootstrap/GreetingResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* | ||
* Copyright 2022 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.resteasy.quickstart.bootstrap; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
/** | ||
* A simple resource for creating a greeting. | ||
* | ||
* @author <a href="mailto:[email protected]">James R. Perkins</a> | ||
*/ | ||
@Path("/") | ||
public class GreetingResource { | ||
|
||
@Inject | ||
private Greeter greeter; | ||
|
||
/** | ||
* A {@link GET} method which returns a greeting for the name passed in, in plain text. | ||
* | ||
* @param name the name for the greeting | ||
* @return a response with a greeting in plain text | ||
*/ | ||
@GET | ||
@Path("/{name}") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public Response greet(@PathParam("name") final String name) { | ||
return Response.ok(greeter.greet(name)).build(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
bootstrap-cdi/src/main/java/dev/resteasy/quickstart/bootstrap/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* | ||
* Copyright 2022 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.resteasy.quickstart.bootstrap; | ||
|
||
import jakarta.ws.rs.SeBootstrap; | ||
|
||
/** | ||
* An entry point for starting a REST container | ||
* | ||
* @author <a href="mailto:[email protected]">James R. Perkins</a> | ||
*/ | ||
public class Main { | ||
private static final boolean USE_CONSOLE = System.console() != null; | ||
|
||
public static void main(final String[] args) throws Exception { | ||
System.setProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager"); | ||
SeBootstrap.start(RestActivator.class) | ||
.thenAccept(instance -> { | ||
instance.stopOnShutdown(stopResult -> print("Stopped container (%s)", stopResult.unwrap(Object.class))); | ||
print("Container running at %s", | ||
instance.configuration().baseUri()); | ||
print("Example: %s", | ||
instance.configuration().baseUriBuilder().path("rest/" + System.getProperty("user.name")).build()); | ||
print("Send SIGKILL to shutdown container"); | ||
}); | ||
Thread.currentThread().join(); | ||
} | ||
|
||
private static void print(final String fmt, final Object... args) { | ||
if (USE_CONSOLE) { | ||
System.console().format(fmt, args) | ||
.printf("%n"); | ||
} else { | ||
System.out.printf(fmt, args); | ||
System.out.println(); | ||
} | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
bootstrap-cdi/src/main/java/dev/resteasy/quickstart/bootstrap/RestActivator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* | ||
* Copyright 2022 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.resteasy.quickstart.bootstrap; | ||
|
||
import jakarta.ws.rs.ApplicationPath; | ||
import jakarta.ws.rs.core.Application; | ||
|
||
/** | ||
* Activates the REST application. | ||
* | ||
* @author <a href="mailto:[email protected]">James R. Perkins</a> | ||
*/ | ||
@ApplicationPath("/rest") | ||
public class RestActivator extends Application { | ||
} |
Oops, something went wrong.