quarkus: Can't read SSE content type with plain Rest client

Describe the bug

When consuming an SSE source with quarkus-rest-client-jsonb, I get the following error: RESTEASY003145: Unable to find a MessageBodyReader of content-type text/event-stream and type class org.jboss.resteasy.plugins.providers.sse.SseEventInputImpl.

Funnily, this only happens in the Quarkus app in the production code; in my unit test, it works as expected (reading the SSE events). My assumption is that the build-time optimization removes some classes it finds unnecessary.

I’m not using resteasy, since this a cli app. This might be the isssue… I’m also not using rest-client-reactive-* because of #35966

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

This code:

@ApplicationScoped
public class SomeClient {

    private Client client;
    private SseEventSource updateSource;

    @PostConstruct
    void init() {
        client = ClientBuilder.newClient();
    }

    // [...]

    @PreDestroy
    void close() throws IOException {
        client.close();
        if (updateSource != null)
            updateSource.close();
    }

    public void someMethod() {
        // [...]

        WebTarget target = client.target("http://localhost:8080/updates");
        updateSource = SseEventSource.target(target).build();
        updateSource.register(ev -> {
            System.out.println(ev.getName());
            System.out.println(ev.readData());
        }, thr -> {
            System.err.println("Error in SSE updates");
            thr.printStackTrace();
        });

        System.out.println("SSE opened");
        updateSource.open();
    }

}

Invocation of the method results in:

jakarta.ws.rs.ProcessingException: RESTEASY003145: Unable to find a MessageBodyReader of content-type text/event-stream and type class org.jboss.resteasy.plugins.providers.sse.SseEventInputImpl
	at org.jboss.resteasy.core.interception.jaxrs.ClientReaderInterceptorContext.throwReaderNotFound(ClientReaderInterceptorContext.java:46)
  at org.jboss.resteasy.core.interception.jaxrs.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:129)
	at org.jboss.resteasy.core.interception.jaxrs.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:76)
	at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:192)
	at org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:75)
	at org.jboss.resteasy.specimpl.AbstractBuiltResponse.readEntity(AbstractBuiltResponse.java:232)
	at org.jboss.resteasy.plugins.providers.sse.client.SseEventSourceImpl$EventHandler.run(SseEventSourceImpl.java:292)
	at org.jboss.resteasy.plugins.providers.sse.client.SseEventSourceScheduler$1.run(SseEventSourceScheduler.java:80)
	at org.jboss.resteasy.concurrent.ContextualExecutors.lambda$runnable$2(ContextualExecutors.java:312)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)

Maybe this issue is connected to #30935

Output of uname -a or ver

No response

Output of java -version

OpenJDK Runtime Environment Temurin-18.0.1+10 (build 18.0.1+10)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

3.2.0.Final

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Comments: 15 (14 by maintainers)

Commits related to this issue

Most upvoted comments

Simply replace

client = ClientBuilder.newClient();

with

client = ClientBuilder.newClient().register(SseEventProvider.class);

No hacks needed 😃

Sure, I’ve added a branch here: https://github.com/sdaschner/quarkus-playground/tree/sse-issue-35967

To reproduce:

git clone # with branch https://github.com/sdaschner/quarkus-playground/tree/sse-issue-35967
cd .../server/
mvn quarkus:dev

# new terminal
cd .../client/
mvn clean package
# you'll notice the SseTest works
java -jar target/quarkus-app/quarkus-run.jar

If the class DummyUpdatesResource gets removed from the client project, the exeption from above appears.

Btw, it seems the quarkus-resteasy-* dependency is not required in the pom, the example also works just by adding the dummy class.