rwsf::HttpServletResponserwsf::ServletResponse
#include rwsf/servlet/http/HttpServletResponse.h
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.
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 }
Value descriptions
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. Responds 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. Responds 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 fulfil the request due to an error inside the HTTP server. This code is typically used for errors which 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. |
StatusCode provides an enumeration over common HTTP status codes.
virtual ~HttpServletResponse();
Destructor.
void addCookie(const rwsf::Cookie & cookie);
Adds cookie to the collection of cookies in the response.
void addDateHeader(const std::string & name, const rwsf::DateTime & date);
Adds the value of date to the header named 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 addHeader(const std::string & name, const std::string & value);
Adds value to the header named 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 addIntHeader(const std::string & name, int value);
Adds value to the header named 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 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 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 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.
void flushBuffer();
Reimplements method in rwsf::ServletResponse
Base class documentation:
Flushes the current response buffer. Any content that has been written to this response will be sent to the client, including any headers.
std::string 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 getContentLength() const;
Returns the value set by setContentLength(), or -1 if no value is set.
std::string 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.
void 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 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 with msg as a payload.
void 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 will modify 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.
void setContentLength(int contentLength);
Reimplements method in rwsf::ServletResponse
Base class documentation:
Sets the content length for the response.
Implementation documentation:
Sets the value of the Content-Length header of the response to contentLength.
void setContentType(const std::string & contentType);
Reimplements method in rwsf::ServletResponse
Base class documentation:
Sets the Content-Type for the response.
Implementation documentation:
Sets the value of the Content-Type header of the response to contentType. This function is an extension to the Servlet Specification.
void setDateHeader(const std::string & name, const rwsf::DateTime & date);
Sets the header named 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 setHeader(const std::string & name, const std::string & value);
Sets the header named 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 setIntHeader(const std::string & name, int value);
Sets the header named 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 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 functions for error responses.
void setStatus(int sc, const std::string & msg);
Sets the HTTP status code of this response to sc, sets the status message of this response to msg. Note that the Servlet Specification deprecates this function. The Servlet Specification recommends the sendError() to return an error to the client and the setStatus(int) to set the status code on responses that do not indicate an error.
© Copyright Rogue Wave Software, Inc. All Rights Reserved. All Rights Reserved. Rogue Wave is a registered trademark of Rogue Wave Software, Inc. in the United States and other countries. HydraExpress is a trademark of Rogue Wave Software, Inc. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.