diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0c98d5d3..5bcba22a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: run: bash ./tools/pr-checker/checker.sh ${{ github.repository }} ${{ github.event.pull_request.number }} | tee checker.log - id: Lint-Code-Base if: always() - uses: github/super-linter@v3 + uses: github/super-linter@v3.17.0 env: VALIDATE_ALL_CODEBASE: false GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.adoc b/README.adoc index 9e8f223b..33421ee5 100644 --- a/README.adoc +++ b/README.adoc @@ -1,4 +1,4 @@ -// Copyright (c) 2018, 2021 IBM Corporation and others. +// Copyright (c) 2018, 2022 IBM Corporation and others. // Licensed under Creative Commons Attribution-NoDerivatives // 4.0 International (CC BY-ND 4.0) // https://creativecommons.org/licenses/by-nd/4.0/ @@ -34,16 +34,11 @@ Learn how to use MicroProfile Rest Client to invoke RESTful microservices over H == What you'll learn -You will learn how to build a MicroProfile Rest Client to access remote RESTful services. You will create a template interface that maps to the remote service that you want to call. -MicroProfile Rest Client automatically generates a client instance based on what is defined and annotated in the template interface. -Thus, you don't have to worry about all of the boilerplate code, such as setting up a client class, connecting to the remote server, or invoking the correct URI with the correct parameters. +You will learn how to build a MicroProfile Rest Client to access remote RESTful services. You will create a template interface that maps to the remote service that you want to call. MicroProfile Rest Client automatically generates a client instance based on what is defined and annotated in the template interface. Thus, you don't have to worry about all of the boilerplate code, such as setting up a client class, connecting to the remote server, or invoking the correct URI with the correct parameters. -The application that you will be working with is an `inventory` service, which fetches and stores the system property information for different hosts. -Whenever a request is made to retrieve the system properties of a particular host, the `inventory` service will create a client to invoke the `system` -service on that host. The `system` service simulates a remote service in the application. +The application that you will be working with is an `inventory` service, which fetches and stores the system property information for different hosts. Whenever a request is made to retrieve the system properties of a particular host, the `inventory` service will create a client to invoke the `system` service on that host. The `system` service simulates a remote service in the application. -You will instantiate the client and use it in the `inventory` service. You can choose from two different approaches, https://openliberty.io/docs/latest/cdi-beans.html[Context and Dependency Injection (CDI)^] with the help of MicroProfile Config or the https://openliberty.io/blog/2018/01/31/mpRestClient.html[RestClientBuilder^] method. -In this guide, you will explore both methods to handle scenarios for providing a valid base URL. +You will instantiate the client and use it in the `inventory` service. You can choose from two different approaches, https://openliberty.io/docs/latest/cdi-beans.html[Context and Dependency Injection (CDI)^] with the help of MicroProfile Config or the https://openliberty.io/blog/2018/01/31/mpRestClient.html[RestClientBuilder^] method. In this guide, you will explore both methods to handle scenarios for providing a valid base URL. * When the base URL of the remote service is static and known, define the default base URL in the configuration file. Inject the client with a CDI method. @@ -58,28 +53,18 @@ include::{common-includes}/gitclone.adoc[] include::{common-includes}/twyb-intro.adoc[] -The `system` microservice simulates a service that returns the system -property information for the host. -The `system` service is accessible at the http://localhost:9080/system/properties[http://localhost:9080/system/properties^] URL. In this case, `localhost` is the host name. +The `system` microservice simulates a service that returns the system property information for the host. The `system` service is accessible at the http://localhost:9080/system/properties[http://localhost:9080/system/properties^] URL. In this case, `localhost` is the host name. -The `inventory` microservice makes a request to the `system` microservice and -stores the system property information. -To fetch and store your system information, visit the http://localhost:9080/inventory/systems/localhost[http://localhost:9080/inventory/systems/localhost^] URL. +The `inventory` microservice makes a request to the `system` microservice and stores the system property information. To fetch and store your system information, visit the http://localhost:9080/inventory/systems/localhost[http://localhost:9080/inventory/systems/localhost^] URL. // static guide instructions: ifndef::cloud-hosted[] -You can also use the `\http://localhost:9080/inventory/systems/{your-hostname}` URL. In Windows, -MacOS, and Linux, get your fully qualified domain name (FQDN) by entering -`hostname` into your command-line. Visit the URL by replacing `{your-hostname}` -with your FQDN. +You can also use the `\http://localhost:9080/inventory/systems/{your-hostname}` URL. In Windows, MacOS, and Linux, get your fully qualified domain name (FQDN) by entering `hostname` into your command-line. Visit the URL by replacing `{your-hostname}` with your FQDN. endif::[] // cloud-hosted guide instructions: ifdef::cloud-hosted[] -You can also use the **http://localhost:9080/inventory/systems/{your-hostname}** URL. In Windows, -MacOS, and Linux, get your fully qualified domain name (FQDN) by entering -**hostname** into your command-line. Visit the URL by replacing **{your-hostname}** -with your FQDN. +You can also use the ***http://localhost:9080/inventory/systems/{your-hostname}*** URL. In Windows, MacOS, and Linux, get your fully qualified domain name (FQDN) by entering **hostname** into your command-line. Visit the URL by replacing ***{your-hostname}*** with your FQDN. endif::[] @@ -116,8 +101,7 @@ include::finish/src/main/liberty/config/server.xml[] The code for the `system` service in the `src/main/java/io/openliberty/guides/system` directory is provided for you. It simulates a remote RESTful service that the `inventory` service invokes. -Create a RESTful client interface for the `system` service. Write a template interface that maps the API of the remote `system` service. -The template interface describes the remote service that you want to access. The interface defines the resource to access as a method by mapping its annotations, return type, list of arguments, and exception declarations. +Create a RESTful client interface for the `system` service. Write a template interface that maps the API of the remote `system` service. The template interface describes the remote service that you want to access. The interface defines the resource to access as a method by mapping its annotations, return type, list of arguments, and exception declarations. [role="code_command hotspot file=2", subs="quotes"] ---- @@ -132,15 +116,13 @@ include::finish/src/main/java/io/openliberty/guides/inventory/client/SystemClien The MicroProfile Rest Client feature automatically builds and generates a client implementation based on what is defined in the [hotspot=SystemClient file=2]`SystemClient` interface. There is no need to set up the client and connect with the remote service. -Notice the [hotspot=SystemClient file=2]`SystemClient` interface inherits the [hotspot=AutoCloseable file=2]`AutoCloseable` interface. -This allows the user to explicitly close the client instance by invoking the `close()` method or to implicitly close the client instance using a try-with-resources block. When the client instance is closed, all underlying resources associated with the client instance are cleaned up. Refer to the https://github.com/eclipse/microprofile-rest-client/releases[MicroProfile Rest Client specification^] for more details. +Notice the [hotspot=SystemClient file=2]`SystemClient` interface inherits the [hotspot=AutoCloseable file=2]`AutoCloseable` interface. This allows the user to explicitly close the client instance by invoking the `close()` method or to implicitly close the client instance using a try-with-resources block. When the client instance is closed, all underlying resources associated with the client instance are cleaned up. Refer to the https://github.com/eclipse/microprofile-rest-client/releases[MicroProfile Rest Client specification^] for more details. When the [hotspot=getProperties file=2]`getProperties()` method is invoked, the [hotspot=SystemClient file=2]`SystemClient` instance sends a GET request to the `/properties` endpoint, where `` is the default base URL of the `system` service. You will see how to configure the base URL in the next section. The [hotspot=Produces file=2]`@Produces` annotation specifies the media (MIME) type of the expected response. The default value is `MediaType.APPLICATION_JSON`. -The [hotspot=RegisterProvider file=2]`@RegisterProvider` annotation tells the framework to register the provider classes to be used when the framework invokes the interface. You can add as many providers as necessary. -In the [hotspot=SystemClient file=2]`SystemClient` interface, add a response exception mapper as a provider to map the `404` response code with the [hotspot=getProperties file=2]`UnknownUriException` exception. +The [hotspot=RegisterProvider file=2]`@RegisterProvider` annotation tells the framework to register the provider classes to be used when the framework invokes the interface. You can add as many providers as necessary. In the [hotspot=SystemClient file=2]`SystemClient` interface, add a response exception mapper as a provider to map the `404` response code with the [hotspot=getProperties file=2]`UnknownUriException` exception. // ================================================================================================= // Handling exceptions through ResponseExceptionMappers @@ -149,8 +131,7 @@ In the [hotspot=SystemClient file=2]`SystemClient` interface, add a response exc Error handling is an important step to ensure that the application can fail safely. If there is an error response such as `404 NOT FOUND` when invoking the remote service, you need to handle it. First, define an exception, and map the exception with the error response code. Then, register the exception mapper in the client interface. -Look at the client interface again, the [hotspot=RegisterProvider file=0]`@RegisterProvider` annotation registers the `UnknownUriExceptionMapper` response exception mapper. -An exception mapper maps various response codes from the remote service to throwable exceptions. +Look at the client interface again, the [hotspot=RegisterProvider file=0]`@RegisterProvider` annotation registers the `UnknownUriExceptionMapper` response exception mapper. An exception mapper maps various response codes from the remote service to throwable exceptions. SystemClient.java [source, Java, linenums, role='code_column hide_tags=copyright'] @@ -193,8 +174,7 @@ The [hotspot=handles file=2]`handles()` method inspects the HTTP response code t Now, instantiate the [hotspot=SystemClient file=1]`SystemClient` interface and use it in the `inventory` service. If you want to connect only with the default host name, you can easily instantiate the [hotspot=SystemClient file=1]`SystemClient` with CDI annotations. CDI injection simplifies the process of bootstrapping the client. -First, you need to define the base URL of the [hotspot=SystemClient file=1]`SystemClient` instance. -Configure the default base URL with the MicroProfile Config feature. This feature is enabled for you in the [hotspot=mpConfig file=3]`server.xml` file. +First, you need to define the base URL of the [hotspot=SystemClient file=1]`SystemClient` instance. Configure the default base URL with the MicroProfile Config feature. This feature is enabled for you in the [hotspot=mpConfig file=3]`server.xml` file. [role="code_command hotspot file=0", subs="quotes"] ---- @@ -221,9 +201,7 @@ include::finish/src/main/java/io/openliberty/guides/inventory/client/SystemClien The [hotspot=RegisterRestClient file=1]`@RegisterRestClient` annotation registers the interface as a RESTful client. The runtime creates a CDI managed bean for every interface that is annotated with the `@RegisterRestClient` annotation. -The [hotspot=RegisterRestClient file=1]`configKey` value in the [hotspot=RegisterRestClient file=1]`@RegisterRestClient` annotation replaces the fully-qualified classname of the properties in the [hotspot file=0]`microprofile-config.properties` configuration file. -For example, the `/mp-rest/uri` property becomes `systemClient/mp-rest/uri`. -The benefit of using Config Keys is when multiple client interfaces have the same `configKey` value, the interfaces can be configured with a single MP config property. +The [hotspot=RegisterRestClient file=1]`configKey` value in the [hotspot=RegisterRestClient file=1]`@RegisterRestClient` annotation replaces the fully-qualified classname of the properties in the [hotspot file=0]`microprofile-config.properties` configuration file. For example, the `/mp-rest/uri` property becomes `systemClient/mp-rest/uri`. The benefit of using Config Keys is when multiple client interfaces have the same `configKey` value, the interfaces can be configured with a single MP config property. The [hotspot=RegisterRestClient file=1]`baseUri` value can also be set in the [hotspot=RegisterRestClient file=1]`@RegisterRestClient` annotation. However, this value will be overridden by the base URI property defined in the [hotspot file=0]`microprofile-config.properties` configuration file, which takes precedence. In a production environment, you can use the `baseUri` variable to specify a different URI for development and testing purposes. @@ -246,8 +224,7 @@ include::finish/src/main/java/io/openliberty/guides/inventory/InventoryManager.j Because the [hotspot file=2]`InventoryManager` class is [hotspot=ApplicationScoped file=2]`@ApplicationScoped`, and the [hotspot=SystemClient file=1]`SystemClient` CDI bean maintains the same scope through the default dependent scope, the client is initialized once per application. -If the `hostname` parameter is `localhost`, the service runs the [hotspot=getPropertiesWithDefaultHostName file=2]`getPropertiesWithDefaultHostName()` helper function to fetch system properties. -The helper function invokes the `system` service by calling the [hotspot=defaultRCGetProperties file=2]`defaultRestClient.getProperties()` method. +If the `hostname` parameter is `localhost`, the service runs the [hotspot=getPropertiesWithDefaultHostName file=2]`getPropertiesWithDefaultHostName()` helper function to fetch system properties. The helper function invokes the `system` service by calling the [hotspot=defaultRCGetProperties file=2]`defaultRestClient.getProperties()` method. server.xml [source,xml,linenums,role="code_column"] @@ -260,8 +237,7 @@ include::finish/src/main/liberty/config/server.xml[] // ================================================================================================= == Building the client with RestClientBuilder -The `inventory` service can also connect with a host other than the default `localhost` host, but you cannot configure a base URL that is not yet known. -In this case, set the host name as a variable and build the client by using the `RestClientBuilder` method. You can customize the base URL from the host name attribute. +The `inventory` service can also connect with a host other than the default `localhost` host, but you cannot configure a base URL that is not yet known. In this case, set the host name as a variable and build the client by using the `RestClientBuilder` method. You can customize the base URL from the host name attribute. Look at the [hotspot=getPropertiesWithGivenHostName]`getPropertiesWithGivenHostName()` method in the [hotspot file=0]`src/main/java/io/openliberty/guides/inventory/InventoryManager.java` file. @@ -271,8 +247,7 @@ InventoryManager.java include::finish/src/main/java/io/openliberty/guides/inventory/InventoryManager.java[] ---- -The host name is provided as a parameter. This method first assembles the base URL that consists of the new host name. -Then, the method instantiates a [hotspot=customRestClientBuilder]`RestClientBuilder` builder with the new URL, registers the response exception mapper, and builds the `SystemClient` instance. +The host name is provided as a parameter. This method first assembles the base URL that consists of the new host name. Then, the method instantiates a [hotspot=customRestClientBuilder]`RestClientBuilder` builder with the new URL, registers the response exception mapper, and builds the `SystemClient` instance. Similarly, call the [hotspot=customRCGetProperties]`customRestClient.getProperties()` method to invoke the `system` service. @@ -294,9 +269,7 @@ endif::[] // cloud-hosted guide instructions: ifdef::cloud-hosted[] -Or, get your FQDN first. Then, visit the **http://localhost:9080/inventory/systems/{your-hostname}** URL -by replacing **{your-hostname}** with your FQDN, which retrieves your system properties -by making a request to the **system** service at **http://{your-hostname}:9080/system/properties**. +Or, get your FQDN first. Then, visit the ***http://localhost:9080/inventory/systems/{your-hostname}*** URL by replacing ***{your-hostname}*** with your FQDN, which retrieves your system properties by making a request to the ***system*** service at ***http://{your-hostname}:9080/system/properties***. endif::[] // ================================================================================================= @@ -350,8 +323,7 @@ Tests run: 5, Failures: 0, Errors: 0, Skipped: 0 The warning and error messages are expected and result from a request to a bad or an unknown hostname. This request is made in the `testUnknownHost()` test from the `InventoryEndpointIT` integration test. -To see whether the tests detect a failure, change the base URL in the configuration file so that when the `inventory` service tries to access the invalid URL, an `UnknownUriException` is thrown. -Rerun the tests to see a test failure occur. +To see whether the tests detect a failure, change the base URL in the configuration file so that when the `inventory` service tries to access the invalid URL, an `UnknownUriException` is thrown. Rerun the tests to see a test failure occur. [role=command] include::{common-includes}/devmode-quit.adoc[] @@ -360,8 +332,7 @@ include::{common-includes}/devmode-quit.adoc[] You just invoked a remote service by using a template interface with MicroProfile Rest Client in Open Liberty. -MicroProfile Rest Client also provides a uniform way to configure SSL for the client. -You can learn more in the https://openliberty.io/blog/2019/06/21/microprofile-rest-client-19006.html#ssl[Hostname verification with SSL on Open Liberty and MicroProfile Rest Client^] blog and the https://github.com/eclipse/microprofile-rest-client/releases[MicroProfile Rest Client specification^]. +MicroProfile Rest Client also provides a uniform way to configure SSL for the client. You can learn more in the https://openliberty.io/blog/2019/06/21/microprofile-rest-client-19006.html#ssl[Hostname verification with SSL on Open Liberty and MicroProfile Rest Client^] blog and the https://github.com/eclipse/microprofile-rest-client/releases[MicroProfile Rest Client specification^]. Feel free to try one of the related guides where you can learn more technologies and expand on what you built here. diff --git a/finish/pom.xml b/finish/pom.xml index e7dccc31..69f2231c 100755 --- a/finish/pom.xml +++ b/finish/pom.xml @@ -23,7 +23,7 @@ jakarta.platform jakarta.jakartaee-api - 8.0.0 + 9.1.0 provided @@ -31,7 +31,7 @@ microprofile - 4.1 + 5.0 pom provided @@ -45,25 +45,25 @@ org.junit.jupiter junit-jupiter - 5.8.1 + 5.8.2 test - org.apache.cxf - cxf-rt-rs-client - 3.4.5 + org.jboss.resteasy + resteasy-client + 6.0.0.Final test - org.apache.cxf - cxf-rt-rs-extension-providers - 3.4.5 + org.jboss.resteasy + resteasy-json-binding-provider + 6.0.0.Final test org.glassfish - javax.json - 1.1.4 + jakarta.json + 2.0.1 test @@ -101,4 +101,4 @@ - \ No newline at end of file + diff --git a/finish/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java b/finish/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java index fddcc67c..0e9e2f8c 100755 --- a/finish/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java +++ b/finish/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java @@ -1,6 +1,6 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2017 IBM Corporation and others. + * Copyright (c) 2017, 2022 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,11 +9,11 @@ * Contributors: * IBM Corporation - Initial implementation *******************************************************************************/ - // end::copyright[] +// end::copyright[] package io.openliberty.guides.inventory; -import javax.ws.rs.ApplicationPath; -import javax.ws.rs.core.Application; +import jakarta.ws.rs.ApplicationPath; +import jakarta.ws.rs.core.Application; @ApplicationPath("inventory") public class InventoryApplication extends Application { diff --git a/finish/src/main/java/io/openliberty/guides/inventory/InventoryManager.java b/finish/src/main/java/io/openliberty/guides/inventory/InventoryManager.java index e6a35d5c..19850a91 100755 --- a/finish/src/main/java/io/openliberty/guides/inventory/InventoryManager.java +++ b/finish/src/main/java/io/openliberty/guides/inventory/InventoryManager.java @@ -1,6 +1,6 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2017, 2020 IBM Corporation and others. + * Copyright (c) 2017, 2022 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -21,9 +21,9 @@ import java.util.List; import java.util.Properties; -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; -import javax.ws.rs.ProcessingException; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import jakarta.ws.rs.ProcessingException; import org.apache.commons.lang3.exception.ExceptionUtils; import org.eclipse.microprofile.rest.client.RestClientBuilder; @@ -75,8 +75,9 @@ public void add(String hostname, Properties systemProps) { props.setProperty("user.name", systemProps.getProperty("user.name")); SystemData host = new SystemData(hostname, props); - if (!systems.contains(host)) + if (!systems.contains(host)) { systems.add(host); + } } public InventoryList list() { diff --git a/finish/src/main/java/io/openliberty/guides/inventory/InventoryResource.java b/finish/src/main/java/io/openliberty/guides/inventory/InventoryResource.java index d0c0b881..a4cf2795 100755 --- a/finish/src/main/java/io/openliberty/guides/inventory/InventoryResource.java +++ b/finish/src/main/java/io/openliberty/guides/inventory/InventoryResource.java @@ -1,6 +1,6 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2017, 2020 IBM Corporation and others. + * Copyright (c) 2017, 2022 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,14 +13,14 @@ package io.openliberty.guides.inventory; import java.util.Properties; -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; +import jakarta.enterprise.context.RequestScoped; +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; import io.openliberty.guides.inventory.model.InventoryList; // tag::RequestScoped[] @@ -42,7 +42,7 @@ public Response getPropertiesForHost(@PathParam("hostname") String hostname) { Properties props = manager.get(hostname); if (props == null) { return Response.status(Response.Status.NOT_FOUND) - .entity("{ \"error\" : \"Unknown hostname or the system service " + .entity("{ \"error\" : \"Unknown hostname or the system service " + "may not be running on " + hostname + "\" }") .build(); } diff --git a/finish/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java b/finish/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java index 8bcaf52d..73ca25ca 100755 --- a/finish/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java +++ b/finish/src/main/java/io/openliberty/guides/inventory/client/SystemClient.java @@ -1,6 +1,6 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2018, 2019 IBM Corporation and others. + * Copyright (c) 2018, 2022 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -15,17 +15,18 @@ import java.util.Properties; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.ProcessingException; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.ProcessingException; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; import org.eclipse.microprofile.rest.client.annotation.RegisterProvider; import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; // tag::RegisterRestClient[] -@RegisterRestClient(configKey = "systemClient", baseUri = "http://localhost:9080/system") +@RegisterRestClient(configKey = "systemClient", + baseUri = "http://localhost:9080/system") // end::RegisterRestClient[] // tag::RegisterProvider[] @RegisterProvider(UnknownUriExceptionMapper.class) @@ -41,7 +42,7 @@ public interface SystemClient extends AutoCloseable { @Produces(MediaType.APPLICATION_JSON) // end::Produces[] // tag::getProperties[] - public Properties getProperties() throws UnknownUriException, ProcessingException; + Properties getProperties() throws UnknownUriException, ProcessingException; // end::getProperties[] } // end::SystemClient[] diff --git a/finish/src/main/java/io/openliberty/guides/inventory/client/UnknownUriException.java b/finish/src/main/java/io/openliberty/guides/inventory/client/UnknownUriException.java index 8fbfb468..f261971f 100644 --- a/finish/src/main/java/io/openliberty/guides/inventory/client/UnknownUriException.java +++ b/finish/src/main/java/io/openliberty/guides/inventory/client/UnknownUriException.java @@ -1,6 +1,6 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2018, 2020 IBM Corporation and others. + * Copyright (c) 2018, 2022 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/finish/src/main/java/io/openliberty/guides/inventory/client/UnknownUriExceptionMapper.java b/finish/src/main/java/io/openliberty/guides/inventory/client/UnknownUriExceptionMapper.java index badd65fc..1921c8d4 100644 --- a/finish/src/main/java/io/openliberty/guides/inventory/client/UnknownUriExceptionMapper.java +++ b/finish/src/main/java/io/openliberty/guides/inventory/client/UnknownUriExceptionMapper.java @@ -1,6 +1,6 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2018, 2020 IBM Corporation and others. + * Copyright (c) 2018, 2022 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -14,9 +14,9 @@ package io.openliberty.guides.inventory.client; import java.util.logging.Logger; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.Response; -import javax.ws.rs.ext.Provider; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.ext.Provider; import org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper; @Provider diff --git a/finish/src/main/java/io/openliberty/guides/inventory/model/InventoryList.java b/finish/src/main/java/io/openliberty/guides/inventory/model/InventoryList.java index 2a562109..685cd333 100755 --- a/finish/src/main/java/io/openliberty/guides/inventory/model/InventoryList.java +++ b/finish/src/main/java/io/openliberty/guides/inventory/model/InventoryList.java @@ -1,6 +1,6 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2017, 2018 IBM Corporation and others. + * Copyright (c) 2017, 2022 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/finish/src/main/java/io/openliberty/guides/inventory/model/SystemData.java b/finish/src/main/java/io/openliberty/guides/inventory/model/SystemData.java index 47647ec4..e3fc03cc 100644 --- a/finish/src/main/java/io/openliberty/guides/inventory/model/SystemData.java +++ b/finish/src/main/java/io/openliberty/guides/inventory/model/SystemData.java @@ -1,6 +1,6 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2017, 2020 IBM Corporation and others. + * Copyright (c) 2017, 2022 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/finish/src/main/java/io/openliberty/guides/system/SystemApplication.java b/finish/src/main/java/io/openliberty/guides/system/SystemApplication.java index 5070fc0f..d3444518 100755 --- a/finish/src/main/java/io/openliberty/guides/system/SystemApplication.java +++ b/finish/src/main/java/io/openliberty/guides/system/SystemApplication.java @@ -1,6 +1,6 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2017 IBM Corporation and others. + * Copyright (c) 2017, 2022 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,11 +9,11 @@ * Contributors: * IBM Corporation - Initial implementation *******************************************************************************/ - // end::copyright[] +// end::copyright[] package io.openliberty.guides.system; -import javax.ws.rs.core.Application; -import javax.ws.rs.ApplicationPath; +import jakarta.ws.rs.core.Application; +import jakarta.ws.rs.ApplicationPath; @ApplicationPath("system") public class SystemApplication extends Application { diff --git a/finish/src/main/java/io/openliberty/guides/system/SystemResource.java b/finish/src/main/java/io/openliberty/guides/system/SystemResource.java index e299dbce..3dcea8cf 100755 --- a/finish/src/main/java/io/openliberty/guides/system/SystemResource.java +++ b/finish/src/main/java/io/openliberty/guides/system/SystemResource.java @@ -1,6 +1,6 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2017, 2018 IBM Corporation and others. + * Copyright (c) 2017, 2022 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,11 +13,11 @@ package io.openliberty.guides.system; import java.util.Properties; -import javax.enterprise.context.RequestScoped; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; +import jakarta.enterprise.context.RequestScoped; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; @RequestScoped @Path("/properties") diff --git a/finish/src/main/liberty/config/server.xml b/finish/src/main/liberty/config/server.xml index c3775a22..510a337f 100755 --- a/finish/src/main/liberty/config/server.xml +++ b/finish/src/main/liberty/config/server.xml @@ -1,14 +1,15 @@ - jaxrs-2.1 - jsonp-1.1 - cdi-2.0 + restfulWS-3.0 + jsonp-2.0 + jsonb-2.0 + cdi-3.0 - mpConfig-2.0 + mpConfig-3.0 - mpRestClient-2.0 + mpRestClient-3.0 @@ -19,4 +20,4 @@ id="defaultHttpEndpoint"/> - \ No newline at end of file + diff --git a/finish/src/main/webapp/index.html b/finish/src/main/webapp/index.html index e71b0aaa..a887af28 100755 --- a/finish/src/main/webapp/index.html +++ b/finish/src/main/webapp/index.html @@ -1,5 +1,5 @@ microprofile - 4.1 + 5.0 pom provided @@ -45,25 +45,25 @@ org.junit.jupiter junit-jupiter - 5.8.1 + 5.8.2 test - org.apache.cxf - cxf-rt-rs-client - 3.4.5 + org.jboss.resteasy + resteasy-client + 6.0.0.Final test - org.apache.cxf - cxf-rt-rs-extension-providers - 3.4.5 + org.jboss.resteasy + resteasy-json-binding-provider + 6.0.0.Final test org.glassfish - javax.json - 1.1.4 + jakarta.json + 2.0.1 test diff --git a/start/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java b/start/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java index fddcc67c..0e9e2f8c 100755 --- a/start/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java +++ b/start/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java @@ -1,6 +1,6 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2017 IBM Corporation and others. + * Copyright (c) 2017, 2022 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,11 +9,11 @@ * Contributors: * IBM Corporation - Initial implementation *******************************************************************************/ - // end::copyright[] +// end::copyright[] package io.openliberty.guides.inventory; -import javax.ws.rs.ApplicationPath; -import javax.ws.rs.core.Application; +import jakarta.ws.rs.ApplicationPath; +import jakarta.ws.rs.core.Application; @ApplicationPath("inventory") public class InventoryApplication extends Application { diff --git a/start/src/main/java/io/openliberty/guides/inventory/InventoryManager.java b/start/src/main/java/io/openliberty/guides/inventory/InventoryManager.java index 6d60fc51..2378941d 100644 --- a/start/src/main/java/io/openliberty/guides/inventory/InventoryManager.java +++ b/start/src/main/java/io/openliberty/guides/inventory/InventoryManager.java @@ -1,22 +1,33 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2017, 2022 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Initial implementation + *******************************************************************************/ +// end::copyright[] package io.openliberty.guides.inventory; import java.util.Properties; -import javax.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.ApplicationScoped; import io.openliberty.guides.inventory.model.InventoryList; @ApplicationScoped public class InventoryManager { + public Properties get(String hostname) { + return null; + } - public Properties get(String hostname) { - return null; - } + public void add(String hostname, Properties props) { - public void add(String hostname, Properties props) { - } + } - public InventoryList list() { - return null; - } - + public InventoryList list() { + return null; + } } diff --git a/start/src/main/java/io/openliberty/guides/inventory/InventoryResource.java b/start/src/main/java/io/openliberty/guides/inventory/InventoryResource.java index d0c0b881..a4cf2795 100755 --- a/start/src/main/java/io/openliberty/guides/inventory/InventoryResource.java +++ b/start/src/main/java/io/openliberty/guides/inventory/InventoryResource.java @@ -1,6 +1,6 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2017, 2020 IBM Corporation and others. + * Copyright (c) 2017, 2022 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,14 +13,14 @@ package io.openliberty.guides.inventory; import java.util.Properties; -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; +import jakarta.enterprise.context.RequestScoped; +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; import io.openliberty.guides.inventory.model.InventoryList; // tag::RequestScoped[] @@ -42,7 +42,7 @@ public Response getPropertiesForHost(@PathParam("hostname") String hostname) { Properties props = manager.get(hostname); if (props == null) { return Response.status(Response.Status.NOT_FOUND) - .entity("{ \"error\" : \"Unknown hostname or the system service " + .entity("{ \"error\" : \"Unknown hostname or the system service " + "may not be running on " + hostname + "\" }") .build(); } diff --git a/start/src/main/java/io/openliberty/guides/inventory/model/InventoryList.java b/start/src/main/java/io/openliberty/guides/inventory/model/InventoryList.java index 2a562109..685cd333 100755 --- a/start/src/main/java/io/openliberty/guides/inventory/model/InventoryList.java +++ b/start/src/main/java/io/openliberty/guides/inventory/model/InventoryList.java @@ -1,6 +1,6 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2017, 2018 IBM Corporation and others. + * Copyright (c) 2017, 2022 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/start/src/main/java/io/openliberty/guides/inventory/model/SystemData.java b/start/src/main/java/io/openliberty/guides/inventory/model/SystemData.java index 47647ec4..e3fc03cc 100644 --- a/start/src/main/java/io/openliberty/guides/inventory/model/SystemData.java +++ b/start/src/main/java/io/openliberty/guides/inventory/model/SystemData.java @@ -1,6 +1,6 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2017, 2020 IBM Corporation and others. + * Copyright (c) 2017, 2022 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/start/src/main/java/io/openliberty/guides/system/SystemApplication.java b/start/src/main/java/io/openliberty/guides/system/SystemApplication.java index 5070fc0f..d3444518 100755 --- a/start/src/main/java/io/openliberty/guides/system/SystemApplication.java +++ b/start/src/main/java/io/openliberty/guides/system/SystemApplication.java @@ -1,6 +1,6 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2017 IBM Corporation and others. + * Copyright (c) 2017, 2022 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,11 +9,11 @@ * Contributors: * IBM Corporation - Initial implementation *******************************************************************************/ - // end::copyright[] +// end::copyright[] package io.openliberty.guides.system; -import javax.ws.rs.core.Application; -import javax.ws.rs.ApplicationPath; +import jakarta.ws.rs.core.Application; +import jakarta.ws.rs.ApplicationPath; @ApplicationPath("system") public class SystemApplication extends Application { diff --git a/start/src/main/java/io/openliberty/guides/system/SystemResource.java b/start/src/main/java/io/openliberty/guides/system/SystemResource.java index e299dbce..3dcea8cf 100755 --- a/start/src/main/java/io/openliberty/guides/system/SystemResource.java +++ b/start/src/main/java/io/openliberty/guides/system/SystemResource.java @@ -1,6 +1,6 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2017, 2018 IBM Corporation and others. + * Copyright (c) 2017, 2022 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,11 +13,11 @@ package io.openliberty.guides.system; import java.util.Properties; -import javax.enterprise.context.RequestScoped; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; +import jakarta.enterprise.context.RequestScoped; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; @RequestScoped @Path("/properties") diff --git a/start/src/main/liberty/config/server.xml b/start/src/main/liberty/config/server.xml index 7a6b804a..0c81d928 100755 --- a/start/src/main/liberty/config/server.xml +++ b/start/src/main/liberty/config/server.xml @@ -1,12 +1,13 @@ - jaxrs-2.1 - jsonp-1.1 - cdi-2.0 - mpConfig-2.0 + restfulWS-3.0 + jsonp-2.0 + jsonb-2.0 + cdi-3.0 + mpConfig-3.0 - mpRestClient-2.0 + mpRestClient-3.0 @@ -17,4 +18,4 @@ id="defaultHttpEndpoint"/> - \ No newline at end of file + diff --git a/start/src/main/webapp/index.html b/start/src/main/webapp/index.html index e71b0aaa..a887af28 100755 --- a/start/src/main/webapp/index.html +++ b/start/src/main/webapp/index.html @@ -1,5 +1,5 @@