4.2.1 Example: Executing a Report
A commonly utilized service is report generation. You can save the generated report locally on the client machine in an exported format (PDF, EXCEL, RTF etc).
In the following example you will generate a report called 'Ad Hoc', and then save the report as a PDF file (AdHoc.pdf) on the client machine. The 'Ad Hoc' report is deployed in the 'Tutorial' folder of the repository, and its accepts a parameter called 'state', for which you will be prompted at the command line. Follow the steps below:
1. Save the client below (Listing 1. MySoapClient.java Source Code) as 'MySoapClient.java'.
2. Add the stub classes to your classpath (see Creating the SoapRepository Client) and compile the client. For example:
set CLASSPATH={StubHome}\classes;.
javac MySoapClient.java
3. Run the client:
java MySoapClient
4. Input a value (e.g., 'NJ') for the state parameter when the prompt appears at the command line.
The client calls the appropriate stub classes to generate and export a PDF version of the report (AdHoc.pdf) in the specified location.
Listing 1. MySoapClient.java Source Code
Note: Add the same parameter name multiple times to pass an array of values.
import inetsoft.sree.soap.*;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class MySoapClient {
public static final String THE_REPORT = "Tutorial/Ad Hoc";
public static final String OUTPUT_FILE = "./AdHoc.pdf";
public static void main(String[] args) {
final SoapRepositoryService service = new SoapRepositoryService();
final SoapRepository repository = service.getSoapRepositoryPort();
//Login with user, password and locale
String ticket = null;
try {
ticket = repository.login("admin", "admin", null);
}
catch(Exception e) {
e.printStackTrace();
return;
}
//List replets
List<RepositoryEntryStruct> replets = repository.getReplets(ticket, null);
for(RepositoryEntryStruct entry : replets) {
System.out.println(entry.getPath());
}
//Get replet Parameters, if any
RepletParametersStruct rps = repository.getRepletParameters(ticket, THE_REPORT);
RepletRequestStruct rrs = readParameters(rps.getParameterNames());
//Execute the report
final String repletID = repository.executeReplet(ticket, THE_REPORT, RepletType.REPLET, rrs);
//Export the report
final String exportID = repository.export(ticket, repletID, FormatType.PDF);
FileOutputStream output = null;
try {
output = new FileOutputStream(OUTPUT_FILE);
byte[] buf = null;
while((buf = repository.nextBlock(ticket, exportID)) != null) {
output.write(buf);
}
output.flush();
}
catch(IOException ioe) {
ioe.printStackTrace();
}
finally {
try {
output.close();
}
catch(Exception e) {}
}
//Destroy the report when finished
repository.destroyReplet(ticket, repletID);
repository.logout(ticket);
}
/**
*
* @param parameterNames List of replet's parameters.
* @return RepletRequestStruct with parameter values input by user.
*/
public static RepletRequestStruct readParameters(final List<String> parameterNames) {
//Create a replet request, to hold parameters
final RepletRequestStruct rrs = new RepletRequestStruct();
rrs.setName("create");
List<String> reqParamNameList = rrs.getParamNames();
List<ParameterValue> reqParamValueList = rrs.getParamValues();
for(int i = 0; i < parameterNames.size(); i++) {
System.out.println("Parameter Name: " + parameterNames.get(i));
BufferedReader buf = null;
try {
//Read in parameter values from command line.
//You can also set them programatically.
System.out.print("Input the value:");
buf = new BufferedReader(new InputStreamReader(System.in));
String value = buf.readLine();
//Add the parameters to the RepletRequestStruct
reqParamNameList.add(parameterNames.get(i));
//Create a ParameterValue object to hold a string parameter
ParameterValue pvalue = new ParameterValue();
pvalue.setType(ParameterValueType.STRING);
pvalue.setValue(value);
reqParamValueList.add(pvalue);
}
catch(Exception e) {
e.printStackTrace();
}
finally {
try {
buf.close();
catch(Exception e) {}
}
}
return rrs;
}
}
| << 4.2 Creating the SoapRepository Client | © 1996-2013 InetSoft Technology Corporation (v11.5) | 4.2.2 Example: Emailing a Report >> |