Servlet technology and application servers are in some cases an unnecessary burden. How do you integrate an application server into your standalone application?
If you have red the chapter about Servlets, you'll know that you need at least three components to view a report; the report viewer on the client side, a servlet which connects the viewer with the report engine and the report engine itself. i-net Clear Reports is shipped with a socket listener that can be used instead of a servlet to connect the engine and the Java viewer together.
No server-side components are required.
As with the report servlet a connection to the listener goes through the following states:
The Listener can be started with “java com.inet.report.Listener”. It doesn't take any arguments and reads the default values from a file crystalclear.properties located in your classpath. Additionally the Listener() constructors can be used to bind it to a specific port or to search for a free port above the default port as specified in configuration.
The listener then runs the following loop:
while (true) { reportSocket = new ReportSocket(ss.accept()); reportSocket.setPropertiesChecker(this); reportSocket.execute(); }
If you want to implement your own listener, you can do this by implementing the interface PropertiesChecker and then using com.inet.report.ReportSocket directly as shown above.
As the report servlet, the listener has three callbacks which will be called in step 1 and before and after the default values from the report file have been red in step 2. Unlike the ReportServlet, the request parameter is always null and cannot be used.
Examples for using the callbacks can be found in the samples/standalone folder.
The following table gives an overview which classes can be used to get the checkProperties() callback to run:
| If you use the class: | then you need to: |
|---|---|
| Listener | Extend the class and override the needed methods. |
| ReportSocket | Implement the interface PropertiesChecker and call the method setPropertiesChecker. |
| ReportServlet | Extend the class and override the needed methods. |
Sometimes a viewer bean and therefore the listener is not needed because the engine provides all functionality itself. In the following section we explain how to program the engine directly instead of using the Servlet or the socket/listener. Because we now do everything ourselves, we don't need any callbacks.
The necessary steps to get report data from the engine are:
e = new Engine(); or with e = new Engine(Engine.EXPORT_PDF); if you want to use it's PDF renderer for example.e.setReportFile(“file:c:/test.rpt”);e.setPrompt(”-1”, 0); sets parameter 0 to the value -1.e.execute();for(int i=1;i<=e.getPageCount();i++) { pdfFile.write(e.getPageData(i)); }
A complete example can be found in the samples/standalone folder.
i-net software strives to provide accurate product documentation. Please give us your feedback using the form below.
NOTE: This form is for documentation feedback only. For technical assistance, please send an email to clearreports@inetsoftware.de.