Skip to content

Commit

Permalink
[WFLY-18499] Update the microprofile-rest-client for the Common Enhan…
Browse files Browse the repository at this point in the history
…cements. Refactor the quickstart to a single module with a test for the MicroProfile REST Client.

Signed-off-by: James R. Perkins <[email protected]>
  • Loading branch information
jamezp committed Nov 22, 2023
1 parent 59d4d80 commit 59dba33
Show file tree
Hide file tree
Showing 29 changed files with 718 additions and 876 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/quickstart_microprofile-rest-client_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: WildFly microprofile-rest-client Quickstart CI

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches-ignore:
- 'dependabot/**'
paths:
- 'microprofile-rest-client/**'
- '.github/workflows/quickstart_ci.yml'

jobs:
call-quickstart_ci:
uses: ./.github/workflows/quickstart_ci.yml
with:
QUICKSTART_PATH: microprofile-rest-client
TEST_PROVISIONED_SERVER: true
TEST_BOOTABLE_JAR: true
44 changes: 22 additions & 22 deletions microprofile-rest-client/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ The `microprofile-rest-client` quickstart demonstrates the use of the MicroProfi
== What is it?

MicroProfile REST Client provides a type-safe approach to invoke RESTful services
over HTTP. It relies on JAX-RS APIs for consistency and easier reuse.
over HTTP. It relies on Jakarta REST APIs for consistency and easier reuse.

== Architecture

In this quickstart, we have two services -- a country server and a country client. The
server provides a simple REST interface providing information about some countries. The
client consumes this API through the MicroProfile REST Client specification.
In this quickstart we have a country server and a country client used in the test. The server provides a simple REST
interface providing information about some countries. The test creates a client that consumes this API through the
MicroProfile REST Client specification.

// System Requirements
include::../shared-doc/system-requirements.adoc[leveloffset=+1]
Expand Down Expand Up @@ -50,6 +50,7 @@ include::../shared-doc/run-arquillian-tests.adoc[leveloffset=+1]

// Run the Quickstart in Red Hat CodeReady Studio or Eclipse
include::../shared-doc/run-the-quickstart-in-jboss-developer-studio.adoc[leveloffset=+1]
include::../shared-doc/build-and-run-the-quickstart-with-openshift.adoc[leveloffset=+1]

[[creating-new-project]]
== Creating the Maven Project
Expand All @@ -60,16 +61,15 @@ application that will be contacting this server.

[source,options="nowrap"]
----
cd country-server
mvn clean package wildfly:deploy
----

NOTE: Make sure that your {productName} server is running.

You can verify that the server is responding by accessing
`http://localhost:8080/country-server/name/France`
`http://localhost:8080/microprofile-rest-client/name/France`
endpoint using your browser or
`curl http://localhost:8080/country-server/name/France`
`curl http://localhost:8080/microprofile-rest-client/name/France`
to get some information about `France`.

Now we can start creating our MicroProfile REST Client application. In different
Expand Down Expand Up @@ -164,11 +164,11 @@ the generated build section):
include::../shared-doc/setup-repositories.adoc[leveloffset=+1]

As this is a Jakarta REST application we need to also create an application class.
Create `org.wildfly.quickstarts.microprofile.rest.client.JaxRsApplication` with the
Create `org.wildfly.quickstarts.microprofile.rest.client.RestApplication` with the
following content:

NOTE: The new file should be created in
`src/main/java/org/quickstarts/microprofile/rest/client/JaxRsApplication.java`.
`src/main/java/org/wildfly/quickstarts/microprofile/rest/client/RestApplication.java`.

[source,java]
----
Expand All @@ -178,7 +178,7 @@ import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
@ApplicationPath("/")
public class JaxRsApplication extends Application {
public class RestApplication extends Application {
}
----

Expand Down Expand Up @@ -210,7 +210,7 @@ Now we can start working with the MicroProfile REST Client.
== Crating the REST Client interface

Using the MicroProfile REST Client is as simple as creating an interface which uses the
proper JAX-RS and MicroProfile annotations. In our case, the
proper Jakarta REST and MicroProfile annotations. In our case, the
interface should be created in
`org.wildfly.quickstarts.microprofile.rest.client.CountriesServiceClient`:

Expand Down Expand Up @@ -241,7 +241,7 @@ from the REST Countries API. The client will handle all the networking and
marshalling leaving our code clean of such technical details.

As you can see, all that our REST client interface uses for now are standard
JAX-RS annotations. There are two ways how to expose the REST client to use it in
Jakarta REST annotations. There are two ways how to expose the REST client to use it in
your application: the CDI lookup and the programmatic lookup.

== CDI lookup
Expand Down Expand Up @@ -297,7 +297,7 @@ import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
@Path("/")
@RegisterRestClient(baseUri = "http://localhost:8080/country-server")
@RegisterRestClient(baseUri = "http://localhost:8080/microprofile-rest-client")
public interface CountriesServiceClient {
@GET
Expand All @@ -312,7 +312,7 @@ section.

Now we can start using our statically configured REST client.

=== Create the JAX-RS resource
=== Create the Jakarta REST resource

Create `org.wildfly.quickstarts.microprofile.rest.client.CountriesResource` with the
following content:
Expand Down Expand Up @@ -369,7 +369,7 @@ endpoint using your browser or
`curl http://localhost:8080/country-client/country/cdi/France`
to get some information about `France`.

Congratulations! You are already invoking custom REST client from your JAX-RS
Congratulations! You are already invoking custom REST client from your Jakarta REST
endpoint.

=== Configuring the REST client base URL/URI dynamically
Expand Down Expand Up @@ -413,18 +413,18 @@ with the following content:

[source,properties]
----
org.wildfly.quickstarts.microprofile.rest.client.CountriesServiceClient/mp-rest/url=http://localhost:8080/country-server
org.wildfly.quickstarts.microprofile.rest.client.CountriesServiceClient/mp-rest/url=http://localhost:8080/microprofile-rest-client
org.wildfly.quickstarts.microprofile.rest.client.CountriesServiceClient/mp-rest/scope=jakarta.inject.Singleton
----

This configuration means that:

* all requests performed using
`org.wildfly.quickstarts.microprofile.rest.client.CountriesServiceClient` will use
`http://localhost:8080/country-server` as a base URL. Using the configuration above, calling
`http://localhost:8080/microprofile-rest-client` as a base URL. Using the configuration above, calling
the `getByName` method of `CountriesServiceClient` with a value of `France` would
result in an HTTP GET request being made to
`http://localhost:8080/country-server/name/France`.
`http://localhost:8080/microprofile-rest-client/name/France`.
* the default scope of
`org.wildfly.quickstarts.microprofile.rest.client.CountriesServiceClient` will be
`@Singleton`. All supported values are described later. The default scope can also
Expand Down Expand Up @@ -506,7 +506,7 @@ following method:
@Produces(MediaType.APPLICATION_JSON)
public Country programmaticName(@PathParam("name") String name) throws MalformedURLException {
CountriesServiceClient client = RestClientBuilder.newBuilder()
.baseUrl(new URL("http://localhost:8080/country-server"))
.baseUrl(new URL("http://localhost:8080/microprofile-rest-client"))
.build(CountriesServiceClient.class);
return client.getByName(name);
Expand Down Expand Up @@ -613,7 +613,7 @@ public CompletionStage<Country> nameAsync(@PathParam("name") String name) {

== Provider registration

MicroProfile REST Client allows you to register custom JAX-RS providers when you
MicroProfile REST Client allows you to register custom Jakarta REST providers when you
are defining the interface or building the client with the builder. The supported
providers which can be registered are:

Expand Down Expand Up @@ -727,7 +727,7 @@ endpoint using your browser or
`curl http://localhost:8080/country-client/country/cdi/doesNotExist`
the application will return a 204 No Content response instead of the 404 error
received from `country-server`. You can verify the `country-server` response at
`http://localhost:8080/country-server/name/doesNotExist`.
`http://localhost:8080/microprofile-rest-client/name/doesNotExist`.

ifdef::EAPXPRelease[]
// Getting Started with OpenShift
Expand All @@ -749,7 +749,7 @@ include::../shared-doc/build-and-run-the-quickstart-with-bootable-jar.adoc[level

MicroProfile REST Client provides you with an option to define REST clients in a
clear, declarative, and intuitive way using the same annotations as for your
JAX-RS resources. It also allows you to make the HTTP communication on the background
Jakarta REST resources. It also allows you to make the HTTP communication on the background
transparent for your services with the direct data conversions and exception mappers.
You can find more information about the MicroProfile REST Client specification at
https://github.com/eclipse/microprofile-rest-client.
6 changes: 6 additions & 0 deletions microprofile-rest-client/charts/helm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build:
uri: https://github.com/wildfly/quickstart.git
ref: main
contextDir: microprofile-rest-client
deploy:
replicas: 1
163 changes: 0 additions & 163 deletions microprofile-rest-client/country-client/pom.xml

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 59dba33

Please sign in to comment.