Using REST API to render a Report template

This entry guides you through the steps to send a report template request via REST API from an application.

  • This could be achieved either by using option “A. Base-64 Encryption” or option “B. Ambience Generated API token”.

A. Using Base-64 Encryption

  1. Firstly, declare the report path and output format.
   String reportPath = "/ElixirSamples/Report/RML/Pivot%20Table.rml";
   String url = "http://localhost:8080/elx/do/eno/re" + reportPath;
   String mimeType = "application/pdf";
  1. Next, send the parameter values in XML format.
   String xml = "<report mime-type=\""+mimeType+"\">"+
                "<parameters>"+
                "\n<parameter name=\"Staff Name\">Joanne Tan</parameter>"+
                "\n</parameters>"+
                "\n<return filename=\"report\" disposition=\"attachment\"/>"+
                "\n</report>";
  1. Next, log in to the Ambience server
   HttpClient httpClient = HttpClients.createDefault();
   String encoding = DatatypeConverter.printBase64Binary("admin:sa".getBytes());
  1. Send POST request to render report template with parameter values.
    HttpPost httppost = new HttpPost(url);
    httppost.setHeader("Authorization", "Basic " + encoding);
    StringEntity se = new StringEntity(xml.toString(), ContentType.APPLICATION_XML);
    httppost.setEntity(se);
    HttpResponse response = httpClient.execute(httppost);
    HttpEntity entity = response.getEntity();
    InputStream is = entity.getContent();
    File f = new File("test.pdf");

    FileOutputStream fos = new FileOutputStream(f);
    IOUtils.copy(is, fos);
    is.close();
    fos.close();

Full Java code sample for Sending Report template request via REST API using Base-64 encryption can be found here (2.1 MB).


B. Ambience Generated API token

1. Firstly, declare the report path and output format.
   String reportPath = "/ElixirSamples/Report/RML/Pivot%20Table.rml";
   String token = "?elx.token=eno:api-d22969d817e9f3688f4b9e0358e88d67";
   String url = "http://localhost:8080/elx/do/eno/re" + reportPath + token;
   String mimeType = "application/pdf";
  1. Next, send the parameter values in XML format.
    String xml = "<report mime-type=\""+mimeType+"\">"+
                 "<parameters>"+
                 "\n<parameter name=\"Staff Name\">Joanne Tan</parameter>"+
                 "\n</parameters>"+
                 "\n<return filename=\"report\" disposition=\"attachment\"/>"+
                 "\n</report>";
  1. Next, declare the HTTPClient
    HttpClient httpClient = HttpClients.createDefault();
  1. Send the POST request to render report template with parameter values.
    StringEntity se = new StringEntity(xml.toString(), ContentType.APPLICATION_XML);
    httppost.setEntity(se);
    HttpResponse response = httpClient.execute(httppost);
    HttpEntity entity = response.getEntity();
    InputStream is = entity.getContent();
    File f = new File("test.pdf");

    FileOutputStream fos = new FileOutputStream(f);
    IOUtils.copy(is, fos);
    is.close();
    fos.close();

Full Java code sample for Sending Report template request via REST API using Ambience Generated API token can be found here (2.1 MB)
.