<@U0BUH9FRD> hi, is there any plans to include <ht...
# spring
s
For now no since I have tried to avoid duplicating Reactive types in order to provide a very thin and maintainable layer. I don't say never but I think i would prefer getting wide feedback before crossing that bridge. Currently you can do:
Copy code
class FooWebFilter : WebFilter {

	override fun filter(exchange: ServerWebExchange, chain: WebFilterChain) = mono(Dispatchers.Unconfined) {
		val principal = exchange.awaitPrincipal<Principal>()
		println(principal.name)
		chain.filter(exchange).awaitFirstOrNull()
	}
}
Which seems to me not so bad given the few number of filters required.
I can maybe add a section in the documentation if that's look like ok to you
l
I think it is a workaround and should not to be included into documentation 🙂
thnx 🙂
d
@sdeleuze what would be a proper way to populate subscriber context in the above? would it be just
Copy code
class FooWebFilter : WebFilter {

    override fun filter(exchange: ServerWebExchange, chain: WebFilterChain): Mono<Void> = mono {
        val context = whatever()
        chain.filter(exchange).subscriberContext { it.put("myContextKey", context) }.awaitFirstOrNull()
    }
    
    suspend fun whatever(): Foo { ... }
}
i'm thinking something like this should also work?
Copy code
override fun filter(exchange: ServerWebExchange, chain: WebFilterChain): Mono<Void> = mono {
        whatever()
    }.flatMap { myContextValue ->
        chain.filter(exchange).subscriberContext { it.put("myContextKey", myContextValue) }
    }
any idea how to verify the context gets populated? e.g.
Copy code
StepVerifier.create(fooFilter.filter(exchange, chain))
    .expectAccessibleContext()
    .hasSize(1)
    .hasKey(myContextKey)
    .assertThat {
        val foo = it.getOrDefault<Foo>(myContextKey, null)
        assertNotNull(foo)
    }
    .then()
    .verifyComplete()
since step verifier doesn't actually complete the publisher chain until the last step that accessible context is empty
to complete the thread -> so the issue was that step verifier attempts to verify the context on the result of the filter mono chain. Since final value is not yet computed there is nothing yet added to the context so the StepVerifier checks against the context will fail. Unit test fix was to manually capture the context in the reactor chain and then complete it before attempting to verify the context (https://github.com/ExpediaGroup/graphql-kotlin/pull/361/commits/f746a886ddd97fa11dd29badecc8d7014d6fc75c)
👍 1