Skip to content

Commit

Permalink
Merge pull request #33146 from cescoffier/fix-flow-issue-native
Browse files Browse the repository at this point in the history
Fix missing method in native mode when an SSE endpoint returns a Flow.Publisher
  • Loading branch information
gsmet authored May 5, 2023
2 parents b6c22bf + 1f7cfc0 commit 8670bba
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static java.util.stream.Collectors.toList;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.DATE_FORMAT;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.MULTI;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.PUBLISHER;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -552,6 +553,7 @@ public void accept(EndpointIndexer.ResourceMethodCallbackEntry entry) {

if (paramsRequireReflection ||
MULTI.toString().equals(entry.getResourceMethod().getSimpleReturnType()) ||
PUBLISHER.toString().equals(entry.getResourceMethod().getSimpleReturnType()) ||
filtersAccessResourceMethod(resourceInterceptorsBuildItem.getResourceInterceptors()) ||
entry.additionalRegisterClassForReflectionCheck()) {
minimallyRegisterResourceClassForReflection(entry, reflectiveClassBuildItemBuildProducer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.it.resteasy.mutiny;

import java.io.IOException;
import java.util.concurrent.Flow;

import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
Expand Down Expand Up @@ -66,6 +67,14 @@ public Multi<Pet> sse() {
return service.getMorePets();
}

@GET
@Path("/pets/flow")
@Produces(MediaType.SERVER_SENT_EVENTS)
@RestStreamElementType(MediaType.APPLICATION_JSON)
public Flow.Publisher<Pet> sseFlow() {
return service.getMorePets();
}

@Inject
@RestClient
MyRestService client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,38 @@ public void accept(UniEmitter<? super List<Pet>> uniEmitter) {
}
}

@Test
public void testSSEWithFlowPublisher() {
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:" + RestAssured.port + "/mutiny/pets/flow");
try (SseEventSource eventSource = SseEventSource.target(target).build()) {
Uni<List<Pet>> petList = Uni.createFrom().emitter(new Consumer<UniEmitter<? super List<Pet>>>() {
@Override
public void accept(UniEmitter<? super List<Pet>> uniEmitter) {
List<Pet> pets = new CopyOnWriteArrayList<>();
eventSource.register(event -> {
Pet pet = event.readData(Pet.class, MediaType.APPLICATION_JSON_TYPE);
pets.add(pet);
if (pets.size() == 5) {
uniEmitter.complete(pets);
}
}, ex -> {
uniEmitter.fail(new IllegalStateException("SSE failure", ex));
});
eventSource.open();

}
});
List<Pet> pets = petList.await().atMost(Duration.ofMinutes(1));
Assertions.assertEquals(5, pets.size());
Assertions.assertEquals("neo", pets.get(0).getName());
Assertions.assertEquals("indy", pets.get(1).getName());
Assertions.assertEquals("plume", pets.get(2).getName());
Assertions.assertEquals("titi", pets.get(3).getName());
Assertions.assertEquals("rex", pets.get(4).getName());
}
}

@Test
public void testClientReturningUni() {
get("/mutiny/client")
Expand Down

0 comments on commit 8670bba

Please sign in to comment.