RSocketRequester already handles Publisher for the body. It would be very nice if it could do the same for metadata values. For example right now a user needs to do something like this:
public Mono<AirportLocation> findRadar(String iata) {
return this.requesterMono.flatMap(req ->
token().flatMap(token ->
req.route("find.radar.{iata}", iata)
.metadata(jwt(token))
.data(Mono.empty())
.retrieveMono(AirportLocation.class)
)
);
}
private Mono<String> token() {
return ReactiveSecurityContextHolder.getContext()
.map(SecurityContext::getAuthentication)
.map(Authentication::getPrincipal)
.cast(Jwt.class)
.map(Jwt::getTokenValue);
}
private Consumer<RSocketRequester.MetadataSpec> jwt(String token) {
return r -> r.metadata(token, BearerTokenMetadata.BEARER_AUTHENTICATION_MIME_TYPE);
}
If metadata could accept a publisher this can be simplified quite a bit:
public Mono<AirportLocation> findRadar(String iata) {
return this.requesterMono.flatMap(req ->
req.route("find.radar.{iata}", iata)
.metadata(jwt())
.data(Mono.empty())
.retrieveMono(AirportLocation.class)
);
}
private Mono<String> token() {
return ReactiveSecurityContextHolder.getContext()
.map(SecurityContext::getAuthentication)
.map(Authentication::getPrincipal)
.cast(Jwt.class)
.map(Jwt::getTokenValue);
}
private Consumer<RSocketRequester.MetadataSpec> jwt() {
return r -> r.metadata(token(), BearerTokenMetadata.BEARER_AUTHENTICATION_MIME_TYPE);
}
Notice that the user no longer needs to subscribe to the Mono<Jwt> which decreases the number of mappings necessary. The user is also able to only consume a single method now Consumer<RSocketRequester.MetadataSpec> jwt().
RSocketRequester already handles
Publisherfor the body. It would be very nice if it could do the same formetadatavalues. For example right now a user needs to do something like this:If
metadatacould accept a publisher this can be simplified quite a bit:Notice that the user no longer needs to subscribe to the
Mono<Jwt>which decreases the number of mappings necessary. The user is also able to only consume a single method nowConsumer<RSocketRequester.MetadataSpec> jwt().