Table of Contents
The ERS Client API allows you to write your own JVM-based programs which can call into Ambience to render reports and generate datastores.
This API can be used to migrate data between older applications such as Elixir Report 4.0 and Ambience.
This example will render the standard Master-Detail RML sample into PDF as
tmp/output.pdf
.
It will also output the number of pages rendered (showing the JobInfo API) and dumps the complete JobInfo so you can
see all the information.
To run this example:
Create a new Java project.
Copy the following jars from the Ambience lib folder to the lib
folder of your project (replace {version} with the appropriate version for your release).
Note the third-party jar versions may also vary over time, so use the corresponding version found in lib.
The ERS Client is in
elx-ers2-client-{version}.jar, the rest are supporting jars.
Create a file called
JavaRender.java
and enter the following code:
package demo;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import com.elixirtech.ers2.client.ERSClient;
import com.elixirtech.report2.runtime.IJobInfo;
public class JavaRender {
public final static void main(String[] args) throws Exception {
ERSClient c = new ERSClient("localhost", 8080, "eno",
"admin", "sa");
try {
c.connect();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IJobInfo jobInfo = c.renderReport("/ElixirSamples/Report/RML/
Master-Detail Report.rml", "application/pdf", baos,
new java.util.Properties());
byte[] bytes = baos.toByteArray();
File output = new File("tmp/output.pdf");
output.getParentFile().mkdirs();
Files.copy(new ByteArrayInputStream(bytes),output.toPath(),
StandardCopyOption.REPLACE_EXISTING);
System.out.println("Report with " +
jobInfo.getLong(IJobInfo.PAGE_COUNT) +
" pages rendered to tmp/output.pdf");
System.out.println(jobInfo.toString());
}
finally {
c.close();
}
}
}
Save and run the file. The output should be the following:
Report with 7 pages rendered to tmp/output.pdf
[byte-size=98085, elapsed-time=418,
log-file=/User/admin/logs/tmp-0000000009.json,
mime-type=application/pdf,
page-count=7, record-count=117,
result=/Temp/admin/tmp-0000000007.pdf,
status-code=1]
The output PDF is in
tmp/output.pdf
.
You can also use the ERS Client to generate data into a DataStore.
The API is almost exactly the same as the old Repertoire client jar. The only changes are as follows:
The constructor supports one more parameter - the domain name. For backwards compatibility, you can leave the domain name out (use the original API args) and "eno" will be used as the domain name by default.
The filesystem API is not supported:
public synchronized IFileSystem getFileSystem(String fs)
This requires duplicating the whole legacy IFileSystem, IFileObject tree
which is quite different in DaCapo.
The DaCapo REST API is more suitable for accessing this information, as it provides much more powerful functionality.
Secure mode API:
public void setSecure(File keystore, String keystorePassword,
File truststore, String truststorePassword)
This is now handled internally if the server uses https. There is no support for client certificates in this release. Only server certificates are supported.
As long as your code does not call these functions, it should run exactly the same as before.