Have HandlerInterceptor being ScopedValue friendly #32837
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
status: waiting-for-triage
An issue we've not yet triaged or decided on
Hi
Since the arrival of Java 21 and the virtual threads, I'm trying to make the most use of it while working on a Proof Of Concept
My goal is to :
springthreads.virtual.enabled: true
flagStructuredTaskScope
ScopedValue
I've reached the third step and globally everything is going pretty smoothly.
Unfortunately, I've hit a corner case for which one, so far, I can't see any straightforward way to work around ... at least without changing Spring boot framework
This case is the following :
Setup an
HandlerInterceptor
that init aScopedValue
according to the received request's propertiesBy design I guess, the current ScopedValue API disallow accessing to Scoped Value outside of the lambas passed to its
run
,call
orget(Supplier<? extends R> op)
methods.I.E. the beast code I've managed to produce is this one :
Which, as you can see, fails on a
NoSuchElementException
Thus, the only solution I can imagine right now, with the current ScopedValue API constraints, is to find a way to have the rest of the processing chain been performed within the lambda passed to one of the previously mentionned methods :
But it would necessitate to really nest the subsequent interceptor's call, and thus, to change the way Spring Boot's
HandlerInterceptor
works.Maybe by introducing some kind of continuous passing style system, a bit like what is done in the Filters ?
For now on, I've decided to go for a
Filter
, but it don't feel rightMy two other options either defeat the purpose of my POC, or the point of using a
HandlerInterceptor
:ScopedValue.where( ... ).run( ... )
I guess they are many other patterns that could help copping with this limitation.
Looking forward to see your advices regarding this problematic !
The text was updated successfully, but these errors were encountered: