HydraExpress™ C++ API Reference Guide

Product Documentation:
   HydraExpress C++
Documentation Home
List of all members | Public Types | Public Member Functions | Private Member Functions
rwsf::HttpServletResponse Class Reference

Represents the response object that the servlet returns to the client. More...

#include <rwsf/servlet/http/HttpServletResponse.h>

Inheritance diagram for rwsf::HttpServletResponse:
rwsf::ServletResponse

Public Types

enum  StatusCode {
  SC_CONTINUE, SC_SWITCHING_PROTOCOLS, SC_OK, SC_CREATED,
  SC_ACCEPTED, SC_NON_AUTHORITATIVE_INFORMATION, SC_NO_CONTENT, SC_RESET_CONTENT,
  SC_PARTIAL_CONTENT, SC_MULTIPLE_CHOICES, SC_MOVED_PERMANENTLY, SC_MOVED_TEMPORARILY,
  SC_SEE_OTHER, SC_NOT_MODIFIED, SC_USE_PROXY, SC_BAD_REQUEST,
  SC_UNAUTHORIZED, SC_PAYMENT_REQUIRED, SC_FORBIDDEN, SC_NOT_FOUND,
  SC_METHOD_NOT_ALLOWED, SC_NOT_ACCEPTABLE, SC_PROXY_AUTHENTICATION_REQUIRED, SC_REQUEST_TIMEOUT,
  SC_CONFLICT, SC_GONE, SC_LENGTH_REQUIRED, SC_PRECONDITION_FAILED,
  SC_REQUEST_ENTITY_TOO_LARGE, SC_REQUEST_URI_TOO_LONG, SC_UNSUPPORTED_MEDIA_TYPE, SC_REQUESTED_RANGE_NOT_SATISFIABLE,
  SC_EXPECTATION_FAILED, SC_INTERNAL_SERVER_ERROR, SC_NOT_IMPLEMENTED, SC_BAD_GATEWAY,
  SC_SERVICE_UNAVAILABLE, SC_GATEWAY_TIMEOUT, SC_HTTP_VERSION_NOT_SUPPORTED
}
 

Public Member Functions

virtual ~HttpServletResponse ()
 
void addCookie (const rwsf::Cookie &cookie)
 
void addDateHeader (const std::string &name, const rwsf::DateTime &date)
 
void addHeader (const std::string &name, const std::string &value)
 
void addIntHeader (const std::string &name, int value)
 
bool containsHeader (const std::string &name) const
 
std::string encodeRedirectURL (const std::string &url) const
 
std::string encodeURL (const std::string &url) const
 
virtual void flushBuffer ()
 
std::string getCharacterEncoding () const
 
int getContentLength () const
 
std::string getContentType () const
 
void sendError (int sc, const std::string &msg)
 
void sendError (int sc)
 
void sendRedirect (const std::string &location)
 
virtual void setContentLength (int contentLength)
 
void setContentType (const std::string &contentType)
 
void setDateHeader (const std::string &name, const rwsf::DateTime &date)
 
void setHeader (const std::string &name, const std::string &value)
 
void setIntHeader (const std::string &name, int value)
 
void setStatus (int sc)
 
void setStatus (int sc, const std::string &msg)
 
- Public Member Functions inherited from rwsf::ServletResponse
virtual ~ServletResponse ()
 
void appendPayload (const std::string &data)
 
rwsf::ServletOutputStreamgetOutputStream ()
 
std::string getPayload () const
 
rwsf::ServletOutputStreamgetWriter ()
 
bool isCommitted () const
 
void reset ()
 
void resetBuffer ()
 
void setPayload (const std::string &payload)
 

Private Member Functions

bool checkSpecialHeader (const std::string &name, const std::string &value)
 
std::string getDateString (const rwsf::DateTime &date) const
 
bool isEncodeable (const std::string &url) const
 
std::string toEncoded (const std::string &url, const std::string &sessionId) const
 

Detailed Description

rwsf::HttpServletResponse provides an HTTP-specific response object and provides a method for accessing HTTP-specific functionality, such as cookies and HTTP headers. For each request from a client, an HTTP servlet receives an instance of rwsf::HttpServletReponse that represents the response to the request.

Member Enumeration Documentation

StatusCode provides an enumeration over common HTTP status codes.

Enumerator
SC_CONTINUE 

Represents HTTP status code 100. The client may continue the request.

SC_SWITCHING_PROTOCOLS 

Represents HTTP status code 101. Responds to an Upgrade header. The server will switch protocols to the protocol requested in the Upgrade header immediately after sending the response.

SC_OK 

Represents HTTP status code 200. The request succeeded.

SC_CREATED 

Represents HTTP status code 201. The request succeeded and created a new resource on the server.

SC_ACCEPTED 

Represents HTTP status code 202. Indicates that the request is accepted for processing and that the processing has not been completed. For example, a server accepting a request to add a directory to a nightly backup job might use 202 to indicate that the request is acceptable, but that the backup has not yet run.

SC_NON_AUTHORITATIVE_INFORMATION 

Represents HTTP status code 203. The request succeeded with no errors. The metainformation included may not be the information provided from the original server. For example, the metainformation may be from a cached copy, or the server may have added additional information.

SC_NO_CONTENT 

Represents HTTP status code 204. The request succeeded, but created no new information.

SC_RESET_CONTENT 

Represents HTTP status code 205. The client should refresh the document view from which the request originated.

SC_PARTIAL_CONTENT 

Represents HTTP status code 206. Response to a partial GET. The response contains the range requested.

SC_MULTIPLE_CHOICES 

Represents HTTP status code 300. The requested resource corresponds to any one of a set of representations, each with its own specific location. The server may provide a URI to the preferred location in the Location header of the response.

SC_MOVED_PERMANENTLY 

Represents HTTP status code 301. The resource has permanently moved to a new location. The server should provide a URI to the new location in the Location header of the response. The client should use the new URI for future requests.

SC_MOVED_TEMPORARILY 

Represents HTTP status code 302. The resource has temporarily moved to a new location. The server should provide a URI to the new location in the Location header of the response. The client should use the original URI for future requests.

SC_SEE_OTHER 

Represents HTTP status code 303. The resource is located at a different URI. The server should provide a URI to the new location in the Location header of the response.

SC_NOT_MODIFIED 

Represents HTTP status code 304. Response to a conditional GET. The resource is available but does not need to be retransmitted.

SC_USE_PROXY 

Represents HTTP status code 305. The resource is only available through a proxy. The URI of the resource on the proxy must be provided in the Location header in the response.

SC_BAD_REQUEST 

Represents HTTP status code 400. The request was syntactically incorrect.

SC_UNAUTHORIZED 

Represents HTTP status code 401. The server requires HTTP authentication for the client to access the resource. The server must include a WWW-Authenticate header in the response.

SC_PAYMENT_REQUIRED 

Represents HTTP status code 402. Reserved for future use.

SC_FORBIDDEN 

Represents HTTP status code 403. The server refuses to fulfill the request. This code should only be used for permanent conditions. If the client lacks permission to execute the request, the server should return SC_UNAUTHORIZED (status code 401).

SC_NOT_FOUND 

Represents HTTP status code 404. The server has no resource that matches the request.

SC_METHOD_NOT_ALLOWED 

Represents HTTP status code 405. The server does not allow the method requested for the resource requested. For example, a server may return this code in response to an attempt to POST data to a static web page.

SC_NOT_ACCEPTABLE 

Represents HTTP status code 406. The resource cannot generate a response that meets the requirements of the Accept headers in the request.

SC_PROXY_AUTHENTICATION_REQUIRED 

Represents HTTP status code 407. The client must authenticate itself with the proxy. A response with this status must include a Proxy-Authenticate header field with a challenge for the requested resource.

SC_REQUEST_TIMEOUT 

Represents HTTP status code 408. The server timed out the request.

SC_CONFLICT 

Represents HTTP status code 409. The server could not complete the request due to a conflict between the request and the current state of the resource.

SC_GONE 

Represents HTTP status code 410. The resource is not available and the server has no other address for the resource. This code should only be used for permanent conditions.

SC_LENGTH_REQUIRED 

Represents HTTP status code 411. The server requires a Content-Length header to fulfill the request.

SC_PRECONDITION_FAILED 

Represents HTTP status code 412. At least one of the preconditions in the request evaluated to false when it was tested on the server. The request was not executed.

SC_REQUEST_ENTITY_TOO_LARGE 

Represents HTTP status code 413. The request is larger than the server allows.

SC_REQUEST_URI_TOO_LONG 

Represents HTTP status code 414. The URI in the request is longer than the server allows.

SC_UNSUPPORTED_MEDIA_TYPE 

Represents HTTP status code 415. The server cannot process the request because the entity of the request is in a format not supported by the requested resource for the requested method.

SC_REQUESTED_RANGE_NOT_SATISFIABLE 

Represents HTTP status code 416. The byte range requested is not available in the resource.

SC_EXPECTATION_FAILED 

Represents HTTP status code 417. The server could not comply with the expectation stated in the Expect header of the request.

SC_INTERNAL_SERVER_ERROR 

Represents HTTP status code 500. The server could not fulfill the request due to an error inside the HTTP server. This code is typically used for errors that do not fit into other categories, such as a CGI program failing to execute.

SC_NOT_IMPLEMENTED 

Represents HTTP status code 501. The server does not support the request method.

SC_BAD_GATEWAY 

Represents HTTP status code 502. The server is acting as a gateway or proxy and received an invalid response from another server.

SC_SERVICE_UNAVAILABLE 

Represents HTTP status code 503. The server is temporarily unable to handle the request. The server may include a suggested time for the client to wait before resending the request in the Retry-After header of the response.

SC_GATEWAY_TIMEOUT 

Represents HTTP status code 504. The server is acting as a gateway or proxy and did not receive a timely response from another server.

SC_HTTP_VERSION_NOT_SUPPORTED 

Represents HTTP status code 505. The server does not support or refuses to support the HTTP protocol version that was used in the request.

Constructor & Destructor Documentation

virtual rwsf::HttpServletResponse::~HttpServletResponse ( )
virtual

Destructor.

Member Function Documentation

void rwsf::HttpServletResponse::addCookie ( const rwsf::Cookie cookie)

Adds cookie to the collection of cookies in the response.

void rwsf::HttpServletResponse::addDateHeader ( const std::string &  name,
const rwsf::DateTime date 
)

Adds the value of date to the header named by name in this response. If no header matching name exists, creates a new header. Otherwise, appends the value of date to the list of values in the header. Header name comparisons are case-insensitive.

void rwsf::HttpServletResponse::addHeader ( const std::string &  name,
const std::string &  value 
)

Adds value to the header named by name in this response. If no header matching name exists, creates a new header. Otherwise, appends value to the list of values in the header. Header name comparisons are case-insensitive.

void rwsf::HttpServletResponse::addIntHeader ( const std::string &  name,
int  value 
)

Adds value to the header named by name in this response. If no header matching name exists, creates a new header. Otherwise, appends value to the list of values in the first matching header. Header name comparisons are case-insensitive.

bool rwsf::HttpServletResponse::checkSpecialHeader ( const std::string &  name,
const std::string &  value 
)
private

Sets internal fields for special header names. Called from setHeader() or addHeader(). Returns true if the header is special and there is no need to set the header.

bool rwsf::HttpServletResponse::containsHeader ( const std::string &  name) const

Returns true if the response contains an HTTP header matching name, false otherwise. Header name comparisons are case- insensitive.

std::string rwsf::HttpServletResponse::encodeRedirectURL ( const std::string &  url) const

Returns url encoded as necessary to preserve session information for a redirect. If the servlet uses session tracking, a location provided to sendRedirect() should be encoded using this function.

std::string rwsf::HttpServletResponse::encodeURL ( const std::string &  url) const

Returns url encoded as necessary to preserve session information. If the servlet uses session tracking, any URLs returned to the client should be encoded using this function.

virtual void rwsf::HttpServletResponse::flushBuffer ( )
virtual

Flushes the current response buffer. Any content that has been written to this response is sent to the client, including any headers.

Reimplemented from rwsf::ServletResponse.

std::string rwsf::HttpServletResponse::getCharacterEncoding ( ) const

Returns the character set specified in the Content-Type of the response, or 8859_1 if the Content-Type contains no character set information.

int rwsf::HttpServletResponse::getContentLength ( ) const

Returns the value set by setContentLength(), or -1 if no value is set.

std::string rwsf::HttpServletResponse::getContentType ( ) const

Returns the value of the Content-Type header of this response. If self contains no Content-Type header, returns the empty string. Header name comparisons are case-insensitive.

std::string rwsf::HttpServletResponse::getDateString ( const rwsf::DateTime date) const
private

Converts the rwsf::DateTime represented by date to an std::string.

bool rwsf::HttpServletResponse::isEncodeable ( const std::string &  url) const
private

Returns true if the URL denoted by url can be encoded, false otherwise.

void rwsf::HttpServletResponse::sendError ( int  sc,
const std::string &  msg 
)

Sends an error to the client with the status code sc and the message msg. If the context web.xml file defines an error-page for sc, the Agent forwards the error to that page. Otherwise, if the global web.xml file defines an error-page for sc, the Agent forwards the request to the global page. If neither file defines an error-page for sc, returns the error directly to the client with msg as a payload.

void rwsf::HttpServletResponse::sendError ( int  sc)

Sends an error to the client with the status code sc. Clears the contents of this response before sending the error. If the context web.xml file defines an error-page for sc, the Agent forwards the error to that resource. Otherwise, if the global web.xml file defines an error-page for sc, the Agent forwards the request to the global page. If neither file defines an error-page for sc, returns the error directly to the client.

void rwsf::HttpServletResponse::sendRedirect ( const std::string &  location)

Redirects the client to location, using SC_MOVED_TEMPORARILY as the redirect status code. If location is a relative URL, the Agent modifies the URL to be a fully qualified URL. If the servlet uses session tracking, encode the location using the encodeRedirectURL() function before providing the location to this function.

virtual void rwsf::HttpServletResponse::setContentLength ( int  contentLength)
virtual

Sets the value of the Content-Length header of the response to contentLength.

Reimplemented from rwsf::ServletResponse.

void rwsf::HttpServletResponse::setContentType ( const std::string &  contentType)
virtual

Sets the value of the Content-Type header of the response to contentType. This function is an extension to the Servlet Specification.

Reimplemented from rwsf::ServletResponse.

void rwsf::HttpServletResponse::setDateHeader ( const std::string &  name,
const rwsf::DateTime date 
)

Sets the header named by name to the value of date, replacing any previous header value. If no header matching name exists, creates a new header. Header name comparisons are case-insensitive.

void rwsf::HttpServletResponse::setHeader ( const std::string &  name,
const std::string &  value 
)

Sets the header named by name to value, replacing any previous header value. If no header matching name exists, creates a new header. Header name comparisons are case-insensitive.

void rwsf::HttpServletResponse::setIntHeader ( const std::string &  name,
int  value 
)

Sets the header named by name to value, replacing any previous header value. If no header matching name exists, creates a new header. Header name comparisons are case-insensitive.

void rwsf::HttpServletResponse::setStatus ( int  sc)

Sets the HTTP status code for this response to sc. Use this function for a status that does not indicate an error. Use the sendError() methods for error responses.

void rwsf::HttpServletResponse::setStatus ( int  sc,
const std::string &  msg 
)

Sets the HTTP status code of this response to sc, and sets the status message of this response to msg. Note that the Servlet Specification deprecates this mehtod. The Servlet Specification recommends the sendError() method to return an error to the client and the setStatus(int) method to set the status code on responses that do not indicate an error.

std::string rwsf::HttpServletResponse::toEncoded ( const std::string &  url,
const std::string &  sessionId 
) const
private

Returns an encoded url for a given session sessionId of a given url.

Copyright © 2019 Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave is registered trademark of Rogue Wave Software, Inc. in the United States and other countries, and HydraExpress is a trademark of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.