Skip to content

Code Examples with Detailed README.adoc for all Chapters (2–11) of MicroProfile Tutorial #20

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

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d3ecabf
Create index.adoc
ttelang Jan 26, 2025
c9ad38c
Add files via upload
ttelang Jan 26, 2025
c0d70b2
source code for chapter 03
ttelang Jan 26, 2025
f77c954
source code for chapter04
ttelang Jan 26, 2025
3d21f0c
source code for chapter04
ttelang Jan 26, 2025
4dd2079
Delete code/chapter04 directory
ttelang Jan 26, 2025
dfbae4a
source code for chapter04
ttelang Jan 26, 2025
16e0be8
Source code for chapter 05
ttelang Jan 26, 2025
4e87f95
Source code for chapter06
ttelang Jan 26, 2025
d25c6db
source code for chapter07
ttelang Jan 26, 2025
a43b449
source code for chapter08
ttelang Jan 27, 2025
24de4c5
Delete code/chapter08/payment/target directory
ttelang Feb 6, 2025
dc66f49
Update pom.xml
ttelang Feb 27, 2025
75cd6fd
Update pom.xml
ttelang Mar 1, 2025
f7397d5
Update pom.xml
ttelang May 13, 2025
4a9978c
Create README.adoc
ttelang May 13, 2025
31f588e
Create .devcontainer.json
ttelang May 13, 2025
a16a6fa
Create .gitignore
ttelang May 13, 2025
cf99866
Create chapter03/mp-ecomm-store/pom.xml
ttelang May 13, 2025
c5e13ee
Update server.xml
ttelang May 13, 2025
7005c37
Delete code/chapter03/mp-ecomm-store directory
ttelang May 14, 2025
2440585
Create dummy
ttelang May 14, 2025
528c5ca
Add files via upload
ttelang May 14, 2025
207ce2f
Update README.adoc.original
ttelang May 14, 2025
5e118a5
Delete code/chapter03/catalog/README.adoc.original
ttelang May 14, 2025
53d782e
Update README.adoc
ttelang May 14, 2025
481379b
Delete code/chapter03/dummy
ttelang May 14, 2025
6344ce0
Create README.adoc
ttelang May 14, 2025
d0d7386
Create README.adoc
ttelang May 14, 2025
765740b
Update README.adoc
ttelang May 14, 2025
418df86
Create .gitignore
ttelang May 14, 2025
7cbe8a8
Create devcontainer.json
ttelang May 22, 2025
5355aa8
Update and document source code for Chapters 2–11
ttelang Jun 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
51 changes: 51 additions & 0 deletions .devcontainer/.devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/java
{
"name": "Microprofile",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/java:1-17-bookworm",

"features": {
"ghcr.io/devcontainers/features/java:1": {
"installMaven": true,
"version": "17",
"jdkDistro": "ms",
"gradleVersion": "latest",
"mavenVersion": "latest",
"antVersion": "latest",
"groovyVersion": "latest"
},
"ghcr.io/ebaskoro/devcontainer-features/sdkman:1": {
"candidate": "java",
"version": "latest"
},
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"moby": true,
"azureDnsAutoDetection": true,
"installDockerBuildx": true,
"installDockerComposeSwitch": true,
"version": "latest",
"dockerDashComposeVersion": "none"
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "java -version",

// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": [
"vscjava.vscode-java-pack",
"github.copilot",
"microprofile-community.vscode-microprofile-pack"
]
}
}

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
71 changes: 71 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

# Maven
log/
target/
release/
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties

# Gradle
.gradle/
build/
!gradle/wrapper/gradle-wrapper.jar

# Eclipse
.classpath
.project
.settings/

# IntelliJ
*.iml
.idea/
out/

# VS Code
.vscode/

# OS Files
.DS_Store
Thumbs.db

# Others
*.mf
*.swp
*.cs
*~

# Liberty
wlp/usr/servers/*/logs/
wlp/usr/servers/*/workarea/
wlp/usr/servers/*/dropins/
wlp/usr/servers/*/apps/
wlp/usr/servers/*/configDropins/

# Specific project directories
liberty-rest-app/target/
mp-ecomm-store/target/
53 changes: 53 additions & 0 deletions code/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/java
{
"name": "Microprofile",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/java:1-17-bookworm",

"features": {
"ghcr.io/devcontainers/features/java:1": {
"installMaven": true,
"version": "17",
"jdkDistro": "ms",
"gradleVersion": "latest",
"mavenVersion": "latest",
"antVersion": "latest",
"groovyVersion": "latest"
},
"ghcr.io/ebaskoro/devcontainer-features/sdkman:1": {
"candidate": "java",
"version": "latest"
},
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"moby": true,
"azureDnsAutoDetection": true,
"installDockerBuildx": true,
"installDockerComposeSwitch": true,
"version": "latest",
"dockerDashComposeVersion": "none"
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "java -version",

// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": [
"vscjava.vscode-java-pack",
"github.copilot",
"microprofile-community.vscode-microprofile-pack",
"asciidoctor.asciidoctor-vscode",
"ms-vscode-remote.remote-containers"
]
}
}

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
83 changes: 83 additions & 0 deletions code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Compiled class files
*.class

# Log files
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# Virtual machine crash logs
hs_err_pid*
replay_pid*

# Maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar

# Liberty
.liberty/
.factorypath
wlp/
liberty/

# IntelliJ IDEA
.idea/
*.iws
*.iml
*.ipr

# Eclipse
.apt_generated/
.settings/
.project
.classpath
.factorypath
.metadata/
bin/
tmp/

# VS Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# Test reports (keeping XML reports)
target/surefire-reports/junitreports/
target/surefire-reports/old/
target/site/
target/failsafe-reports/

# JaCoCo coverage reports except the main report
target/jacoco/
!target/site/jacoco/index.html

# Miscellaneous
*.swp
*.bak
*.tmp
*~
.DS_Store
Thumbs.db
134 changes: 134 additions & 0 deletions code/chapter02/mp-ecomm-store/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
= MicroProfile E-Commerce Store
:toc:
:icons: font
:source-highlighter: highlight.js
:experimental:

== Overview

This project demonstrates a MicroProfile-based e-commerce microservice. It provides REST endpoints for product management and showcases Jakarta EE 10 and MicroProfile 6.1 features in a practical application.

== Prerequisites

* JDK 17
* Maven 3.8+

== Development Environment

This project includes a GitHub Codespace configuration with:

* JDK 17 via SDKMAN
* Maven build tools
* VS Code extensions for Java and MicroProfile development

=== Switching Java Versions

The development container comes with SDKMAN installed, which allows easy switching between Java versions:

[source,bash]
----
# List installed Java versions
sdk list java | grep -E ".*\s+installed"

# Switch to JDK 17 for the current shell session
sdk use java 17.0.15-ms

# Make JDK 17 the default for all sessions
sdk default java 17.0.15-ms

# Verify the current Java version
java -version
----

== Project Structure

[source]
----
mp-ecomm-store/
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── io/microprofile/tutorial/store/product/
│ │ │ ├── entity/
│ │ │ │ └── Product.java
│ │ │ ├── resource/
│ │ │ │ └── ProductResource.java
│ │ │ └── ProductRestApplication.java
│ │ ├── liberty/config/
│ │ │ └── server.xml
│ │ └── webapp/
│ │ └── WEB-INF/
│ │ └── web.xml
│ └── test/
└── pom.xml
----

== REST Endpoints

[cols="2,1,3"]
|===
|Endpoint |Method |Description

|`/mp-ecomm-store/api/products`
|GET
|Returns a list of products in JSON format
|===

== Technology Stack

* Jakarta EE 10
* MicroProfile 6.1
* Open Liberty
* Lombok
* JUnit 5

== Model Class

The Product model demonstrates the use of Lombok annotations for boilerplate code reduction:

[source,java]
----
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Product {
private Long id;
private String name;
private String description;
private Double price;
}
----

== Building the Application

[source,bash]
----
mvn clean package
----

== Running the Application

=== Using Liberty Maven Plugin

[source,bash]
----
mvn liberty:dev
----

This starts Open Liberty server in development mode with hot reloading enabled, allowing for rapid development cycles.

=== Accessing the Application

Once the server is running, you can access:

* Products Endpoint: http://<hostname>:5050/mp-ecomm-store/api/products

Replace <hostname> with _localhost_ or the hostname of the system, where you are running this code.

== Features and Future Enhancements

Current features:

* Basic product listing functionality

* JSON-B serialization
Loading