Friday, May 22, 2015

How to call BI publisher API (E-text Template based report) from java? (Step by Step Approach to call Document Processor Engine)














As we all know, that BI publisher engine is written in Java. Further, Oracle has shared us a set of public Java API’s to invoke document processor. Smile
In this article, I tried to explain the methodology to call BI publisher Document Processor Engine API using a Java wrapper with an example (Etext Template and Sample XML).
Requirement:
1.       To generate the text file based on XML file using Etext template.
2.       The call to XML Publisher Document Processor Engine should be via Java class file

Pre-Requisite:

Before proceeding with an example, it’s very important to understand the Parameter XML of standard Oracle BI Publisher Java Class oracle.apps.xdo.batch.DocumentProcessor.

Implementation

Step1: Prepare a wrapper Java file for calling “DocumentProcessor”
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.security.*;
import java.util.Arrays;
import java.util.Collections;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import java.io.*;
import java.security.spec.*;
import oracle.apps.xdo.batch.DocumentProcessor;

public class callBIPublisher {

  public static void main(String[] args)
  {
    try
    {
      // arg0 --- File path of the Document Processor Parameter XML
      // arg1  --- Temporary Directory path
      DocumentProcessor  docProcessor = new DocumentProcessor(args[0], args[1]);
      docProcessor.process();
    }
    catch(Exception e)
    {
        e.printStackTrace();
       System.exit(1);
    }
    System.exit(0);
  }
 }
Step2: Generate the Java Class File for wrapper java for calling “Document Processor”
javac -classpath $CLASSPATH callBIPublisher.java
Step3: Place the generate class file to $JAVA_TOP
                cp callBIPublisher.class $JAVA_TOP
Step4: Prepare the Input Parameter file as per the oracle documentation
xml version="1.0" encoding="UTF-8" ?> 
     <xapi:requestset xmlns:xapi="http://xmlns.oracle.com/oxp/xapi">
       <xapi:request>
         <xapi:delivery>
           <xapi:filesystem output="report.txt" /> 
         </xapi:delivery>
         <xapi:document output-type="text">
           <xapi:template type="etext" location="ETEXTTEMPLATE.rtf">
             <xapi:data location="INPUTDATAXML.xml">
    </xapi:data>
           </xapi:template>
         </xapi:document>
      </xapi:request>
    </xapi:requestset>
Step5: Prepare the E-text Template file and Input XML File
Incase, if you want to  know more about E-Text Templates, Please refer http://www.shareoracleapps.com/2015/05/etextrtf-template-example-generate-comma-seperated-file-oracle-apps.html

clip_image002[5]

clip_image003[5]

Testing:

Step1: Call the java wrapper class callBIPublisher with parameter file

               java -classpath $CLASSPATH callBIPublisher PARAMETERXML.xml .

Step2: Check the output file
image

Now, the mentioned command can be called from a host based concurrent program. I hope this helps !!  Happy Sharing Smile Smile Smile

1 Responses to “How to call BI publisher API (E-text Template based report) from java? (Step by Step Approach to call Document Processor Engine)”

Anonymous said...
December 10, 2017 at 12:29 AM

How do you call eText that has sequence definitions defined in the template? above code gives error. it works with simpler eText templates for sure. any pointers? thx.


Post a Comment

Disclaimer

The ideas, thoughts and concepts expressed here are my own. They, in no way reflect those of my employer or any other organization/client that I am associated. The articles presented doesn't imply to any particular organization or client and are meant only for knowledge Sharing purpose. The articles can't be reproduced or copied without the Owner's knowledge or permission.