You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Although in most cases we want to render PDFs directly to the HTTP output on the HTTP thread using renderPDF(), sometimes we want to be able to write PDFs to a file so we can attach them to emails. This can cause problems when the process used to create the PDF is expensive (i.e. running a large report, creating JFreeChart output, etc). Normally in Play we would do this inside a job, but unfortunately in PDF module version 0.6 this is impossible because there are a number of references to Http.Request.current(), which is null inside jobs. This causes the following exception:
Caused by: java.lang.NullPointerException
at play.modules.pdf.PDF.writePDF(PDF.java:159)
at play.modules.pdf.PDF.writePDF(PDF.java:144)
at controllers.Reports$1.doJobWithResult(Reports.java:316)
at controllers.Reports$1.doJobWithResult(Reports.java:1)
at play.jobs.Job.call(Job.java:146)
... 8 more
Looking at the current PDF module source code, it looks like it only really needs the request for three things:
to find the current template name when none is supplied (PDF line 159),
to resolve the template name if it hasn't been supplied with full dotted notation (PDF line 197/RenderPDFTemplate line 60), and
to pass the base URI into YaHP (RenderPDFTemplate line 116)
I think we could do a "quick fix" solution for the first two that simply moves around the accesses to the request object to the places where they are specifically required (rather than having them at the beginning of general-purpose methods). For item 3, perhaps we could allow passing an empty string as a base URI into YaHP when the request is null. I'm not sure if this will work, but it should be okay if all the references in the template are absolute (@@{} tags or file:// addresses).
This isn't a perfect solution and it's probably worth considering a better way of doing it in the future, but I think this would cover 90% of cases for the people who need to run the PDF generation inside a job.
Although in most cases we want to render PDFs directly to the HTTP output on the HTTP thread using renderPDF(), sometimes we want to be able to write PDFs to a file so we can attach them to emails. This can cause problems when the process used to create the PDF is expensive (i.e. running a large report, creating JFreeChart output, etc). Normally in Play we would do this inside a job, but unfortunately in PDF module version 0.6 this is impossible because there are a number of references to Http.Request.current(), which is null inside jobs. This causes the following exception:
Looking at the current PDF module source code, it looks like it only really needs the request for three things:
I think we could do a "quick fix" solution for the first two that simply moves around the accesses to the request object to the places where they are specifically required (rather than having them at the beginning of general-purpose methods). For item 3, perhaps we could allow passing an empty string as a base URI into YaHP when the request is null. I'm not sure if this will work, but it should be okay if all the references in the template are absolute (@@{} tags or file:// addresses).
This isn't a perfect solution and it's probably worth considering a better way of doing it in the future, but I think this would cover 90% of cases for the people who need to run the PDF generation inside a job.
See also:
http://groups.google.com/group/play-framework/browse_thread/thread/464dce35312b5afd
http://groups.google.com/group/play-framework/browse_thread/thread/cbf2af5b20a43893
The text was updated successfully, but these errors were encountered: