Using modern Java features
This commit is contained in:
committed by
Josh Cummings
parent
7e01ebdd92
commit
9b603b99ab
+5
-5
@@ -91,9 +91,9 @@ class PayloadInterceptorRSocket extends RSocketProxy {
|
||||
public Flux<Payload> requestChannel(Publisher<Payload> payloads) {
|
||||
return Flux.from(payloads).switchOnFirst((signal, innerFlux) -> {
|
||||
Payload firstPayload = signal.get();
|
||||
return intercept(PayloadExchangeType.REQUEST_CHANNEL, firstPayload).flatMapMany((context) -> innerFlux
|
||||
.index().concatMap((tuple) -> justOrIntercept(tuple.getT1(), tuple.getT2()))
|
||||
.transform((securedPayloads) -> this.source.requestChannel(securedPayloads)).contextWrite(context));
|
||||
return intercept(PayloadExchangeType.REQUEST_CHANNEL, firstPayload).flatMapMany(
|
||||
(context) -> innerFlux.index().concatMap((tuple) -> justOrIntercept(tuple.getT1(), tuple.getT2()))
|
||||
.transform(this.source::requestChannel).contextWrite(context));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -112,8 +112,8 @@ class PayloadInterceptorRSocket extends RSocketProxy {
|
||||
ContextPayloadInterceptorChain chain = new ContextPayloadInterceptorChain(this.interceptors);
|
||||
DefaultPayloadExchange exchange = new DefaultPayloadExchange(type, payload, this.metadataMimeType,
|
||||
this.dataMimeType);
|
||||
return chain.next(exchange).then(Mono.fromCallable(() -> chain.getContext()))
|
||||
.defaultIfEmpty(Context.empty()).contextWrite(this.context);
|
||||
return chain.next(exchange).then(Mono.fromCallable(chain::getContext)).defaultIfEmpty(Context.empty())
|
||||
.contextWrite(this.context);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -83,8 +83,7 @@ class PayloadSocketAcceptor implements SocketAcceptor {
|
||||
ContextPayloadInterceptorChain chain = new ContextPayloadInterceptorChain(this.interceptors);
|
||||
DefaultPayloadExchange exchange = new DefaultPayloadExchange(PayloadExchangeType.SETUP, payload,
|
||||
metadataMimeType, dataMimeType);
|
||||
return chain.next(exchange).then(Mono.fromCallable(() -> chain.getContext()))
|
||||
.defaultIfEmpty(Context.empty());
|
||||
return chain.next(exchange).then(Mono.fromCallable(chain::getContext)).defaultIfEmpty(Context.empty());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+5
-28
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.springframework.security.rsocket.util.matcher;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.security.rsocket.api.PayloadExchange;
|
||||
import org.springframework.security.rsocket.api.PayloadExchangeType;
|
||||
|
||||
/**
|
||||
@@ -30,37 +27,17 @@ public final class PayloadExchangeMatchers {
|
||||
}
|
||||
|
||||
public static PayloadExchangeMatcher setup() {
|
||||
return new PayloadExchangeMatcher() {
|
||||
|
||||
@Override
|
||||
public Mono<MatchResult> matches(PayloadExchange exchange) {
|
||||
return PayloadExchangeType.SETUP.equals(exchange.getType()) ? MatchResult.match()
|
||||
: MatchResult.notMatch();
|
||||
}
|
||||
|
||||
};
|
||||
return (exchange) -> PayloadExchangeType.SETUP.equals(exchange.getType())
|
||||
? PayloadExchangeMatcher.MatchResult.match() : PayloadExchangeMatcher.MatchResult.notMatch();
|
||||
}
|
||||
|
||||
public static PayloadExchangeMatcher anyRequest() {
|
||||
return new PayloadExchangeMatcher() {
|
||||
|
||||
@Override
|
||||
public Mono<MatchResult> matches(PayloadExchange exchange) {
|
||||
return exchange.getType().isRequest() ? MatchResult.match() : MatchResult.notMatch();
|
||||
}
|
||||
|
||||
};
|
||||
return (exchange) -> exchange.getType().isRequest() ? PayloadExchangeMatcher.MatchResult.match()
|
||||
: PayloadExchangeMatcher.MatchResult.notMatch();
|
||||
}
|
||||
|
||||
public static PayloadExchangeMatcher anyExchange() {
|
||||
return new PayloadExchangeMatcher() {
|
||||
|
||||
@Override
|
||||
public Mono<MatchResult> matches(PayloadExchange exchange) {
|
||||
return MatchResult.match();
|
||||
}
|
||||
|
||||
};
|
||||
return (exchange) -> PayloadExchangeMatcher.MatchResult.match();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -52,8 +52,8 @@ public class RoutePayloadExchangeMatcher implements PayloadExchangeMatcher {
|
||||
Map<String, Object> metadata = this.metadataExtractor.extract(exchange.getPayload(),
|
||||
exchange.getMetadataMimeType());
|
||||
return Optional.ofNullable((String) metadata.get(MetadataExtractor.ROUTE_KEY))
|
||||
.map((routeValue) -> this.routeMatcher.parseRoute(routeValue))
|
||||
.map((route) -> this.routeMatcher.matchAndExtract(this.pattern, route)).map((v) -> MatchResult.match(v))
|
||||
.map(this.routeMatcher::parseRoute)
|
||||
.map((route) -> this.routeMatcher.matchAndExtract(this.pattern, route)).map(MatchResult::match)
|
||||
.orElse(MatchResult.notMatch());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user