@@ -149,6 +149,9 @@ private static HttpMessageWriter<Resource> resourceHttpMessageWriter(BodyInserte
149
149
150
150
/**
151
151
* Return a {@code BodyInserter} that writes the given {@code ServerSentEvent} publisher.
152
+ * <p>Note that a SSE {@code BodyInserter} can also be obtained by passing a stream of strings
153
+ * or POJOs (to be encoded as JSON) to {@link #fromPublisher(Publisher, Class)}, and specifying a
154
+ * {@link MediaType#TEXT_EVENT_STREAM text/event-stream} Content-Type.
152
155
* @param eventsPublisher the {@code ServerSentEvent} publisher to write to the response body
153
156
* @param <T> the type of the elements contained in the {@link ServerSentEvent}
154
157
* @return a {@code BodyInserter} that writes a {@code ServerSentEvent} publisher
@@ -173,66 +176,6 @@ public static <T, S extends Publisher<ServerSentEvent<T>>> BodyInserter<S, Serve
173
176
};
174
177
}
175
178
176
- /**
177
- * Return a {@code BodyInserter} that writes the given {@code Publisher} publisher as
178
- * Server-Sent Events.
179
- * @param eventsPublisher the publisher to write to the response body as Server-Sent Events
180
- * @param eventClass the class of event contained in the publisher
181
- * @param <T> the type of the elements contained in the publisher
182
- * @return a {@code BodyInserter} that writes the given {@code Publisher} publisher as
183
- * Server-Sent Events
184
- * @see <a href="https://www.w3.org/TR/eventsource/">Server-Sent Events W3C recommendation</a>
185
- */
186
- // Note that the returned BodyInserter is parameterized to ServerHttpResponse, not
187
- // ReactiveHttpOutputMessage like other methods, since sending SSEs only typically happens on
188
- // the server-side
189
- public static <T , S extends Publisher <T >> BodyInserter <S , ServerHttpResponse > fromServerSentEvents (S eventsPublisher ,
190
- Class <T > eventClass ) {
191
-
192
- Assert .notNull (eventsPublisher , "'eventsPublisher' must not be null" );
193
- Assert .notNull (eventClass , "'eventClass' must not be null" );
194
- return fromServerSentEvents (eventsPublisher , ResolvableType .forClass (eventClass ));
195
- }
196
-
197
- /**
198
- * Return a {@code BodyInserter} that writes the given {@code Publisher} publisher as
199
- * Server-Sent Events.
200
- * @param eventsPublisher the publisher to write to the response body as Server-Sent Events
201
- * @param typeReference the type of event contained in the publisher
202
- * @param <T> the type of the elements contained in the publisher
203
- * @return a {@code BodyInserter} that writes the given {@code Publisher} publisher as
204
- * Server-Sent Events
205
- * @see <a href="https://www.w3.org/TR/eventsource/">Server-Sent Events W3C recommendation</a>
206
- */
207
- // Note that the returned BodyInserter is parameterized to ServerHttpResponse, not
208
- // ReactiveHttpOutputMessage like other methods, since sending SSEs only typically happens on
209
- // the server-side
210
- public static <T , S extends Publisher <T >> BodyInserter <S , ServerHttpResponse > fromServerSentEvents (S eventsPublisher ,
211
- ParameterizedTypeReference <T > typeReference ) {
212
-
213
- Assert .notNull (eventsPublisher , "'eventsPublisher' must not be null" );
214
- Assert .notNull (typeReference , "'typeReference' must not be null" );
215
- return fromServerSentEvents (eventsPublisher ,
216
- ResolvableType .forType (typeReference .getType ()));
217
- }
218
-
219
- static <T , S extends Publisher <T >> BodyInserter <S , ServerHttpResponse > fromServerSentEvents (S eventsPublisher ,
220
- ResolvableType eventType ) {
221
-
222
- Assert .notNull (eventsPublisher , "'eventsPublisher' must not be null" );
223
- Assert .notNull (eventType , "'eventType' must not be null" );
224
- return (serverResponse , context ) -> {
225
- HttpMessageWriter <T > messageWriter =
226
- findMessageWriter (context , SERVER_SIDE_EVENT_TYPE , MediaType .TEXT_EVENT_STREAM );
227
- return context .serverRequest ()
228
- .map (serverRequest -> messageWriter .write (eventsPublisher , eventType ,
229
- eventType , MediaType .TEXT_EVENT_STREAM , serverRequest ,
230
- serverResponse , context .hints ()))
231
- .orElseGet (() -> messageWriter .write (eventsPublisher , eventType ,
232
- MediaType .TEXT_EVENT_STREAM , serverResponse , context .hints ()));
233
- };
234
- }
235
-
236
179
/**
237
180
* Return a {@code BodyInserter} that writes the given {@code MultiValueMap} as URL-encoded
238
181
* form data.
@@ -241,7 +184,7 @@ static <T, S extends Publisher<T>> BodyInserter<S, ServerHttpResponse> fromServe
241
184
*/
242
185
// Note that the returned BodyInserter is parameterized to ClientHttpRequest, not
243
186
// ReactiveHttpOutputMessage like other methods, since sending form data only typically happens
244
- // on the server -side
187
+ // on the client -side
245
188
public static BodyInserter <MultiValueMap <String , String >, ClientHttpRequest > fromFormData (
246
189
MultiValueMap <String , String > formData ) {
247
190
@@ -262,7 +205,7 @@ public static BodyInserter<MultiValueMap<String, String>, ClientHttpRequest> fro
262
205
*/
263
206
// Note that the returned BodyInserter is parameterized to ClientHttpRequest, not
264
207
// ReactiveHttpOutputMessage like other methods, since sending form data only typically happens
265
- // on the server -side
208
+ // on the client -side
266
209
public static BodyInserter <MultiValueMap <String , ?>, ClientHttpRequest > fromMultipartData (
267
210
MultiValueMap <String , ?> multipartData ) {
268
211
0 commit comments