Oracle BI EE 10.1.3.3/2 - Calling Java Scripts and Java Classes from iBots
Posted by Venkatakrishnan J on December 17, 2007
One of the very good features of BI EE is its ability to call custom Java Scripts and Java Classes after the execution of iBots. Lets look at some examples today. In the first example we shall see how to save the reports scheduled via ibots to a local directory using a simple Java Script. It is assumed that you have your scheduler up and running. The first step in this process is to create a simple Java Script like the one below. I have taken this directly from the docs for demonstration purposes. You can customize this to your needs.
var FSO = new ActiveXObject(”Scripting.FileSystemObject”);
var fileName = “D:\\” + Parameter(1);
var fooFile = FSO.CopyFile(Parameter(0), fileName, true);
As you see above what this Java Script basically does is that it accepts one parameter (Parameter(1)) which is the file name and saves this file to a desired location that is in D drive. You need to save this file under {OracleBI}\server\Scripts\Common folder.
Once this is done, the next step is to call these scripts in your ibots. For example, lets choose a dashboard for content, PDF for attachment and schedule it to run immediately. In the Advanced of this ibot, choose the Java Script that you had created earlier. Remember you need to pass the file name (in my case it is sample.pdf) for Parameter(1) as a parameter.
The above was pretty straight forward. All we needed to do was to put the custom Java Script in a designated folder and call that in the Advanced tab of an ibot. Now lets look at calling a Java Class from an Ibot. There are certain things that we need to understand before we proceed further. Oracle Delivers uses the Java Host Service to make calls to a Java Procedure. So, if you go to {OracleBI}\web\javahost you would find a directory called Scheduler. Under this directory you would find a jar file called schedulerrpccalls.jar. This is the scheduler jar file that we can use to directly obtain the scheduler objects like the iBot attachments, the instance, job ids etc. So, our aim is to call a Java Program after the execution of an iBot is to write the details of the iBot schedule to a text file. In this example, i shall be using JDeveloper. Lets look at the steps one by one.
1. Open the Config.xml file under {OracleBI}\web\javahost\config in a text editor. Search for the Scheduler tag and change it as shown below.
<Scheduler>
<Enabled>True</Enabled> <DefaultUserJarFilePath>D:\Oracle\OracleBI\web\javahost\lib</DefaultUserJarFilePath>
</Scheduler>
The reason why we are changing the above tags is to make Java Host aware of the Java Classes that scheduler would be calling. And the DefaultUserJarFilePath tag points to the directory where we would be placing our Jar file( custom jar file using our custom Java Class). After changing this restart the Java Host Service.
2. Open JDeveloper and create a simple Application, Project with a simple Java Class. In my case i have created a simple Application called SAWSched which in turn has an application called sawsched. The final class file that i created under this project is called as sawsched.java.
3. In this custom java file lets include the following code. Ensure that you are including the schedulerrpccalls.jar in your Project Properties.
package sawsched;import java.io.*;
import java.lang.Thread;import com.siebel.analytics.scheduler.javahostrpccalls.SchedulerJavaExtension;
import com.siebel.analytics.scheduler.javahostrpccalls.SchedulerJobException;
import com.siebel.analytics.scheduler.javahostrpccalls.SchedulerJobInfo;public class sawsched implements SchedulerJavaExtension{
public void run(SchedulerJobInfo jobInfo) throws SchedulerJobException
{
System.out.println(”JobID is:” + jobInfo.jobID());
System.out.println(”Instance ID is:” + jobInfo.instanceID());
System.out.println(”JobInfo to string is:” + jobInfo.toString());
try
{
File outputFile = new File(”D:\\JavaJob.txt”);
File attachFile = jobInfo.getResultSetFile();
attachFile.createNewFile();
FileWriter out = new FileWriter(outputFile);
out.write(”User ID:\t\t” + jobInfo.userID() + “\r\n”);
out.write(”Job ID:\t\t” + jobInfo.jobID() + “\r\n”);
out.write(”Instance ID:\t\t” + jobInfo.instanceID() + “\r\n”);
out.write(”Parameter Count:\t\t” + jobInfo.parameterCount() + “\r\n”);
out.write(”File Path: ” + attachFile.getAbsolutePath());
for(int i = 0; i < jobInfo.parameterCount(); ++i)
{
out.write(”\tParameter “);
out.write(new Integer(i).toString());
out.write(”:\t” + jobInfo.parameter(i) + “\r\n”);
}
out.close();
}
catch(Exception ex)
{
throw new SchedulerJobException(1, 1, ex.getMessage());
}
}
public void cancel()
{
}
}
What this class basically does is it creates a text file which would have details about the iBot job. The above example is available in the bookshelf.
4. Once this is done compile this code to ensure that you have no errors. The next step is to create a JAR file out of this class. So, right click on your Project and create a Jar File. In your JAR ensure that you are also including your schedulerrpccalls.jar and the above compiled class.
I have named my Jar file as BISched.
Once this is done right click on your resources ( you would find your Jar there) and then click on Deploy.
Copy your Deployed Jar file to {OracleBI}\web\javahost\lib (The one that we included in the DefaultUserJarFilePath tag).
5. Now lets go back to delivers and create a simple iBot and choose Java Program in the Advanced Options.
In the Java Properties enter the class name, in our case it is sawsched.sawsched and then in the CLASSPATH enter the jar file that we had bundled. Save the ibot and you would notice that a text would have been created under D drive.


















December 17, 2007 at 3:08 pm
Venkatakrishnan,
Is it possible to modify the output even before the iBot is delivered?
Thanks,
Bindu
December 17, 2007 at 3:17 pm
I dont quite understand. An example would help. Do you want make changes to the report before running the iBot?
December 17, 2007 at 3:40 pm
To be more elaborate on my previous question, in the example above, the report content is saved in sample.pdf, if the file had been a CSV / Excel file instead of PDF, would it be possible to edit the file before the iBot is delievered.
December 19, 2007 at 11:37 am
Venkatakrishnan,
Jscript does not work on UNIX platforms. It would be extremely useful for me if you provide me with a Java code example that does the copy file (FTP) on file system of a delivered item as in your example with JScripts.
Thanks
Gianluca
February 1, 2008 at 6:36 pm
[...] by Venkatakrishnan J on February 1, 2008 If you had gone through my previous blog entry here i would have talked about the means of storing BI EE reports on a periodic basis using Java [...]
February 4, 2008 at 1:17 pm
[...] versioninfo.jar and xdocore.jar). For more details on how to do this refer my blog entry here and [...]
February 25, 2008 at 6:26 pm
Venkatakrishnan,
I’ve tried your example, but I’m encountering the following exception. We are currently running OBIEE on the Windows NT platform. Any suggestions to get this example to work would be appreciated.
Regards,
Joe
Feb 25, 2008 9:44:49 AM Main main
INFO: Javahost config file(s): E:\oracle\apps\dev2ntbi\10.1.3\web\javahost\config\config.xml. Xpath:.
Feb 25, 2008 9:44:49 AM ApplicationImpl createEnvironment
INFO: Config environment properties:
presentation.cordaroot=E:\oracle\apps\dev2ntbi\10.1.3\Corda50
presentation.dataconfigdir=E:\oracle\apps\dev2ntbi\10.1.3\data\web\config
javahostdir=E:\oracle\apps\dev2ntbi\10.1.3\web\javahost
rootdir=E:\oracle\apps\dev2ntbi\10.1.3
presentation.rootdir=E:\oracle\apps\dev2ntbi\10.1.3\web
presentation.coreconfigdir=E:\oracle\apps\dev2ntbi\10.1.3\web\config
tempdir=E:\oracle\apps\dev2ntbi\10.1.3\data\tmp
Feb 25, 2008 9:44:53 AM SchedulerComponentLoad load
INFO: Loading config …
Feb 25, 2008 9:44:53 AM SchedulerComponentLoader load
INFO: 150011
Feb 25, 2008 9:44:54 AM ApplicationImpl init
INFO: Running configuration:
JVM=Java HotSpot(TM) Server VM(1.5.0_06-b05)
Listener.Port=9810
Listener.PermittedClientList=*
Listener.Address=null
JobManager.MinThreads=100
JobManager.MaxThreads=100
JobManager.MaxPendingJobs=100
JobManager.IdleThreadTimeoutMls=300000
MessageProcessor.SocketTimeoutMls=5000
Charts.InputStreamLimitInKB=1024
Charts.RequestResponseLogDirectory=C:\WINDOWS\TEMP\
Chart.Enabled=true
Chart.InputStreamLimitInKB=1024
Chart.ChartRoot=E:\oracle\apps\dev2ntbi\10.1.3\Corda50/chart_root
Chart.CordaRoot=E:\oracle\apps\dev2ntbi\10.1.3\Corda50
Chart.EnableConsoleOutput=false
Batik.InputStreamLimitInKB=1024
Batik.RequestResponseLogDirectory=C:\WINDOWS\TEMP\
Batik.EnableXmlValidation=false
Scheduler.Java.Enabled=true
Scheduler.Java.DefaultUserJarFilePath=E:\oracle\apps\dev2ntbi\10.1.3\web\javahost\lib
Scheduler.Java.PurgePeriod=300000
Scheduler.Java.TempPath=C:\WINDOWS\TEMP\
XMLP.InputStreamLimitInKB=8192
XMLP.RequestResponseLogDirectory=C:\WINDOWS\TEMP\
Feb 25, 2008 9:44:54 AM Main main
INFO: Listening for new connections
Feb 25, 2008 9:46:35 AM MessageProcessorImpl processMessage
WARNING: Unexpected exception. Connection will be closed
java.io.EOFException
at com.siebel.analytics.web.sawconnect.sawprotocol.SAWProtocol.readInt(SAWProtocol.java:167)
at com.siebel.analytics.javahost.MessageProcessorImpl.processMessage(MessageProcessorImpl.java:133)
at com.siebel.analytics.javahost.Listener$Job.run(Listener.java:223)
at com.siebel.analytics.javahost.standalone.SAJobManagerImpl.threadMain(SAJobManagerImpl.java:205)
at com.siebel.analytics.javahost.standalone.SAJobManagerImpl$1.run(SAJobManagerImpl.java:153)
at java.lang.Thread.run(Thread.java:595)
Feb 25, 2008 9:46:35 AM MessageProcessorImpl processMessage
WARNING: Unexpected exception. Connection will be closed
java.io.EOFException
at com.siebel.analytics.web.sawconnect.sawprotocol.SAWProtocol.readInt(SAWProtocol.java:167)
at com.siebel.analytics.javahost.MessageProcessorImpl.processMessage(MessageProcessorImpl.java:133)
at com.siebel.analytics.javahost.Listener$Job.run(Listener.java:223)
at com.siebel.analytics.javahost.standalone.SAJobManagerImpl.threadMain(SAJobManagerImpl.java:205)
at com.siebel.analytics.javahost.standalone.SAJobManagerImpl$1.run(SAJobManagerImpl.java:153)
at java.lang.Thread.run(Thread.java:595)
Feb 25, 2008 9:46:35 AM MessageProcessorImpl processMessage
WARNING: Unexpected exception. Connection will be closed
java.io.EOFException
at com.siebel.analytics.web.sawconnect.sawprotocol.SAWProtocol.readInt(SAWProtocol.java:167)
at com.siebel.analytics.javahost.MessageProcessorImpl.processMessage(MessageProcessorImpl.java:133)
at com.siebel.analytics.javahost.Listener$Job.run(Listener.java:223)
at com.siebel.analytics.javahost.standalone.SAJobManagerImpl.threadMain(SAJobManagerImpl.java:205)
at com.siebel.analytics.javahost.standalone.SAJobManagerImpl$1.run(SAJobManagerImpl.java:153)
at java.lang.Thread.run(Thread.java:595)
February 25, 2008 at 6:39 pm
Joe - Did you test the java class as a standalone first (without the run method)? Also, can you check whether you have schedulerrpccalls.jar bundled within your final jar file.
February 25, 2008 at 7:45 pm
Venkatakrishnan,
I created a new class with a main method that was able to instantiate the sawsched.sawsched class.
Below is a listing of the files that I have in my bisched.jar.
Thanks,
Joe
ExecutionState.class com\siebel\analytics\scheduler\javahostrpccalls
Manifest.mf meta-inf\
RpcDisabledSchedulerJob.class com\siebel\analytics\scheduler\javahostrpccalls
RpcSchedulerCancelJob.class com\siebel\analytics\scheduler\javahostrpccalls
RpcSchedulerJob.class com\siebel\analytics\scheduler\javahostrpccalls
sawsched.class sawsched\
SchedulerComponentLoader.class com\siebel\analytics\scheduler\javahostrpccalls
SchedulerConfig.class com\siebel\analytics\scheduler\javahostrpccalls
SchedulerInternalJobInfo.class com\siebel\analytics\scheduler\javahostrpccalls
SchedulerJavaExtension.class com\siebel\analytics\scheduler\javahostrpccalls
SchedulerJavaUtil.class com\siebel\analytics\scheduler\javahostrpccalls
SchedulerJobException.class com\siebel\analytics\scheduler\javahostrpccalls
SchedulerJobInfo.class com\siebel\analytics\scheduler\javahostrpccalls
SchedulerJobInfoImpl.class com\siebel\analytics\scheduler\javahostrpccalls
SchedulerJobMapCleaner.class com\siebel\analytics\scheduler\javahostrpccalls
SchedulerJobStateMap.class com\siebel\analytics\scheduler\javahostrpccalls
SchedulerResultSetFilter.class com\siebel\analytics\scheduler\javahostrpccalls
February 28, 2008 at 1:12 pm
Hi Venkat,
I wanted to add a timestamp tag to the file saved in the first example. Instead of saving the file as Sample.pdf I want to save it as Sample_28FEB2008_183846.pdf(filename_date_time).So that I can keep a track of the versions of the file. How can I achieve this?
Thanks,
Gaurav
March 10, 2008 at 5:23 pm
[...] Top Posts Oracle BI EE 10.1.3.3 - Configuring Delivers - iBotsOracle BI EE 10.1.3.3/2 - Between Prompts for Date Columns - Using Presentation VariablesCustomizing OBI EE – GO URL ParametersContact MeOracle BI EE 10.1.3.3/2 - Combining Multiple Excel Report Outputs(Workbooks) to a Single Excel Report - Using BI Delivers, BI Publisher APIs and VB ScriptsOracle BI EE 10.1.3.3 - Support for Native database Functions and AggregatesOWB 10g/11g - Heterogeneous Data Sources - Excel, MySQL and SQL ServerOracle BI EE 10.1.3.3 - Metadata Dictionary StatisticsOracle BI EE 10.1.3.3 - Customizing look and feel - Styles and SkinsOracle 10g/11g - OLAP, CUBE and ROLLUPOracle BI EE 10.1.3.3/2 - Write Back Option - Budgeting/PlanningOracle BI EE 10.1.3.3/2 - Calling Java Scripts and Java Classes from iBots [...]