Skip to content

Add MethodInterceptor extension point with feign-validation and feign-http-cache modules#3346

Merged
velo merged 5 commits into
masterfrom
method-interceptor
May 7, 2026
Merged

Add MethodInterceptor extension point with feign-validation and feign-http-cache modules#3346
velo merged 5 commits into
masterfrom
method-interceptor

Conversation

@velo
Copy link
Copy Markdown
Member

@velo velo commented May 7, 2026

Summary

  • New feign.MethodInterceptor extension point: an around-style interceptor that wraps the entire HTTP exchange after Contract resolution. It has access to raw method arguments, MethodMetadata, the resolved RequestTemplate, and (after chain.next() completes) the captured Response. Marked @Experimental.
  • New feign-validation and feign-validation-jakarta modules: BeanValidationMethodInterceptor runs JSR-303 / Jakarta Bean Validation against the body argument and any @Valid-annotated parameters before the request is dispatched. Constraint violations surface as ConstraintViolationException.
  • New feign-http-cache module: HttpCacheInterceptor adds conditional If-None-Match / If-Modified-Since headers, stores 2xx responses with ETag / Last-Modified validators, and short-circuits to the cached value on 304 Not Modified. Pluggable HttpCacheStore SPI plus an InMemoryHttpCacheStore default.

Why

RequestInterceptor only sees the encoded RequestTemplate; ResponseInterceptor only sees the response. Use cases like body validation (needs the typed object before encoding) and HTTP cache (needs both the request and the response, and may short-circuit) needed a third extension point. The two new modules ship as flagship implementations.

Test plan

  • mvn -Pdev clean install -DskipITs (full reactor, 54 modules, all green)
  • core/src/test/java/feign/MethodInterceptorTest.java covers chain order, short-circuit, exception propagation, and Invocation.response() visibility.
  • Validation modules tested for: valid body passes, invalid body throws before any request is sent, @Valid on non-body parameters honoured, no-arg methods pass through.
  • HTTP cache tested for: ETag / Last-Modified storage, 304 short-circuit, fresh 200 replaces cached entry, non-validators not stored, POST bypasses, Cache-Control: no-store skipped, 5xx propagates without evicting.

velo added 5 commits May 7, 2026 09:55
…-http-cache modules

Signed-off-by: Marvin Froeder <velo.br@gmail.com>
Signed-off-by: Marvin Froeder <velo.br@gmail.com>
Signed-off-by: Marvin Froeder <velo.br@gmail.com>
Signed-off-by: Marvin Froeder <velo.br@gmail.com>
…re regex, annotation cache)

Signed-off-by: Marvin Froeder <velo.br@gmail.com>
@velo velo merged commit 5345da5 into master May 7, 2026
4 checks passed
@velo velo deleted the method-interceptor branch May 7, 2026 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant