CPPSERV


Home Projects Jobs Clientele Contact
CPPSERV Documentation Download TODO Mailing lists Bug tracker News RSS Feed Browse source

container::HttpServletResponseImpl Class Reference

#include <HttpServletResponseImpl.h>

Inheritance diagram for container::HttpServletResponseImpl:
Collaboration diagram for container::HttpServletResponseImpl:

List of all members.


Public Member Functions

 HttpServletResponseImpl (Connection &con, const std::string &, const std::string &)
 ~HttpServletResponseImpl ()
void setReqRef (HttpServletRequestImpl *req)
std::string getStatusMessage ()
virtual std::string getCharacterEncoding ()
virtual std::string getContentType ()
virtual std::ostream & getOutputStream ()
virtual void setCharacterEncoding (const std::string &charset)
virtual void setContentLength (int len)
virtual void setContentType (const std::string &type)
virtual void setBufferSize (int size)
virtual int getBufferSize ()
virtual void flushBuffer ()
virtual bool isCommitted ()
virtual void reset ()
virtual void addCookie (const servlet::Cookie &cookie)
virtual bool containsHeader (const std::string &name) const
virtual std::string encodeURL (const std::string &url)
virtual std::string encodeRedirectURL (const std::string &url)
virtual void sendError (int sc, const std::string &msg)
virtual void sendError (int sc)
virtual void sendRedirect (const std::string &location)
virtual void setDateHeader (const std::string &name, long date)
virtual void addDateHeader (const std::string &name, long date)
virtual void setHeader (const std::string &name, const std::string &value)
virtual void addHeader (const std::string &name, const std::string &value)
virtual void setIntHeader (const std::string &name, int value)
virtual void addIntHeader (const std::string &name, int value)
virtual void setStatus (int sc)

Protected Attributes

HttpServletRequestImplm_req

Private Types

typedef std::list
< servlet::Cookie
cookielist_t

Private Member Functions

void sendHeaders (Connection &con)
void resetBuffer ()
std::string quoteString (const std::string &)

Private Attributes

int m_contentLength
std::string m_contentType
std::string m_characterEncoding
ServletOutputStream m_outputStream
bool m_committed
util::mparam_t m_headers
int m_statusCode
std::string m_statusMsg
cookielist_t m_cookies

Friends

class ServletOutputStreamBuf

Detailed Description

Servlet Response implementation

Author:
Ilya A. Volynets-Evenbakh

Definition at line 37 of file HttpServletResponseImpl.h.


Member Typedef Documentation

Definition at line 43 of file HttpServletResponseImpl.h.


Constructor & Destructor Documentation

container::HttpServletResponseImpl::HttpServletResponseImpl ( Connection con,
const std::string &  mimeType,
const std::string &  charEnc 
)

Definition at line 28 of file HttpServletResponseImpl.cpp.

container::HttpServletResponseImpl::~HttpServletResponseImpl (  ) 

Definition at line 40 of file HttpServletResponseImpl.cpp.


Member Function Documentation

void container::HttpServletResponseImpl::addCookie ( const servlet::Cookie cookie  )  [virtual]

Adds the specified cookie to the response. This method can be called multiple times to set more than one cookie.

Parameters:
cookie the Cookie to return to the client

Implements servlet::HttpServletResponse.

Definition at line 268 of file HttpServletResponseImpl.cpp.

References isCommitted(), and m_cookies.

Referenced by container::HttpServletRequestImpl::getSession().

Here is the call graph for this function:

void container::HttpServletResponseImpl::addDateHeader ( const std::string &  name,
long  date 
) [virtual]

Adds a response header with the given name and date-value. The date is specified in terms of milliseconds since the epoch. This method allows response headers to have multiple values.

Parameters:
name the name of the header to set
date the additional date value
See also:
setDateHeader

Implements servlet::HttpServletResponse.

Definition at line 343 of file HttpServletResponseImpl.cpp.

References addHeader().

Here is the call graph for this function:

void container::HttpServletResponseImpl::addHeader ( const std::string &  name,
const std::string &  value 
) [virtual]

Adds a response header with the given name and value. This method allows response headers to have multiple values.

Parameters:
name the name of the header
value the additional header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)
See also:
setHeader

Implements servlet::HttpServletResponse.

Definition at line 162 of file HttpServletResponseImpl.cpp.

References isCommitted(), and m_headers.

Referenced by addDateHeader(), addIntHeader(), and sendRedirect().

Here is the call graph for this function:

void container::HttpServletResponseImpl::addIntHeader ( const std::string &  name,
int  value 
) [virtual]

Adds a response header with the given name and integer value. This method allows response headers to have multiple values.

Parameters:
name the name of the header
value the assigned integer value
See also:
setIntHeader

Implements servlet::HttpServletResponse.

Definition at line 357 of file HttpServletResponseImpl.cpp.

References addHeader().

Here is the call graph for this function:

bool container::HttpServletResponseImpl::containsHeader ( const std::string &  name  )  const [virtual]

Returns a boolean indicating whether the named response header has already been set.

Parameters:
name the header name
Returns:
true if the named response header has already been set; false otherwise

Implements servlet::HttpServletResponse.

Definition at line 186 of file HttpServletResponseImpl.cpp.

References m_headers.

std::string container::HttpServletResponseImpl::encodeRedirectURL ( const std::string &  url  )  [virtual]

Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. Because the rules for making this determination can differ from those used to decide whether to encode a normal link, this method is separated from the encodeURL method.

All URLs sent to the HttpServletResponse.sendRedirect method should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.

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

encodeURL

Implements servlet::HttpServletResponse.

Definition at line 330 of file HttpServletResponseImpl.cpp.

std::string container::HttpServletResponseImpl::encodeURL ( const std::string &  url  )  [virtual]

Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. For example, if the browser supports cookies, or session tracking is turned off, URL encoding is unnecessary.

For robust session tracking, all URLs emitted by a servlet should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.

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

Implements servlet::HttpServletResponse.

Definition at line 325 of file HttpServletResponseImpl.cpp.

void container::HttpServletResponseImpl::flushBuffer (  )  [virtual]

Forces any content in the buffer to be written to the client. A call to this method automatically commits the response, meaning the status code and headers will be written.

See also:
setBufferSize

getBufferSize

isCommitted

reset

Implements servlet::ServletResponse.

Definition at line 125 of file HttpServletResponseImpl.cpp.

References getOutputStream().

Here is the call graph for this function:

int container::HttpServletResponseImpl::getBufferSize (  )  [virtual]

Returns the actual buffer size used for the response. If no buffering is used, this method returns 0.

Returns:
the actual buffer size used
See also:
setBufferSize

flushBuffer

isCommitted

reset

Implements servlet::ServletResponse.

Definition at line 315 of file HttpServletResponseImpl.cpp.

References container::ServletOutputStream::getBufferSize(), and m_outputStream.

Here is the call graph for this function:

std::string container::HttpServletResponseImpl::getCharacterEncoding (  )  [virtual]

Returns the name of the character encoding (MIME charset) used for the body sent in this response. The character encoding may have been specified explicitly using the setCharacterEncoding or setContentType methods, or implicitly using the setLocale method. Explicit specifications take precedence over implicit specifications. Calls made to these methods after getWriter has been called or after the response has been committed have no effect on the character encoding. If no character encoding has been specified, ISO-8859-1 is returned.

See RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt) for more information about character encoding and MIME.

Returns:
a String specifying the name of the character encoding, for example, UTF-8

Implements servlet::ServletResponse.

Definition at line 278 of file HttpServletResponseImpl.cpp.

References m_characterEncoding.

Referenced by sendHeaders().

std::string container::HttpServletResponseImpl::getContentType (  )  [virtual]

Returns the content type used for the MIME body sent in this response. The content type proper must have been specified using setContentType before the response is committed. If no content type has been specified, this method returns null. If a content type has been specified and a character encoding has been explicitly or implicitly specified as described in getCharacterEncoding, the charset parameter is included in the string returned. If no character encoding has been specified, the charset parameter is omitted.

Returns:
a String specifying the content type, for example, text/html; charset=UTF-8, or null
Since:
2.4

Implements servlet::ServletResponse.

Definition at line 282 of file HttpServletResponseImpl.cpp.

References m_contentType.

Referenced by sendHeaders().

std::ostream & container::HttpServletResponseImpl::getOutputStream (  )  [virtual]

Returns a std::ostream suitable for writing binary data in the response. The servlet container does not encode the binary data.

Calling flush() on the output stream commits the response.

Either this method or getWriter may be called to write the body, not both.

Returns:
a std::ostream for writing binary data
Exceptions:
IllegalStateException if the getWriter method has been called on this response
IOException if an input or output exception occurred
See also:
getWriter

Implements servlet::ServletResponse.

Definition at line 286 of file HttpServletResponseImpl.cpp.

References m_outputStream.

Referenced by flushBuffer(), and sendRedirect().

std::string container::HttpServletResponseImpl::getStatusMessage (  ) 

bool container::HttpServletResponseImpl::isCommitted (  )  [virtual]

Returns a boolean indicating if the response has been committed. A committed response has already had its status code and headers written.

Returns:
a boolean indicating if the response has been committed
See also:
setBufferSize

getBufferSize

flushBuffer

reset

Implements servlet::ServletResponse.

Definition at line 319 of file HttpServletResponseImpl.cpp.

References m_committed.

Referenced by addCookie(), addHeader(), container::ServletOutputStreamBuf::overflow(), container::ServletOutputStreamBuf::pbackfail(), resetBuffer(), sendError(), sendRedirect(), setCharacterEncoding(), setContentLength(), setContentType(), setHeader(), setStatus(), container::ServletOutputStreamBuf::sync(), and container::ServletOutputStreamBuf::xsputn().

std::string container::HttpServletResponseImpl::quoteString ( const std::string &  in  )  [private]

Definition at line 97 of file HttpServletResponseImpl.cpp.

Referenced by sendHeaders().

void container::HttpServletResponseImpl::reset (  )  [virtual]

Clears any data that exists in the buffer as well as the status code and headers. If the response has been committed, this method throws an IllegalStateException.

Exceptions:
IllegalStateException if the response has already been committed
See also:
setBufferSize

getBufferSize

flushBuffer

isCommitted

Todo:
make sure everything that needs to be reset is in fact reset

Implements servlet::ServletResponse.

Definition at line 134 of file HttpServletResponseImpl.cpp.

References m_cookies, m_headers, resetBuffer(), and setContentType().

Here is the call graph for this function:

void container::HttpServletResponseImpl::resetBuffer (  )  [private]

This function is supposed to clear internal buffer, but in current implementation any output will cause isCommitted() to becom true, so we look like we are "unbuffered", even though in reality there is some buffering going on.

Todo:
find a way to clear internal stream buffer..

Definition at line 151 of file HttpServletResponseImpl.cpp.

References isCommitted().

Referenced by reset().

Here is the call graph for this function:

void container::HttpServletResponseImpl::sendError ( int  sc  )  [virtual]

Sends an error response to the client using the specified status code and clearing the buffer.

If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.

Parameters:
sc the error status code
Exceptions:
IOException If an input or output exception occurs
IllegalStateException If the response was committed before this method call

Implements servlet::HttpServletResponse.

Definition at line 224 of file HttpServletResponseImpl.cpp.

References isCommitted(), m_statusCode, and m_statusMsg.

Here is the call graph for this function:

void container::HttpServletResponseImpl::sendError ( int  sc,
const std::string &  msg 
) [virtual]

Sends an error response to the client using the specified status. The server defaults to creating the response to look like an HTML-formatted server error page containing the specified message, setting the content type to "text/html", leaving cookies and other headers unmodified.

If an error-page declaration has been made for the web application corresponding to the status code passed in, it will be served back in preference to the suggested msg parameter.

If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.

Parameters:
sc the error status code
msg the descriptive message
Exceptions:
IOException If an input or output exception occurs
IllegalStateException If the response was committed

Implements servlet::HttpServletResponse.

Definition at line 237 of file HttpServletResponseImpl.cpp.

References isCommitted(), m_statusCode, and m_statusMsg.

Referenced by sendRedirect().

Here is the call graph for this function:

void container::HttpServletResponseImpl::sendHeaders ( container::Connection c  )  [private]

This function is called by container::ServletOutputStreamBuf before request body data is sent for the first time (or whenever response is committed in some other manner)

Definition at line 50 of file HttpServletResponseImpl.cpp.

References getCharacterEncoding(), getContentType(), m_committed, m_contentLength, m_cookies, m_headers, m_statusCode, quoteString(), and setHeader().

Referenced by container::ServletOutputStreamBuf::overflow(), container::ServletOutputStreamBuf::pbackfail(), container::ServletOutputStreamBuf::sync(), and container::ServletOutputStreamBuf::xsputn().

Here is the call graph for this function:

void container::HttpServletResponseImpl::sendRedirect ( const std::string &  location  )  [virtual]

Sends a temporary redirect response to the client using the specified redirect location URL. This method can accept relative URLs; the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root.

If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.

Parameters:
location the redirect location URL
Exceptions:
IOException If an input or output exception occurs
IllegalStateException If the response was committed or if a partial URL is given and cannot be converted into a valid URL

Implements servlet::HttpServletResponse.

Definition at line 209 of file HttpServletResponseImpl.cpp.

References addHeader(), getOutputStream(), isCommitted(), servlet::HttpServletResponse::SC_SEE_OTHER, and sendError().

Here is the call graph for this function:

void container::HttpServletResponseImpl::setBufferSize ( int  size  )  [virtual]

Sets the preferred buffer size for the body of the response. The servlet container will use a buffer at least as large as the size requested. The actual buffer size used can be found using getBufferSize.

A larger buffer allows more content to be written before anything is actually sent, thus providing the servlet with more time to set appropriate status codes and headers. A smaller buffer decreases server memory load and allows the client to start receiving data more quickly.

This method must be called before any response body content is written; if content has been written or the response object has been committed, this method throws an IllegalStateException.

Parameters:
size the preferred buffer size
Exceptions:
IllegalStateException if this method is called after content has been written
See also:
getBufferSize

flushBuffer

isCommitted

reset

Implements servlet::ServletResponse.

Definition at line 311 of file HttpServletResponseImpl.cpp.

References m_outputStream, and container::ServletOutputStream::setBufferSize().

Here is the call graph for this function:

void container::HttpServletResponseImpl::setCharacterEncoding ( const std::string &  charset  )  [virtual]

Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8. If the character encoding has already been set by setContentType or setLocale, this method overrides it. Calling setContentType with the String of text/html and calling this method with the String of UTF-8 is equivalent with calling setContentType with the String of text/html; charset=UTF-8.

This method can be called repeatedly to change the character encoding. This method has no effect if it is called after getWriter has been called or after the response has been committed.

Containers must communicate the character encoding used for the servlet response's writer to the client if the protocol provides a way for doing so. In the case of HTTP, the character encoding is communicated as part of the Content-Type header for text media types. Note that the character encoding cannot be communicated via HTTP headers if the servlet does not specify a content type; however, it is still used to encode text written via the servlet response's writer.

Parameters:
charset a String specifying only the character set defined by IANA Character Sets (http://www.iana.org/assignments/character-sets)
See also:
setContentType setLocale
Since:
2.4

Implements servlet::ServletResponse.

Definition at line 290 of file HttpServletResponseImpl.cpp.

References isCommitted(), and m_characterEncoding.

Here is the call graph for this function:

void container::HttpServletResponseImpl::setContentLength ( int  len  )  [virtual]

Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.

Parameters:
len an integer specifying the length of the content being returned to the client; sets the Content-Length header

Implements servlet::ServletResponse.

Definition at line 297 of file HttpServletResponseImpl.cpp.

References isCommitted(), and m_contentLength.

Here is the call graph for this function:

void container::HttpServletResponseImpl::setContentType ( const std::string &  type  )  [virtual]

Sets the content type of the response being sent to the client, if the response has not been committed yet. The given content type may include a character encoding specification, for example, text/html;charset=UTF-8. The response's character encoding is only set from the given content type if this method is called before getWriter is called.

This method may be called repeatedly to change content type and character encoding. This method has no effect if called after the response has been committed. It does not set the response's character encoding if it is called after getWriter has been called or after the response has been committed.

Containers must communicate the content type and the character encoding used for the servlet response's writer to the client if the protocol provides a way for doing so. In the case of HTTP, the Content-Type header is used.

Parameters:
type a String specifying the MIME type of the content
See also:
setLocale

setCharacterEncoding

getOutputStream

getWriter

Implements servlet::ServletResponse.

Definition at line 304 of file HttpServletResponseImpl.cpp.

References isCommitted(), and m_contentType.

Referenced by reset().

Here is the call graph for this function:

void container::HttpServletResponseImpl::setDateHeader ( const std::string &  name,
long  date 
) [virtual]

Sets a response header with the given name and date-value. The date is specified in terms of milliseconds since the epoch. If the header 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.

Parameters:
name the name of the header to set
date the assigned date value
See also:
containsHeader

addDateHeader

Implements servlet::HttpServletResponse.

Definition at line 335 of file HttpServletResponseImpl.cpp.

References setHeader().

Here is the call graph for this function:

void container::HttpServletResponseImpl::setHeader ( const std::string &  name,
const std::string &  value 
) [virtual]

Sets a response header with the given name and value. If the header 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.

Parameters:
name the name of the header
value the header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)
See also:
containsHeader

addHeader

Implements servlet::HttpServletResponse.

Definition at line 172 of file HttpServletResponseImpl.cpp.

References isCommitted(), and m_headers.

Referenced by sendHeaders(), setDateHeader(), and setIntHeader().

Here is the call graph for this function:

void container::HttpServletResponseImpl::setIntHeader ( const std::string &  name,
int  value 
) [virtual]

Sets a response header with the given name and integer value. If the header 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.

Parameters:
name the name of the header
value the assigned integer value
See also:
containsHeader

addIntHeader

Implements servlet::HttpServletResponse.

Definition at line 351 of file HttpServletResponseImpl.cpp.

References setHeader().

Here is the call graph for this function:

void container::HttpServletResponseImpl::setReqRef ( HttpServletRequestImpl req  )  [inline]

Definition at line 61 of file HttpServletResponseImpl.h.

References m_req.

void container::HttpServletResponseImpl::setStatus ( int  sc  )  [virtual]

Sets the status code for this response. This method is used to set the return status code when there is no error (for example, for the status codes SC_OK or SC_MOVED_TEMPORARILY). If there is an error, and the caller wishes to invoke an error-page defined in the web application, the sendError method should be used instead.

The container clears the buffer and sets the Location header, preserving cookies and other headers.

Parameters:
sc the status code
See also:
sendError

Implements servlet::HttpServletResponse.

Definition at line 197 of file HttpServletResponseImpl.cpp.

References isCommitted(), and m_statusCode.

Here is the call graph for this function:


Friends And Related Function Documentation

friend class ServletOutputStreamBuf [friend]

Definition at line 42 of file HttpServletResponseImpl.h.


Member Data Documentation

Definition at line 52 of file HttpServletResponseImpl.h.

Referenced by isCommitted(), and sendHeaders().

Definition at line 49 of file HttpServletResponseImpl.h.

Referenced by getContentType(), and setContentType().

Definition at line 55 of file HttpServletResponseImpl.h.

Referenced by getStatusMessage(), and sendError().


The documentation for this class was generated from the following files:

SourceForge.net Logo