@Override public Mono<Void> removeSession(String id) { this.sessions.remove(id); return Mono.empty(); }
@Override public Mono<Void> invalidate() { this.state.set(State.EXPIRED); getAttributes().clear(); InMemoryWebSessionStore.this.sessions.remove(this.id.get()); return Mono.empty(); }
@Override public Mono<Resource> resolveResource(@Nullable ServerWebExchange exchange, String requestPath, List<? extends Resource> locations) { return (this.resolver != null && this.nextChain != null ? this.resolver.resolveResource(exchange, requestPath, locations, this.nextChain) : Mono.empty()); }
@Override public Mono<String> resolveUrlPath(String resourcePath, List<? extends Resource> locations) { return (this.resolver != null && this.nextChain != null ? this.resolver.resolveUrlPath(resourcePath, locations, this.nextChain) : Mono.empty()); }
@Override public Mono<Void> doFilter(ServerWebExchange exchange, WebFilterChain chain) { return Mono.empty(); } }
@Override public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) { this.request = request; return Mono.empty(); } }
@Override protected Mono<String> resolveUrlPathInternal(String path, List<? extends Resource> locations, ResourceResolverChain chain) { if (StringUtils.hasText(path)) { return getResource(path, locations).map(resource -> path); } else { return Mono.empty(); } }
@Override public Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler) { WebHandler webHandler = (WebHandler) handler; Mono<Void> mono = webHandler.handle(exchange); return mono.then(Mono.empty()); }
private <T> Function<Flux<T>, Publisher<?>> reconnectFunction(ReconnectStrategy reconnectStrategy) { return flux -> flux .scan(1, (count, element) -> count++) .flatMap(attempt -> Optional.ofNullable(reconnectStrategy.getTimeToNextAttempt(attempt)) .map(time -> Mono.delay(Duration.ofMillis(time), this.scheduler)) .orElse(Mono.empty())); }
private HandshakeInfo createHandshakeInfo(URI url, DefaultNegotiation negotiation) { HttpHeaders responseHeaders = negotiation.getResponseHeaders(); String protocol = responseHeaders.getFirst("Sec-WebSocket-Protocol"); return new HandshakeInfo(url, responseHeaders, Mono.empty(), protocol); }
@Override public Mono<Void> close(CloseStatus status) { getDelegate().close(status.getCode(), status.getReason()); return Mono.empty(); }
/** * Send a redirect back to the HTTP client. * @param targetUrl the target URL to redirect to * @param exchange current exchange */ protected Mono<Void> sendRedirect(String targetUrl, ServerWebExchange exchange) { String transformedUrl = (isRemoteHost(targetUrl) ? targetUrl : exchange.transformUrl(targetUrl)); ServerHttpResponse response = exchange.getResponse(); response.getHeaders().setLocation(URI.create(transformedUrl)); response.setStatusCode(getStatusCode()); return Mono.empty(); }
@Override public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) { exchange.getResponse().setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR); return Mono.empty(); } }
private ServerHttpRequest adaptFromForwardedHeaders(MockServerHttpRequest.BaseBuilder<?> builder) { AtomicReference<ServerHttpRequest> requestRef = new AtomicReference<>(); MockServerWebExchange exchange = MockServerWebExchange.from(builder); new ForwardedHeaderFilter().filter(exchange, exchange2 -> { requestRef.set(exchange2.getRequest()); return Mono.empty(); }).block(); return requestRef.get(); }
@Test public void cancellationAfterTerminated() { Future<Void> future = new MonoToListenableFutureAdapter<>(Mono.empty()); assertFalse("Should return false if task already completed", future.cancel(true)); assertFalse(future.isCancelled()); }
@Override public Mono<Void> close(CloseStatus status) { CloseMessage cm = new CloseMessage(status.getCode(), status.getReason()); if (!getDelegate().isCloseFrameSent()) { WebSockets.sendClose(cm, getDelegate(), null); } return Mono.empty(); }
@Override public Mono<Void> close(CloseStatus status) { try { CloseReason.CloseCode code = CloseCodes.getCloseCode(status.getCode()); getDelegate().close(new CloseReason(code, status.getReason())); } catch (IOException ex) { return Mono.error(ex); } return Mono.empty(); }
@Override public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) { URI uri = request.getURI(); assertEquals("http", uri.getScheme()); assertNotNull(uri.getHost()); assertNotEquals(-1, uri.getPort()); assertNotNull(request.getRemoteAddress()); assertEquals("/foo", uri.getPath()); assertEquals("param=bar", uri.getQuery()); return Mono.empty(); } }
@Test public void resolveUrlExistingNotInJarFile() { this.locations = singletonList(new ClassPathResource("/META-INF/resources/webjars/", getClass())); String file = "foo/foo.txt"; given(this.chain.resolveUrlPath(file, this.locations)).willReturn(Mono.empty()); String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain).block(TIMEOUT); assertNull(actual); verify(this.chain, times(1)).resolveUrlPath(file, this.locations); verify(this.chain, never()).resolveUrlPath("foo/2.3/foo.txt", this.locations); }
@Test public void resolveUrlWebJarResourceNotFound() { String file = "something/something.js"; given(this.chain.resolveUrlPath(file, this.locations)).willReturn(Mono.empty()); String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain).block(TIMEOUT); assertNull(actual); verify(this.chain, times(1)).resolveUrlPath(file, this.locations); verify(this.chain, never()).resolveUrlPath(null, this.locations); }