Skip Headers

Oracle Fusion Middleware Administrator's and Developer's Guide for Oracle Business Intelligence Publisher
Release 11g (11.1.1)
Part Number E13880-01
Go to Table of Contents
Contents
Go to previous page
Previous
Go to next page
Next

Setting Up an After Report Trigger

Overview

BI Publisher enables you to set up an HTTP notification that will execute after report generation as an after report trigger. This enables you to integrate BI Publisher with other Oracle and third-party applications such as a BPEL process, Content Management applications, or other workflow applications.

Limitations

Note that immediately upon the generation of the report in BI Publisher, the notification will execute. There is currently no ability to call back or introduce a listener or process between the report generation and the HTTP notification to your servlet.

Process Overview for Adding the After Report Trigger to a Report

The following tasks are required to complete the setup of an after report trigger for your report:

  1. Create your servlet or third-party application, as described in this chapter.

  2. Register your servlet URL as an HTTP delivery server in the BI Publisher Administration page. See Set Up an HTTP Server.

    Note: The servlet has to be made available bypassing security, therefore, the servlet mapping is required in web.xml (under WEB-INF folder).

  3. Create a schedule for the report, choosing HTTP Notification. See Scheduling a Report, Oracle Fusion Middleware Report Designer's Guide for Business Intelligence Publisher.

Setting Up the After Report Trigger

When the report generation has completed BI Publisher will call the HTTP notification as a postprocess and submit the URL (that you registered as an HTTP server) with the following additional parameters:

Your remote application can then access these parameters using BI Publisher's APIs and Web services to access the job details, including report output and XML data as shown in the following code sample:

String id=    request.getParameter("jobid");
      String report_url = request.getParameter("report_url");
      String status = request.getParameter("status");
      
      try
      {
       Scheduler sch =new SchedulerImpl();
       JobHistoryInfo[] jobs= sch.getJobHistoryInfo(id);
       for (int i = 0; i<jobs.length; i++){
       JobHistoryInfo outinfo = jobs[i]; 
       FileOutputStream fos = new FileOutputStream(targetDir+id+".pdf");
       byte[] buf = new byte[256];
       int read = 0;
       InputStream in  = outinfo.getDocumentOutput();
       
       while ((read =in.read(buf)) > 0) {
                       fos.write(buf, 0, read);
     }
                       in.close();
                       fos.close();
       }  
      } catch (Exception e) {
         Logger.log(e); 
      }

Registering the HTTP Servlet

Note that if the HTTP servlet is running inside the BI Publisher application on the same server, you must register it in the web.xml (located in the WEB-INF folder). Update the web.xml file as follows:

<servlet>
<servlet-name>HttpNotificationTest</servlet-name>
<servlet-class>oracle.xdo.service.scheduling.HttpNotificationTest</servlet-class>
</servlet> 

<servlet-mapping>
<servlet-name>HttpNotificationTest</servlet-name>
<url-pattern>/services/HttpNotificationTest</url-pattern>
</servlet-mapping>

Sample Program

Following is a sample HTTP servlet that is called as an HTTP Notification. In this example, the servlet is deployed on the same server as the BI Publisher application. If your servlet is deployed on a remote server, use the BI Publisher Web service APIs to access the report details. For more information about the BI Publisher Web service APIs, see Oracle Fusion Middleware Java API Reference for Oracle Business Intelligence Publisher 11g.

In this sample, the servlet uses the information provided by the HTTP request as input to the BI Publisher Web services to retrieve the report output. This could then be used to insert in an approval workflow.

package oracle.xdo.service.scheduling;

import java.io.FileOutputStream;


import java.io.IOException;
import java.io.InputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import oracle.xdo.common.log.Logger;
import oracle.xdo.server.JobHistoryInfo;
import oracle.xdo.server.Scheduler;
import oracle.xdo.server.impl.SchedulerImpl;

public class HttpNotificationTest extends HttpServlet
{
 public String targetDir = "c://scratch/example/apphome/xmlpserver/xmlpserver/output/"; 
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response) throws ServletException, IOException
  {
    doPost(request, response);
  }
 public void doPost(HttpServletRequest request,
                     HttpServletResponse response) throws ServletException, IOException
  {
   
 
      String id=    request.getParameter("jobid");
      String report_url = request.getParameter("report_url");
      String status = request.getParameter("status");
      
      try
      {
       Scheduler sch =new SchedulerImpl();
       JobHistoryInfo[] jobs= sch.getJobHistoryInfo(id);
       for (int i = 0; i<jobs.length; i++){
       JobHistoryInfo outinfo = jobs[i]; 
       FileOutputStream fos = new FileOutputStream(targetDir+id+"."+getFileExtension(outinfo.getDocumentDataContentType()));
       byte[] buf = new byte[256];
       int read = 0;
       InputStream in  = outinfo.getDocumentOutput();
       
       while ((read =in.read(buf)) > 0) {
                       fos.write(buf, 0, read);
     }
                       in.close();
                       fos.close();
       }  
      } catch (Exception e) {
         Logger.log(e); 
      }
      }
     
      
       public static String getFileExtension(String contentType)
         {
          String ext="pdf";  
         
          if (contentType == "application/pdf")
          ext="pdf" ;
          
          else if (contentType == "text/html; charset=UTF-8")
          ext="html";
          return ext;
         }