Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue downloading report exported to PPTX when deployed on server

We are generating our reports using JasperReports 5.6.1, and allow exporting the same template to PDF or Powerpoint. When running locally, the PDF and PPTX file downloaded work perfectly. When we deploy to our servers PDF works fine, but PPTX files cannot be opened. When we run locally, it is deployed to tomcat, but when deployed to the server it is running on Websphere.

Things I tried and noticed:

  • I have checked the logs, and there are no exceptions or anything to raise any eyebrows.
  • The file downloaded is usually slightly larger than the one we get when we run locally.
  • If I changed the extension of the files to zip, and unarchived them. The file structure and file names are the same, along with the files actually being the same file size. The contents seem to only be different in the names for the objects found in each slide.
  • thinking it may be a problem with the x type files I tried exporting to xlsx also, just to see what would happen, and it works fine with the same template.
  • I added a static pptx file that was known good, and can download it without issue from the server. I did this to try to eliminate a server config from the issue, and sense it worked, I am assuming it is something with my code, just not sure what.

Here is the code for where we write the response:

if ("xlsx".equals(type)) {
    response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    response.setHeader("Content-Disposition", "attachment; filename=" + filename + ".xlsx");
} else if ("pptx".equals(type)) {
    response.setContentType("application/vnd.openxmlformats-officedocument.presentationml.presentation");
    response.setHeader("Content-Disposition", "attachment; filename=" + filename + ".pptx");
    response.setCharacterEncoding("UTF-8");
} else {
    response.setContentType("application/pdf");
    response.setHeader("Content-Disposition", "attachment; filename=" + filename + ".pdf");
}
try (final ByteArrayOutputStream reportResult = reportsService.generateReport(
        getDeal(userId, dealId, sessionStore),
        getScenarioModel(userId, dealId, scenarioId, sessionStore), reportId, type)) {
    configureResponse(response, type, reportResult, dealId + "-" + scenarioId);
    // Write to http response
    reportResult.writeTo(response.getOutputStream());
}

response.flushBuffer();

I have run out of ideas on troubleshooting steps, and without being able to reproduce it locally, I am finding it difficult to diagnose.

like image 595
Jacob Schoen Avatar asked Oct 17 '14 05:10

Jacob Schoen


Video Answer


1 Answers

This is a bit of a shot in the dark, but are you sure that the mime type is correctly configured in your WebSphere instances? (I realize that setting the content type in the response should obviate the requirement for the web server to be configured for that MIME type, but it's WebSphere after all ;-))

I'm willing to bet that PDF is a configured MIME type but PPTX is not. Can you check?

  1. Login to WAS Admin Console
  2. Go to Virtual Hosts
  3. Click the link called MIME types

(here's a more detailed technote)

IIRC, unlike Tomcat which is (for lack of a better term) kind of a "bundled" all-in-one http stack and servlet container, WebSphere has a separate http stack (along with a separate JVM for each app), so it's not surprising that configuration might be required there that would not be for simpler containers.

like image 199
Gojira Avatar answered Oct 23 '22 22:10

Gojira