Page 1 of 1

ClassCastException from Velocity

PostPosted: Mon May 24, 2021 8:23 am
by roddy
I am getting the following error on calling: plugins.VelocityReport.previewReport()
whether calling with a String or a Template File name.

Code: Select all
JavaException: java.lang.ClassCastException: com.servoy.j2db.server.ngclient.NGClientPluginAccessProvider incompatible with com.servoy.j2db.server.headlessclient.IWebClientPluginAccess


I have no idea how to begin working out what to do about this error; any indicators would be much appreciated.

Re: ClassCastException from Velocity

PostPosted: Mon May 24, 2021 9:24 pm
by ptalbot
The previewReport() is used to show a window that contains the preview of the filled template.
It works with Smart Client and Web Client but not in NG.

However, you can easily use the getPDFReport() which will return the bytes of the PDF report, which you can then either store on the server, or push to the client to be displayed in the PDF viewer (using a form variable as dataProvider for example)

Re: ClassCastException from Velocity

PostPosted: Tue May 25, 2021 12:41 am
by roddy
Thanks for the response; it looks like the getPDFReport() is what uses the Eastwood dependency? Is this the engine that translates the HTML to PDF? With the Eastwood dependency, there is a the dependency on the reports folder, which seems to have examples and samples in it. Can we remove the files not part of the dependency as am not keen, if possible, to transfer samples and examples with the core of the app for migration.

Re: ClassCastException from Velocity

PostPosted: Tue May 25, 2021 1:01 am
by roddy
Apologies if I am missing something; I am getting an exception after calling getPDFReport (am unable to catch it) with:
Code: Select all
ERROR com.servoy.j2db.util.Debug - IO problem for http://localhost:8080/eastwood/reports/styles.css
   at /Users/roddy/git/servoy/mod_ui/printing.js:213 (printEstimate_velocity)
java.net.ConnectException: Connection refused

followed by:
Code: Select all
ERROR com.servoy.j2db.util.Debug - InputStream is null for URI http://localhost:8080/eastwood/reports/styles.css
   at /Users/roddy/git/servoy/mod_ui/printing.js:213 (printEstimate_velocity)


The Eastwood WAR is placed in the webapps folder. Have also placed the velocity_listener.jar in the lib folder and the unzipped report file in the configured velocityreport.reportfolder directory (where it is picking up the file for the renderTemplate() function call). The velocityreport.serverURL has been setup to http://localhost:8080/.

I also removed the pdf_output files just in case because of the iText jar conflict mentioned in your documentation and have restarted the Servoy Developer quite a few times to ensure the configuration is picked up.

There are no charts in this template (is very simple), so am not sure why it is trying to stream something to Eastwood?

Re: ClassCastException from Velocity

PostPosted: Tue May 25, 2021 4:01 am
by roddy
I've found the issue causing the exception; it is the
Code: Select all
   <link rel="stylesheet" type="text/css" media="all" href="styles.css"/>


Taken from the example templates. Does this entail that there needs to be a styles file somewhere? The $baseHREF has been set in the file; from reading the docs, this would indicate it is taking it from the reports files I unzipped into the required directory?

Re: ClassCastException from Velocity

PostPosted: Wed May 26, 2021 12:39 am
by ptalbot
$baseHREF is tricky, it's trying to find the URL of the reports folder. I might deprecate it altogether.
Because it's hard to find it when it's deployed on a server inside a context for example, in Developer it's trying to read the servoy.properties for the velocityreport.reportFolder property, but on a server, it will not reliably find it.

Easiest is to make sure your href is either using a full url (http://domain[:port]//path/to/css/) or using a relative url, which should be relative to the location of the template itself.

So if your template is in /reports/templates/ and you have a css file in /reports/templates/css/styles.css you should be able to use href="css/styles.css"

Re: ClassCastException from Velocity

PostPosted: Wed May 26, 2021 12:42 am
by ptalbot
You could also take advantage of the #include() directive and include the content of your css file inline, so add something like the following in your html header:

Code: Select all
<style>
   #include("css/styles.css")
</style>


where the css file is located in a "css" subfolder, relative to your template.

Re: ClassCastException from Velocity

PostPosted: Thu May 27, 2021 1:00 am
by roddy
Thanks, that is really good to know :-)