Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSocketRequestSpec handling metadata values that is a Publisher type #23640

Closed
rwinch opened this issue Sep 13, 2019 · 0 comments
Closed

RSocketRequestSpec handling metadata values that is a Publisher type #23640

rwinch opened this issue Sep 13, 2019 · 0 comments
Assignees
Labels
in: messaging Issues in messaging modules (jms, messaging) type: enhancement A general enhancement
Milestone

Comments

@rwinch
Copy link
Member

rwinch commented Sep 13, 2019

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().

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 13, 2019
@rstoyanchev rstoyanchev self-assigned this Sep 16, 2019
@rstoyanchev rstoyanchev added in: messaging Issues in messaging modules (jms, messaging) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 16, 2019
@rstoyanchev rstoyanchev added this to the 5.2 GA milestone Sep 16, 2019
@snicoll snicoll modified the milestones: 5.2 GA, 5.x Backlog Sep 27, 2019
@rstoyanchev rstoyanchev modified the milestones: 5.x Backlog, 5.2.2 Oct 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: messaging Issues in messaging modules (jms, messaging) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants