Last active
April 17, 2025 20:16
-
-
Save jwmatthews/e74d8dbcd7a37fc18220ad4af17053bc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
codex | |
I’ve converted the EAP monolith into a Quarkus-based application: | |
• Removed all WebLogic/EJB-specific classes (MDBs, startup listeners, JNDI lookups). | |
• Migrated service beans (@Stateless/@Stateful) to CDI (@ApplicationScoped), inlined shipping and order persistence (no more remote EJBs or JMS). | |
• Swapped out JMS-based order processing for direct JPA persistence via a CDI processor. | |
• Reworked the POM: | |
– Changed packaging from WAR to JAR. | |
– Imported the Quarkus BOM and added core Quarkus extensions (RESTEasy, Jackson, Hibernate ORM, JDBC‐PostgreSQL, Flyway, JSON-P, JMS). | |
– Added the Quarkus Maven plugin for quarkus:dev and native builds. | |
• Moved the Angular/Static UI from src/main/webapp to src/main/resources/META-INF/resources so Quarkus will serve it as static content. | |
• Introduced application.properties with in‐memory H2 datasource and Flyway settings to replace the old DataBaseMigrationStartup. | |
Next steps: | |
1. Adjust `application.properties` for your real target DB (PostgreSQL or others) and credentials. | |
2. Refine CORS, security (Keycloak OIDC), and any missing reactive‐messaging or Kafka adapters if you still need async flows. | |
3. Run `mvn clean package quarkus:dev` and verify functionality end‐to‐end. | |
diff --git a/pom.xml b/pom.xml | |
index 0e760b8..56d78d1 100644 | |
--- a/pom.xml | |
+++ b/pom.xml | |
@@ -13,39 +13,69 @@ | |
<maven.build.timestamp.format>yyyyMMdd'T'HHmmss</maven.build.timestamp.format> | |
<project.encoding>UTF-8</project.encoding> | |
<maven.test.skip>true</maven.test.skip> | |
+ <!-- Quarkus platform version --> | |
+ <quarkus.platform.version>2.16.7.Final</quarkus.platform.version> | |
+ <quarkus-plugin.version>${quarkus.platform.version}</quarkus-plugin.version> | |
</properties> | |
+ <dependencyManagement> | |
+ <dependencies> | |
+ <dependency> | |
+ <groupId>io.quarkus</groupId> | |
+ <artifactId>quarkus-bom</artifactId> | |
+ <version>${quarkus-plugin.version}</version> | |
+ <type>pom</type> | |
+ <scope>import</scope> | |
+ </dependency> | |
+ </dependencies> | |
+ </dependencyManagement> | |
<dependencies> | |
+ <!-- Quarkus extensions --> | |
<dependency> | |
- <groupId>javax</groupId> | |
- <artifactId>javaee-web-api</artifactId> | |
- <version>7.0</version> | |
- <scope>provided</scope> | |
+ <groupId>io.quarkus</groupId> | |
+ <artifactId>quarkus-resteasy</artifactId> | |
</dependency> | |
<dependency> | |
- <groupId>javax</groupId> | |
- <artifactId>javaee-api</artifactId> | |
- <version>7.0</version> | |
- <scope>provided</scope> | |
+ <groupId>io.quarkus</groupId> | |
+ <artifactId>quarkus-resteasy-jackson</artifactId> | |
</dependency> | |
<dependency> | |
- <groupId>org.jboss.spec.javax.jms</groupId> | |
- <artifactId>jboss-jms-api_2.0_spec</artifactId> | |
- <version>2.0.0.Final</version> | |
+ <groupId>io.quarkus</groupId> | |
+ <artifactId>quarkus-hibernate-orm</artifactId> | |
</dependency> | |
<dependency> | |
- <groupId>org.flywaydb</groupId> | |
- <artifactId>flyway-core</artifactId> | |
- <version>4.1.2</version> | |
+ <groupId>io.quarkus</groupId> | |
+ <artifactId>quarkus-jdbc-postgresql</artifactId> | |
</dependency> | |
<dependency> | |
- <groupId>org.jboss.spec.javax.rmi</groupId> | |
- <artifactId>jboss-rmi-api_1.0_spec</artifactId> | |
- <version>1.0.2.Final</version> | |
+ <groupId>io.quarkus</groupId> | |
+ <artifactId>quarkus-flyway</artifactId> | |
+ </dependency> | |
+ <dependency> | |
+ <groupId>io.quarkus</groupId> | |
+ <artifactId>quarkus-jsonp</artifactId> | |
+ </dependency> | |
+ <dependency> | |
+ <groupId>io.quarkus</groupId> | |
+ <artifactId>quarkus-smallrye-reactive-messaging-jms</artifactId> | |
</dependency> | |
</dependencies> | |
<build> | |
<finalName>ROOT</finalName> | |
<plugins> | |
+ <!-- Quarkus Maven Plugin --> | |
+ <plugin> | |
+ <groupId>io.quarkus</groupId> | |
+ <artifactId>quarkus-maven-plugin</artifactId> | |
+ <version>${quarkus-plugin.version}</version> | |
+ <executions> | |
+ <execution> | |
+ <goals> | |
+ <goal>build</goal> | |
+ <goal>dev</goal> | |
+ </goals> | |
+ </execution> | |
+ </executions> | |
+ </plugin> | |
<plugin> | |
<artifactId>maven-compiler-plugin</artifactId> | |
<version>3.0</version> | |
diff --git a/src/main/java/com/redhat/coolstore/rest/CartEndpoint.java b/src/main/java/com/redhat/coolstore/rest/CartEndpoint.java | |
index f82283b..9a184c6 100644 | |
--- a/src/main/java/com/redhat/coolstore/rest/CartEndpoint.java | |
+++ b/src/main/java/com/redhat/coolstore/rest/CartEndpoint.java | |
@@ -6,7 +6,7 @@ import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
-import javax.enterprise.context.SessionScoped; | |
+import javax.enterprise.context.ApplicationScoped; | |
import javax.inject.Inject; | |
import javax.ws.rs.DELETE; | |
import javax.ws.rs.GET; | |
@@ -21,7 +21,7 @@ import com.redhat.coolstore.model.ShoppingCart; | |
import com.redhat.coolstore.model.ShoppingCartItem; | |
import com.redhat.coolstore.service.ShoppingCartService; | |
-@SessionScoped | |
+@ApplicationScoped | |
@Path("/cart") | |
public class CartEndpoint implements Serializable { | |
diff --git a/src/main/java/com/redhat/coolstore/service/CatalogService.java b/src/main/java/com/redhat/coolstore/service/CatalogService.java | |
index 422a3f4..4612485 100644 | |
--- a/src/main/java/com/redhat/coolstore/service/CatalogService.java | |
+++ b/src/main/java/com/redhat/coolstore/service/CatalogService.java | |
@@ -9,12 +9,12 @@ import javax.persistence.criteria.CriteriaBuilder; | |
import javax.persistence.criteria.CriteriaQuery; | |
import javax.persistence.criteria.Root; | |
-import javax.ejb.Stateless; | |
+import javax.enterprise.context.ApplicationScoped; | |
import javax.persistence.EntityManager; | |
import com.redhat.coolstore.model.*; | |
-@Stateless | |
+@ApplicationScoped | |
public class CatalogService { | |
@Inject | |
diff --git a/src/main/java/com/redhat/coolstore/service/OrderService.java b/src/main/java/com/redhat/coolstore/service/OrderService.java | |
index 748e413..f4a327d 100644 | |
--- a/src/main/java/com/redhat/coolstore/service/OrderService.java | |
+++ b/src/main/java/com/redhat/coolstore/service/OrderService.java | |
@@ -2,14 +2,14 @@ package com.redhat.coolstore.service; | |
import com.redhat.coolstore.model.Order; | |
import java.util.List; | |
-import javax.ejb.Stateless; | |
+import javax.enterprise.context.ApplicationScoped; | |
import javax.inject.Inject; | |
import javax.persistence.EntityManager; | |
import javax.persistence.criteria.CriteriaBuilder; | |
import javax.persistence.criteria.CriteriaQuery; | |
import javax.persistence.criteria.Root; | |
-@Stateless | |
+@ApplicationScoped | |
public class OrderService { | |
@Inject | |
diff --git a/src/main/java/com/redhat/coolstore/service/ProductService.java b/src/main/java/com/redhat/coolstore/service/ProductService.java | |
index 33002fd..8aedad2 100644 | |
--- a/src/main/java/com/redhat/coolstore/service/ProductService.java | |
+++ b/src/main/java/com/redhat/coolstore/service/ProductService.java | |
@@ -4,14 +4,14 @@ import com.redhat.coolstore.model.CatalogItemEntity; | |
import com.redhat.coolstore.model.Product; | |
import com.redhat.coolstore.utils.Transformers; | |
-import javax.ejb.Stateless; | |
+import javax.enterprise.context.ApplicationScoped; | |
import javax.inject.Inject; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
import static com.redhat.coolstore.utils.Transformers.toProduct; | |
-@Stateless | |
+@ApplicationScoped | |
public class ProductService { | |
@Inject | |
diff --git a/src/main/java/com/redhat/coolstore/service/ShippingService.java b/src/main/java/com/redhat/coolstore/service/ShippingService.java | |
index c820fcd..e574fd3 100644 | |
--- a/src/main/java/com/redhat/coolstore/service/ShippingService.java | |
+++ b/src/main/java/com/redhat/coolstore/service/ShippingService.java | |
@@ -3,13 +3,11 @@ package com.redhat.coolstore.service; | |
import java.math.BigDecimal; | |
import java.math.RoundingMode; | |
-import javax.ejb.Remote; | |
-import javax.ejb.Stateless; | |
+import javax.enterprise.context.ApplicationScoped; | |
import com.redhat.coolstore.model.ShoppingCart; | |
-@Stateless | |
-@Remote | |
+@ApplicationScoped | |
public class ShippingService implements ShippingServiceRemote { | |
@Override | |
diff --git a/src/main/java/com/redhat/coolstore/service/ShoppingCartOrderProcessor.java b/src/main/java/com/redhat/coolstore/service/ShoppingCartOrderProcessor.java | |
index e6ee388..c1c93a2 100644 | |
--- a/src/main/java/com/redhat/coolstore/service/ShoppingCartOrderProcessor.java | |
+++ b/src/main/java/com/redhat/coolstore/service/ShoppingCartOrderProcessor.java | |
@@ -1,16 +1,19 @@ | |
package com.redhat.coolstore.service; | |
import java.util.logging.Logger; | |
-import javax.ejb.Stateless; | |
-import javax.annotation.Resource; | |
+import javax.enterprise.context.ApplicationScoped; | |
import javax.inject.Inject; | |
-import javax.jms.JMSContext; | |
-import javax.jms.Topic; | |
+import com.redhat.coolstore.model.ShoppingCart; | |
+import com.redhat.coolstore.model.Order; | |
+import com.redhat.coolstore.model.OrderItem; | |
+import com.redhat.coolstore.service.OrderService; | |
+import com.redhat.coolstore.service.CatalogService; | |
+import com.redhat.coolstore.utils.Transformers; | |
import com.redhat.coolstore.model.ShoppingCart; | |
import com.redhat.coolstore.utils.Transformers; | |
-@Stateless | |
+@ApplicationScoped | |
public class ShoppingCartOrderProcessor { | |
@Inject | |
@@ -18,16 +21,21 @@ public class ShoppingCartOrderProcessor { | |
@Inject | |
- private transient JMSContext context; | |
+ OrderService orderService; | |
- @Resource(lookup = "java:/topic/orders") | |
- private Topic ordersTopic; | |
+ @Inject | |
+ CatalogService catalogService; | |
- public void process(ShoppingCart cart) { | |
- log.info("Sending order from processor: "); | |
- context.createProducer().send(ordersTopic, Transformers.shoppingCartToJson(cart)); | |
+ public void process(ShoppingCart cart) { | |
+ log.info("Processing order for cart: " + cart); | |
+ String orderJson = Transformers.shoppingCartToJson(cart); | |
+ Order order = Transformers.jsonToOrder(orderJson); | |
+ orderService.save(order); | |
+ for (OrderItem oi : order.getItemList()) { | |
+ catalogService.updateInventoryItems(oi.getProductId(), oi.getQuantity()); | |
+ } | |
} | |
diff --git a/src/main/java/com/redhat/coolstore/service/ShoppingCartService.java b/src/main/java/com/redhat/coolstore/service/ShoppingCartService.java | |
index 06df53e..d195fa2 100644 | |
--- a/src/main/java/com/redhat/coolstore/service/ShoppingCartService.java | |
+++ b/src/main/java/com/redhat/coolstore/service/ShoppingCartService.java | |
@@ -1,19 +1,15 @@ | |
package com.redhat.coolstore.service; | |
-import java.util.Hashtable; | |
import java.util.logging.Logger; | |
- | |
-import javax.ejb.Stateful; | |
+import javax.enterprise.context.ApplicationScoped; | |
import javax.inject.Inject; | |
-import javax.naming.Context; | |
-import javax.naming.InitialContext; | |
-import javax.naming.NamingException; | |
+import com.redhat.coolstore.service.ShippingService; | |
import com.redhat.coolstore.model.Product; | |
import com.redhat.coolstore.model.ShoppingCart; | |
import com.redhat.coolstore.model.ShoppingCartItem; | |
-@Stateful | |
+@ApplicationScoped | |
public class ShoppingCartService { | |
@Inject | |
@@ -28,6 +24,9 @@ public class ShoppingCartService { | |
@Inject | |
ShoppingCartOrderProcessor shoppingCartOrderProcessor; | |
+ | |
+ @Inject | |
+ ShippingService shippingService; | |
private ShoppingCart cart = new ShoppingCart(); //Each user can have multiple shopping carts (tabbed browsing) | |
@@ -69,11 +68,11 @@ public class ShoppingCartService { | |
} | |
- sc.setShippingTotal(lookupShippingServiceRemote().calculateShipping(sc)); | |
+ sc.setShippingTotal(shippingService.calculateShipping(sc)); | |
if (sc.getCartItemTotal() >= 25) { | |
sc.setShippingTotal(sc.getShippingTotal() | |
- + lookupShippingServiceRemote().calculateShippingInsurance(sc)); | |
+ + shippingService.calculateShippingInsurance(sc)); | |
} | |
} | |
@@ -111,16 +110,5 @@ public class ShoppingCartService { | |
return productServices.getProductByItemId(itemId); | |
} | |
- private static ShippingServiceRemote lookupShippingServiceRemote() { | |
- try { | |
- final Hashtable<String, String> jndiProperties = new Hashtable<>(); | |
- jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory"); | |
- | |
- final Context context = new InitialContext(jndiProperties); | |
- | |
- return (ShippingServiceRemote) context.lookup("ejb:/ROOT/ShippingService!" + ShippingServiceRemote.class.getName()); | |
- } catch (NamingException e) { | |
- throw new RuntimeException(e); | |
- } | |
- } | |
+ // ShippingService is injected via CDI | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment