diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/response/ChunkedResponseTest.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/response/ChunkedResponseTest.java index 1bd68e6a2d9bb..ae68349b887c2 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/response/ChunkedResponseTest.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/response/ChunkedResponseTest.java @@ -7,14 +7,21 @@ import java.io.IOException; import java.io.OutputStream; import java.io.UncheckedIOException; +import java.lang.annotation.Annotation; import java.lang.reflect.Type; +import java.nio.charset.StandardCharsets; +import javax.annotation.Priority; import javax.ws.rs.GET; import javax.ws.rs.Path; +import javax.ws.rs.Priorities; import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.ext.Provider; -import org.jboss.resteasy.reactive.server.providers.serialisers.ServerStringMessageBodyHandler; +import org.jboss.resteasy.reactive.server.spi.ResteasyReactiveResourceInfo; +import org.jboss.resteasy.reactive.server.spi.ServerMessageBodyWriter; import org.jboss.resteasy.reactive.server.spi.ServerRequestContext; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.junit.jupiter.api.Test; @@ -68,29 +75,39 @@ public String helloSmall() { } @Provider - public static class CustomStringMessageBodyWriter extends ServerStringMessageBodyHandler { + public static class CustomStringMessageBodyWriter implements ServerMessageBodyWriter { @Override - public void writeResponse(Object o, Type genericType, ServerRequestContext context) - throws WebApplicationException { + public boolean isWriteable(Class type, Type genericType, ResteasyReactiveResourceInfo target, MediaType mediaType) { + return true; + } - try (OutputStream stream = context.getOrCreateOutputStream()) { - stream.write(((String) o).getBytes()); - } catch (IOException e) { - throw new UncheckedIOException(e); - } + @Override + public void writeResponse(String o, Type genericType, ServerRequestContext context) throws WebApplicationException { + context.serverResponse().end(o); + } + + public boolean isWriteable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { + return true; + } + + public void writeTo(String o, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, + MultivaluedMap httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write(o.getBytes(StandardCharsets.UTF_8)); } } @Provider + @Priority(Priorities.USER + 1) // the spec says that when it comes to writers, higher number means higher priority... public static final class CustomStringMessageBodyWriter2 extends CustomStringMessageBodyWriter { @Override - public void writeResponse(Object o, Type genericType, ServerRequestContext context) + public void writeResponse(String o, Type genericType, ServerRequestContext context) throws WebApplicationException { try (OutputStream stream = context.getOrCreateOutputStream()) { - stream.write(((String) o).getBytes()); + stream.write(o.getBytes()); } catch (IOException e) { throw new UncheckedIOException(e); }