@Override public Mono<Void> handle(ServerWebExchange exchange) { return this.delegate.handle(exchange); }
@Override public Mono<Void> handle(ServerWebExchange exchange) { return this.delegate.handle(exchange); }
@Override public Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler) { WebHandler webHandler = (WebHandler) handler; Mono<Void> mono = webHandler.handle(exchange); return mono.then(Mono.empty()); }
@Override public Mono<Void> filter(ServerWebExchange exchange) { return Mono.defer(() -> this.currentFilter != null && this.next != null ? this.currentFilter.filter(exchange, this.next) : this.handler.handle(exchange)); }
@Override public Mono<Void> filter(ServerWebExchange exchange) { return Mono.defer(() -> this.currentFilter != null && this.next != null ? this.currentFilter.filter(exchange, this.next) : this.handler.handle(exchange)); }
@Test public void webExceptionHandler() { ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/unknown-argument-type")); List<WebExceptionHandler> handlers = Collections.singletonList(new ServerError500ExceptionHandler()); WebHandler webHandler = new ExceptionHandlingWebHandler(this.dispatcherHandler, handlers); webHandler.handle(exchange).block(Duration.ofSeconds(5)); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, exchange.getResponse().getStatusCode()); }
@Test public void thrownExceptionBecomesErrorSignal() throws Exception { createWebHandler(new BadRequestExceptionHandler()).handle(this.exchange).block(); assertEquals(HttpStatus.BAD_REQUEST, this.exchange.getResponse().getStatusCode()); }
@Test public void handleErrorSignal() throws Exception { createWebHandler(new BadRequestExceptionHandler()).handle(this.exchange).block(); assertEquals(HttpStatus.BAD_REQUEST, this.exchange.getResponse().getStatusCode()); }
@Test public void handleErrorSignalWithMultipleHttpErrorHandlers() throws Exception { createWebHandler( new UnresolvedExceptionHandler(), new UnresolvedExceptionHandler(), new BadRequestExceptionHandler(), new UnresolvedExceptionHandler()).handle(this.exchange).block(); assertEquals(HttpStatus.BAD_REQUEST, this.exchange.getResponse().getStatusCode()); }
@Override public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) { if (this.forwardedHeaderTransformer != null) { request = this.forwardedHeaderTransformer.apply(request); } ServerWebExchange exchange = createExchange(request, response); LogFormatUtils.traceDebug(logger, traceOn -> exchange.getLogPrefix() + formatRequest(exchange.getRequest()) + (traceOn ? ", headers=" + formatHeaders(exchange.getRequest().getHeaders()) : "")); return getDelegate().handle(exchange) .doOnSuccess(aVoid -> logResponse(exchange)) .onErrorResume(ex -> handleUnresolvedError(exchange, ex)) .then(Mono.defer(response::setComplete)); }
@Test public void unresolvedException() throws Exception { Mono<Void> mono = createWebHandler(new UnresolvedExceptionHandler()).handle(this.exchange); StepVerifier.create(mono).expectErrorMessage("boo").verify(); assertNull(this.exchange.getResponse().getStatusCode()); }
@Override public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) { if (this.forwardedHeaderTransformer != null) { request = this.forwardedHeaderTransformer.apply(request); } ServerWebExchange exchange = createExchange(request, response); LogFormatUtils.traceDebug(logger, traceOn -> exchange.getLogPrefix() + formatRequest(exchange.getRequest()) + (traceOn ? ", headers=" + formatHeaders(exchange.getRequest().getHeaders()) : "")); return getDelegate().handle(exchange) .doOnSuccess(aVoid -> logResponse(exchange)) .onErrorResume(ex -> handleUnresolvedError(exchange, ex)) .then(Mono.defer(response::setComplete)); }
@Override public Mono<Void> handle(ServerWebExchange exchange) { return this.delegate.handle(exchange); }
@Override public Mono<Void> handle(ServerWebExchange exchange) { return this.delegate.handle(exchange); }
@Override public Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler) { WebHandler webHandler = (WebHandler) handler; Mono<Void> mono = webHandler.handle(exchange); return mono.then(aVoid -> Mono.empty()); }
@Override public Mono<Void> filter(ServerWebExchange exchange) { return Mono.defer(() -> this.currentFilter != null && this.next != null ? this.currentFilter.filter(exchange, this.next) : this.handler.handle(exchange)); }
@Override public Mono<Void> filter(ServerWebExchange exchange) { return Mono.defer(() -> { if (this.index < this.filters.size()) { WebFilter filter = this.filters.get(this.index); WebFilterChain chain = new DefaultWebFilterChain(this, this.index + 1); return filter.filter(exchange, chain); } else { return this.handler.handle(exchange); } }); }
@Override public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) { ServerWebExchange exchange = createExchange(request, response); return getDelegate().handle(exchange) .onErrorResume(ex -> handleFailure(request, response, ex)) .then(Mono.defer(response::setComplete)); }
@Override public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) { if (this.forwardedHeaderTransformer != null) { request = this.forwardedHeaderTransformer.apply(request); } ServerWebExchange exchange = createExchange(request, response); LogFormatUtils.traceDebug(logger, traceOn -> exchange.getLogPrefix() + formatRequest(exchange.getRequest()) + (traceOn ? ", headers=" + formatHeaders(exchange.getRequest().getHeaders()) : "")); return getDelegate().handle(exchange) .doOnSuccess(aVoid -> logResponse(exchange)) .onErrorResume(ex -> handleUnresolvedError(exchange, ex)) .then(Mono.defer(response::setComplete)); }