feat: add Service-Oriented Architecture pattern (#2937) - #3600
Conversation
PR SummaryIntroduces a new service-oriented-architecture module implementing the SOA pattern in plain Java (no framework). Adds core building blocks (Service, ServiceRequest/ServiceResponse), a ServiceRegistry for discovery, a ServiceBus for routing with central cross-cutting concerns, and an AccessPolicy. Includes atomic services (Customer, Inventory, Payment) and a composite OrderService, plus an App bootstrap and 24 tests. Also adds documentation: README and UML diagrams. Updates parent pom to register the new module. Changes
autogenerated by presubmit.ai |
There was a problem hiding this comment.
🚨 Pull request needs attention.
Review Summary
Files Processed (22)
- pom.xml (1 hunk)
- service-oriented-architecture/README.md (1 hunk)
- service-oriented-architecture/etc/service-oriented-architecture.urm.puml (1 hunk)
- service-oriented-architecture/pom.xml (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/App.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/Customer.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/CustomerService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/InventoryService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/OrderService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/PaymentService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/Service.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceBus.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceRegistry.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceRequest.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceResponse.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/AppTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/CustomerServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/InventoryServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/OrderServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/PaymentServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/ServiceBusTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/ServiceRegistryTest.java (1 hunk)
Actionable Comments (4)
-
service-oriented-architecture/src/main/java/com/iluwatar/soa/App.java [61-61]
best_practice: "Fix incorrect logger usage in App.java"
-
service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceBus.java [57-57]
best_practice: "Logger usage mismatch with Lombok @slf4j in ServiceBus"
-
service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceRegistry.java [56-56]
best_practice: "Logger usage mismatch in ServiceRegistry"
-
service-oriented-architecture/src/main/java/com/iluwatar/soa/InventoryService.java [93-101]
possible bug: "Malformed string concatenation in reserve() error path"
Skipped Comments (0)
|
Note on the automated review comments: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3600 +/- ##
============================================
+ Coverage 83.79% 84.03% +0.24%
- Complexity 4277 4352 +75
============================================
Files 1121 1132 +11
Lines 15144 15343 +199
Branches 723 739 +16
============================================
+ Hits 12690 12894 +204
+ Misses 2159 2155 -4
+ Partials 295 294 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
993cea1 to
84e5c17
Compare
|
Updated the branch to cover point 8 (Security) of the issue guidelines: the bus now enforces an |
There was a problem hiding this comment.
🚨 Pull request needs attention.
Review Summary
Files Processed (24)
- pom.xml (1 hunk)
- service-oriented-architecture/README.md (1 hunk)
- service-oriented-architecture/etc/service-oriented-architecture.urm.puml (1 hunk)
- service-oriented-architecture/pom.xml (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/AccessPolicy.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/App.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/Customer.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/CustomerService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/InventoryService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/OrderService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/PaymentService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/Service.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceBus.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceRegistry.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceRequest.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceResponse.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/AccessPolicyTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/AppTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/CustomerServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/InventoryServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/OrderServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/PaymentServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/ServiceBusTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/ServiceRegistryTest.java (1 hunk)
Actionable Comments (1)
-
service-oriented-architecture/pom.xml [46-50]
enhancement: "Missing JUnit Jupiter API test dependency"
Skipped Comments (0)
84e5c17 to
453f532
Compare
|
Follow-up on the Codecov note: added |
There was a problem hiding this comment.
🚨 Pull request needs attention.
Review Summary
Files Processed (24)
- pom.xml (1 hunk)
- service-oriented-architecture/README.md (1 hunk)
- service-oriented-architecture/etc/service-oriented-architecture.urm.puml (1 hunk)
- service-oriented-architecture/pom.xml (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/AccessPolicy.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/App.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/Customer.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/CustomerService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/InventoryService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/OrderService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/PaymentService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/Service.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceBus.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceRegistry.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceRequest.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceResponse.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/AccessPolicyTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/AppTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/CustomerServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/InventoryServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/OrderServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/PaymentServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/ServiceBusTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/ServiceRegistryTest.java (1 hunk)
Actionable Comments (1)
-
service-oriented-architecture/src/main/java/com/iluwatar/soa/InventoryService.java [92-100]
possible bug: "Fix potential string concatenation bug in error message"
Skipped Comments (8)
-
service-oriented-architecture/src/main/java/com/iluwatar/soa/App.java [67-67]
best_practice: "Logger usage mismatch with Lombok @slf4j"
-
service-oriented-architecture/src/main/java/com/iluwatar/soa/App.java [76-76]
best_practice: "Replace LOGGER with log when using @slf4j"
-
service-oriented-architecture/src/main/java/com/iluwatar/soa/App.java [78-78]
best_practice: "Consistent logging with Lombok"
-
service-oriented-architecture/src/main/java/com/iluwatar/soa/App.java [88-88]
best_practice: "Consistent logging with Lombok"
-
service-oriented-architecture/src/main/java/com/iluwatar/soa/App.java [98-98]
best_practice: "Consistent logging with Lombok"
-
service-oriented-architecture/src/main/java/com/iluwatar/soa/App.java [102-102]
best_practice: "Consistent logging with Lombok"
-
service-oriented-architecture/src/main/java/com/iluwatar/soa/App.java [106-106]
best_practice: "Consistent logging with Lombok"
-
service-oriented-architecture/pom.xml [36-50]
test: "Add junit-jupiter-api as test dependency"
453f532 to
bf16d6e
Compare
|
Coverage follow-up: added |
There was a problem hiding this comment.
✅ LGTM!
Review Summary
Files Processed (24)
- pom.xml (1 hunk)
- service-oriented-architecture/README.md (1 hunk)
- service-oriented-architecture/etc/service-oriented-architecture.urm.puml (1 hunk)
- service-oriented-architecture/pom.xml (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/AccessPolicy.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/App.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/Customer.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/CustomerService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/InventoryService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/OrderService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/PaymentService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/Service.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceBus.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceRegistry.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceRequest.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceResponse.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/AccessPolicyTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/AppTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/CustomerServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/InventoryServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/OrderServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/PaymentServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/ServiceBusTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/ServiceRegistryTest.java (1 hunk)
Actionable Comments (0)
Skipped Comments (5)
-
service-oriented-architecture/src/main/java/com/iluwatar/soa/App.java [67-70]
best_practice: "Use the correct Lombok logger field"
-
service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceBus.java [66-92]
best_practice: "Logger usage should use the Lombok-provided 'log' field"
-
service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceRegistry.java [51-57]
best_practice: "Logger usage should use the Lombok-provided 'log' field"
-
service-oriented-architecture/src/main/java/com/iluwatar/soa/InventoryService.java [93-98]
readability: "Clarify error message construction"
-
service-oriented-architecture/pom.xml [36-39]
best_practice: "Add junit-jupiter-api test dependency"
There was a problem hiding this comment.
🚨 Pull request needs attention.
Review Summary
Commits Considered (4)
- 12e9aa7: fix: surface the inventory error when the stock check fails
OrderService reported every failed stock check as insufficient stock, which hid the real reason, for example a non-positive quantity. It now forwards the inventory message and only reports insufficient stock when the check itself succeeded.
- 23462b6: docs: embed the rendered class diagram in the service-oriented-architecture README
Render etc/service-oriented-architecture.urm.puml to PNG and embed it in the detailed explanation section, matching the other modules, instead of the inline mermaid block.
- a88f9d8: chore: tidy service javadoc and use the customer id in confirmations
Reword the App class javadoc so it describes the services the same way as the Service contract and the README: they keep no per-conversation state instead of being called stateless.
Note in OrderService.placeOrder that the checkStock call is there to illustrate service composition and not as a guard, since reserve re-checks the stock atomically.
Carry the customer id into OrderConfirmation so the confirmation identifies the customer it belongs to, and drop the unused email component from the Customer record. Update the tests, the URM diagram and the sample output in the README accordingly.
-
83eb3c8: fix: reserve stock before charging and validate order quantity
-
OrderService now reserves stock before charging and releases the reservation when the charge fails, so a rejected order never leaves the customer charged.
-
InventoryService gains a release operation and rejects a non-positive quantity in checkStock, reserve and release.
-
ServiceBus applies the access policy before the registry lookup, so a denied caller cannot probe which services exist.
-
Corrected the statelessness and interoperability claims in the javadoc and the README.
-
Replaced the class diagram link with an inline mermaid diagram, refreshed the sample output and kept the puml in sync.
Files Processed (15)
- service-oriented-architecture/README.md (1 hunk)
- service-oriented-architecture/etc/service-oriented-architecture.urm.png (0 hunks)
- service-oriented-architecture/etc/service-oriented-architecture.urm.puml (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/App.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/Customer.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/CustomerService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/InventoryService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/OrderService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/Service.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceBus.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceRequest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/CustomerServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/InventoryServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/OrderServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/ServiceBusTest.java (1 hunk)
Actionable Comments (1)
-
service-oriented-architecture/src/main/java/com/iluwatar/soa/InventoryService.java [102-109]
bug: "Fix string concatenation in error message"
Skipped Comments (0)
12e9aa7 to
a569f16
Compare
The order flow is now reserve, charge, release on failure. Inventory rejects non-positive quantities and its errors are surfaced, the access policy runs before the registry lookup, the statelessness and interoperability wording is corrected, and confirmations carry the customer id. The class diagram is a rendered PNG.
a569f16 to
cd7ff04
Compare
There was a problem hiding this comment.
✅ LGTM!
Review Summary
Commits Considered (2)
- cd7ff04: fix: reserve stock before charging and validate order quantity
The order flow is now reserve, charge, release on failure. Inventory rejects non-positive quantities and its errors are surfaced, the access policy runs before the registry lookup, the statelessness and interoperability wording is corrected, and confirmations carry the customer id. The class diagram is a rendered PNG.
Files Processed (25)
- pom.xml (1 hunk)
- service-oriented-architecture/README.md (1 hunk)
- service-oriented-architecture/etc/service-oriented-architecture.urm.png (0 hunks)
- service-oriented-architecture/etc/service-oriented-architecture.urm.puml (1 hunk)
- service-oriented-architecture/pom.xml (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/AccessPolicy.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/App.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/Customer.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/CustomerService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/InventoryService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/OrderService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/PaymentService.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/Service.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceBus.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceRegistry.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceRequest.java (1 hunk)
- service-oriented-architecture/src/main/java/com/iluwatar/soa/ServiceResponse.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/AccessPolicyTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/AppTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/CustomerServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/InventoryServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/OrderServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/PaymentServiceTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/ServiceBusTest.java (1 hunk)
- service-oriented-architecture/src/test/java/com/iluwatar/soa/ServiceRegistryTest.java (1 hunk)
What does this PR do?
Adds the Service-Oriented Architecture (SOA) pattern as a new
service-oriented-architecturemodule, implemented in plain Java without frameworks so the architectural mechanism stays visible.Service: the contract every service exposes (name()andhandle(ServiceRequest)); services are stateless.ServiceRequest/ServiceResponse: coarse-grained, self-describing messages that form the interoperability boundary (flat payload, uniform response envelope).ServiceRegistry: discovery by name on aConcurrentHashMap, rejects duplicate registrations.ServiceBus: routes messages to the registered service, applies cross-cutting concerns (tracing, timing) in one place and translates provider failures into error responses, so consumers only ever talk to the bus.CustomerService,InventoryService,PaymentService: reusable atomic services.OrderService: composite service that orchestrates the three atomic services through the bus to place an order.App: bootstraps registry and bus, registers the services, places an order that succeeds, one that is rejected for stock, and addresses an unregistered service. Logging traces every message.README.md: intent, real-world example, diagram, code walkthrough, applicability, real-world uses (ESBs, SOAP/WSDL), trade-offs, related patterns including how SOA differs from microservices. PlantUML class diagram underetc/.AppTest.pom.xml../mvnw clean verify -pl service-oriented-architecturepasses locally on JDK 21 and inside aneclipse-temurin:21container.Fixes #2937