use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class DefaultCorsProcessorTests method actualRequestCredentialsWithOriginWildcard.
@Test
public void actualRequestCredentialsWithOriginWildcard() throws Exception {
ServerWebExchange exchange = actualRequest();
this.conf.addAllowedOrigin("*");
this.conf.setAllowCredentials(true);
this.processor.processRequest(this.conf, exchange);
ServerHttpResponse response = exchange.getResponse();
assertTrue(response.getHeaders().containsKey(ACCESS_CONTROL_ALLOW_ORIGIN));
assertEquals("http://domain2.com", response.getHeaders().getFirst(ACCESS_CONTROL_ALLOW_ORIGIN));
assertTrue(response.getHeaders().containsKey(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS));
assertEquals("true", response.getHeaders().getFirst(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS));
assertNull(response.getStatusCode());
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class UrlBasedCorsConfigurationSourceTests method empty.
@Test
public void empty() {
ServerWebExchange exchange = MockServerHttpRequest.get("/bar/test.html").toExchange();
assertNull(this.configSource.getCorsConfiguration(exchange));
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class DispatcherHandlerErrorTests method requestBodyError.
@Test
public void requestBodyError() throws Exception {
ServerWebExchange exchange = MockServerHttpRequest.post("/request-body").body(Mono.error(EXCEPTION)).toExchange();
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
StepVerifier.create(publisher).consumeErrorWith(error -> {
assertThat(error, instanceOf(ServerWebInputException.class));
assertSame(EXCEPTION, error.getCause());
}).verify();
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class DispatcherHandlerErrorTests method webExceptionHandler.
@Test
public void webExceptionHandler() throws Exception {
ServerWebExchange exchange = MockServerHttpRequest.get("/unknown-argument-type").toExchange();
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());
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class DispatcherHandlerErrorTests method controllerThrowsException.
@Test
public void controllerThrowsException() throws Exception {
ServerWebExchange exchange = MockServerHttpRequest.get("/raise-exception").toExchange();
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
StepVerifier.create(publisher).consumeErrorWith(error -> assertSame(EXCEPTION, error)).verify();
}
Aggregations