Chapter 2. ERS Client API

Table of Contents

ERS Client Example

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.

ERS Client Example

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:

  1. Make sure that Ambience is listening on its default port - 8080. If you have changed the Ambience listening port, then change it in the code also.
  2. Create a new Java project.

  3. 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.

    • commons-io-2.4.jar
    • commons-logging-1.1.1.jar
    • elx-arch-{version}.jar
    • elx-ers2-client-{version}.jar
    • elx-jdom-{version}.jar
    • elx-json-{version}.jar
    • httpclient-4.2.1.jar
    • httpcore-4.2.2.jar
    • httpmime-4.2.1.jar
    • logback-classic-1.0.13.jar
    • logback-core-1.0.13.jar
    • paranamer-2.1.jar
    • scala-library-2.11.8.jar
    • slf4j-api-1.7.5.jar
    • typesafe-config-1.2.1.jar

    The ERS Client is in elx-ers2-client-{version}.jar, the rest are supporting jars.

  4. 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();
        }
      }
    }
    
    
    
            
  5. 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:

  1. 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.

  2. 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.

  3. 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.