feat: add Service-Oriented Architecture pattern (#2937) - #3600
Conversation
PR SummaryIntroduces a framework-free Service-Oriented Architecture (SOA) pattern as a new module. Adds core components (Service, ServiceRequest, ServiceResponse, ServiceRegistry, ServiceBus, AccessPolicy) and atomic services (CustomerService, InventoryService, PaymentService) plus a composite OrderService. Includes App bootstrap, 24 JUnit 5 tests, a PlantUML class diagram, and README. The new module is wired into the parent Maven POM and demonstrates end-to-end orchestration with logging. 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)
| * @param args command line arguments, not used | ||
| */ | ||
| public static void main(String[] args) { | ||
| LOGGER.info("Bootstrapping the service registry and the service bus"); |
There was a problem hiding this comment.
In a class annotated with @slf4j, Lombok provides a "log" field, not "LOGGER". This will fail compilation. Replace with log.info(...) (and align all other LOGGER usages in this file to log).
| LOGGER.warn("No service registered under '{}'", request.service()); | ||
| return ServiceResponse.error("No such service: " + request.service()); | ||
| } | ||
| LOGGER.info("-> {}.{} payload={}", request.service(), request.operation(), request.payload()); |
There was a problem hiding this comment.
Logger usage should be "log" instead of "LOGGER" when using @slf4j. Update to log.info(...) to compile and to follow project conventions.
| if (previous != null) { | ||
| throw new IllegalStateException("Service already registered: " + service.name()); | ||
| } | ||
| LOGGER.info("Registered service '{}' ({})", service.name(), service.getClass().getSimpleName()); |
There was a problem hiding this comment.
Same Lombok-based logger usage issue in ServiceRegistry. Replace with log.info(...) to compile and adopt a consistent logging approach.
| "Insufficient stock for " | ||
| + sku | ||
| + ": requested " | ||
| + quantity | ||
| + ", available " | ||
| + (remaining == null ? 0 : remaining)); | ||
| } | ||
| return ServiceResponse.ok(remaining); | ||
| } |
There was a problem hiding this comment.
There is a potential formatting / concatenation issue in the error message construction across multiple lines. The intended expression should be a single concatenation. Ensure there are no stray plus signs and that the message matches tests: "Insufficient stock for LAPTOP: requested 5, available 3".
|
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% 83.94% +0.15%
- Complexity 4277 4339 +62
============================================
Files 1121 1132 +11
Lines 15144 15325 +181
Branches 723 737 +14
============================================
+ Hits 12690 12865 +175
- Misses 2159 2162 +3
- Partials 295 298 +3 ☔ 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)
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-engine</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> |
There was a problem hiding this comment.
Add junit-jupiter-api as a test dependency since the module's tests rely on the JUnit Jupiter API (org.junit.jupiter.api). Without it, compilation and test execution may fail.
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"
| return ServiceResponse.error( | ||
| "Insufficient stock for " | ||
| + sku | ||
| + ": requested " | ||
| + quantity | ||
| + ", available " | ||
| + (remaining == null ? 0 : remaining)); | ||
| } | ||
| return ServiceResponse.ok(remaining); |
There was a problem hiding this comment.
Potential formatting issue in the error message construction. There is an extra '+' in '+ sku' which would cause a syntax error. Rebuild the string with a single concatenation expression.
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"
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