Reputation: 85
I want to return two distinct data using one outputStream in java.
I want to return xml response and download a file.
I am using JAXB to write my xml response,
DataOutputStream dos = new DataOutputStream(request.getResponseStream());
JAXBContext newInstance = JAXBContext.newInstance(GetCoverageType.class);
Marshaller marshaller = newInstance.createMarshaller();
marshaller.marshal(responseData.getCoverage(), dos);
File file = new File(responseData.getLocation());
response.addHeader("ContentDisposition", "attachment; filename=test");
response.setContentType("application/netcdf");
Files.copy(file, dos);
With my code, the file is downloaded but the xml generated by JAXB does not appear.
I have tried to use response.flushBuffer()
after that, but the xml response is written in my downloaded file.
If someone has an idea to download my file and return xml response on the browser
Thanks
Upvotes: 0
Views: 69