-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add streaming support for files in RESTEasy Reactive #15891
Comments
/cc @FroMage, @geoand, @stuartwdouglas |
Yup, supporting |
It does to me |
Does this feature request have a release plan? Currently this blocks the upgrade to resteasy-reactive |
Hopefully we'll get something in for |
@StFS can you add the code you ended using so we can have a reference of what we want to achive / simplify? |
I was reading this post where the 1.14 could be the last 1.x version before the 2.x. Is there any chance to have this enhancement in the 1.14 before the migration? |
As you have read in that announcement, At this point, I can't promise anything regarding the timeline of this issue. @indalaterre are you using |
@geoand yes we use |
@indalaterre can you paste an example snippet of how you are using it? |
Here's the snippet |
Thanks |
Snippet inline: package com.cgm.nais.catalog;
import io.smallrye.mutiny.Uni;
import org.eclipse.microprofile.openapi.annotations.media.Content;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;
import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
public class Snippet {
public Uni<Response> getDocumentationByFilename(
@Parameter(
required = true,
content = @Content(mediaType = TEXT_PLAIN, schema = @Schema(implementation = String.class)))
@PathParam("filename") String fileName) {
return getService()
.getDocumentationByFilename(fileName)
.map(item -> {
StreamingOutput stream = output -> output.write(item.array());
return Response.ok(stream)
.header("Content-Type", "application/pdf")
.build();
});
} |
I forget who's our openapi expert, is it @phillip-kruger ? @indalaterre can you tell us the type of |
Exactly |
So, @phillip-kruger do you confirm that as far as (SR) open-api is concerned, the previous endpoint signature should be equivalent to: public Uni<Response> getDocumentationByFilename(String filename) { |
@FroMage item it's a |
Hah, we should support those out of the box, if we don't already. https://quarkus.io/guides/resteasy-reactive#resource-types says we don't yet, but there's no good reason. |
@FroMage Not sure what you mean ? Do you mean we should be able to omit the |
I mean it looks like all that annotation specifies should be optional and can be inferred by the rest of the signature, no? For the content-type, you're right we can't infer it. Though it's wrong anway since it claims to be text but then it's set to PDF ;) |
Wait the text content-type is for the request while the pdf is for the response. This code works without resteasy-reactive so I think it's not a problem of the api |
Yes, except for content type yes. Required I am not sure what the default is, so that might also needs to be set somehow, either with |
OK lemme take that. |
💪🏼 |
Hello, is there any chance to have this in 2.0? |
@geoand I saw that there is a 13.3 milestone? Can also this one be released there? |
I am not sure we want to make such a change in |
Yes, we now support sending files async. I guess we could backport this, I don't see why not, if there's a need. |
Well, it's tested. If the tests pass, then it works and is tested exactly as much as it is currently on 2.0, so I'd say about the same level of confidence in both cases. If it doesn't apply cleanly or the tests break, then we can decide if it's worth it or not. |
OK, than can you please open a PR against the |
OK done, thanks: #16653 |
And it did not apply cleanly ;) |
Thanks! Let's see how it goes |
If we transform a |
I wouldn't use that. Try |
@geoand ok, i will have that in mind. |
The difference is that because of the strong typing, Quarkus knows how to handle it under all circumstances. With |
When I use
Both are the same classes (maybe different libs on the classpath?). Both seem to point to io:quarkus.resteasy:resteasy-reactive-common:2.12.3.Final though.
UPDATE:
|
That is very odd... I'll have a look next week |
The problem you mentione above has nothing to do with Quarkus, it's a limitation of the |
I'm using RestAssured to test my resources. Is it expected behaviour when returning a StreamingOutput, that the body is initially empty? How would you test this with RestAssured? Real code:
The test:
|
Description
It would be nice to have a simple way to return file content as a stream in a reactive way in a REST resource method.
The original discussion is here.
Implementation ideas
This discussion took place on Zulip so I'm only conveying the ideas discussed there (by other people).
@geoand suggested to Stephane Epardaud making
AsyncFile
a known return type and properly handling it under the covers.@Ladicek chimed in with:
Also, something to keep in mind is that it would be nice if a solution to this supported both whole files as well as some range from a file. I don't know enough about the Vert.X FS API to know if this would be handled transparently by calling
AsyncFile.setReadPos(long)
andAsyncFile.setReadLength(long)
before returning it or whether some special handling would be required for this.The text was updated successfully, but these errors were encountered: