diff --git a/spring-web-reactive/src/main/java/org/springframework/http/codec/SseEventEncoder.java b/spring-web-reactive/src/main/java/org/springframework/http/codec/SseEventEncoder.java index f06fedc25f8..5cbac76600a 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/codec/SseEventEncoder.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/codec/SseEventEncoder.java @@ -31,6 +31,7 @@ import org.springframework.core.codec.support.AbstractEncoder; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.FlushingDataBuffer; +import org.springframework.http.MediaType; import org.springframework.util.Assert; import org.springframework.util.MimeType; import org.springframework.web.reactive.sse.SseEvent; @@ -87,8 +88,8 @@ public class SseEventEncoder extends AbstractEncoder { Object data = event.getData(); Flux dataBuffer = Flux.empty(); - MimeType mimeType = (event.getMimeType() == null ? - new MimeType("*") : event.getMimeType()); + MediaType mediaType = (event.getMediaType() == null ? + MediaType.ALL : event.getMediaType()); if (data != null) { sb.append("data:"); if (data instanceof String) { @@ -97,13 +98,13 @@ public class SseEventEncoder extends AbstractEncoder { else { Optional> encoder = dataEncoders .stream() - .filter(e -> e.canEncode(ResolvableType.forClass(data.getClass()), mimeType)) + .filter(e -> e.canEncode(ResolvableType.forClass(data.getClass()), mediaType)) .findFirst(); if (encoder.isPresent()) { dataBuffer = ((Encoder)encoder.get()) .encode(Mono.just(data), bufferFactory, - ResolvableType.forClass(data.getClass()), mimeType) + ResolvableType.forClass(data.getClass()), mediaType) .concatWith(encodeString("\n", bufferFactory)); } else { diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/sse/SseEvent.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/sse/SseEvent.java index 1b2f99b9dc1..9386e59d570 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/sse/SseEvent.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/sse/SseEvent.java @@ -16,8 +16,8 @@ package org.springframework.web.reactive.sse; +import org.springframework.http.MediaType; import org.springframework.http.codec.SseEventEncoder; -import org.springframework.util.MimeType; /** * Represent a Server-Sent Event. @@ -27,7 +27,7 @@ import org.springframework.util.MimeType; * * @author Sebastien Deleuze * @see SseEventEncoder - * @see Server-Sent Events W3C recommandation + * @see Server-Sent Events W3C recommendation */ public class SseEvent { @@ -37,7 +37,7 @@ public class SseEvent { private Object data; - private MimeType mimeType; + private MediaType mediaType; private Long reconnectTime; @@ -59,9 +59,9 @@ public class SseEvent { /** * Create an instance with the provided {@code data} and {@code mediaType}. */ - public SseEvent(Object data, MimeType mimeType) { + public SseEvent(Object data, MediaType mediaType) { this.data = data; - this.mimeType = mimeType; + this.mediaType = mediaType; } /** @@ -102,7 +102,7 @@ public class SseEvent { * - Turn multiline line {@code String} to multiple {@code data} fields * - Serialize other {@code Object} as JSON * - * @see #setMimeType(MimeType) + * @see #setMediaType(MediaType) */ public void setData(Object data) { this.data = data; @@ -116,19 +116,19 @@ public class SseEvent { } /** - * Set the {@link MimeType} used to serialize the {@code data}. + * Set the {@link MediaType} used to serialize the {@code data}. * {@link SseEventEncoder} should be configured with the relevant encoder to be * able to serialize it. */ - public void setMimeType(MimeType mimeType) { - this.mimeType = mimeType; + public void setMediaType(MediaType mediaType) { + this.mediaType = mediaType; } /** - * @see #setMimeType(MimeType) + * @see #setMediaType(MediaType) */ - public MimeType getMimeType() { - return mimeType; + public MediaType getMediaType() { + return this.mediaType; } /**