
Loading the Desktop Viewer Bean from a URL or RandomInputable directly
Here, we assume that you have your own server, which you built with the JReport Server Engine. If you want to load the Desktop Viewer Bean to view a result file generated on the server side, but you do not want to transport the result file directly, you can use the following methods:
- If your server and client uses the HTTP protocol to communicate with, you can call the method setURLAddress("URL address") in the Desktop Viewer Bean. The URL must be a valid result file generated using the Engine on the server side. The code is as follows:
RRunViewer viewerBean = new JRRunViewer();
viewerBean.setURLAddress("the url address");
viewerBean.runReport();
|
- If your server and client do not use the HTTP protocol to communicate with, you can call the method setRandomInput() in the Desktop Viewer Bean. This method has one parameter. It is an instance of the interface RandomInputable. The interface defines how to transport the result file generated by JReport Engine Bean on the server side to the client side. You must define a class which implements all methods in the interface RandomInputable, and then pass this class's instance to the method setRandomInput as a parameter. The code is as follows:
JRRunViewer viewerBean = new JRRunViewer();
viewerBean.setRandomInput("the class which implement interface RandomInputable");
viewerBean.runReport();
|
We provide a class that has already implemented the interface RandomInputable. If you do not want to write a new class, you can use this. The class is named jet.ie.io.RAStreamInput. It has one constructor public RAStreamInput(InputStream in, long totalLength) throws IOException.
The first parameter is the input stream opened by the connection. The second is the stream's length. See example TestRAStreamInput.java in <install_root>\help\samples\APIClient\ViewerBean
.
Note: In the above case, you do not need to set the other properties of the Viewer Bean. Also, if JReport Server requires a permission check for login, this will have to be performed before calling the Desktop Viewer Bean.
