lambda
lambda

Reputation: 1

springboo-rsocket how to use contextView

"I have an interceptor:

public class RSocketMetadataInterceptor implements SocketAcceptorInterceptor {
    @Override
    public SocketAcceptor apply(SocketAcceptor socketAcceptor) {
        return (setup, sendingSocket) -> {
            ByteBuf byteBuf = setup.metadata();
            SecurityStash securityStash = getValueFromMetadata(byteBuf);
            String authToken = securityStash.getAuthToken();
            String principal = securityStash.getPrincipal();
            return socketAcceptor.accept(setup, sendingSocket)
                    .contextWrite(Context.of(AUTHTOKEN_STASH_NAMING, authToken))
                    .contextWrite(Context.of(AUTHTOKEN_STASH_NAMING, principal));
        };
    }
}

In the interceptor, I put variables into the contextView. Consequently, in the following method:

@MessageMapping(LOGIN + "/test")
public Flux<String> test(@Payload SmsLoginDTO dto, @Headers Map<String, Object> metadata){
    //return Flux.just("1","2","3");
    rsocketPrincipalFactory.fetchPrincipal().subscribe();
    int i = 0;
    throw new EventException(EB_USER_000);
}

I attempt to retrieve the contextView through fetchPrincipal:

private Mono<String> fetchPrincipal() {
    return Mono.deferContextual(Mono::just)
            .map(contextView -> {
                Object o = contextView.get(PRINCIPAL_STASH_NAMING);
                return o.toString();
            });  
}

However, the contextView I obtain is empty. Why is this happening? Could it be that the interceptor is not propagating the context to the subsequent methods?"

Upvotes: 0

Views: 35

Answers (0)

Related Questions