Skip Headers
Oracle® Fusion Middleware Developer's Guide for Oracle Business Intelligence Publisher
11g Release 1 (11.1.1)

Part Number E22259-04
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
PDF · Mobi · ePub

10 Setting Up After-Report Triggers

This chapter describes how to set up an after-report trigger using an HTTP servlet.

It includes the following sections:

10.1 Overview of After-Report Triggers

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.

BI Publisher supports Event triggers (Before Data and After Data triggers) in the Data Model Definition, which you can use to trigger programs during data generation. HTTP notification will trigger after the report is generated.

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

10.1.2 Process Overview for Adding After-Report Triggers to Reports

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 Section 10.2.1, "Registering the HTTP Servlet."

    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.

10.2 Setting Up After-Report Triggers

When the report generation has completed BI Publisher will call the HTTP notification as a post-process 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:

Example 10-1 Sample Code for Setting Up After-Report Triggers

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); 
      }

10.2.1 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 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>

Alternatively, you can create a JSP page instead of a HTTP Servlet to handle this HTTP notification. With JSP, you do not need to modify web.xml.

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

Example 10-2 Sample Program Code

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;
         }