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.
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:
DataStreaming.FILE_NAME
DataStreaming.CONTENT_TYPE
DataStreaming.FILE_SIZE
DataStreaming.CNT_DISPO_TYPE
DataStreaming.ERROR_MESSAGE
DataStreaming.APP_SHORT_NAME
DataStreaming.ERR_TK_<token name>
Call the DataStreaming.putBlob() API passing in these properties:
DataStreaming.FILE_NAME, DataStreaming.FILE_SIZE, DataStreaming.CNT_DISPO_TYPE: These properties for file name, file size and content-disposition type need to be set to construct the Content-Disposition header in the response.
The file name and file size are optional and are not set in the header if they are not passed.
The content-disposition type should be set to either inline
or attachment
. The default value is attachment
if not specified.
DataStreaming.ERROR_MESSAGE, DataStreaming.APP_SHORT_NAME, and DataStreaming.ERR_TK_<token name>: The error message, application short name, and token properties are needed to construct the error text that will be displayed in the fnderror.jsp page.
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.
<%@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>