@Override public Mono<? extends Principal> principal() { return Mono.justOrEmpty(this.principal); }
@Override public Mono<WebSession> session() { return Mono.justOrEmpty(this.session); }
/** * {@inheritDoc} * <p>By default this simply delegates to {@link #resolveArgumentValue} for * synchronous resolution. */ @Override default Mono<Object> resolveArgument( MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange) { return Mono.justOrEmpty(resolveArgumentValue(parameter, bindingContext, exchange)); }
@Override public Mono<? extends Principal> principal() { return Mono.justOrEmpty(this.principal); }
@Override protected final Mono<Object> resolveName(String name, MethodParameter param, ServerWebExchange exchange) { return Mono.justOrEmpty(resolveNamedValue(name, param, exchange)); }
@Override public Mono<WebSession> session() { return Mono.justOrEmpty(this.session); }
@Override public Mono<View> resolveViewName(String viewName, Locale locale) { View view = this.views.get(viewName); return Mono.justOrEmpty(view); } }
@Override public Mono<Instance> find(InstanceId id) { return Mono.defer(() -> Mono.justOrEmpty(this.snapshots.get(id))); }
@Override @SuppressWarnings("unchecked") public <T extends OAuth2AuthorizedClient> Mono<T> loadAuthorizedClient(String clientRegistrationId, Authentication principal, ServerWebExchange exchange) { Assert.hasText(clientRegistrationId, "clientRegistrationId cannot be empty"); Assert.notNull(exchange, "exchange cannot be null"); return exchange.getSession() .map(this::getAuthorizedClients) .flatMap(clients -> Mono.justOrEmpty((T) clients.get(clientRegistrationId))); }
@Override public <T extends OAuth2AuthorizedClient> Mono<T> loadAuthorizedClient(String clientRegistrationId, String principalName) { Assert.hasText(clientRegistrationId, "clientRegistrationId cannot be empty"); Assert.hasText(principalName, "principalName cannot be empty"); return (Mono<T>) getIdentifier(clientRegistrationId, principalName) .flatMap(identifier -> Mono.justOrEmpty(this.authorizedClients.get(identifier))); }
@Override public Mono<Instance> find(InstanceId id) { //hmm a simple reduce doesn't return empty when not found... return eventStore.find(id).collect((Supplier<AtomicReference<Instance>>) AtomicReference::new, (ref, event) -> { Instance instance = ref.get() != null ? ref.get() : Instance.create(id); ref.set(instance.apply(event)); }).flatMap(ref -> Mono.justOrEmpty(ref.get())); }
@SuppressWarnings("unchecked") private <T> Mono<Void> write(T value, @Nullable MediaType contentType, ServerWebExchange exchange) { Publisher<T> input = Mono.justOrEmpty(value); ResolvableType elementType = ResolvableType.forClass(value.getClass()); return ((HttpMessageWriter<T>) this.writer).write( input, elementType, contentType, exchange.getResponse(), Hints.from(Hints.LOG_PREFIX_HINT, exchange.getLogPrefix())); }
private Mono<Map<String, OAuth2AuthorizationRequest>> getStateToAuthorizationRequest(ServerWebExchange exchange, boolean create) { Assert.notNull(exchange, "exchange cannot be null"); return getSessionAttributes(exchange) .doOnNext(sessionAttrs -> { if (create) { sessionAttrs.putIfAbsent(this.sessionAttributeName, new HashMap<String, OAuth2AuthorizationRequest>()); } }) .flatMap(sessionAttrs -> Mono.justOrEmpty(this.sessionAttrsMapStateToAuthorizationRequest(sessionAttrs))); }
@Override public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next) { Optional<OAuth2AuthorizedClient> attribute = request.attribute(OAUTH2_AUTHORIZED_CLIENT_ATTR_NAME) .map(OAuth2AuthorizedClient.class::cast); return Mono.justOrEmpty(attribute) .flatMap(authorizedClient -> authorizedClient(request, next, authorizedClient)) .map(authorizedClient -> bearer(request, authorizedClient)) .flatMap(next::exchange) .switchIfEmpty(next.exchange(request)); }
@Override public Mono<Object> getHandlerInternal(ServerWebExchange exchange) { PathContainer lookupPath = exchange.getRequest().getPath().pathWithinApplication(); Object handler; try { handler = lookupHandler(lookupPath, exchange); } catch (Exception ex) { return Mono.error(ex); } return Mono.justOrEmpty(handler); }
@Override public Mono<Object> resolveArgument( MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange) { NamedValueInfo namedValueInfo = getNamedValueInfo(parameter); MethodParameter nestedParameter = parameter.nestedIfOptional(); Object resolvedName = resolveStringValue(namedValueInfo.name); if (resolvedName == null) { return Mono.error(new IllegalArgumentException( "Specified name must not resolve to null: [" + namedValueInfo.name + "]")); } Model model = bindingContext.getModel(); return resolveName(resolvedName.toString(), nestedParameter, exchange) .flatMap(arg -> { if ("".equals(arg) && namedValueInfo.defaultValue != null) { arg = resolveStringValue(namedValueInfo.defaultValue); } arg = applyConversion(arg, namedValueInfo, parameter, bindingContext, exchange); handleResolvedValue(arg, namedValueInfo.name, parameter, model, exchange); return Mono.justOrEmpty(arg); }) .switchIfEmpty(getDefaultValue( namedValueInfo, parameter, bindingContext, model, exchange)); }
private Mono<OAuth2AuthorizedClient> authorizedClient(ClientRequest request, ExchangeFunction next) { OAuth2AuthorizedClient authorizedClientFromAttrs = oauth2AuthorizedClient(request); return Mono.justOrEmpty(authorizedClientFromAttrs) .switchIfEmpty(Mono.defer(() -> loadAuthorizedClient(request))) .flatMap(authorizedClient -> refreshIfNecessary(request, next, authorizedClient)); }
/** * Look up a handler method for the given request. * @param exchange the current exchange */ @Override public Mono<HandlerMethod> getHandlerInternal(ServerWebExchange exchange) { this.mappingRegistry.acquireReadLock(); try { HandlerMethod handlerMethod; try { handlerMethod = lookupHandlerMethod(exchange); } catch (Exception ex) { return Mono.error(ex); } if (handlerMethod != null) { handlerMethod = handlerMethod.createWithResolvedBean(); } return Mono.justOrEmpty(handlerMethod); } finally { this.mappingRegistry.releaseReadLock(); } }
private Mono<?> prepareAttributeMono(String attributeName, ResolvableType attributeType, BindingContext context, ServerWebExchange exchange) { Object attribute = context.getModel().asMap().get(attributeName); if (attribute == null) { attribute = findAndRemoveReactiveAttribute(context.getModel(), attributeName); } if (attribute == null) { return createAttribute(attributeName, attributeType.toClass(), context, exchange); } ReactiveAdapter adapterFrom = getAdapterRegistry().getAdapter(null, attribute); if (adapterFrom != null) { Assert.isTrue(!adapterFrom.isMultiValue(), "Data binding only supports single-value async types"); return Mono.from(adapterFrom.toPublisher(attribute)); } else { return Mono.justOrEmpty(attribute); } }
}); return Mono.justOrEmpty(value);