Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better support for creating PDF inside a job #18

Open
alisonatwork opened this issue Jul 18, 2011 · 0 comments
Open

better support for creating PDF inside a job #18

alisonatwork opened this issue Jul 18, 2011 · 0 comments

Comments

@alisonatwork
Copy link

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:

  1. to find the current template name when none is supplied (PDF line 159),
  2. to resolve the template name if it hasn't been supplied with full dotted notation (PDF line 197/RenderPDFTemplate line 60), and
  3. 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.

See also:
http://groups.google.com/group/play-framework/browse_thread/thread/464dce35312b5afd
http://groups.google.com/group/play-framework/browse_thread/thread/cbf2af5b20a43893

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant