i-net Clear Reports

Standalone Component

Overview

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.

Requirements

No server-side components are required.

As with the report servlet a connection to the listener goes through the following states:

  1. When a report is requested, it creates an engine object and an HTML page based on the request parameters and sends the HTML page with a link to the applet back to the client.
  2. The Java viewer is loaded from the location described in the HTML page and sends a request to the URL described by the report parameter in the HTML page. It appends a parameter “viewer=java2” plus an export format (optional) to express that it requests binary data in the given export format.

Starting the Listener

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.

Using the checkProperties() callbacks

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.

Using the engine directly

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:

  • create a engine with e = new Engine(); or with e = new Engine(Engine.EXPORT_PDF); if you want to use it's PDF renderer for example.
  • set the report file with e.g: e.setReportFile(“file:c:/test.rpt”);
  • set all needed parameters: e.setPrompt(”-1”, 0); sets parameter 0 to the value -1.
  • execute the engine with e.execute();
  • request the page data from the engine:
    for(int i=1;i<=e.getPageCount();i++) {
    	pdfFile.write(e.getPageData(i));
    }

A complete example can be found in the samples/standalone folder.

See Also:


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.

 

© Copyright 1996 - 2012, i-net software; All Rights Reserved.