Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning Uni<AsyncFile> doesn't work as described #20352

Closed
madprogrammer opened this issue Sep 23, 2021 · 6 comments · Fixed by #20374
Closed

Returning Uni<AsyncFile> doesn't work as described #20352

madprogrammer opened this issue Sep 23, 2021 · 6 comments · Fixed by #20374
Assignees
Labels
kind/bug Something isn't working
Milestone

Comments

@madprogrammer
Copy link

madprogrammer commented Sep 23, 2021

Describe the bug

Hello,

In documentation, it is stated that returning an AsyncFile or Uni<AsyncFile> should lead to contents of the file being returned, however, when I try to return Uni<AsyncFile>, or particularly Uni<io.vertx.mutiny.core.file.AsyncFile> which is by default returned from vertx.fileSystem().open(), what I get is just a string representation of the AsyncFile class.

Expected behavior

The contents of the file should be returned by the server

Actual behavior

A reply with following content is returned io.vertx.core.file.impl.AsyncFileImpl@54d3c384

How to Reproduce?

The following code reproduces the problem for me:

@Path("/photo")
@ApplicationScoped
public class PhotoResource {
    private final Vertx vertx;

    @Inject
    public PhotoResource(Vertx vertx) {
        this.vertx = vertx;
    }

    @GET
    @Blocking
    @Produces("image/jpeg")
    public Uni<AsyncFile> getPhoto(@QueryParam("id") String id) {
        return vertx.eventBus().<JsonObject>request("photo", new JsonObject().put("id", id))
          .onItem().transformToUni(message -> vertx.fileSystem()
            .open(message.body().getString("path"), new OpenOptions().setRead(true)));  
    }
}

Output of uname -a or ver

Microsoft Windows [Version 10.0.19043.1237]

Output of java -version

openjdk version "11.0.10" 2021-01-19 LTS

GraalVM version (if different from Java)

OpenJDK Runtime Environment GraalVM CE 21.2.0 (build 11.0.12+6-jvmci-21.2-b08)

Quarkus version or git rev

2.2.2.Final

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

Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)

Additional information

No response

@madprogrammer madprogrammer added the kind/bug Something isn't working label Sep 23, 2021
@quarkus-bot quarkus-bot bot added env/windows Impacts Windows machines triage/needs-triage labels Sep 23, 2021
@madprogrammer
Copy link
Author

I also have an additional related question: is returning a Uni<RestResponse<AsyncFile>> or Uni<Response> with an AsyncFile supposed to work or not? Because I want to return a file body with an additional ETag header set in the response in case if the requested file was found, or return a 404 response otherwise. Currently, trying to return Uni<RestResponse<Path>> or Uni<RestResponse<AsyncFile>> produces the same behaviour (toString representation is returned in the response)

@michalszynkiewicz
Copy link
Member

@madprogrammer which REST extension do you use?

@madprogrammer
Copy link
Author

@michalszynkiewicz in "Installed features" the following relevant extensions are listed: quarkus-resteasy-reactive, quarkus-resteasy-reactive-jackson

@madprogrammer
Copy link
Author

madprogrammer commented Sep 23, 2021

@michalszynkiewicz it seems to be related specifically to Mutiny API. I've rewrited the code without Mutiny to test, and it works:

@javax.ws.rs.Path("/photo")
@ApplicationScoped
public class PhotoResource {
    private final Vertx vertx;

    @Inject
    public PhotoResource(Vertx vertx) {
        this.vertx = vertx;
    }

    @GET
    @Blocking
    @Produces("image/jpeg")
    public Uni<AsyncFile> getPhoto(@QueryParam("id") String id) {
        return Uni.createFrom().emitter(emitter -> {
            vertx.eventBus().<JsonObject>request("photo", new JsonObject().put("id", id), ar -> {
                if (ar.failed()) {
                    emitter.fail(ar.cause());
                } else {
                    String path = ar.result().body().getString("path");
                    vertx.fileSystem().open(path, new OpenOptions().setRead(true), result -> {
                       if (result.failed())  {
                           emitter.fail(result.cause());
                       } else {
                           emitter.complete(result.result());
                       }
                    });
                }
            });
        });
    }
}

@geoand
Copy link
Contributor

geoand commented Sep 24, 2021

Can you try returning io.vertx.core.file.AsyncFile?

Nevermind, I just read your last post. I will provide a fix for allowing the Mutity type as well.

@geoand geoand removed the env/windows Impacts Windows machines label Sep 24, 2021
@geoand geoand self-assigned this Sep 24, 2021
geoand added a commit to geoand/quarkus that referenced this issue Sep 24, 2021
@geoand
Copy link
Contributor

geoand commented Sep 24, 2021

#20374 fixes the issue

geoand added a commit that referenced this issue Sep 24, 2021
Support the Mutiny AsyncFile type as a return type
@quarkus-bot quarkus-bot bot added this to the 2.4 - main milestone Sep 24, 2021
@geoand geoand modified the milestones: 2.4 - main, 2.3.0.Final Sep 28, 2021
geoand added a commit to geoand/quarkus that referenced this issue Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants