Refine search
@Override public RouterFunctions.Builder after( BiFunction<ServerRequest, ServerResponse, ServerResponse> responseProcessor) { Assert.notNull(responseProcessor, "ResponseProcessor must not be null"); return filter((request, next) -> next.handle(request) .map(serverResponse -> responseProcessor.apply(request, serverResponse))); }
@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))); }
/** * Get multiple values in one batch. * * @param keys must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/mget">Redis Documentation: MGET</a> */ default Mono<List<ByteBuffer>> mGet(List<ByteBuffer> keys) { Assert.notNull(keys, "Keys must not be null!"); return mGet(Mono.just(keys)).next().map(MultiValueResponse::getOutput); }
/** * Register instance. * * @param registration instance to be registered. * @return the if of the registered instance. */ public Mono<InstanceId> register(Registration registration) { Assert.notNull(registration, "'registration' must not be null"); InstanceId id = generator.generateId(registration); Assert.notNull(id, "'id' must not be null"); return repository.compute(id, (key, instance) -> { if (instance == null) { instance = Instance.create(key); } return Mono.just(instance.register(registration)); }).map(Instance::getId); }
@Override public <T, P extends Publisher<T>> Mono<ServerResponse> body(P publisher, Class<T> elementClass) { Assert.notNull(publisher, "Publisher must not be null"); Assert.notNull(elementClass, "Element Class must not be null"); return new DefaultEntityResponseBuilder<>(publisher, BodyInserters.fromPublisher(publisher, elementClass)) .headers(this.headers) .status(this.statusCode) .build() .map(entityResponse -> entityResponse); }
@Nullable private String formatBody(@Nullable MediaType contentType, Mono<byte[]> body) { return body .map(bytes -> { if (contentType == null) { return bytes.length + " bytes of content (unknown content-type)."; } Charset charset = contentType.getCharset(); if (charset != null) { return new String(bytes, charset); } if (PRINTABLE_MEDIA_TYPES.stream().anyMatch(contentType::isCompatibleWith)) { return new String(bytes, StandardCharsets.UTF_8); } return bytes.length + " bytes of content."; }) .defaultIfEmpty("No content") .onErrorResume(ex -> Mono.just("Failed to obtain content: " + ex.getMessage())) .block(this.timeout); }
/** * Delete {@literal key}. * * @param key must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/del">Redis Documentation: DEL</a> */ default Mono<Long> del(ByteBuffer key) { Assert.notNull(key, "Key must not be null!"); return del(Mono.just(new KeyCommand(key))).next().map(NumericResponse::getOutput); }
@Override public <T, P extends Publisher<T>> Mono<ServerResponse> body(P publisher, ParameterizedTypeReference<T> typeReference) { Assert.notNull(publisher, "Publisher must not be null"); Assert.notNull(typeReference, "ParameterizedTypeReference must not be null"); return new DefaultEntityResponseBuilder<>(publisher, BodyInserters.fromPublisher(publisher, typeReference)) .headers(this.headers) .status(this.statusCode) .build() .map(entityResponse -> entityResponse); }
/** * Remove a specific instance from services * * @param id the instances id to unregister * @return the id of the unregistered instance */ public Mono<InstanceId> deregister(InstanceId id) { return repository.computeIfPresent(id, (key, instance) -> Mono.just(instance.deregister())) .map(Instance::getId); } }
/** * Get the time to live for {@code key} in seconds. * * @param key must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/ttl">Redis Documentation: TTL</a> */ default Mono<Long> ttl(ByteBuffer key) { Assert.notNull(key, "Key must not be null!"); return ttl(Mono.just(new KeyCommand(key))).next().map(NumericResponse::getOutput); }
@Override public Mono<ServerResponse> syncBody(Object body) { Assert.notNull(body, "Body must not be null"); Assert.isTrue(!(body instanceof Publisher), "Please specify the element class by using body(Publisher, Class)"); return new DefaultEntityResponseBuilder<>(body, BodyInserters.fromObject(body)) .headers(this.headers) .status(this.statusCode) .build() .map(entityResponse -> entityResponse); }
@Override protected Mono<String> resolveUrlPathInternal(String resourceUrlPath, List<? extends Resource> locations, ResourceResolverChain chain) { return chain.resolveUrlPath(resourceUrlPath, locations) .flatMap(baseUrl -> { if (StringUtils.hasText(baseUrl)) { VersionStrategy strategy = getStrategyForPath(resourceUrlPath); if (strategy == null) { return Mono.just(baseUrl); } return chain.resolveResource(null, baseUrl, locations) .flatMap(resource -> strategy.getResourceVersion(resource) .map(version -> strategy.addVersion(baseUrl, version))); } return Mono.empty(); }); }
/** * Get the time to live for {@code key} in milliseconds. * * @param key must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/ttl">Redis Documentation: TTL</a> */ default Mono<Long> pTtl(ByteBuffer key) { Assert.notNull(key, "Key must not be null!"); return pTtl(Mono.just(new KeyCommand(key))).next().map(NumericResponse::getOutput); }
private Mono<? extends Resource> transform(String content, Resource resource, ResourceTransformerChain chain, ServerWebExchange exchange) { if (!content.startsWith(MANIFEST_HEADER)) { if (logger.isTraceEnabled()) { logger.trace(exchange.getLogPrefix() + "Skipping " + resource + ": Manifest does not start with 'CACHE MANIFEST'"); } return Mono.just(resource); } return Flux.generate(new LineInfoGenerator(content)) .concatMap(info -> processLine(info, exchange, resource, chain)) .reduce(new ByteArrayOutputStream(), (out, line) -> { writeToByteArrayOutputStream(out, line + "\n"); return out; }) .map(out -> { String hash = DigestUtils.md5DigestAsHex(out.toByteArray()); writeToByteArrayOutputStream(out, "\n" + "# Hash: " + hash); return new TransformedResource(resource, out.toByteArray()); }); }
/** * Get size of set at {@literal key}. * * @param key must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/scard">Redis Documentation: SCARD</a> */ default Mono<Long> sCard(ByteBuffer key) { Assert.notNull(key, "Key must not be null!"); return sCard(Mono.just(new KeyCommand(key))).next().map(NumericResponse::getOutput); }
ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { Assert.notNull(inputStream, "'inputStream' must not be null"); Assert.notNull(bufferFactory, "'bufferFactory' must not be null"); Assert.notNull(elementType, "'elementType' must not be null"); return Mono.from(inputStream).map(value -> encodeValue(value, mimeType, bufferFactory, elementType, hints, encoding)).flux(); ResolvableType listType = ResolvableType.forClassWithGenerics(List.class, elementType); return Flux.from(inputStream).collectList().map(list -> encodeValue(list, mimeType, bufferFactory, listType, hints, encoding)).flux();
return Mono.just(BeanUtils.instantiateClass(ctor)); return WebExchangeDataBinder.extractValuesToBind(exchange).map(bindValues -> { ConstructorProperties cp = ctor.getAnnotation(ConstructorProperties.class); String[] paramNames = (cp != null ? cp.value() : parameterNameDiscoverer.getParameterNames(ctor));
/** * Set multiple keys to multiple values using key-value pairs provided in {@literal tuple}. * * @param keyValuePairs must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/mset">Redis Documentation: MSET</a> */ default Mono<Boolean> mSet(Map<ByteBuffer, ByteBuffer> keyValuePairs) { Assert.notNull(keyValuePairs, "Key-value pairs must not be null!"); return mSet(Mono.just(MSetCommand.mset(keyValuePairs))).next().map(BooleanResponse::getOutput); }