Enhydra 5.1 API

com.lutris.appserver.server.httpPresentation.servlet
Class ServletHttpPresentationResponse

java.lang.Object
  |
  +--com.lutris.appserver.server.httpPresentation.servlet.ServletHttpPresentationResponse
All Implemented Interfaces:
DebugResponse, HttpPresentationResponse

public class ServletHttpPresentationResponse
extends java.lang.Object
implements HttpPresentationResponse, DebugResponse

Object passed to presentation objects that is used to generate HTTP responses.


Field Summary
 
Fields inherited from interface com.lutris.appserver.server.httpPresentation.HttpPresentationResponse
SC_ACCEPTED, SC_BAD_GATEWAY, SC_BAD_REQUEST, SC_CREATED, SC_FORBIDDEN, SC_INTERNAL_SERVER_ERROR, SC_MOVED_PERMANENTLY, SC_MOVED_TEMPORARILY, SC_NO_CONTENT, SC_NOT_FOUND, SC_NOT_IMPLEMENTED, SC_NOT_MODIFIED, SC_OK, SC_SERVICE_UNAVAILABLE, SC_UNAUTHORIZED
 
Constructor Summary
protected ServletHttpPresentationResponse(javax.servlet.http.HttpServletResponse response, org.apache.log4j.Logger domStatsLogger)
          Construct an object associated with a servlet response.
 
Method Summary
 void addCookie(javax.servlet.http.Cookie cookie)
          Adds the specified cookie to the response.
 boolean containsHeader(java.lang.String name)
          Returns true if the response message header has a field with the specified name.
 OutputOptions createOutputOptions(XMLObject document)
          Create an OutputOptions object for a document.
 java.lang.String encodeRedirectUrl(java.lang.String url)
          Encodes a url with session id for sendRedirect for use with cookieless browsers.
 java.lang.String encodeUrl(java.lang.String url)
          Encodes a url with session id for use with cookieless browsers.
 void flush()
          Called at the end of processing a response to force any cached headers to be written and buffers flushed.
 int getContentLength()
          Returns the size of the request entity data, or -1 if not available.
 java.lang.String getContentType()
          Returns the Internet Media Type of the response, or null if not known This is necessary to support the DebugResponse interface.
 javax.servlet.http.Cookie[] getCookies()
          Returns an array of cookies to be set by this response, or a 0 length array if the information is not available.
 java.lang.String getEncoding()
          Get the output character encoding.
 java.lang.String getHeader(java.lang.String name)
          Returns the values of the specified header for the response as an array of strings, or a 0 length array if the named header does not exist.
 java.util.Enumeration getHeaderNames()
          Returns an array of strings representing the header names for this response.
 javax.servlet.http.HttpServletResponse getHttpServletResponse()
          Returns the original HttpServletResponse.
 HttpPresentationOutputStream getOutputStream()
          Returns an output stream for writing response data.
 java.lang.String getResponseData()
          Returns null.
 int getStatusCode()
          Returns the status code for the response, or -1 if not available.
 java.lang.String getStatusMessage()
          Returns the status message for the response, or null if not available.
 int getTotalBytes()
          Returns the total number of bytes that make up this response.
 boolean isSessionIdCookieRequired()
          Indicates whether client response requires a sessionId cookie
 boolean isSessionIdEncodeUrlRequired()
          Indicates whether client response requires url encoding for sessionId
 void sendError(int sc)
          Sends an error response to the client using the specified status code and a default message.
 void sendError(int sc, java.lang.String msg)
          Sends an error response to the client using the specified status code and descriptive message.
 void setContentLength(int len)
          Sets the content length for this response.
 void setContentType(java.lang.String type)
          Sets the content type for this response.
 void setDateHeader(java.lang.String name, long date)
          Adds a field to the response header with a given name and date-valued field.
 void setEncoding(java.lang.String enc)
          Set the output character encoding.
 void setHeader(java.lang.String name, java.lang.String value)
          Adds a field to the response header with a given name and value.
 void setIntHeader(java.lang.String name, int value)
          Adds a field to the response header with a given name and integer value.
 void setSessionIdCookieRequired(boolean sessionIdCookie)
           
 void setSessionIdEncodeUrlRequired(boolean sessionIdUrl)
           
 void setSessionKey(java.lang.String sessionKey)
          Sets the current session key for this response
 void setSessionManager(SessionManager sessionManager)
          Sets the session manager.
 void setStatus(int sc)
          Sets the status code and a default message for this response.
 void setStatus(int sc, java.lang.String sm)
          Sets the status code and message for this response.
 void writeDOM(OutputOptions outputOptions, XMLObject document)
          Output an an XMLC document object (DOM).
 void writeDOM(XMLObject document)
          Output an an XMLC document object (DOM).
 void writeHTML(HTMLDocument doc)
          Deprecated. use writeDOM
 void writeHTML(java.lang.String html)
          Utility method to output an HTML page.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServletHttpPresentationResponse

protected ServletHttpPresentationResponse(javax.servlet.http.HttpServletResponse response,
                                          org.apache.log4j.Logger domStatsLogger)
Construct an object associated with a servlet response.

Parameters:
response - Servlet response object that this object will front-end.
Method Detail

getHttpServletResponse

public javax.servlet.http.HttpServletResponse getHttpServletResponse()
Returns the original HttpServletResponse.

Specified by:
getHttpServletResponse in interface HttpPresentationResponse

setContentLength

public void setContentLength(int len)
                      throws HttpPresentationException
Sets the content length for this response.

Specified by:
setContentLength in interface HttpPresentationResponse
Parameters:
len - the content length
HttpPresentationException

setContentType

public void setContentType(java.lang.String type)
                    throws HttpPresentationException
Sets the content type for this response.

Specified by:
setContentType in interface HttpPresentationResponse
Parameters:
type - the content's MIME type
HttpPresentationException

getOutputStream

public HttpPresentationOutputStream getOutputStream()
                                             throws HttpPresentationException
Returns an output stream for writing response data.

Specified by:
getOutputStream in interface HttpPresentationResponse
HttpPresentationException

addCookie

public void addCookie(javax.servlet.http.Cookie cookie)
               throws HttpPresentationException
Adds the specified cookie to the response. It can be called multiple times to set more than one cookie.

Specified by:
addCookie in interface HttpPresentationResponse
Parameters:
cookie - - The Cookie to return to the client.
HttpPresentationException

containsHeader

public boolean containsHeader(java.lang.String name)
                       throws HttpPresentationException
Returns true if the response message header has a field with the specified name.

Specified by:
containsHeader in interface HttpPresentationResponse
Parameters:
name - the header field name
HttpPresentationException

setStatus

public void setStatus(int sc,
                      java.lang.String sm)
               throws HttpPresentationException
Sets the status code and message for this response.

Specified by:
setStatus in interface HttpPresentationResponse
Parameters:
sc - the status code
sm - the status message
HttpPresentationException

setStatus

public void setStatus(int sc)
               throws HttpPresentationException
Sets the status code and a default message for this response.

Specified by:
setStatus in interface HttpPresentationResponse
Parameters:
sc - the status code
HttpPresentationException

setHeader

public void setHeader(java.lang.String name,
                      java.lang.String value)
               throws HttpPresentationException
Adds a field to the response header with a given name and value. If the field had already been set, the new value overwrites the previous one. The containsHeader method can be used to test for the presence of a header before setting its value.

Specified by:
setHeader in interface HttpPresentationResponse
Parameters:
name - the header field name
value - the header field value
HttpPresentationException

setIntHeader

public void setIntHeader(java.lang.String name,
                         int value)
                  throws HttpPresentationException
Adds a field to the response header with a given name and integer value. If the field had already been set, the new value overwrites the previous one. The containsHeader method can be used to test for the presence of a header before setting its value.

Specified by:
setIntHeader in interface HttpPresentationResponse
Parameters:
name - the header field name
value - the header field integer value
HttpPresentationException

setDateHeader

public void setDateHeader(java.lang.String name,
                          long date)
                   throws HttpPresentationException
Adds a field to the response header with a given name and date-valued field. The date is specified in terms of milliseconds since the epoch. If the date field had already been set, the new value overwrites the previous one. The containsHeader method can be used to test for the presence of a header before setting its value.

Specified by:
setDateHeader in interface HttpPresentationResponse
Parameters:
name - the header field name
HttpPresentationException

sendError

public void sendError(int sc,
                      java.lang.String msg)
               throws HttpPresentationException
Sends an error response to the client using the specified status code and descriptive message.

Specified by:
sendError in interface HttpPresentationResponse
Parameters:
sc - the status code
msg - the detail message
HttpPresentationException

sendError

public void sendError(int sc)
               throws HttpPresentationException
Sends an error response to the client using the specified status code and a default message.

Specified by:
sendError in interface HttpPresentationResponse
Parameters:
sc - the status code
HttpPresentationException

flush

public void flush()
           throws HttpPresentationException
Called at the end of processing a response to force any cached headers to be written and buffers flushed.

Specified by:
flush in interface HttpPresentationResponse
HttpPresentationException

encodeUrl

public java.lang.String encodeUrl(java.lang.String url)
Encodes a url with session id for use with cookieless browsers.

Parameters:
url - the url to be encoded.
Returns:
the encoded URL if encoding is needed; the unchanged URL otherwise.

encodeRedirectUrl

public java.lang.String encodeRedirectUrl(java.lang.String url)
Encodes a url with session id for sendRedirect for use with cookieless browsers.

Parameters:
url - the url to be encoded.
Returns:
the encoded URL if encoding is needed; the unchanged URL otherwise.
See Also:
#sendRedirect, encodeUrl(java.lang.String)

getContentLength

public int getContentLength()
Returns the size of the request entity data, or -1 if not available. This is necessary to support the DebugResponse interface.

Specified by:
getContentLength in interface DebugResponse
Returns:
the content length.
See Also:
DebugResponse

getContentType

public java.lang.String getContentType()
Returns the Internet Media Type of the response, or null if not known This is necessary to support the DebugResponse interface.

Specified by:
getContentType in interface DebugResponse
Returns:
the content type.
See Also:
DebugResponse

getStatusCode

public int getStatusCode()
Returns the status code for the response, or -1 if not available. This is necessary to support the DebugResponse interface.

Specified by:
getStatusCode in interface DebugResponse
Returns:
the status code.
See Also:
DebugResponse

getStatusMessage

public java.lang.String getStatusMessage()
Returns the status message for the response, or null if not available. This is necessary to support the DebugResponse interface.

Specified by:
getStatusMessage in interface DebugResponse
Returns:
the status message.
See Also:
DebugResponse

getCookies

public javax.servlet.http.Cookie[] getCookies()
Returns an array of cookies to be set by this response, or a 0 length array if the information is not available. This is necessary to support the DebugResponse interface.

Specified by:
getCookies in interface DebugResponse
Returns:
The array of cookies found in this response.
See Also:
DebugResponse

getHeader

public java.lang.String getHeader(java.lang.String name)
Returns the values of the specified header for the response as an array of strings, or a 0 length array if the named header does not exist. This is necessary to support the DebugResponse interface.

Specified by:
getHeader in interface DebugResponse
Parameters:
name - the case-insensitive header field name
Returns:
the value of the supplied header.
See Also:
DebugResponse

getHeaderNames

public java.util.Enumeration getHeaderNames()
Returns an array of strings representing the header names for this response. This does not have return cookies - use getCookies().

Specified by:
getHeaderNames in interface DebugResponse
Returns:
name the case-insensitive header field name
See Also:
DebugResponse

getTotalBytes

public int getTotalBytes()
Returns the total number of bytes that make up this response. This is not supported for Jolt Presentations and is necessary to support the DebugResponse interface.

Specified by:
getTotalBytes in interface DebugResponse
Returns:
the total number of bytes in the response.
See Also:
DebugResponse

getResponseData

public java.lang.String getResponseData()
Returns null. Normally this function returns the data written to the output stream associated with this request.

Specified by:
getResponseData in interface DebugResponse

setEncoding

public void setEncoding(java.lang.String enc)
Set the output character encoding.

Specified by:
setEncoding in interface HttpPresentationResponse
Parameters:
enc - character encoding

getEncoding

public java.lang.String getEncoding()
Get the output character encoding.

Specified by:
getEncoding in interface HttpPresentationResponse
Returns:
the current encoding

setSessionKey

public void setSessionKey(java.lang.String sessionKey)
Sets the current session key for this response

Specified by:
setSessionKey in interface HttpPresentationResponse
Parameters:
sessionKey - The current sessionKey

setSessionManager

public void setSessionManager(SessionManager sessionManager)
Sets the session manager.

Specified by:
setSessionManager in interface HttpPresentationResponse

isSessionIdCookieRequired

public boolean isSessionIdCookieRequired()
                                  throws HttpPresentationException
Indicates whether client response requires a sessionId cookie

Specified by:
isSessionIdCookieRequired in interface HttpPresentationResponse
Returns:
true if client response requires a sessionId cookie false otherwise
HttpPresentationException

setSessionIdCookieRequired

public void setSessionIdCookieRequired(boolean sessionIdCookie)
                                throws HttpPresentationException
Specified by:
setSessionIdCookieRequired in interface HttpPresentationResponse
HttpPresentationException

isSessionIdEncodeUrlRequired

public boolean isSessionIdEncodeUrlRequired()
                                     throws HttpPresentationException
Indicates whether client response requires url encoding for sessionId

Specified by:
isSessionIdEncodeUrlRequired in interface HttpPresentationResponse
Returns:
true if client response requires url encoding for sessionId; false otherwise
HttpPresentationException

setSessionIdEncodeUrlRequired

public void setSessionIdEncodeUrlRequired(boolean sessionIdUrl)
                                   throws HttpPresentationException
Specified by:
setSessionIdEncodeUrlRequired in interface HttpPresentationResponse
HttpPresentationException

createOutputOptions

public OutputOptions createOutputOptions(XMLObject document)
                                  throws HttpPresentationException
Create an OutputOptions object for a document. Options are default for the specified document. The object maybe then modified as needed to override the default values.

The following attributes are set in the object:

Specified by:
createOutputOptions in interface HttpPresentationResponse
HttpPresentationException

writeDOM

public void writeDOM(OutputOptions outputOptions,
                     XMLObject document)
              throws HttpPresentationException
Output an an XMLC document object (DOM). The document is formatted according to it's type. The MIME type of the response is automatically set.

Specified by:
writeDOM in interface HttpPresentationResponse
HttpPresentationException

writeDOM

public void writeDOM(XMLObject document)
              throws HttpPresentationException
Output an an XMLC document object (DOM). The document is formatted according to it's type. The MIME type of the response is automatically set.

Specified by:
writeDOM in interface HttpPresentationResponse
HttpPresentationException

writeHTML

public void writeHTML(java.lang.String html)
               throws HttpPresentationException
Utility method to output an HTML page. The appropriate headers are set for MIME type and to disable caching of the HTML by the broswer.

Specified by:
writeHTML in interface HttpPresentationResponse
HttpPresentationException

writeHTML

public void writeHTML(HTMLDocument doc)
               throws HttpPresentationException
Deprecated. use writeDOM

Utility method to output an HTML page from a DOM object. The appropriate headers are set for MIME type and to disable caching of the HTML by the broswer.

Specified by:
writeHTML in interface HttpPresentationResponse
Parameters:
doc - The DOM object to be returned as response
HttpPresentationException
See Also:
HttpPresentationResponse.writeDOM(org.enhydra.xml.io.OutputOptions, org.enhydra.xml.xmlc.XMLObject)

Enhydra 5.1 API