Search in sources :

Example 66 with ServerWebExchange

use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.

the class RequestParamMapMethodArgumentResolverTests method resolveMultiValueMapArgument.

@Test
public void resolveMultiValueMapArgument() throws Exception {
    MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultiValueMap.class);
    ServerWebExchange exchange = MockServerHttpRequest.get("/path?foo=bar&foo=baz").toExchange();
    Object result = resolve(param, exchange);
    assertTrue(result instanceof MultiValueMap);
    assertEquals(Collections.singletonMap("foo", Arrays.asList("bar", "baz")), result);
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) RequestParam(org.springframework.web.bind.annotation.RequestParam) MethodParameter(org.springframework.core.MethodParameter) MultiValueMap(org.springframework.util.MultiValueMap) Test(org.junit.Test)

Example 67 with ServerWebExchange

use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.

the class RequestParamMethodArgumentResolverTests method resolveSimpleTypeParam.

@Test
public void resolveSimpleTypeParam() throws Exception {
    ServerWebExchange exchange = MockServerHttpRequest.get("/path?stringNotAnnot=plainValue").toExchange();
    MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
    Object result = resolve(param, exchange);
    assertEquals("plainValue", result);
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) RequestParam(org.springframework.web.bind.annotation.RequestParam) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 68 with ServerWebExchange

use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.

the class RequestParamMethodArgumentResolverTests method resolveWithFormData.

@Test
public void resolveWithFormData() throws Exception {
    ServerWebExchange exchange = MockServerHttpRequest.post("/path").contentType(MediaType.APPLICATION_FORM_URLENCODED).body("name=foo").toExchange();
    MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
    assertEquals("foo", resolve(param, exchange));
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 69 with ServerWebExchange

use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.

the class HiddenHttpMethodFilter method mapExchange.

private ServerWebExchange mapExchange(ServerWebExchange exchange, String methodParamValue) {
    HttpMethod httpMethod = HttpMethod.resolve(methodParamValue.toUpperCase(Locale.ENGLISH));
    Assert.notNull(httpMethod, () -> "HttpMethod '" + methodParamValue + "' not supported");
    return exchange.mutate().request(builder -> builder.method(httpMethod)).build();
}
Also used : WebFilter(org.springframework.web.server.WebFilter) Locale(java.util.Locale) HttpMethod(org.springframework.http.HttpMethod) Mono(reactor.core.publisher.Mono) ServerHttpRequest(org.springframework.http.server.reactive.ServerHttpRequest) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) ServerWebExchange(org.springframework.web.server.ServerWebExchange) WebFilterChain(org.springframework.web.server.WebFilterChain) HttpMethod(org.springframework.http.HttpMethod)

Example 70 with ServerWebExchange

use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.

the class DefaultCorsProcessorTests method preflightRequestWithoutRequestMethod.

@Test
public void preflightRequestWithoutRequestMethod() throws Exception {
    ServerWebExchange exchange = preFlightRequest().header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1").toExchange();
    this.processor.processRequest(this.conf, exchange);
    ServerHttpResponse response = exchange.getResponse();
    assertFalse(response.getHeaders().containsKey(ACCESS_CONTROL_ALLOW_ORIGIN));
    assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode());
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) ServerHttpResponse(org.springframework.http.server.reactive.ServerHttpResponse) Test(org.junit.Test)

Aggregations

ServerWebExchange (org.springframework.web.server.ServerWebExchange)158 Test (org.junit.Test)138 MockServerWebExchange (org.springframework.mock.http.server.reactive.test.MockServerWebExchange)53 Mono (reactor.core.publisher.Mono)22 ServerHttpResponse (org.springframework.http.server.reactive.ServerHttpResponse)20 MediaType (org.springframework.http.MediaType)18 BindingContext (org.springframework.web.reactive.BindingContext)17 MethodParameter (org.springframework.core.MethodParameter)15 List (java.util.List)14 ResolvableType (org.springframework.core.ResolvableType)14 Map (java.util.Map)12 Collections (java.util.Collections)11 HttpStatus (org.springframework.http.HttpStatus)11 StepVerifier (reactor.test.StepVerifier)11 Assert.assertEquals (org.junit.Assert.assertEquals)10 MockServerHttpRequest (org.springframework.mock.http.server.reactive.test.MockServerHttpRequest)10 ResponseStatusException (org.springframework.web.server.ResponseStatusException)9 ServerWebInputException (org.springframework.web.server.ServerWebInputException)9 ReactiveAdapterRegistry (org.springframework.core.ReactiveAdapterRegistry)8 NotAcceptableStatusException (org.springframework.web.server.NotAcceptableStatusException)8