Chenile Interceptor Chain
Copied from [`chenile-core/docs/interceptor-chain.md`](https://github.com/ajapros/chenile-core/blob/main/docs/interceptor-chain.md) on 1 December 2026.
This document explains:
- where the interceptor chain is defined
- how OWIZ turns the XML into executable commands
- how a request moves through the chain at runtime
- how interpolation commands expand dynamically
Where the chain is defined
The concrete Chenile interceptor flow is in chenile-core/src/main/resources/org/chenile/core/chenile-core.xml.
It defines one default OWIZ flow, chenile-highway, whose first command is another command also named chenile-highway, and under that a nested chenile-interceptor-chain with the actual interceptor sequence.
<?xml version="1.0" encoding="UTF-8"?>
<flows>
<flow id='chenile-highway' defaultFlow="true">
<chenile-highway first="true">
<chenile-interceptor-chain>
<log-output/>
<generic-response-builder/>
<exception-handler-interpolation/>
<validate-copy-headers/>
<pre-processors-interpolation/>
<transformation-class-selector/>
<transformers-interpolation/>
<construct-service-reference/>
<post-processors-interpolation/>
<operation-specific-processors-interpolation/>
<service-specific-processors-interpolation/>
<service-invoker/>
</chenile-interceptor-chain>
</chenile-highway>
</flow>
</flows>
That file is loaded by chenile-core/src/main/java/org/chenile/configuration/core/ChenileCoreConfiguration.java, where chenileOrchExecutor() creates an XmlOrchConfigurator, points it at chenile.interceptors.path, and supplies a Spring bean lookup adapter.
How the XML becomes commands
OWIZ parses the XML in owiz/src/main/java/org/chenile/owiz/config/impl/XmlOrchConfigurator.java.
The important behavior is:
- XML tags become
CommandDescriptorobjects. - Tag names are converted from kebab-case to camelCase.
- That camelCase name is used as the component name if none is explicitly supplied.
- OWIZ first looks up a Spring bean by that component name.
- If Spring does not contain it, OWIZ tries to instantiate a class by that name.
That means these XML tags map directly to Spring beans:
<log-output/>->logOutput<generic-response-builder/>->genericResponseBuilder<construct-service-reference/>->constructServiceReference<service-invoker/>->serviceInvoker
Those beans are all created in chenile-core/src/main/java/org/chenile/configuration/core/ChenileCoreConfiguration.java.
Why the XML can be so short
Nested commands are automatically attached to their parent command. OWIZ infers the attachment from XML structure.
For example:
<chenile-highway first="true">
<chenile-interceptor-chain>
<log-output/>
<generic-response-builder/>
</chenile-interceptor-chain>
</chenile-highway>
is interpreted roughly as:
chenileHighwayis the first command in the flowchenileInterceptorChainis attached tochenileHighwaylogOutputis attached tochenileInterceptorChaingenericResponseBuilderis attached tochenileInterceptorChain
The chain parent is an OWIZ Chain, so the attachment order becomes execution order.
Fixed commands vs interpolation commands
Some entries in chenile-core.xml are regular commands. Some are interpolation commands.
Regular commands do work themselves:
validateCopyHeaderstransformationClassSelectortransformersInterpolation(expands into the transformers inchenile.transformers; defaultjsonTransformer)constructServiceReferenceserviceInvokergenericResponseBuilderlogOutput
Interpolation commands are placeholders that expand to a list of commands at runtime for the current ChenileExchange.
exceptionHandlerInterpolationpreProcessorsInterpolationpostProcessorsInterpolationoperationSpecificProcessorsInterpolationserviceSpecificProcessorsInterpolation
OWIZ detects this in owiz/src/main/java/org/chenile/owiz/impl/Chain.java. If a command is an InterpolationCommand, the chain asks it for the actual commands to execute for the current exchange and inserts those commands into the runtime sequence.
This is how Chenile mixes:
- a fixed pipeline shape from XML
- dynamic per-module, per-service, and per-operation interceptors from metadata
Where each interpolation command gets its list
The interpolation command classes are in chenile-core/src/main/java/org/chenile/core/interceptors/interpolations.
ExceptionHandlerInterpolation
Returns a one-element list containing the configured exception handler bean from ChenileConfiguration.
Source:
chenileConfiguration.getChenileExceptionHandler()
PreProcessorsInterpolation
Returns deployable-wide pre-processors configured in chenile.properties and resolved through Spring bean lookup.
Source:
chenileConfiguration.getPreProcessorCommands()
PostProcessorsInterpolation
Returns deployable-wide post-processors configured in chenile.properties.
Since 2.1.35, ChenileInterceptorValidator resolves pre-processors, post-processors and the exception handler once
all singletons exist, before the application takes traffic. Resolution is all or nothing:
- A missing bean fails with E526; a bean that is not a
Commandfails with E527. - Nothing is cached until every name resolves, so a bad name cannot leave a partial list behind.
chenile.interceptors.validate-on-startup=falsedefers resolution to the first request, with the same all-or-nothing rules.
Source:
chenileConfiguration.getPostProcessorCommands()
OperationSpecificProcessorsInterpolation
Returns the interceptor list attached directly to the selected OperationDefinition.
Source:
exchange.getOperationDefinition().getInterceptorCommands()
ServiceSpecificProcessorsInterpolation
Returns the interceptor list attached directly to the selected ChenileServiceDefinition.
Source:
exchange.getServiceDefinition().getInterceptorCommands()
This is the main reason the framework can keep one common XML skeleton while allowing each service and operation to contribute custom behavior.
Those service and operation interceptor lists typically originate in service-definition JSON or annotation-based registration. For the JSON format, see docs/service-definition-json.md.
For the detailed transformation flow behind transformationClassSelector, transformersInterpolation (any payload format, JSON by default), BodyTypeSelector, and subclass selection, see docs/transformation.md.
Runtime walkthrough for one HTTP request
An HTTP request enters at chenile-http/src/main/java/org/chenile/http/handler/HttpEntryPoint.java.
HttpEntryPoint builds a ChenileExchange by setting:
- service definition
- operation definition
- headers
- multipart files
- locale
- raw request body
It then calls chenileEntryPoint.execute(exchange).
chenile-core/src/main/java/org/chenile/core/entrypoint/ChenileEntryPoint.java hands that exchange to the OWIZ executor, which starts the chenile-highway flow.
Forward path
The request moves through the chain in this order:
logOutputgenericResponseBuilderexceptionHandlerInterpolationvalidateCopyHeaderspreProcessorsInterpolationtransformationClassSelectortransformersInterpolationconstructServiceReferencepostProcessorsInterpolationoperationSpecificProcessorsInterpolationserviceSpecificProcessorsInterpolationserviceInvoker
What each stage is doing:
logOutputenters and delegates.genericResponseBuilderenters and delegates.exceptionHandlerInterpolationexpands into configured exception-handling commands.validateCopyHeadersvalidates protected headers and copies allowed values into the context container.preProcessorsInterpolationinserts deployable-wide pre-processors fromChenileConfiguration.transformationClassSelectordetermines the Java body type.transformersInterpolationruns the configured transformers (by default the JSON transformer), which convert the request body into that type.constructServiceReferencechooses the target Spring bean and method, considering mock mode and trajectory overrides.postProcessorsInterpolationinserts deployable-wide post-processors.operationSpecificProcessorsInterpolationinserts interceptors configured on the selected operation.serviceSpecificProcessorsInterpolationinserts interceptors configured on the service.serviceInvokerconstructs the Java argument list and invokes the method reflectively.
Around-interceptor behavior
Most Chenile interceptors extend chenile-core/src/main/java/org/chenile/core/interceptors/BaseChenileInterceptor.java.
That base class implements a standard pattern:
- run
doPreProcessing(exchange) - continue the rest of the chain
- capture downstream exceptions into
exchange - run
doPostProcessing(exchange)infinally
That means many interceptors are not simple one-way filters. They behave like wrappers around the downstream chain.
This matters when reading chenile-core.xml:
- an interceptor near the top can still do important work after the service returns
genericResponseBuilderis intentionally near the top because it wraps almost the whole flowlogOutputcan log the final response state even though it appears before the service invocation
Why the response builder appears near the top
Several Chenile interceptors are around-interceptors. They execute logic before delegating, then execute more logic when control returns.
So the XML order is not a one-way pipeline. It is a nested call stack.
That is why generic-response-builder is near the top of the XML. It needs to wrap almost everything beneath it so it can convert the final success or failure into Chenile’s generic response format.
Return path
After serviceInvoker returns or throws, control unwinds back up the stack in reverse order.
The return path is conceptually:
- service-specific interceptors finish
- operation-specific interceptors finish
- global post-processors finish
constructServiceReferencecompletes- the transformers complete
- global pre-processors complete
- exception-handling wrapper sees any failure and normalizes it
genericResponseBuilderwraps success or error into the standard response and sets HTTP statuslogOutputlogs final result state
Finally control returns to HttpEntryPoint, which reads exchange.getResponse(), exchange.getException(), and exchange.getHttpResponseStatusCode() and writes the HTTP response.
Header and context handling
One early interceptor in the chain deserves special attention: validateCopyHeaders.
chenile-core/src/main/java/org/chenile/core/interceptors/ValidateCopyHeaders.java does two things:
- ensures a request id exists
- copies all external
x-...headers intoContextContainer
It also blocks incoming x-p-... headers. Those are treated as protected internal headers, and attempts to pass them from outside result in an error.
This is how Chenile propagates internal metadata across the rest of the pipeline while preserving a distinction between user-supplied headers and framework-internal headers.
The related helper chenile-core/src/main/java/org/chenile/core/context/PopulateContextContainer.java can copy values between ChenileExchange and ContextContainer when an exchange is built programmatically.
Practical mental model
Use this model when reading Chenile:
ChenileExchangeis the shared mutable request/response context.chenile-core.xmldefines the skeleton of execution.- interpolation commands inject dynamic interceptors based on the current service and operation metadata.
constructServiceReferencepicks the target bean.serviceInvokerperforms the actual method call.genericResponseBuilderstandardizes the output on the way back.ContextContaineris where framework-level request metadata is propagated after header validation.
Most relevant source files
chenile-core/src/main/resources/org/chenile/core/chenile-core.xmlchenile-core/src/main/java/org/chenile/configuration/core/ChenileCoreConfiguration.javachenile-core/src/main/java/org/chenile/core/entrypoint/ChenileEntryPoint.javachenile-core/src/main/java/org/chenile/core/interceptors/BaseChenileInterceptor.javachenile-core/src/main/java/org/chenile/core/interceptors/ConstructServiceReference.javachenile-core/src/main/java/org/chenile/core/interceptors/ServiceInvoker.javachenile-core/src/main/java/org/chenile/core/interceptors/GenericResponseBuilder.javachenile-core/src/main/java/org/chenile/core/interceptors/ValidateCopyHeaders.javachenile-core/src/main/java/org/chenile/core/interceptors/interpolations/PreProcessorsInterpolation.javachenile-core/src/main/java/org/chenile/core/interceptors/interpolations/PostProcessorsInterpolation.javachenile-core/src/main/java/org/chenile/core/interceptors/interpolations/OperationSpecificProcessorsInterpolation.javachenile-core/src/main/java/org/chenile/core/interceptors/interpolations/ServiceSpecificProcessorsInterpolation.javaowiz/src/main/java/org/chenile/owiz/config/impl/XmlOrchConfigurator.javaowiz/src/main/java/org/chenile/owiz/config/impl/HandleCommand.javaowiz/src/main/java/org/chenile/owiz/config/impl/HandleAttachment.javaowiz/src/main/java/org/chenile/owiz/impl/Chain.java
Response headers on the return journey
GenericResponseBuilder extracts ResponseHeadersAware metadata on success before wrapping the
service result. It stores validated headers separately from request headers in ChenileExchange.
Failures clear success metadata. Both HTTP adapters emit the exchange response headers and repeated
warning values. See Response headers for the service contract and precedence.