This is an extension of the previous post I made.
To summarize what is happening:
- I use a task that runs hourly that will generate a PDF file to be sent as an attachment in an email
The task does nothing but directly contact the controller to create a PDF file and send an email message. I am invoking a controller to do the work, as I am using the PDF module, which (currently) requires an HTTP request as part of its processing of the PDF. This is how I call the controller through Job:
WS.url ("my / url / what / dots / in / in / controller") we get () ;.
My previous problem with the PDF'in template, which includes the JS Highcharts chart, was that it created a client chart chart that was too late to create a PDF file, and therefore my PDF code was minus the graph . To get around this, I now use highcharts-serverside-export to create the server side of the diagram
If I use the same classes above and render the template in the browser (i.e. go through the controller directly and ignore the task), the diagram will be created on the server side and the view will be displayed correctly in the browser.
I create a chart in a template by invoking another controller as follows:
<img src="@{ChartGenerator.go()}">
The ChartGenerator controller simply basically creates the server diagram according to the documentation based on highcharts-serverside-export and calls the play renderBinary method.
As I said, the template displays a fine in the browser with a diagram created on the server side. However, when going through a task that runs hourly, the call to ChartGenerator.go () does not work. The console spat out:
INFO ~ /chartgenerator/go is not a URL; may be relative.
Does anyone have any ideas how to fix this? I proved that it works minus "Work", and now I need to find out why it does not work when working through "Work".
Edit: As per Pere's suggestion, my template now calls the ChartGenerator class, doing this (note the double @):
<img src="@@{ChartGenerator.go()}">
I think it improved me a bit, now it spits out in the logs:
Error during job execution (fun.EmailJob) Execution exception (In /fun/EmailJob.java around line 19) RuntimeException occured : java.util.concurrent.ExecutionException: java.util.concurrent.TimeoutException: No response received after 60000 ... 09:23:54,687 WARN ~ bad URL given: http://<full url>/chartgenerator/go java.net.SocketTimeoutException: Read timed out
If I find the URL http: // <full url> / chartgenerator / go in the browser, the highcharts png file displays correctly in the browser. And, as expected, even after that double @change, if I render the template in the browser (without a pdf file), the template will correctly display with the diagram created on the server side.
Edit # 2: With these problems, I seem to get controller calls from a template to render an image (binary), I wonder if it is possible to pass an object (containing an image) file as a parameter of the render (...) method for the template. For example, say the controller that displays the template does this:
File image = ... // PNG chart as built by the highcharts-serverside-export library ... File emailAttachment = new File("attachment.pdf"); PDF.writePDF(emailAttachment, "myTemplate.html", image); // This calls the PDF module to render the PDF from the given template and write it to the attachment.pdf File object
I am wondering if I can somehow edit this image in the template directly, without going @@ {...} ?
I tried putting $ {image} in the template, but just displayed attachment.pdf on the screen (expected view).
Edit # 3 : This is what the ChartGenerator class looks like:
public final class ChartGenerator extends Controller { public static void go() throws Exception { ChartOptions options = SamplesFactory.getSingleton().createColumnBasic(); HighchartsExporter pngExporter = ExportType.png.createExporter(); File chart = new File("column-basic.png"); pngExporter.export(options, null, chart); response.setContentTypeIfNotSet("image/png"); renderBinary(chart); } }
Currently, I'm just creating an example server diagram to prove that it can be a pdf. Creating a selection chart is performed in accordance with the documentation based on highcharts-serverside-export.
Edit # 4: I also tried to add an action method to the controller to allow its use in the browser, and the generated high level on the server side is also not displayed in pdf format and the previously mentioned exception still occurs. Therefore, I can exclude that this is a problem with the Job to Controller workflow. (of course, creating a template without a pdf file still works fine)
Edit No. 5: To narrow down the possible causes of the problem, I decided to ignore highcharts (along with the highcharts-serverside-export library) and just use a simple JFreeChart server-side map library. Again, I can display a template without a pdf file, but as soon as I try a pdf template that includes a diagram (visualized using the above @@ call), it fails for the same reason (i.e. java.net .SocketTimeoutException: read timeout).