2.1 KiB
2.1 KiB
Advanced Context Extraction: Payloads and Interceptors
1. Incoming Payload Analysis
To understand what data drives the state machine, we need to capture metadata about the incoming parameters at entry points.
REST Endpoints
For methods annotated with @PostMapping, @PutMapping, etc.:
- Extract Parameters: Scan method parameters for
@RequestBody,@PathVariable, or@RequestParam. - Type Extraction: Capture the FQN of the parameter type (e.g.,
com.example.OrderRequest). - Data Linkage: If a field from this payload is used in a
sendEvent(payload.getEvent())call, mark the transition as "Dynamic based on Payload".
Message Listeners
For @RabbitListener or @JmsListener:
- Identify the parameter receiving the message body.
- Extract its type and any
@Headeror@Payloadannotations.
2. Interceptor and Filter Analysis
Interceptors often perform cross-cutting logic (authentication, context injection) that affects how state machines are driven.
Discovery Strategy
- Find Interceptors: Scan for classes implementing
HandlerInterceptororWebRequestInterceptor. - Registration Mapping: Look for
WebMvcConfigurer.addInterceptors()calls to identify which URL patterns each interceptor applies to. - Context Injection: Analyze if the interceptor modifies the request (e.g.,
request.setAttribute("userContext", ...)) or populates aThreadLocal(likeSecurityContextHolder).
Linking to State Machines
If a controller uses a value from a known Interceptor-injected context to decide which event to send or which state machine to restore, we can link the Interceptor's logic to the State Machine flow.
3. Implementation in EnrichmentService
We will introduce a ContextEnricher that:
- Builds a map of Active Interceptors per path.
- Augments
EntryPointmetadata with Payload Type information.
4. Modeling Updates
Update EntryPoint and TriggerPoint to include payloadType and interceptors.
public record EntryPoint(
// ... existing fields ...
String payloadType,
List<String> activeInterceptors
) {}