Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use versionless features #196

Open
wants to merge 20 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
canSkip: ${{ steps.Checker.outputs.canSkip }}
steps:
- name: Get files
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Get tools
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
path: tools/
repository: openliberty/guides-common
Expand Down Expand Up @@ -45,10 +45,11 @@ jobs:
working-directory: finish

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
distribution: 'semeru'
java-version: 11
- run: unset _JAVA_OPTIONS

Expand Down
2 changes: 1 addition & 1 deletion finish/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<version>6.1</version>
<version>7.0</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// tag::copyright[]
/*******************************************************************************
* Copyright (c) 2017, 2022 IBM Corporation and others.
* Copyright (c) 2017, 2025 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -35,9 +35,11 @@ public class InventoryUtil {
public static JsonObject getProperties(String hostname) {
Client client = ClientBuilder.newClient();
URI propURI = InventoryUtil.buildUri(hostname);
return client.target(propURI)
.request(MediaType.APPLICATION_JSON)
.get(JsonObject.class);
JsonObject properties = client.target(propURI)
.request(MediaType.APPLICATION_JSON)
.get(JsonObject.class);
client.close();
return properties;
}

// tag::buildLinksForHost[]
Expand Down Expand Up @@ -69,7 +71,7 @@ public static boolean responseOk(String hostname) {
HttpURLConnection http = (HttpURLConnection) target.openConnection();
http.setConnectTimeout(50);
int response = http.getResponseCode();
return (response != 200) ? false : true;
return response == 200;
} catch (Exception e) {
return false;
}
Expand Down
9 changes: 5 additions & 4 deletions finish/src/main/liberty/config/server.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<server description="Sample Liberty server">

<featureManager>
<feature>restfulWS-3.1</feature>
<feature>jsonb-3.0</feature>
<feature>jsonp-2.1</feature>
<feature>cdi-4.0</feature>
<platform>jakartaee-10.0</platform>
<feature>restfulWS</feature>
<feature>jsonb</feature>
<feature>jsonp</feature>
<feature>cdi</feature>
</featureManager>

<httpEndpoint host="*" httpPort="${http.port}" httpsPort="${https.port}" id="defaultHttpEndpoint"/>
Expand Down
Binary file added finish/src/main/webapp/favicon.ico
Binary file not shown.
10 changes: 5 additions & 5 deletions finish/src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ <h2>Eclipse MicroProfile</h2>
<p>
For more information about the features used in this application, see the Open Liberty documentation:
<ul>
<li><a href="https://openliberty.io/docs/ref/feature/#microProfile-6.1.html" target="_blank" rel="noopener noreferrer">MicroProfile 6.1</a></li>
<li><a href="https://openliberty.io/docs/ref/feature/#restfulWS-3.1.html" target="_blank" rel="noopener noreferrer">Jakarta RESTful Web Services 3.1</a></li>
<li><a href="https://openliberty.io/docs/ref/feature/#jsonp-2.1.html" target="_blank" rel="noopener noreferrer">Jakarta JSON Processing 2.1</a></li>
<li><a href="https://openliberty.io/docs/ref/feature/#cdi-4.0.html" target="_blank" rel="noopener noreferrer">Jakarta Contexts and Dependency Injection 4.0</a></li>
<li><a href="https://openliberty.io/docs/ref/feature/#jsonb-3.0.html" target="_blank" rel="noopener noreferrer">Jakarta JSON Binding 3.0</a></li>
<li><a href="https://openliberty.io/docs/ref/feature/#microProfile.html" target="_blank" rel="noopener noreferrer">MicroProfile</a></li>
<li><a href="https://openliberty.io/docs/ref/feature/#restfulWS.html" target="_blank" rel="noopener noreferrer">Jakarta RESTful Web Services</a></li>
<li><a href="https://openliberty.io/docs/ref/feature/#jsonp.html" target="_blank" rel="noopener noreferrer">Jakarta JSON Processing</a></li>
<li><a href="https://openliberty.io/docs/ref/feature/#cdi.html" target="_blank" rel="noopener noreferrer">Jakarta Contexts and Dependency Injection</a></li>
<li><a href="https://openliberty.io/docs/ref/feature/#jsonb.html" target="_blank" rel="noopener noreferrer">Jakarta JSON Binding</a></li>
</ul>
</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion start/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<version>6.1</version>
<version>7.0</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// tag::copyright[]
/*******************************************************************************
* Copyright (c) 2017, 2022 IBM Corporation and others.
* Copyright (c) 2017, 2025 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -22,18 +22,12 @@
import io.openliberty.guides.microprofile.util.InventoryUtil;
import io.openliberty.guides.microprofile.util.ReadyJson;

// tag::header[]
// tag::cdi-scope[]
@ApplicationScoped
// end::cdi-scope[]
public class InventoryManager {
// end::header[]

private ConcurrentMap<String, JsonObject> inv = new ConcurrentHashMap<>();

// tag::get[]
public JsonObject get(String hostname) {
// tag::method-contents[]
JsonObject properties = inv.get(hostname);
if (properties == null) {
if (InventoryUtil.responseOk(hostname)) {
Expand All @@ -44,21 +38,13 @@ public JsonObject get(String hostname) {
}
}
return properties;
// end::method-contents[]
}
// end::get[]

// tag::add[]
public void add(String hostname, JsonObject systemProps) {
// tag::method-contents[]
inv.putIfAbsent(hostname, systemProps);
// end::method-contents[]
}
// end::add[]

// tag::list[]
public JsonObject list() {
// tag::method-contents[]
JsonObjectBuilder systems = Json.createObjectBuilder();
inv.forEach((host, props) -> {
JsonObject systemProps = Json.createObjectBuilder()
Expand All @@ -70,8 +56,6 @@ public JsonObject list() {
systems.add("hosts", systems);
systems.add("total", inv.size());
return systems.build();
// end::method-contents[]
}
// end::list[]

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// tag::copyright[]
/*******************************************************************************
* Copyright (c) 2017, 2022 IBM Corporation and others.
* Copyright (c) 2017, 2025 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -20,38 +20,23 @@
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

// tag::header[]
// tag::cdi-scope[]
@ApplicationScoped
// end::cdi-scope[]
@Path("hosts")
public class InventoryResource {
// end::header[]

// tag::injection[]
@Inject
InventoryManager manager;
// end::injection[]

// tag::getPropertiesForHost[]
@GET
@Path("{hostname}")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject getPropertiesForHost(@PathParam("hostname") String hostname) {
// tag::method-contents[]
return manager.get(hostname);
// end::method-contents[]
}
// end::getPropertiesForHost[]

// tag::listContents[]
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonObject listContents() {
// tag::method-contents[]
return manager.list();
// end::method-contents[]
}
// end::listContents[]

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// tag::copyright[]
/*******************************************************************************
* Copyright (c) 2017, 2022 IBM Corporation and others.
* Copyright (c) 2017, 2025 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -30,9 +30,11 @@ public class InventoryUtil {
public static JsonObject getProperties(String hostname) {
Client client = ClientBuilder.newClient();
URI propURI = InventoryUtil.buildUri(hostname);
return client.target(propURI)
.request(MediaType.APPLICATION_JSON)
.get(JsonObject.class);
JsonObject properties = client.target(propURI)
.request(MediaType.APPLICATION_JSON)
.get(JsonObject.class);
client.close();
return properties;
}

public static boolean responseOk(String hostname) {
Expand All @@ -41,7 +43,7 @@ public static boolean responseOk(String hostname) {
HttpURLConnection http = (HttpURLConnection) target.openConnection();
http.setConnectTimeout(50);
int response = http.getResponseCode();
return (response != 200) ? false : true;
return response == 200;
} catch (Exception e) {
return false;
}
Expand Down
9 changes: 5 additions & 4 deletions start/src/main/liberty/config/server.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<server description="Sample Liberty server">

<featureManager>
<feature>restfulWS-3.1</feature>
<feature>jsonb-3.0</feature>
<feature>jsonp-2.1</feature>
<feature>cdi-4.0</feature>
<platform>jakartaee-10.0</platform>
<feature>restfulWS</feature>
<feature>jsonb</feature>
<feature>jsonp</feature>
<feature>cdi</feature>
</featureManager>

<httpEndpoint host="*" httpPort="${http.port}" httpsPort="${https.port}" id="defaultHttpEndpoint"/>
Expand Down
Binary file added start/src/main/webapp/favicon.ico
Binary file not shown.
10 changes: 5 additions & 5 deletions start/src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ <h2>Eclipse MicroProfile</h2>
<p>
For more information about the features used in this application, see the Open Liberty documentation:
<ul>
<li><a href="https://openliberty.io/docs/ref/feature/#microProfile-6.1.html" target="_blank" rel="noopener noreferrer">MicroProfile 6.1</a></li>
<li><a href="https://openliberty.io/docs/ref/feature/#restfulWS-3.1.html" target="_blank" rel="noopener noreferrer">Jakarta RESTful Web Services 3.1</a></li>
<li><a href="https://openliberty.io/docs/ref/feature/#jsonp-2.1.html" target="_blank" rel="noopener noreferrer">Jakarta JSON Processing 2.1</a></li>
<li><a href="https://openliberty.io/docs/ref/feature/#cdi-4.0.html" target="_blank" rel="noopener noreferrer">Jakarta Contexts and Dependency Injection 4.0</a></li>
<li><a href="https://openliberty.io/docs/ref/feature/#jsonb-3.0.html" target="_blank" rel="noopener noreferrer">Jakarta JSON Binding 3.0</a></li>
<li><a href="https://openliberty.io/docs/ref/feature/#microProfile.html" target="_blank" rel="noopener noreferrer">MicroProfile</a></li>
<li><a href="https://openliberty.io/docs/ref/feature/#restfulWS.html" target="_blank" rel="noopener noreferrer">Jakarta RESTful Web Services</a></li>
<li><a href="https://openliberty.io/docs/ref/feature/#jsonp.html" target="_blank" rel="noopener noreferrer">Jakarta JSON Processing</a></li>
<li><a href="https://openliberty.io/docs/ref/feature/#cdi.html" target="_blank" rel="noopener noreferrer">Jakarta Contexts and Dependency Injection</a></li>
<li><a href="https://openliberty.io/docs/ref/feature/#jsonb.html" target="_blank" rel="noopener noreferrer">Jakarta JSON Binding</a></li>
</ul>
</p>
</div>
Expand Down
Loading