|
Oracle interMedia Java Classes for Servlets and JSP API Reference 10g Release 2 (10.2) Part No. B14300-01 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object
oracle.ord.im.OrdHttpResponseHandler
The OrdHttpResponseHandler class facilitates the retrieval of media data from Oracle Database, and its delivery to a browser or other HTTP client from a Java servlet.
An interMedia Java object, such as an OrdImage object, is not dependent on the JDBC statement or result set from which it was obtained. However, an interMedia Java object is dependent on the JDBC connection it is using and on which the SQL statement was executed, or from which the result set was obtained. Therefore, having obtained an interMedia Java object from the database, an application must not release the JDBC connection before delivering the media data to the browser.
This class contains the following field: public static final int DEFAULT_BUFFER_SIZE
.
The OrdHttpResponseHandler class uses a default buffer size of 32768 to retrieve LOB data from the database and deliver it to the client. You can override this value with the setBufferSize method.
The following example shows how to use the OrdHttpResponseHandler class to retrieve an image from a database and deliver it to a browser:
PreparedStatement stmt = conn.prepareStatement( "select photo from photo_album where id = ?" ); stmt.setString( 1, request.getParameter( "photo_id" ) ); OracleResultSet rset = (OracleResultSet)stmt.executeQuery(); if ( rset.next() ) { OrdImage media = (OrdImage)rset.getORAData( 1, OrdImage.getORADataFactory() ); OrdHttpResponseHandler handler = new OrdHttpResponseHandler( request, response ); handler.sendImage(media); } else { response.setStatus( response.SC_NOT_FOUND ); } rset.close(); stmt.close();
If the charset specification is included in the MIME type attribute in the OrdDoc object, then your application needs to call only the sendDoc
method to retrieve the document and deliver it to the browser. For example, an HTML page that is written in Japanese might be stored in the OrdDoc object with a MIME type of text/html; charset=Shift_JIS
. In this case, calling sendDoc
method will send the appropriate Content-Type header, allowing the browser to display the page correctly.
However, if the MIME type in the OrdDoc object does not include the charset specification, then you must call one of the sendResponse methods and specify the MIME type explicitly. For example, if the MIME type of an HTML page written in Japanese is stored in the OrdDoc object as text/html
, and the charset name is specified in a separate column, then the application must append the charset specification to the MIME type before calling a sendResponse method. For example:
OraclePreparedStatement stmt = (OraclePreparedStatement)conn.prepareStatement( "select doc, charset from documents where id = ?" ); stmt.setString( 1, request.getParameter("id") ); OracleResultSet rset = (OracleResultSet)stmt.executeQuery(); if ( rset.next() ) { OrdDoc doc = (OrdDoc)rset.getORAData( 1, OrdDoc.getORADataFactory() ); String charset = rset.getString( 2 ); String mimeType = doc.getMimeType() + "; charset=" + charset; OrdHttpResponseHandler handler = new OrdHttpResponseHandler( request, response ); handler.sendResponse( mimeType, doc.getContentLength(), doc.getContent(), doc.getUpdateTime() ); } else { response.setStatus( response.SC_NOT_FOUND ); } rset.close(); stmt.close();
In order to run interMedia methods for servlets and JSP, you will need to import classes from the oracle.ord.im package into your Java file.
You may also need to import classes from the following Java packages:
java.sql. java.io. javax.servlet. javax.servlet.http. oracle.jdbc. oracle.sql.
Field Summary | |
static int |
DEFAULT_BUFFER_SIZE The OrdHttpResponseHandler class uses a default buffer size of 32768 to retrieve LOB data from the database and deliver it to the client. |
Constructor Summary | |
OrdHttpResponseHandler() Creates an OrdHttpResponseHandler object to handle the response to a media retrieval request. |
|
OrdHttpResponseHandler(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Creates an OrdHttpResponseHandler object to handle the response to a media retrieval request and specifies the HttpServletRequest and HttpServletResponse objects for the response handler. |
Method Summary | |
void |
sendAudio(oracle.ord.im.OrdAudio media) Retrieves an audio clip from an OrdAudio object and delivers it to the browser. |
void |
sendDoc(oracle.ord.im.OrdDoc media) Retrieves media data from an OrdDoc object and delivers it to the browser. |
void |
sendImage(oracle.ord.im.OrdImage media) Retrieves an image from an OrdImage object and delivers it to the browser. |
void |
sendResponse() Retrieves a media object from one of the interMedia objects (OrdImage, OrdAudio, OrdVideo, or OrdDoc) and delivers it to the browser. |
void |
sendResponse(java.lang.String contentType, int length, oracle.sql.BFILE bfile, java.sql.Timestamp lastModified) Builds the HTTP response header, then retrieves the contents of the BFILE from the database and delivers it to the browser. |
void |
sendResponse(java.lang.String contentType, int length, oracle.sql.BLOB blob, java.sql.Timestamp lastModified) Builds the HTTP response header, then retrieves the contents of the BLOB from the database and delivers it to the browser. |
void |
sendResponse(java.lang.String contentType, int length, java.io.InputStream in, java.sql.Timestamp lastModified) Builds the HTTP response header, then retrieves the contents of the InputStream object and delivers it to the browser. |
void |
sendResponseBody(int length, oracle.sql.BFILE bfile) Retrieves the content of a BFILE from the database and delivers it as the response body to the browser. |
void |
sendResponseBody(int length, oracle.sql.BLOB blob) Retrieves the content of a BLOB from the database and delivers it as the response body to the browser. |
void |
sendResponseBody(int length, java.io.InputStream in) Retrieves the content of the InputStream object and delivers it as the response body to the browser. |
void |
sendVideo(oracle.ord.im.OrdVideo media) Retrieves a video clip from an OrdVideo object and delivers it to the browser. |
void |
setBufferSize(int bufferSize) Sets the buffer size for LOB read and HTTP response write operations. |
void |
setEncodeHtml(boolean doEncode) Enables the encoding of special characters (! " % & ' ( ) ; < >) from the response output stream with HTML numeric code. |
void |
setHeader(java.lang.String name, int value) Sets the HTTP response header with the integer (int) value. |
void |
setHeader(java.lang.String name, long date) Sets the HTTP response header with the date value. |
void |
setHeader(java.lang.String name, java.lang.String value) Sets the HTTP response header with the String value. |
void |
setMedia(oracle.ord.im.OrdAudio media) Sets the OrdAudio object as the media object to be delivered. |
void |
setMedia(oracle.ord.im.OrdDoc media) Sets the OrdDoc object as the media object to be delivered. |
void |
setMedia(oracle.ord.im.OrdImage media) Sets the OrdImage object as the media object to be delivered. |
void |
setMedia(oracle.ord.im.OrdVideo media) Sets the OrdVideo object as the media object to be delivered. |
void |
setServletRequest(javax.servlet.http.HttpServletRequest request) Specifies the HttpServletRequest object for this response handler. |
void |
setServletResponse(javax.servlet.http.HttpServletResponse response) Specifies the HttpServletResponse object for this response handler. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int DEFAULT_BUFFER_SIZE
setBufferSize()
method.
Constructor Detail |
public OrdHttpResponseHandler()
setServletResponse
method, and can optionally specify the HttpServletRequest object by calling the setServletRequest
method.public OrdHttpResponseHandler(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
request
- an object of type HttpServletRequest
.response
- an object of type HttpServletResponse
.Method Detail |
public void setServletRequest(javax.servlet.http.HttpServletRequest request)
request
- an object of type HttpServletRequest
.public void setServletResponse(javax.servlet.http.HttpServletResponse response)
response
- an object of type HttpServletResponse
.public void sendImage(oracle.ord.im.OrdImage media) throws javax.servlet.ServletException, java.sql.SQLException, java.io.IOException
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.
media
- an object of type oracle.ord.im.OrdImage
.java.lang.IllegalStateException
- if HttpServletRequest or HttpServletResponse has not been specified.OrdHttpResponseException
- if the source type is not recognized.javax.servlet.ServletException
- if an error occurs accessing the binary output stream.java.sql.SQLException
- if an error occurs obtaining an InputStream object to read the media data.java.io.IOException
- if an error occurs reading the media data.public void sendAudio(oracle.ord.im.OrdAudio media) throws javax.servlet.ServletException, java.sql.SQLException, java.io.IOException
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.
media
- an object of type oracle.ord.im.OrdAudio
.java.lang.IllegalStateException
- if HttpServletRequest or HttpServletResponse has not been specified.OrdHttpResponseException
- if the source type is not recognized.javax.servlet.ServletException
- if an error occurs accessing the binary output stream.java.sql.SQLException
- if an error occurs obtaining an InputStream object to read the media data.java.io.IOException
- if an error occurs reading the media data.public void sendVideo(oracle.ord.im.OrdVideo media) throws javax.servlet.ServletException, java.sql.SQLException, java.io.IOException
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.
media
- an object of type oracle.ord.im.OrdVideo
.java.lang.IllegalStateException
- if HttpServletRequest or HttpServletResponse has not been specified.OrdHttpResponseException
- if the source type is not recognized.javax.servlet.ServletException
- if an error occurs accessing the binary output stream.java.sql.SQLException
- if an error occurs obtaining an InputStream object to read the media data.java.io.IOException
- if an error occurs reading the media data.public void sendDoc(oracle.ord.im.OrdDoc media) throws javax.servlet.ServletException, java.sql.SQLException, java.io.IOException
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.
media
- an object of type oracle.ord.im.OrdDoc
.java.lang.IllegalStateException
- if HttpServletRequest or HttpServletResponse has not been specified.OrdHttpResponseException
- if the source type is not recognized.javax.servlet.ServletException
- if an error occurs accessing the binary output stream.java.sql.SQLException
- if an error occurs obtaining an InputStream object to read the media data.java.io.IOException
- if an error occurs reading the media data.public void sendResponse(java.lang.String contentType, int length, oracle.sql.BLOB blob, java.sql.Timestamp lastModified) throws javax.servlet.ServletException, java.sql.SQLException, java.io.IOException
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.
contentType
- a String
that specifies the MIME type of the content.length
- an integer (int
) that specifies the length of the data.blob
- an object of type oracle.sql.BLOB
from which the media data is retrieved.lastModified
- a java.sql.Timestamp object that specifies the date and time when the data was last modified, or null
if no last modified date and time are available.java.lang.IllegalStateException
- if HttpServletRequest or HttpServletResponse has not been specified.java.lang.IllegalArgumentException
- if the length is negative.javax.servlet.ServletException
- if an error occurs accessing the binary output stream.java.sql.SQLException
- if an error occurs obtaining an InputStream object to read the media data.java.io.IOException
- if an error occurs reading the media data.public void sendResponse(java.lang.String contentType, int length, oracle.sql.BFILE bfile, java.sql.Timestamp lastModified) throws javax.servlet.ServletException, java.sql.SQLException, java.io.IOException
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.
contentType
- a String
that specifies the MIME type of the content.length
- an integer (int
) that specifies the length of the data.bfile
- an object of type oracle.sql.BFILE
from which the media data is retrieved.lastModified
- a java.sql.Timestamp object that specifies the date and time when the data was last modified, or null
if no last modified date and time are available.java.lang.IllegalStateException
- if HttpServletRequest or HttpServletResponse has not been specified.java.lang.IllegalArgumentException
- if the length is negative.javax.servlet.ServletException
- if an error occurs accessing the binary output stream.java.sql.SQLException
- if an error occurs obtaining an InputStream object to read the media data.java.io.IOException
- if an error occurs reading the media data.public void sendResponse(java.lang.String contentType, int length, java.io.InputStream in, java.sql.Timestamp lastModified) throws javax.servlet.ServletException, java.io.IOException
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.
contentType
- a String
that specifies the MIME type of the content.length
- an integer (int
) that specifies the length of the data.in
- an InputStream
object from which the media data is retrieved.lastModified
- a java.sql.Timestamp object that specifies the date and time when the data was last modified, or null
if no last modified date and time are available.java.lang.IllegalStateException
- if HttpServletRequest or HttpServletResponse has not been specified.java.lang.IllegalArgumentException
- if the length is negative.javax.servlet.ServletException
- if an error occurs accessing the binary output stream.java.io.IOException
- if an error occurs reading the media data.public void sendResponseBody(int length, oracle.sql.BLOB blob) throws javax.servlet.ServletException, java.sql.SQLException, java.io.IOException
length
- an integer (int
) that specifies the length of the data.blob
- an object of type oracle.sql.BLOB
from which the media data is retrieved.java.lang.IllegalStateException
- if HttpServletResponse has not been specified.java.lang.IllegalArgumentException
- if the length is negative.javax.servlet.ServletException
- if an error occurs accessing the binary output stream.java.sql.SQLException
- if an error occurs obtaining an InputStream object to read the media data.java.io.IOException
- if an error occurs reading the media data.public void sendResponseBody(int length, oracle.sql.BFILE bfile) throws javax.servlet.ServletException, java.sql.SQLException, java.io.IOException
length
- an integer (int
) that specifies the length of the data.bfile
- an object of type oracle.sql.BFILE
from which the media data is retrieved.java.lang.IllegalStateException
- if HttpServletResponse has not been specified.java.lang.IllegalArgumentException
- if the length is negative.javax.servlet.ServletException
- if an error occurs accessing the binary output stream.java.sql.SQLException
- if an error occurs obtaining an InputStream object to read the media data.java.io.IOException
- if an error occurs reading the media data.public void sendResponseBody(int length, java.io.InputStream in) throws javax.servlet.ServletException, java.io.IOException
length
- an integer (int
) that specifies the length of the data.in
- an InputStream
object from which the media data is retrieved.java.lang.IllegalStateException
- if HttpServletResponse has not been specified.java.lang.IllegalArgumentException
- if the length is negative.javax.servlet.ServletException
- if an error occurs accessing the binary output stream.java.io.IOException
- if an error occurs reading the media data.public void setBufferSize(int bufferSize) throws java.lang.IllegalArgumentException
bufferSize
- an integer (int
) that specifies the buffer size.java.lang.IllegalArgumentException
- if the buffer size is negative or zero.public void setMedia(oracle.ord.im.OrdImage media)
media
- an object of type oracle.ord.im.OrdImage
.public void setMedia(oracle.ord.im.OrdAudio media)
media
- an object of type oracle.ord.im.OrdAudio
.public void setMedia(oracle.ord.im.OrdVideo media)
media
- an object of type oracle.ord.im.OrdVideo
.public void setMedia(oracle.ord.im.OrdDoc media)
media
- an object of type oracle.ord.im.OrdDoc
.public void setHeader(java.lang.String name, java.lang.String value)
name
- the name of the header.value
- the value of the header.public void setHeader(java.lang.String name, long date)
name
- the name of the header.date
- the date value of the header.public void setHeader(java.lang.String name, int value)
name
- the name of the header.value
- the integer (int
) value of the header.public void sendResponse() throws javax.servlet.ServletException, java.sql.SQLException, java.io.IOException
setMedia(oracle.ord.im.OrdImage)
method must be called before calling this method. The media object to be delivered is determined by the last setMedia method.
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.
java.lang.IllegalStateException
- if HttpServletRequest or HttpServletResponse has not been specified.OrdHttpResponseException
- if the source type is not recognized.javax.servlet.ServletException
- if an error occurs accessing the binary output stream.java.sql.SQLException
- if an error occurs obtaining an InputStream object to read the media data.java.io.IOException
- if an error occurs reading the media data.public void setEncodeHtml(boolean doEncode)
doEncode
- a boolean
value indicating whether or not to encode the response output stream.
|
Oracle interMedia Java Classes for Servlets and JSP API Reference 10g Release 2 (10.2) Part No. B14300-01 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |