/** * Adapt from the given Reactive Streams Publisher. * @param publisher the publisher to adapt from * @return the reactive type instance representing the adapted publisher */ public Object fromPublisher(Publisher<?> publisher) { return this.fromPublisherFunction.apply(publisher); }
static <T, K, V> Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends V> valueFunction) { checkNotNull(keyFunction); checkNotNull(valueFunction); return Collector.of( ImmutableMap.Builder<K, V>::new, (builder, input) -> builder.put(keyFunction.apply(input), valueFunction.apply(input)), ImmutableMap.Builder::combine, ImmutableMap.Builder::build); }
/** * Adapt the given request processor function to a filter function that only operates * on the {@code ServerRequest}. * @param requestProcessor the request processor * @return the filter adaptation of the request processor */ static HandlerFilterFunction<?, ?> ofRequestProcessor( Function<ServerRequest, Mono<ServerRequest>> requestProcessor) { Assert.notNull(requestProcessor, "Function must not be null"); return (request, next) -> requestProcessor.apply(request).flatMap(next::handle); }
static <T, K, V> Collector<T, ?, ImmutableBiMap<K, V>> toImmutableBiMap( Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends V> valueFunction) { checkNotNull(keyFunction); checkNotNull(valueFunction); return Collector.of( ImmutableBiMap.Builder<K, V>::new, (builder, input) -> builder.put(keyFunction.apply(input), valueFunction.apply(input)), ImmutableBiMap.Builder::combine, ImmutableBiMap.Builder::build, new Collector.Characteristics[0]); }
@Override public V computeIfAbsent(K key, Function<? super K, ? extends V> function) { checkNotNull(key); checkNotNull(function); return compute(key, (k, oldValue) -> (oldValue == null) ? function.apply(key) : oldValue); }
@Override public boolean tryAdvance(Consumer<? super T> action) { return fromSpliterator.tryAdvance( fromElement -> action.accept(function.apply(fromElement))); }
@Override public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) { this.savedRequest = request; return this.responseMonoFunction.apply(response); } }
private Marshaller initMarshaller(Class<?> clazz) throws JAXBException { Marshaller marshaller = this.jaxbContexts.createMarshaller(clazz); marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.name()); marshaller = this.marshallerProcessor.apply(marshaller); return marshaller; }
/** * Default constructor. Initializes {@link HttpClient} via: * <pre class="code"> * HttpClient.create().compress() * </pre> */ public ReactorClientHttpConnector() { this.httpClient = defaultInitializer.apply(HttpClient.create()); }
/** * Apply the exception handler and return the alternative result. * @param failure the exception * @return the new result or the same error if there is no exception handler */ public Mono<HandlerResult> applyExceptionHandler(Throwable failure) { return (this.exceptionHandler != null ? this.exceptionHandler.apply(failure) : Mono.error(failure)); }
/** * Return a {@code RequestPredicate} that tests the request path * against the given path pattern. * @param pattern the pattern to match to * @return a predicate that tests against the given path pattern */ public static RequestPredicate path(String pattern) { Assert.notNull(pattern, "'pattern' must not be null"); return pathPredicates(DEFAULT_PATTERN_PARSER).apply(pattern); }
@Override public ResponseSpec onStatus(Predicate<HttpStatus> statusPredicate, Function<ClientResponse, Mono<? extends Throwable>> exceptionFunction) { if (this.statusHandlers.size() == 1 && this.statusHandlers.get(0) == DEFAULT_STATUS_HANDLER) { this.statusHandlers.clear(); } this.statusHandlers.add(new StatusHandler(statusPredicate, (clientResponse, request) -> exceptionFunction.apply(clientResponse))); return this; }
@Override public RouterFunctions.Builder before(Function<ServerRequest, ServerRequest> requestProcessor) { Assert.notNull(requestProcessor, "RequestProcessor must not be null"); return filter((request, next) -> next.handle(requestProcessor.apply(request))); }
@Override protected Mono<Void> writeAndFlushWithInternal( Publisher<? extends Publisher<? extends DataBuffer>> body) { return this.writeHandler.apply(Flux.from(body).concatMap(Flux::from)); }
@Override public WebSocketMessage pingMessage(Function<DataBufferFactory, DataBuffer> payloadFactory) { DataBuffer payload = payloadFactory.apply(bufferFactory()); return new WebSocketMessage(WebSocketMessage.Type.PING, payload); }
@Override public WebSocketMessage binaryMessage(Function<DataBufferFactory, DataBuffer> payloadFactory) { DataBuffer payload = payloadFactory.apply(bufferFactory()); return new WebSocketMessage(WebSocketMessage.Type.BINARY, payload); }
@Override public WebSocketMessage pongMessage(Function<DataBufferFactory, DataBuffer> payloadFactory) { DataBuffer payload = payloadFactory.apply(bufferFactory()); return new WebSocketMessage(WebSocketMessage.Type.PONG, payload); }
@OnWebSocketConnect public void onWebSocketConnect(Session session) { this.delegateSession = this.sessionFactory.apply(session); this.delegateHandler.handle(this.delegateSession).subscribe(this.delegateSession); }
private void doExpectCollects(@Nullable R expectedResult, List<T> inputs) { for (CollectStrategy scheme : EnumSet.allOf(CollectStrategy.class)) { A finalAccum = scheme.result(collector, inputs); if (collector.characteristics().contains(Collector.Characteristics.IDENTITY_FINISH)) { assertEquivalent(expectedResult, (R) finalAccum); } assertEquivalent(expectedResult, collector.finisher().apply(finalAccum)); } }
@Test public void pathPredicates() { PathPatternParser parser = new PathPatternParser(); parser.setCaseSensitive(false); Function<String, RequestPredicate> pathPredicates = RequestPredicates.pathPredicates(parser); URI uri = URI.create("http://localhost/path"); RequestPredicate predicate = pathPredicates.apply("/P*"); MockServerRequest request = MockServerRequest.builder().uri(uri).build(); assertTrue(predicate.test(request)); }