Skip Headers

Oracle® interMedia Java Classes Reference
10g Release 1 (10.1)

Part Number B10830-01
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
Feedback

Go to previous page
Previous
Go to next page
Next
View PDF

OrdHttpResponseHandler Class

This section presents reference information on the methods of the oracle.ord.im.OrdHttpResponseHandler class.

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:

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

A Note on the Use of Charsets Other Than ISO-8859-1 (Latin-1)

If you wish to retrieve from an OrdDoc object a text-based document with a character set (charset) other than ISO-8859-1 (also called Latin-1), and deliver that document to a browser, your application must specify the charset name in the HTTP Content-Type header.

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 the 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( );

OrdHttpResponseHandler( )

Format

public OrdHttpResponseHandler( )

Description

Creates an OrdHttpResponseHandler object to handle the response to a multimedia retrieval request. The application must subsequently specify the HttpServletResponse object by calling the setServletResponse( ) method, and can optionally specify the HttpServletRequest object by calling the setServletRequest( ) method.

Parameters

None.

Return Value

None.

Exceptions

None.

Examples

None.


OrdHttpResponseHandler(HttpServletRequest, HttpServletResponse)

Format

public OrdHttpResponseHandler(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)

Description

Creates an OrdHttpResponseHandler object to handle the response to a multimedia retrieval request and specifies the HttpServletRequest and HttpServletResponse objects for the response handler.

Parameters

request

An object of type HttpServletRequest.

response

An object of type HttpServletResponse.

Return Value

None.

Exceptions

None.

Examples

None.


sendAudio(OrdAudio)

Format

public void sendAudio(oracle.ord.im.OrdAudio media)

Description

Retrieves an audio clip from an OrdAudio object and delivers it to the browser.

This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.

Parameters

media

An object of type oracle.ord.im.OrdAudio.

Return Value

None.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletRequest or HttpServletResponse has not been specified.

OrdHttpResponseException

This exception is thrown if the source type is not recognized.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

None.


sendDoc(OrdDoc)

Format

public void sendDoc(oracle.ord.im.OrdDoc media)

Description

Retrieves media data from an OrdDoc object and delivers it to the browser.

This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.

Parameters

media

An object of type oracle.ord.im.OrdDoc.

Return Value

None.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletRequest or HttpServletResponse has not been specified.

OrdHttpResponseException

This exception is thrown if the source type is not recognized.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

None.


sendImage(OrdImage)

Format

public void sendImage(oracle.ord.im.OrdImage media)

Description

Retrieves an image from an OrdImage object and delivers it to the browser.

This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.

Parameters

media

An object of type oracle.ord.im.OrdImage.

Return Value

None.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletRequest or HttpServletResponse has not been specified.

OrdHttpResponseException

This exception is thrown if the source type is not recognized.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

None.


sendResponse( )

Format

public void sendResponse( )

Description

Retrieves a media object from one of the interMedia objects (OrdImage, OrdAudio, OrdVideo, or OrdDoc) and delivers it to the browser. 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.

Parameters

None.

Return Value

None.

Exceptions

java.io.IOException

This exception is thrown if an error occurs reading the media data.

java.lang.IllegalStateException

This exception is thrown if HttpServletRequest or HttpServletResponse has not been specified.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

OrdHttpResponseException

This exception is thrown if the source type is not recognized.

Examples

None.


sendResponse(String, int, BFILE, Timestamp)

Format

public void sendResponse(String contentType, int length, oracle.sql.BFILE bfile,
java.sql.Timestamp lastModified)

Description

Builds the HTTP response header, then retrieves the contents of the BFILE from the database and delivers it to the browser.

This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.

Parameters

contentType

A string that specifies the MIME type of the content.

length

An integer 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.

Return Value

None.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletRequest or HttpServletResponse has not been specified.

java.lang.IllegalArgumentException

This exception is thrown if the length is negative.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

None.


sendResponse(String, int, BLOB, Timestamp)

Format

public void sendResponse(String contentType, int length, oracle.sql.BLOB blob,
java.sql.Timestamp lastModified)

Description

Builds the HTTP response header, then retrieves the contents of the BLOB from the database and delivers it to the browser.

This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.

Parameters

contentType

A string that specifies the MIME type of the content.

length

An integer 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.

Return Value

None.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletRequest or HttpServletResponse has not been specified.

java.lang.IllegalArgumentException

This exception is thrown if the length is negative.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

None.


sendResponse(String, int, InputStream, Timestamp)

Format

public void sendResponse(String contentType, int length, java.io.InputStream in,
java.sql.Timestamp lastModified)

Description

Builds the HTTP response header, then retrieves the contents of the InputStream object and delivers it to the browser.

This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.

Parameters

contentType

A String that specifies the MIME type of the content.

length

An integer 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.

Return Value

None.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletRequest or HttpServletResponse has not been specified.

java.lang.IllegalArgumentException

This exception is thrown if the length is negative.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

None.


sendResponseBody(int, BFILE)

Format

public void sendResponseBody(int length, oracle.sql.BFILE bfile)

Description

Retrieves the content of a BFILE from the database and delivers it as the response body to the browser. The caller is responsible for building the HTTP header.

Parameters

length

An integer that specifies the length of the data.

bfile

An object of type oracle.sql.BFILE from which the media data is retrieved.

Return Value

None.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletResponse has not been specified.

java.lang.IllegalArgumentException

This exception is thrown if the length is negative.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

None.


sendResponseBody(int, BLOB)

Format

public void sendResponseBody(int length, oracle.sql.BLOB blob)

Description

Retrieves the content of a BLOB from the database and delivers it as the response body to the browser. The caller is responsible for building the HTTP header.

Parameters

length

An integer that specifies the length of the data.

blob

An object of type oracle.sql.BLOB from which the media data is retrieved.

Return Value

None.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletResponse has not been specified.

java.lang.IllegalArgumentException

This exception is thrown if the length is negative.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

None.


sendResponseBody(int, InputStream)

Format

public void sendResponseBody(int length, java.io.InputStream in)

Description

Retrieves the content of the InputStream object and delivers it to the client. The caller is responsible for building the HTTP header.

Parameters

length

An integer that specifies the length of the data.

in

An InputStream object from which the media data is retrieved.

Return Value

None.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletResponse has not been specified.

java.lang.IllegalArgumentException

This exception is thrown if the length is negative.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

None.


sendVideo(OrdVideo)

Format

public void sendVideo(oracle.ord.im.OrdVideo media)

Description

Retrieves a video clip from an OrdVideo object and delivers it to the browser.

This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.

Parameters

media

An object of type oracle.ord.im.OrdVideo.

Return Value

None.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletRequest or HttpServletResponse has not been specified.

OrdHttpResponseException

This exception is thrown if the source type is not recognized.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

None.


setBufferSize(int)

Format

public void setBufferSize(int bufferSize)

Description

Sets the buffer size for LOB read and HTTP response write operations.

Parameters

bufferSize

An integer that specifies the buffer size.

Return Value

None.

Exceptions

java.lang.IllegalArgumentException

This exception is thrown if the buffer size is negative or zero.

Examples

None.


setEncodeHtml(boolean)

Format

public void setEncodeHtml(boolean doEncode)

Description

Enables the encoding of special characters (! " % & ' ( ) ; < >) from the response output stream with MIME type text or html. By default, there is no encoding.

Parameters

doEncode

A Boolean value indicating whether or not to encode the response output stream.

Return Value

None.

Exceptions

None.

Examples

None.


setHeader(String, String)

Format

public void setHeader(String name, String value)

Description

Sets the HTTP response header with the String value. If the header is already set, the new value overwrites the previous value.

Parameters

name

The name of the header.

value

The value of the header.

Return Value

None.

Exceptions

None.

Examples

None.


setHeader(String, long)

Format

public void setHeader(String name, long date)

Description

Sets the HTTP response header with the date value. If the header is already set, the new value overwrites the previous value.

Parameters

name

The name of the header.

date

The date value of the header.

Return Value

None.

Exceptions

None.

Examples

None.


setHeader(String, int)

Format

public void setHeader(java.lang.String name, int value)

Description

Sets the HTTP response header with the integer value. If the header is already set, the new value overwrites the previous value.

Parameters

name

The name of the header.

value

The integer value of the header.

Return Value

None.

Exceptions

None.

Examples

None.


setMedia(OrdAudio)

Format

public void setMedia(OrdAudio media)

Description

Sets the media object to be delivered. To deliver the data in the response body, this method must be called before calling the sendResponse( ) method.

Parameters

media

An object of type oracle.ord.im.OrdAudio.

Return Value

None.

Exceptions

None.

Examples

None.


setMedia(OrdDoc)

Format

public void setMedia(OrdDoc media)

Description

Sets the media object to be delivered. To deliver the data in the response body, this method must be called before calling the sendResponse( ) method.

Parameters

media

An object of type oracle.ord.im.OrdDoc.

Return Value

None.

Exceptions

None.

Examples

None.


setMedia(OrdImage)

Format

public void setMedia(OrdImage media)

Description

Sets the media object to be delivered. To deliver the data in the response body, this method must be called before calling the sendResponse( ) method.

Parameters

media

An object of type oracle.ord.im.OrdImage.

Return Value

None.

Exceptions

None.

Examples

None.


setMedia(OrdVideo)

Format

public void setMedia(OrdVideo media)

Description

Sets the media object to be delivered. To deliver the data in the response body, this method must be called before calling the sendResponse( ) method.

Parameters

media

An object of type oracle.ord.im.OrdVideo.

Return Value

None.

Exceptions

None.

Examples

None.


setServletRequest(HttpServletRequest)

Format

public void setServletRequest(javax.servlet.http.HttpServletRequest request)

Description

Specifies the HttpServletRequest object for this response handler. You must call this method if you did not specify the HttpServletRequest object in the constructor and you want to call any of the send methods other than the sendResponseBody methods. You do not need to call this method if you call only the sendResponseBody methods.

Parameters

request

An object of type HttpServletRequest.

Return Value

None.

Exceptions

None.

Examples

None.


setServletResponse(HttpServletResponse)

Format

public void setServletResponse(javax.servlet.http.HttpServletResponse response)

Description

Specifies the HttpServletResponse object for this response handler. You must call this method before calling any of the send methods if you did not specify the HttpServletResponse object in the constructor.

Parameters

response

An object of type HttpServletResponse.

Return Value

None.

Exceptions

None.

Examples

None.