diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/BodyInsertor.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/BodyInserter.java similarity index 76% rename from spring-web-reactive/src/main/java/org/springframework/web/reactive/function/BodyInsertor.java rename to spring-web-reactive/src/main/java/org/springframework/web/reactive/function/BodyInserter.java index 43764bd35d..b85eee0ba2 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/BodyInsertor.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/BodyInserter.java @@ -31,10 +31,10 @@ import org.springframework.util.Assert; * @author Arjen Poutsma * @since 5.0 * @see Response#body() - * @see Response.BodyBuilder#body(BodyInsertor) - * @see BodyInsertors + * @see Response.BodyBuilder#body(BodyInserter) + * @see BodyInserters */ -public interface BodyInsertor { +public interface BodyInserter { /** * Insert into the given response. @@ -52,19 +52,19 @@ public interface BodyInsertor { /** - * Return a new {@code BodyInsertor} described by the given writer and supplier functions. - * @param writer the writer function for the new insertor - * @param supplier the supplier function for the new insertor - * @param the type supplied and written by the insertor - * @return the new {@code BodyInsertor} + * Return a new {@code BodyInserter} described by the given writer and supplier functions. + * @param writer the writer function for the new inserter + * @param supplier the supplier function for the new inserter + * @param the type supplied and written by the inserter + * @return the new {@code BodyInserter} */ - static BodyInsertor of(BiFunction> writer, + static BodyInserter of(BiFunction> writer, Supplier supplier) { Assert.notNull(writer, "'writer' must not be null"); Assert.notNull(supplier, "'supplier' must not be null"); - return new BodyInsertors.DefaultBodyInsertor(writer, supplier); + return new BodyInserters.DefaultBodyInserter(writer, supplier); } } diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/BodyInsertors.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/BodyInserters.java similarity index 82% rename from spring-web-reactive/src/main/java/org/springframework/web/reactive/function/BodyInsertors.java rename to spring-web-reactive/src/main/java/org/springframework/web/reactive/function/BodyInserters.java index 856f38a37b..9cd9eb709e 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/BodyInsertors.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/BodyInserters.java @@ -37,13 +37,13 @@ import org.springframework.util.Assert; import org.springframework.util.ClassUtils; /** - * Implementations of {@link BodyInsertor} that write various bodies, such a reactive streams, + * Implementations of {@link BodyInserter} that write various bodies, such a reactive streams, * server-sent events, resources, etc. * * @author Arjen Poutsma * @since 5.0 */ -public abstract class BodyInsertors { +public abstract class BodyInserters { private static final ResolvableType RESOURCE_TYPE = ResolvableType.forClass(Resource.class); @@ -52,32 +52,32 @@ public abstract class BodyInsertors { private static final boolean jackson2Present = ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", - BodyInsertors.class.getClassLoader()) && + BodyInserters.class.getClassLoader()) && ClassUtils.isPresent("com.fasterxml.jackson.core.JsonGenerator", - BodyInsertors.class.getClassLoader()); + BodyInserters.class.getClassLoader()); /** - * Return a {@code BodyInsertor} that writes the given single object. + * Return a {@code BodyInserter} that writes the given single object. * @param body the body of the response - * @return a {@code BodyInsertor} that writes a single object + * @return a {@code BodyInserter} that writes a single object */ - public static BodyInsertor fromObject(T body) { + public static BodyInserter fromObject(T body) { Assert.notNull(body, "'body' must not be null"); - return BodyInsertor.of( + return BodyInserter.of( (response, configuration) -> writeWithMessageWriters(response, configuration, Mono.just(body), ResolvableType.forInstance(body)), () -> body); } /** - * Return a {@code BodyInsertor} that writes the given {@link Publisher}. + * Return a {@code BodyInserter} that writes the given {@link Publisher}. * @param publisher the publisher to stream to the response body * @param elementClass the class of elements contained in the publisher * @param the type of the elements contained in the publisher * @param the type of the {@code Publisher}. - * @return a {@code BodyInsertor} that writes a {@code Publisher} + * @return a {@code BodyInserter} that writes a {@code Publisher} */ - public static , T> BodyInsertor fromPublisher(S publisher, + public static , T> BodyInserter fromPublisher(S publisher, Class elementClass) { Assert.notNull(publisher, "'publisher' must not be null"); @@ -86,19 +86,19 @@ public abstract class BodyInsertors { } /** - * Return a {@code BodyInsertor} that writes the given {@link Publisher}. + * Return a {@code BodyInserter} that writes the given {@link Publisher}. * @param publisher the publisher to stream to the response body * @param elementType the type of elements contained in the publisher * @param the type of the elements contained in the publisher * @param the type of the {@code Publisher}. - * @return a {@code BodyInsertor} that writes a {@code Publisher} + * @return a {@code BodyInserter} that writes a {@code Publisher} */ - public static , T> BodyInsertor fromPublisher(S publisher, + public static , T> BodyInserter fromPublisher(S publisher, ResolvableType elementType) { Assert.notNull(publisher, "'publisher' must not be null"); Assert.notNull(elementType, "'elementType' must not be null"); - return BodyInsertor.of( + return BodyInserter.of( (response, configuration) -> writeWithMessageWriters(response, configuration, publisher, elementType), () -> publisher @@ -106,17 +106,17 @@ public abstract class BodyInsertors { } /** - * Return a {@code BodyInsertor} that writes the given {@code Resource}. + * Return a {@code BodyInserter} that writes the given {@code Resource}. * If the resource can be resolved to a {@linkplain Resource#getFile() file}, it will be copied * using * zero-copy * @param resource the resource to write to the response * @param the type of the {@code Resource} - * @return a {@code BodyInsertor} that writes a {@code Publisher} + * @return a {@code BodyInserter} that writes a {@code Publisher} */ - public static BodyInsertor fromResource(T resource) { + public static BodyInserter fromResource(T resource) { Assert.notNull(resource, "'resource' must not be null"); - return BodyInsertor.of( + return BodyInserter.of( (response, configuration) -> { ResourceHttpMessageWriter messageWriter = new ResourceHttpMessageWriter(); MediaType contentType = response.getHeaders().getContentType(); @@ -128,17 +128,17 @@ public abstract class BodyInsertors { } /** - * Return a {@code BodyInsertor} that writes the given {@code ServerSentEvent} publisher. + * Return a {@code BodyInserter} that writes the given {@code ServerSentEvent} publisher. * @param eventsPublisher the {@code ServerSentEvent} publisher to write to the response body * @param the type of the elements contained in the {@link ServerSentEvent} - * @return a {@code BodyInsertor} that writes a {@code ServerSentEvent} publisher + * @return a {@code BodyInserter} that writes a {@code ServerSentEvent} publisher * @see Server-Sent Events W3C recommendation */ - public static >> BodyInsertor fromServerSentEvents( + public static >> BodyInserter fromServerSentEvents( S eventsPublisher) { Assert.notNull(eventsPublisher, "'eventsPublisher' must not be null"); - return BodyInsertor.of( + return BodyInserter.of( (response, configuration) -> { ServerSentEventHttpMessageWriter messageWriter = sseMessageWriter(); MediaType contentType = response.getHeaders().getContentType(); @@ -150,16 +150,16 @@ public abstract class BodyInsertors { } /** - * Return a {@code BodyInsertor} that writes the given {@code Publisher} publisher as + * Return a {@code BodyInserter} that writes the given {@code Publisher} publisher as * Server-Sent Events. * @param eventsPublisher the publisher to write to the response body as Server-Sent Events * @param eventClass the class of event contained in the publisher * @param the type of the elements contained in the publisher - * @return a {@code BodyInsertor} that writes the given {@code Publisher} publisher as + * @return a {@code BodyInserter} that writes the given {@code Publisher} publisher as * Server-Sent Events * @see Server-Sent Events W3C recommendation */ - public static > BodyInsertor fromServerSentEvents(S eventsPublisher, + public static > BodyInserter fromServerSentEvents(S eventsPublisher, Class eventClass) { Assert.notNull(eventsPublisher, "'eventsPublisher' must not be null"); @@ -168,21 +168,21 @@ public abstract class BodyInsertors { } /** - * Return a {@code BodyInsertor} that writes the given {@code Publisher} publisher as + * Return a {@code BodyInserter} that writes the given {@code Publisher} publisher as * Server-Sent Events. * @param eventsPublisher the publisher to write to the response body as Server-Sent Events * @param eventType the type of event contained in the publisher * @param the type of the elements contained in the publisher - * @return a {@code BodyInsertor} that writes the given {@code Publisher} publisher as + * @return a {@code BodyInserter} that writes the given {@code Publisher} publisher as * Server-Sent Events * @see Server-Sent Events W3C recommendation */ - public static > BodyInsertor fromServerSentEvents(S eventsPublisher, + public static > BodyInserter fromServerSentEvents(S eventsPublisher, ResolvableType eventType) { Assert.notNull(eventsPublisher, "'eventsPublisher' must not be null"); Assert.notNull(eventType, "'eventType' must not be null"); - return BodyInsertor.of( + return BodyInserter.of( (response, configuration) -> { ServerSentEventHttpMessageWriter messageWriter = sseMessageWriter(); MediaType contentType = response.getHeaders().getContentType(); @@ -211,7 +211,7 @@ public abstract class BodyInsertors { .filter(messageWriter -> messageWriter.canWrite(bodyType, contentType, Collections .emptyMap())) .findFirst() - .map(BodyInsertors::cast) + .map(BodyInserters::cast) .map(messageWriter -> messageWriter .write(body, bodyType, contentType, response, Collections .emptyMap())) @@ -226,13 +226,13 @@ public abstract class BodyInsertors { return (HttpMessageWriter) messageWriter; } - static class DefaultBodyInsertor implements BodyInsertor { + static class DefaultBodyInserter implements BodyInserter { private final BiFunction> writer; private final Supplier supplier; - public DefaultBodyInsertor( + public DefaultBodyInserter( BiFunction> writer, Supplier supplier) { this.writer = writer; diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/DefaultResponseBuilder.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/DefaultResponseBuilder.java index dca54d6e66..902ffebde8 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/DefaultResponseBuilder.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/DefaultResponseBuilder.java @@ -141,7 +141,7 @@ class DefaultResponseBuilder implements Response.BodyBuilder { @Override public Response build() { - return body(BodyInsertor.of( + return body(BodyInserter.of( (response, configuration) -> response.setComplete(), () -> null)); } @@ -149,7 +149,7 @@ class DefaultResponseBuilder implements Response.BodyBuilder { @Override public > Response build(T voidPublisher) { Assert.notNull(voidPublisher, "'voidPublisher' must not be null"); - return body(BodyInsertor.of( + return body(BodyInserter.of( (response, configuration) -> Flux.from(voidPublisher).then(response.setComplete()), () -> null)); } @@ -157,13 +157,13 @@ class DefaultResponseBuilder implements Response.BodyBuilder { @Override public Response body(BiFunction> writer, Supplier supplier) { - return body(BodyInsertor.of(writer, supplier)); + return body(BodyInserter.of(writer, supplier)); } @Override - public Response body(BodyInsertor insertor) { - Assert.notNull(insertor, "'insertor' must not be null"); - return new BodyInsertorResponse(this.statusCode, this.headers, insertor); + public Response body(BodyInserter inserter) { + Assert.notNull(inserter, "'inserter' must not be null"); + return new BodyInserterResponse(this.statusCode, this.headers, inserter); } @Override @@ -233,27 +233,27 @@ class DefaultResponseBuilder implements Response.BodyBuilder { } } - private static final class BodyInsertorResponse extends AbstractResponse { + private static final class BodyInserterResponse extends AbstractResponse { - private final BodyInsertor insertor; + private final BodyInserter inserter; - public BodyInsertorResponse( - int statusCode, HttpHeaders headers, BodyInsertor insertor) { + public BodyInserterResponse( + int statusCode, HttpHeaders headers, BodyInserter inserter) { super(statusCode, headers); - this.insertor = insertor; + this.inserter = inserter; } @Override public T body() { - return this.insertor.t(); + return this.inserter.t(); } @Override public Mono writeTo(ServerWebExchange exchange, Configuration configuration) { ServerHttpResponse response = exchange.getResponse(); writeStatusAndHeaders(response); - return this.insertor.insert(response, configuration); + return this.inserter.insert(response, configuration); } } diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/Response.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/Response.java index 88dc5b6d05..2c1fd09395 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/Response.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/Response.java @@ -308,7 +308,8 @@ public interface Response { BodyBuilder contentType(MediaType contentType); /** - * Write the body to the given {@code BodyInsertor} and return it. + * Set the body with the given {@code supplier} function, and write it with the given + * {@code writer} function. * @param writer a function that writes the body to the {@code ServerHttpResponse} * @param supplier a function that returns the body instance * @param the type contained in the body @@ -318,12 +319,12 @@ public interface Response { Supplier supplier); /** - * Set the body of the response to the given {@code BodyInsertor} and return it. - * @param insertor the {@code BodyInsertor} that writes to the response + * Set the body of the response to the given {@code BodyInserter} and return it. + * @param inserter the {@code BodyInserter} that writes to the response * @param the type contained in the body * @return the built response */ - Response body(BodyInsertor insertor); + Response body(BodyInserter inserter); /** * Render the template with the given {@code name} using the given {@code modelAttributes}. diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/BodyInsertorsTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/BodyInsertersTests.java similarity index 79% rename from spring-web-reactive/src/test/java/org/springframework/web/reactive/function/BodyInsertorsTests.java rename to spring-web-reactive/src/test/java/org/springframework/web/reactive/function/BodyInsertersTests.java index 072f783519..2ceec27762 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/BodyInsertorsTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/BodyInsertersTests.java @@ -38,17 +38,17 @@ import static org.junit.Assert.assertEquals; /** * @author Arjen Poutsma */ -public class BodyInsertorsTests { +public class BodyInsertersTests { @Test public void ofObject() throws Exception { String body = "foo"; - BodyInsertor insertor = BodyInsertors.fromObject(body); + BodyInserter inserter = BodyInserters.fromObject(body); - assertEquals(body, insertor.t()); + assertEquals(body, inserter.t()); MockServerHttpResponse response = new MockServerHttpResponse(); - Mono result = insertor.insert(response, Configuration.builder().build()); + Mono result = inserter.insert(response, Configuration.builder().build()); TestSubscriber.subscribe(result) .assertComplete(); @@ -62,12 +62,12 @@ public class BodyInsertorsTests { @Test public void ofPublisher() throws Exception { Flux body = Flux.just("foo"); - BodyInsertor> insertor = BodyInsertors.fromPublisher(body, String.class); + BodyInserter> inserter = BodyInserters.fromPublisher(body, String.class); - assertEquals(body, insertor.t()); + assertEquals(body, inserter.t()); MockServerHttpResponse response = new MockServerHttpResponse(); - Mono result = insertor.insert(response, Configuration.builder().build()); + Mono result = inserter.insert(response, Configuration.builder().build()); TestSubscriber.subscribe(result) .assertComplete(); @@ -81,12 +81,12 @@ public class BodyInsertorsTests { @Test public void ofResource() throws Exception { Resource body = new ClassPathResource("response.txt", getClass()); - BodyInsertor insertor = BodyInsertors.fromResource(body); + BodyInserter inserter = BodyInserters.fromResource(body); - assertEquals(body, insertor.t()); + assertEquals(body, inserter.t()); MockServerHttpResponse response = new MockServerHttpResponse(); - Mono result = insertor.insert(response, Configuration.builder().build()); + Mono result = inserter.insert(response, Configuration.builder().build()); TestSubscriber.subscribe(result) .assertComplete(); @@ -105,13 +105,13 @@ public class BodyInsertorsTests { public void ofServerSentEventFlux() throws Exception { ServerSentEvent event = ServerSentEvent.builder("foo").build(); Flux> body = Flux.just(event); - BodyInsertor>> insertor = - BodyInsertors.fromServerSentEvents(body); + BodyInserter>> inserter = + BodyInserters.fromServerSentEvents(body); - assertEquals(body, insertor.t()); + assertEquals(body, inserter.t()); MockServerHttpResponse response = new MockServerHttpResponse(); - Mono result = insertor.insert(response, Configuration.builder().build()); + Mono result = inserter.insert(response, Configuration.builder().build()); TestSubscriber.subscribe(result) .assertComplete(); @@ -120,13 +120,13 @@ public class BodyInsertorsTests { @Test public void ofServerSentEventClass() throws Exception { Flux body = Flux.just("foo"); - BodyInsertor> insertor = - BodyInsertors.fromServerSentEvents(body, String.class); + BodyInserter> inserter = + BodyInserters.fromServerSentEvents(body, String.class); - assertEquals(body, insertor.t()); + assertEquals(body, inserter.t()); MockServerHttpResponse response = new MockServerHttpResponse(); - Mono result = insertor.insert(response, Configuration.builder().build()); + Mono result = inserter.insert(response, Configuration.builder().build()); TestSubscriber.subscribe(result) .assertComplete(); diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/DefaultResponseBuilderTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/DefaultResponseBuilderTests.java index 940d4191e9..0b216403f2 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/DefaultResponseBuilderTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/DefaultResponseBuilderTests.java @@ -214,7 +214,7 @@ public class DefaultResponseBuilderTests { } @Test - public void bodyInsertor() throws Exception { + public void bodyInserter() throws Exception { String body = "foo"; Supplier supplier = () -> body; BiFunction> writer = diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/DispatcherHandlerIntegrationTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/DispatcherHandlerIntegrationTests.java index 21dce77b78..4c04246ff4 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/DispatcherHandlerIntegrationTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/DispatcherHandlerIntegrationTests.java @@ -155,14 +155,14 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr public Response> mono(Request request) { Person person = new Person("John"); - return Response.ok().body(BodyInsertors.fromPublisher(Mono.just(person), Person.class)); + return Response.ok().body(BodyInserters.fromPublisher(Mono.just(person), Person.class)); } public Response> flux(Request request) { Person person1 = new Person("John"); Person person2 = new Person("Jane"); return Response.ok().body( - BodyInsertors.fromPublisher(Flux.just(person1, person2), Person.class)); + BodyInserters.fromPublisher(Flux.just(person1, person2), Person.class)); } } diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/PublisherHandlerFunctionIntegrationTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/PublisherHandlerFunctionIntegrationTests.java index 51d22f9057..439edd50cf 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/PublisherHandlerFunctionIntegrationTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/PublisherHandlerFunctionIntegrationTests.java @@ -34,7 +34,7 @@ import org.springframework.web.client.RestTemplate; import static org.junit.Assert.assertEquals; import static org.springframework.web.reactive.function.BodyExtractors.toMono; -import static org.springframework.web.reactive.function.BodyInsertors.fromPublisher; +import static org.springframework.web.reactive.function.BodyInserters.fromPublisher; import static org.springframework.web.reactive.function.RequestPredicates.GET; import static org.springframework.web.reactive.function.RequestPredicates.POST; import static org.springframework.web.reactive.function.RouterFunctions.route; diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/RouterFunctionTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/RouterFunctionTests.java index 3d52ef0b2b..0ffdb3c906 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/RouterFunctionTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/RouterFunctionTests.java @@ -23,7 +23,7 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.springframework.web.reactive.function.BodyInsertors.fromObject; +import static org.springframework.web.reactive.function.BodyInserters.fromObject; /** * @author Arjen Poutsma diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/SseHandlerFunctionIntegrationTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/SseHandlerFunctionIntegrationTests.java index 7993c6d1fb..b403025059 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/SseHandlerFunctionIntegrationTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/SseHandlerFunctionIntegrationTests.java @@ -111,13 +111,13 @@ public class SseHandlerFunctionIntegrationTests public Response> string(Request request) { Flux flux = Flux.interval(Duration.ofMillis(100)).map(l -> "foo " + l).take(2); - return Response.ok().body(BodyInsertors.fromServerSentEvents(flux, String.class)); + return Response.ok().body(BodyInserters.fromServerSentEvents(flux, String.class)); } public Response> person(Request request) { Flux flux = Flux.interval(Duration.ofMillis(100)) .map(l -> new Person("foo " + l)).take(2); - return Response.ok().body(BodyInsertors.fromServerSentEvents(flux, Person.class)); + return Response.ok().body(BodyInserters.fromServerSentEvents(flux, Person.class)); } public Response>> sse(Request request) { @@ -127,7 +127,7 @@ public class SseHandlerFunctionIntegrationTests .comment("bar") .build()).take(2); - return Response.ok().body(BodyInsertors.fromServerSentEvents(flux)); + return Response.ok().body(BodyInserters.fromServerSentEvents(flux)); } }