@MatrixVariable resolvers for WebFlux
The information was already parsed and available in a request attribute but until now there were no argument resolvers to expose it. Issue: SPR-16005
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.web.reactive.result.method.annotation;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.MatrixVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.reactive.config.EnableWebFlux;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* {@code @RequestMapping} integration focusing on controller method parameters.
|
||||
* Also see:
|
||||
* <ul>
|
||||
* <li>{@link RequestMappingDataBindingIntegrationTests}
|
||||
* <li>{@link RequestMappingMessageConversionIntegrationTests}
|
||||
* </ul>
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class ControllerInputIntegrationTests extends AbstractRequestMappingIntegrationTests {
|
||||
|
||||
|
||||
@Override
|
||||
protected ApplicationContext initApplicationContext() {
|
||||
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
|
||||
wac.register(WebConfig.class, TestRestController.class);
|
||||
wac.refresh();
|
||||
return wac;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void handleWithParam() throws Exception {
|
||||
String expected = "Hello George!";
|
||||
assertEquals(expected, performGet("/param?name=George", new HttpHeaders(), String.class).getBody());
|
||||
}
|
||||
|
||||
@Test // SPR-15140
|
||||
public void handleWithEncodedParam() throws Exception {
|
||||
String expected = "Hello + \u00e0!";
|
||||
assertEquals(expected, performGet("/param?name=%20%2B+%C3%A0", new HttpHeaders(), String.class).getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matrixVariable() throws Exception {
|
||||
String expected = "p=11, q2=22, q4=44";
|
||||
String url = "/first;p=11/second;q=22/third-fourth;q=44";
|
||||
assertEquals(expected, performGet(url, new HttpHeaders(), String.class).getBody());
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableWebFlux
|
||||
static class WebConfig {
|
||||
}
|
||||
|
||||
@RestController
|
||||
@SuppressWarnings("unused")
|
||||
private static class TestRestController {
|
||||
|
||||
@GetMapping("/param")
|
||||
public Publisher<String> param(@RequestParam String name) {
|
||||
return Flux.just("Hello ", name, "!");
|
||||
}
|
||||
|
||||
@GetMapping("/{one}/{two}/{three}-{four}")
|
||||
public String matrixVar(
|
||||
@MatrixVariable int p,
|
||||
@MatrixVariable(name = "q", pathVar = "two") int q2,
|
||||
@MatrixVariable(name = "q", pathVar = "four") int q4) {
|
||||
|
||||
return "p=" + p + ", q2=" + q2 + ", q4=" + q4;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.web.reactive.result.method.annotation;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.ReactiveAdapterRegistry;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.bind.annotation.MatrixVariable;
|
||||
import org.springframework.web.method.ResolvableMethod;
|
||||
import org.springframework.web.reactive.BindingContext;
|
||||
import org.springframework.web.reactive.HandlerMapping;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.web.method.MvcAnnotationPredicates.matrixAttribute;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link MatrixVariableMapMethodArgumentResolver}.
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class MatrixVariablesMapMethodArgumentResolverTests {
|
||||
|
||||
private final MatrixVariableMapMethodArgumentResolver resolver =
|
||||
new MatrixVariableMapMethodArgumentResolver(new ReactiveAdapterRegistry());
|
||||
|
||||
private final MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
|
||||
private final ResolvableMethod testMethod = ResolvableMethod.on(this.getClass()).named("handle").build();
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
this.exchange.getAttributes().put(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, new LinkedHashMap<>());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void supportsParameter() {
|
||||
|
||||
assertFalse(this.resolver.supportsParameter(this.testMethod.arg(String.class)));
|
||||
|
||||
assertTrue(this.resolver.supportsParameter(this.testMethod.annot(matrixAttribute().noName())
|
||||
.arg(Map.class, String.class, String.class)));
|
||||
|
||||
assertTrue(this.resolver.supportsParameter(this.testMethod.annot(matrixAttribute().noPathVar())
|
||||
.arg(MultiValueMap.class, String.class, String.class)));
|
||||
|
||||
assertTrue(this.resolver.supportsParameter(this.testMethod.annot(matrixAttribute().pathVar("cars"))
|
||||
.arg(MultiValueMap.class, String.class, String.class)));
|
||||
|
||||
assertFalse(this.resolver.supportsParameter(this.testMethod.annot(matrixAttribute().name("name"))
|
||||
.arg(Map.class, String.class, String.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgument() throws Exception {
|
||||
MultiValueMap<String, String> params = getMatrixVariables("cars");
|
||||
params.add("colors", "red");
|
||||
params.add("colors", "green");
|
||||
params.add("colors", "blue");
|
||||
params.add("year", "2012");
|
||||
|
||||
MethodParameter param = this.testMethod.annot(matrixAttribute().noName())
|
||||
.arg(Map.class, String.class, String.class);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> map =
|
||||
(Map<String, String>) this.resolver.resolveArgument(
|
||||
param, new BindingContext(), this.exchange).block(Duration.ZERO);
|
||||
|
||||
assertNotNull(map);
|
||||
assertEquals("red", map.get("colors"));
|
||||
|
||||
param = this.testMethod
|
||||
.annot(matrixAttribute().noPathVar())
|
||||
.arg(MultiValueMap.class, String.class, String.class);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
MultiValueMap<String, String> multivalueMap =
|
||||
(MultiValueMap<String, String>) this.resolver.resolveArgument(
|
||||
param, new BindingContext(), this.exchange).block(Duration.ZERO);
|
||||
|
||||
assertEquals(Arrays.asList("red", "green", "blue"), multivalueMap.get("colors"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentPathVariable() throws Exception {
|
||||
MultiValueMap<String, String> params1 = getMatrixVariables("cars");
|
||||
params1.add("colors", "red");
|
||||
params1.add("colors", "purple");
|
||||
|
||||
MultiValueMap<String, String> params2 = getMatrixVariables("planes");
|
||||
params2.add("colors", "yellow");
|
||||
params2.add("colors", "orange");
|
||||
|
||||
MethodParameter param = this.testMethod.annot(matrixAttribute().pathVar("cars"))
|
||||
.arg(MultiValueMap.class, String.class, String.class);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> mapForPathVar = (Map<String, String>)
|
||||
this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block(Duration.ZERO);
|
||||
|
||||
assertNotNull(mapForPathVar);
|
||||
assertEquals(Arrays.asList("red", "purple"), mapForPathVar.get("colors"));
|
||||
|
||||
param = this.testMethod.annot(matrixAttribute().noName()).arg(Map.class, String.class, String.class);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> mapAll = (Map<String, String>)
|
||||
this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block(Duration.ZERO);
|
||||
|
||||
assertNotNull(mapAll);
|
||||
assertEquals("red", mapAll.get("colors"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentNoParams() throws Exception {
|
||||
|
||||
MethodParameter param = this.testMethod.annot(matrixAttribute().noName())
|
||||
.arg(Map.class, String.class, String.class);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> map = (Map<String, String>)
|
||||
this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block(Duration.ZERO);
|
||||
|
||||
assertEquals(Collections.emptyMap(), map);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentNoMatch() throws Exception {
|
||||
MultiValueMap<String, String> params2 = getMatrixVariables("planes");
|
||||
params2.add("colors", "yellow");
|
||||
params2.add("colors", "orange");
|
||||
|
||||
MethodParameter param = this.testMethod.annot(matrixAttribute().pathVar("cars"))
|
||||
.arg(MultiValueMap.class, String.class, String.class);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> map = (Map<String, String>) this.resolver.resolveArgument(
|
||||
param, new BindingContext(), this.exchange).block(Duration.ZERO);
|
||||
|
||||
assertEquals(Collections.emptyMap(), map);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private MultiValueMap<String, String> getMatrixVariables(String pathVarName) {
|
||||
Map<String, MultiValueMap<String, String>> matrixVariables =
|
||||
this.exchange.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE);
|
||||
|
||||
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
||||
matrixVariables.put(pathVarName, params);
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
void handle(
|
||||
String stringArg,
|
||||
@MatrixVariable Map<String, String> map,
|
||||
@MatrixVariable MultiValueMap<String, String> multivalueMap,
|
||||
@MatrixVariable(pathVar="cars") MultiValueMap<String, String> mapForPathVar,
|
||||
@MatrixVariable("name") Map<String, String> mapWithName) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.web.reactive.result.method.annotation;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.ReactiveAdapterRegistry;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.bind.annotation.MatrixVariable;
|
||||
import org.springframework.web.method.ResolvableMethod;
|
||||
import org.springframework.web.reactive.BindingContext;
|
||||
import org.springframework.web.reactive.HandlerMapping;
|
||||
import org.springframework.web.server.ServerErrorException;
|
||||
import org.springframework.web.server.ServerWebInputException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.web.method.MvcAnnotationPredicates.matrixAttribute;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link MatrixVariableMethodArgumentResolver}.
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class MatrixVariablesMethodArgumentResolverTests {
|
||||
|
||||
private MatrixVariableMethodArgumentResolver resolver =
|
||||
new MatrixVariableMethodArgumentResolver(null, new ReactiveAdapterRegistry());
|
||||
|
||||
private final MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
|
||||
private ResolvableMethod testMethod = ResolvableMethod.on(this.getClass()).named("handle").build();
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
this.exchange.getAttributes().put(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, new LinkedHashMap<>());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void supportsParameter() {
|
||||
|
||||
assertFalse(this.resolver.supportsParameter(this.testMethod.arg(String.class)));
|
||||
|
||||
assertTrue(this.resolver.supportsParameter(this.testMethod
|
||||
.annot(matrixAttribute().noName()).arg(List.class, String.class)));
|
||||
|
||||
assertTrue(this.resolver.supportsParameter(this.testMethod
|
||||
.annot(matrixAttribute().name("year")).arg(int.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgument() throws Exception {
|
||||
MultiValueMap<String, String> params = getVariablesFor("cars");
|
||||
params.add("colors", "red");
|
||||
params.add("colors", "green");
|
||||
params.add("colors", "blue");
|
||||
MethodParameter param = this.testMethod.annot(matrixAttribute().noName()).arg(List.class, String.class);
|
||||
|
||||
assertEquals(Arrays.asList("red", "green", "blue"),
|
||||
this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block(Duration.ZERO));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentPathVariable() throws Exception {
|
||||
getVariablesFor("cars").add("year", "2006");
|
||||
getVariablesFor("bikes").add("year", "2005");
|
||||
MethodParameter param = this.testMethod.annot(matrixAttribute().name("year")).arg(int.class);
|
||||
|
||||
Object actual = this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block(Duration.ZERO);
|
||||
assertEquals(2006, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentDefaultValue() throws Exception {
|
||||
MethodParameter param = this.testMethod.annot(matrixAttribute().name("year")).arg(int.class);
|
||||
Object actual = this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block(Duration.ZERO);
|
||||
assertEquals(2013, actual);
|
||||
}
|
||||
|
||||
@Test(expected = ServerErrorException.class)
|
||||
public void resolveArgumentMultipleMatches() throws Exception {
|
||||
getVariablesFor("var1").add("colors", "red");
|
||||
getVariablesFor("var2").add("colors", "green");
|
||||
|
||||
MethodParameter param = this.testMethod.annot(matrixAttribute().noName()).arg(List.class, String.class);
|
||||
this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block(Duration.ZERO);
|
||||
}
|
||||
|
||||
@Test(expected = ServerWebInputException.class)
|
||||
public void resolveArgumentRequired() throws Exception {
|
||||
MethodParameter param = this.testMethod.annot(matrixAttribute().noName()).arg(List.class, String.class);
|
||||
this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block(Duration.ZERO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentNoMatch() throws Exception {
|
||||
MultiValueMap<String, String> params = getVariablesFor("cars");
|
||||
params.add("anotherYear", "2012");
|
||||
MethodParameter param = this.testMethod.annot(matrixAttribute().name("year")).arg(int.class);
|
||||
|
||||
Object actual = this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block(Duration.ZERO);
|
||||
assertEquals(2013, actual);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private MultiValueMap<String, String> getVariablesFor(String pathVarName) {
|
||||
Map<String, MultiValueMap<String, String>> matrixVariables =
|
||||
this.exchange.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE);
|
||||
|
||||
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
||||
matrixVariables.put(pathVarName, params);
|
||||
return params;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
void handle(
|
||||
String stringArg,
|
||||
@MatrixVariable List<String> colors,
|
||||
@MatrixVariable(name = "year", pathVar = "cars", required = false, defaultValue = "2013") int preferredYear) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,13 +26,13 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.reactive.config.EnableWebFlux;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* Integration tests with {@code @RequestMapping} handler methods.
|
||||
@@ -55,40 +55,23 @@ public class RequestMappingIntegrationTests extends AbstractRequestMappingIntegr
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void handleWithParam() throws Exception {
|
||||
String expected = "Hello George!";
|
||||
assertEquals(expected, performGet("/param?name=George", new HttpHeaders(), String.class).getBody());
|
||||
}
|
||||
|
||||
@Test // SPR-15140
|
||||
public void handleWithEncodedParam() throws Exception {
|
||||
String expected = "Hello + \u00e0!";
|
||||
assertEquals(expected, performGet("/param?name=%20%2B+%C3%A0", new HttpHeaders(), String.class).getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longStreamResult() throws Exception {
|
||||
String[] expected = {"0", "1", "2", "3", "4"};
|
||||
assertArrayEquals(expected, performGet("/long-stream-result", new HttpHeaders(), String[].class).getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void objectStreamResultWithAllMediaType() throws Exception {
|
||||
String expected = "[{\"name\":\"bar\"}]";
|
||||
assertEquals(expected, performGet("/object-stream-result", MediaType.ALL, String.class).getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpHead() throws Exception {
|
||||
String url = "http://localhost:" + this.port + "/param?name=George";
|
||||
String url = "http://localhost:" + this.port + "/text";
|
||||
HttpHeaders headers = getRestTemplate().headForHeaders(url);
|
||||
String contentType = headers.getFirst("Content-Type");
|
||||
assertNotNull(contentType);
|
||||
assertEquals("text/html;charset=utf-8", contentType.toLowerCase());
|
||||
assertEquals(13, headers.getContentLength());
|
||||
assertEquals(3, headers.getContentLength());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stream() throws Exception {
|
||||
String[] expected = {"0", "1", "2", "3", "4"};
|
||||
assertArrayEquals(expected, performGet("/stream", new HttpHeaders(), String[].class).getBody());
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableWebFlux
|
||||
static class WebConfig {
|
||||
@@ -96,41 +79,17 @@ public class RequestMappingIntegrationTests extends AbstractRequestMappingIntegr
|
||||
|
||||
|
||||
@RestController
|
||||
@SuppressWarnings("unused")
|
||||
private static class TestRestController {
|
||||
|
||||
@GetMapping("/param")
|
||||
public Publisher<String> handleWithParam(@RequestParam String name) {
|
||||
return Flux.just("Hello ", name, "!");
|
||||
@GetMapping("/text")
|
||||
public String text() {
|
||||
return "Foo";
|
||||
}
|
||||
|
||||
@GetMapping("/long-stream-result")
|
||||
public Publisher<Long> longStreamResponseBody() {
|
||||
return Flux.interval(Duration.ofMillis(100)).take(5);
|
||||
}
|
||||
|
||||
@GetMapping("/object-stream-result")
|
||||
public Publisher<Foo> objectStreamResponseBody() {
|
||||
return Flux.just(new Foo("bar"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class Foo {
|
||||
|
||||
private String name;
|
||||
|
||||
public Foo(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
@GetMapping("/stream")
|
||||
public Publisher<Long> stream() {
|
||||
return Flux.interval(Duration.ofMillis(50)).take(5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user