In my Java EE web application I want to provide a download functionality of a file, which is created on the fly.
- The user clicks a
p:commandButton
which triggers some action in the underlying CDIViewScoped
bean. (non-AJAX call) - From the CDI Bean my business logic is called, to do some security checks, prepare data etc. The service returns a DTO to the CDI Bean, containing the data which is required to create the requested file.
- The next step is to send a POST request to my PHP and submit the DTO as JSON in the request body.
- The PHP now creates the file based on the received information. I am already able to create the HTTP response with the correct header information and the file in the response body.
I am missing the last step how to ship this file to the user. Am I able to chain this response and directly send it to the user client? Or do I have to read the content, and create a new HTTP response in the CDI Bean manually? Maybe it would be even better to encapsualte the communication with PHP in the business logic (and hide it completely from the View) and only return the File to the CDI Bean. After this I would be able to create the response and ship the file to the user.
My thoughts, so far... Any ideas, recommendations how I should and could ship the file to the user?