question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add streaming support for files in RESTEasy Reactive

See original GitHub issue

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:

Ladislav Thon: don’t we have a way to do an equivalent of Vert.x’s ReadStream.pipeTo(WriteStream)? Ladislav Thon: I know we don’t support StreamOutput in RESTEasy Reactive, but having a non-blocking variant of that would be really nice IMHO

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) and AsyncFile.setReadLength(long) before returning it or whether some special handling would be required for this.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:43 (30 by maintainers)

github_iconTop GitHub Comments

1reaction
geoandcommented, Nov 21, 2022

The problem you mentione above has nothing to do with Quarkus, it’s a limitation of the var usage. If you use final StreamingOutput streamingOutput then everything works as expected

0reactions
Manfred73commented, Nov 21, 2022

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:

@GET
@Path("/filename/{filename}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Uni<RestResponse<StreamingOutput>> readFileByFilename(@PathParam("filename") String filename) {
   validationService.validate(FileParams.builder().filename(filename).build());
   return resultCreator.create(queryService.getFileByFilename(filename));
}

The test:

@Test
void readByFilename() {
   // GIVEN
   final var testParams = mockSomeThings();

   // WHEN / THEN
   // How to test this StreamingOutput with restassured? Or should an IntegrationTest suffice here?
   given()
      .pathParam("filename", testParams.filename)
      .when()
      .get("/filename/{filename}")
      .then()
      .statusCode(200)
      .headers(
         "Content-Disposition", "attachment;filename=" + testParams.filename,
         "Content-Type", "application/octet-stream")
      .body(emptyString()); // is emptyString expected with StreamingOutput?
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Writing REST Services with RESTEasy Reactive - Quarkus
This is the reference guide for RESTEasy Reactive. For a more lightweight introduction, please refer to the Writing JSON REST services ...
Read more >
Quarkus Resteasy reactive multipart stream - Stack Overflow
Quarkus with RESTEasy Reactive does not support that use case. I am not even sure that if Vert.x does to be honest.
Read more >
Uploading Files With Quarkus - YouTube
We're gonna have a look at how to read the file names and contents with both RESTEasy Classic and RESTEasy Reactive.
Read more >
Quarkus Insights #82: What's new in RESTEasy Reactive
Clement Escoffier @clementplop & Georgios Andrianakis @geoand stop by to discuss the latest changes to RESTEasy Reactive and Quarkus.
Read more >
Boost throughput with RESTEasy Reactive in Quarkus 2.2
For example, RESTEasy Reactive in Quarkus is a new JAX-RS implementation ... Go back to the ReactiveGreetingResource.java file and add a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found