File Streaming Using AOL/J

AOL/J JSP and Java API for File Streaming

Applications often need to stream a file, such as a PDF file or other document, from the server to the web browser. AOL/J provides a mechanism using a Java API and JSP to stream such files to the client. This mechanism can be used by Oracle Application Framework application pages to stream documents generated via BI Publisher, for example.

A new Java API (oracle.apps.fnd.util.DataStreaming) and a new JSP (AOLDataStreaming.jsp) provide a secure mechanism to store and stream files from the server to a user's browser.

The API takes a binary object and puts it in the database. The object can then be securely streamed to the browser via the AOLDataStreaming.jsp and an ID associated with the object. The JSP can be called as a redirect directly or embedded as an iFrame in a surrounding page.

Java API for File Streaming

The API specification of DataStreaming.java is:

public static String putBLOB(oracle.jbo.domain.BlobDomain data, Properties params,
           HttpServletRequest request,
           HttpServletResponse response) throws IOException,
                                                SQLException

The Properties object "params" can have the following properties set. These are available as string constants in DataStreaming.java:

Call the DataStreaming.putBlob() API passing in these properties:

The API then constructs an AOLDataStreaming.jsp URL after setting certain session attributes, which will then stream the data to the client with the response.

Valid calls to DataStreaming.putBLOB() would return a URL in the form of "/OA_HTML/jsp/fnd/AOLDataStreaming.jsp?fileId=nnnnnn". Any exceptions caused would return NULL.

Example of a JSP

<%@page import="java.util.Properties"%>
<%@page import="oracle.jbo.domain.BlobDomain"%>
<%@page import="oracle.apps.fnd.util.DataStreaming" %>
<%@page import="oracle.apps.fnd.common.WebAppsContext" %>
<%@page import="oracle.apps.fnd.common.WebRequestUtil" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>AOLDataStreaming Test</title>
</head>
<body>
<%
        WebAppsContext wac = WebRequestUtil.validateContext(request, response);
        String text = null;
        if(wac!=null)
        text = request.getParameter("textContent") + wac.getSessionId();

        BlobDomain dummyBlob = new  BlobDomain(text.getBytes());
        Properties prop = new Properties();
        String fileName = request.getParameter("fileName");
        String contentType = request.getParameter("contentType");
        String contentDispType = request.getParameter("contentDispType");
        String appName = request.getParameter("appName");
        String msgName = request.getParameter("msgName");
        String token1 = request.getParameter("token1");
        String token2 = request.getParameter("token2");

        if(fileName!=null)
                prop.put("FILE_NAME", fileName);

        if(contentType!=null)
                prop.put("CNT_TYPE", contentType);

        if(contentDispType!=null)
                prop.put("CNT_DISPOSITION_TYPE", contentDispType);

        if(appName!=null)
                prop.put("APP_SHORT_NAME", appName);

        if(msgName!=null)
                prop.put("ERR_MSG_NAME", msgName);

        if(token1!=null)
                prop.put("TK_TOKEN1", token1);

        if(token2!=null)
                prop.put("TK_DUMMY", token2);


        if(request.getParameter("buttonName")!=null){
                String redirect = DataStreaming.putBLOB(dummyBlob, prop, request, response);
                response.sendRedirect(redirect);
        }
%>
<FORM NAME="form1" METHOD="POST">
            <INPUT TYPE="HIDDEN" NAME="buttonName">
            Text<br><INPUT type="text" name="textContent"><br>
            Filename<br><INPUT type="text" name="fileName"><br>
            Content-Type<br><INPUT type="text" name="contentType"><br>
            Content-Disposition<br><INPUT type="text" name="contentDispType"><br>
            AppName<br><INPUT type="text" name="appName"><br>
            MessageName<br><INPUT type="text" name="msgName"><br>
            Token1<br><INPUT type="text" name="token1"><br>
            Token2<br><INPUT type="text" name="token2"><br>
            <INPUT TYPE="BUTTON" VALUE="Test" ONCLICK="button1()">
</FORM>
<SCRIPT LANGUAGE="JavaScript">
            <!--
            function button1()
            {
                document.form1.buttonName.value = "button 1";
                form1.submit();
            }    
 
            // -->
</SCRIPT>
</body>
</html>