public class ResteasyHttpServletResponseWrapper extends ServletResponseWrapper implements HttpServletResponse
SC_ACCEPTED, SC_BAD_GATEWAY, SC_BAD_REQUEST, SC_CONFLICT, SC_CONTINUE, SC_CREATED, SC_EXPECTATION_FAILED, SC_FORBIDDEN, SC_FOUND, SC_GATEWAY_TIMEOUT, SC_GONE, SC_HTTP_VERSION_NOT_SUPPORTED, SC_INTERNAL_SERVER_ERROR, SC_LENGTH_REQUIRED, SC_METHOD_NOT_ALLOWED, SC_MOVED_PERMANENTLY, SC_MOVED_TEMPORARILY, SC_MULTIPLE_CHOICES, SC_NO_CONTENT, SC_NON_AUTHORITATIVE_INFORMATION, SC_NOT_ACCEPTABLE, SC_NOT_FOUND, SC_NOT_IMPLEMENTED, SC_NOT_MODIFIED, SC_OK, SC_PARTIAL_CONTENT, SC_PAYMENT_REQUIRED, SC_PRECONDITION_FAILED, SC_PROXY_AUTHENTICATION_REQUIRED, SC_REQUEST_ENTITY_TOO_LARGE, SC_REQUEST_TIMEOUT, SC_REQUEST_URI_TOO_LONG, SC_REQUESTED_RANGE_NOT_SATISFIABLE, SC_RESET_CONTENT, SC_SEE_OTHER, SC_SERVICE_UNAVAILABLE, SC_SWITCHING_PROTOCOLS, SC_TEMPORARY_REDIRECT, SC_UNAUTHORIZED, SC_UNSUPPORTED_MEDIA_TYPE, SC_USE_PROXY
Constructor and Description |
---|
ResteasyHttpServletResponseWrapper(HttpServletResponse response,
HttpServletResponse proxy) |
Modifier and Type | Method and Description |
---|---|
void |
addCookie(Cookie cookie)
Adds the specified cookie to the response.
|
void |
addDateHeader(String name,
long date)
Adds a response header with the given name and
date-value.
|
void |
addHeader(String name,
String value)
Adds a response header with the given name and value.
|
void |
addIntHeader(String name,
int value)
Adds a response header with the given name and
integer value.
|
boolean |
containsHeader(String name)
Returns a boolean indicating whether the named response header
has already been set.
|
String |
encodeRedirectUrl(String url)
Deprecated.
As of version 2.1, use
encodeRedirectURL(String url) instead
|
String |
encodeRedirectURL(String url)
Encodes the specified URL for use in the
sendRedirect method or, if encoding is not needed,
returns the URL unchanged. |
String |
encodeUrl(String url)
Deprecated.
As of version 2.1, use encodeURL(String url) instead
|
String |
encodeURL(String url)
Encodes the specified URL by including the session ID,
or, if encoding is not needed, returns the URL unchanged.
|
void |
flushBuffer()
The default behavior of this method is to call flushBuffer()
on the wrapped response object.
|
int |
getBufferSize()
The default behavior of this method is to return getBufferSize()
on the wrapped response object.
|
String |
getCharacterEncoding()
The default behavior of this method is to return getCharacterEncoding()
on the wrapped response object.
|
String |
getContentType()
The default behavior of this method is to return getContentType()
on the wrapped response object.
|
String |
getHeader(String name)
Gets the value of the response header with the given name.
|
Collection<String> |
getHeaderNames()
Gets the names of the headers of this response.
|
Collection<String> |
getHeaders(String name)
Gets the values of the response header with the given name.
|
HttpServletResponse |
getHttpServletResponse() |
Locale |
getLocale()
The default behavior of this method is to return getLocale()
on the wrapped response object.
|
ServletOutputStream |
getOutputStream()
The default behavior of this method is to return getOutputStream()
on the wrapped response object.
|
ServletResponse |
getResponse()
Return the wrapped ServletResponse object.
|
int |
getStatus()
Gets the current status code of this response.
|
PrintWriter |
getWriter()
The default behavior of this method is to return getWriter()
on the wrapped response object.
|
boolean |
isCommitted()
The default behavior of this method is to return isCommitted()
on the wrapped response object.
|
void |
reset()
The default behavior of this method is to call reset()
on the wrapped response object.
|
void |
resetBuffer()
The default behavior of this method is to call resetBuffer()
on the wrapped response object.
|
void |
sendError(int sc)
Sends an error response to the client using the specified status
code and clears the buffer.
|
void |
sendError(int sc,
String msg)
Sends an error response to the client using the specified
status and clears the buffer.
|
void |
sendRedirect(String location)
Sends a temporary redirect response to the client using the
specified redirect location URL and clears the buffer.
|
void |
setBufferSize(int size)
The default behavior of this method is to call setBufferSize(int size)
on the wrapped response object.
|
void |
setCharacterEncoding(String charset)
The default behavior of this method is to call setCharacterEncoding(String charset)
on the wrapped response object.
|
void |
setContentLength(int len)
The default behavior of this method is to call setContentLength(int len)
on the wrapped response object.
|
void |
setContentType(String type)
The default behavior of this method is to call setContentType(String type)
on the wrapped response object.
|
void |
setDateHeader(String name,
long date)
Sets a response header with the given name and
date-value.
|
void |
setHeader(String name,
String value)
Sets a response header with the given name and value.
|
void |
setIntHeader(String name,
int value)
Sets a response header with the given name and
integer value.
|
void |
setLocale(Locale loc)
The default behavior of this method is to call setLocale(Locale loc)
on the wrapped response object.
|
void |
setStatus(int sc)
Sets the status code for this response.
|
void |
setStatus(int sc,
String sm)
Deprecated.
As of version 2.1, due to ambiguous meaning of the
message parameter. To set a status code
use
setStatus(int) , to send an error with a description
use sendError(int, String) .
Sets the status code and message for this response. |
isWrapperFor, isWrapperFor, setContentLengthLong, setResponse
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
setContentLengthLong
public ResteasyHttpServletResponseWrapper(HttpServletResponse response, HttpServletResponse proxy)
public HttpServletResponse getHttpServletResponse()
public ServletResponse getResponse()
ServletResponseWrapper
getResponse
in class ServletResponseWrapper
public String getCharacterEncoding()
ServletResponseWrapper
getCharacterEncoding
in interface ServletResponse
getCharacterEncoding
in class ServletResponseWrapper
String
specifying the name of
the character encoding, for example, UTF-8
public String getContentType()
ServletResponseWrapper
getContentType
in interface ServletResponse
getContentType
in class ServletResponseWrapper
String
specifying the content type,
for example, text/html; charset=UTF-8
, or nullpublic ServletOutputStream getOutputStream() throws IOException
ServletResponseWrapper
getOutputStream
in interface ServletResponse
getOutputStream
in class ServletResponseWrapper
ServletOutputStream
for writing binary dataIOException
- if an input or output exception occurredServletResponse.getWriter()
,
ServletResponse.reset()
public PrintWriter getWriter() throws IOException
ServletResponseWrapper
getWriter
in interface ServletResponse
getWriter
in class ServletResponseWrapper
PrintWriter
object that
can return character data to the clientUnsupportedEncodingException
- if the character encoding returned
by getCharacterEncoding
cannot be usedIOException
- if an input or output exception occurredServletResponse.getOutputStream()
,
ServletResponse.setCharacterEncoding(java.lang.String)
,
ServletResponse.reset()
public void setCharacterEncoding(String charset)
ServletResponseWrapper
setCharacterEncoding
in interface ServletResponse
setCharacterEncoding
in class ServletResponseWrapper
charset
- a String specifying only the character set
defined by IANA Character Sets
(http://www.iana.org/assignments/character-sets)ServletResponse.setContentType(java.lang.String)
,
ServletResponse.setLocale(java.util.Locale)
public void setContentLength(int len)
ServletResponseWrapper
setContentLength
in interface ServletResponse
setContentLength
in class ServletResponseWrapper
len
- an integer specifying the length of the
content being returned to the client; sets the Content-Length headerpublic void setContentType(String type)
ServletResponseWrapper
setContentType
in interface ServletResponse
setContentType
in class ServletResponseWrapper
type
- a String
specifying the MIME
type of the contentServletResponse.setLocale(java.util.Locale)
,
ServletResponse.setCharacterEncoding(java.lang.String)
,
ServletResponse.getOutputStream()
,
ServletResponse.getWriter()
public void setBufferSize(int size)
ServletResponseWrapper
setBufferSize
in interface ServletResponse
setBufferSize
in class ServletResponseWrapper
size
- the preferred buffer sizeServletResponse.getBufferSize()
,
ServletResponse.flushBuffer()
,
ServletResponse.isCommitted()
,
ServletResponse.reset()
public int getBufferSize()
ServletResponseWrapper
getBufferSize
in interface ServletResponse
getBufferSize
in class ServletResponseWrapper
ServletResponse.setBufferSize(int)
,
ServletResponse.flushBuffer()
,
ServletResponse.isCommitted()
,
ServletResponse.reset()
public void flushBuffer() throws IOException
ServletResponseWrapper
flushBuffer
in interface ServletResponse
flushBuffer
in class ServletResponseWrapper
IOException
ServletResponse.setBufferSize(int)
,
ServletResponse.getBufferSize()
,
ServletResponse.isCommitted()
,
ServletResponse.reset()
public void resetBuffer()
ServletResponseWrapper
resetBuffer
in interface ServletResponse
resetBuffer
in class ServletResponseWrapper
ServletResponse.setBufferSize(int)
,
ServletResponse.getBufferSize()
,
ServletResponse.isCommitted()
,
ServletResponse.reset()
public boolean isCommitted()
ServletResponseWrapper
isCommitted
in interface ServletResponse
isCommitted
in class ServletResponseWrapper
ServletResponse.setBufferSize(int)
,
ServletResponse.getBufferSize()
,
ServletResponse.flushBuffer()
,
ServletResponse.reset()
public void reset()
ServletResponseWrapper
reset
in interface ServletResponse
reset
in class ServletResponseWrapper
ServletResponse.setBufferSize(int)
,
ServletResponse.getBufferSize()
,
ServletResponse.flushBuffer()
,
ServletResponse.isCommitted()
public void setLocale(Locale loc)
ServletResponseWrapper
setLocale
in interface ServletResponse
setLocale
in class ServletResponseWrapper
loc
- the locale of the responseServletResponse.getLocale()
,
ServletResponse.setContentType(java.lang.String)
,
ServletResponse.setCharacterEncoding(java.lang.String)
public Locale getLocale()
ServletResponseWrapper
getLocale
in interface ServletResponse
getLocale
in class ServletResponseWrapper
ServletResponse.setLocale(java.util.Locale)
public void addCookie(Cookie cookie)
HttpServletResponse
addCookie
in interface HttpServletResponse
cookie
- the Cookie to return to the clientpublic boolean containsHeader(String name)
HttpServletResponse
containsHeader
in interface HttpServletResponse
name
- the header nametrue
if the named response header
has already been set;
false
otherwisepublic String encodeURL(String url)
HttpServletResponse
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.
If the URL is relative, it is always relative to the current HttpServletRequest.
encodeURL
in interface HttpServletResponse
url
- the url to be encoded.public String encodeRedirectURL(String url)
HttpServletResponse
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. For example, if the browser supports
cookies, or session tracking is turned off, URL encoding is
unnecessary. 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.
If the URL is relative, it is always relative to the current HttpServletRequest.
encodeRedirectURL
in interface HttpServletResponse
url
- the url to be encoded.HttpServletResponse.sendRedirect(java.lang.String)
,
HttpServletResponse.encodeUrl(java.lang.String)
public String encodeUrl(String url)
encodeUrl
in interface HttpServletResponse
url
- the url to be encoded.public String encodeRedirectUrl(String url)
encodeRedirectUrl
in interface HttpServletResponse
url
- the url to be encoded.public void sendError(int sc, String msg) throws IOException
HttpServletResponse
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.
sendError
in interface HttpServletResponse
sc
- the error status codemsg
- the descriptive messageIOException
- If an input or output exception occurspublic void sendError(int sc) throws IOException
HttpServletResponse
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.
sendError
in interface HttpServletResponse
sc
- the error status codeIOException
- If an input or output exception occurspublic void sendRedirect(String location) throws IOException
HttpServletResponse
HttpServletResponse.SC_FOUND
302 (Found).
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 location is relative with two leading '/' the container interprets
it as a network-path reference (see
RFC 3986: Uniform Resource Identifier (URI): Generic Syntax, section 4.2
"Relative Reference").
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.
sendRedirect
in interface HttpServletResponse
location
- the redirect location URLIOException
- If an input or output exception occurspublic void setDateHeader(String name, long date)
HttpServletResponse
containsHeader
method can be used to test for the
presence of a header before setting its value.setDateHeader
in interface HttpServletResponse
name
- the name of the header to setdate
- the assigned date valueHttpServletResponse.containsHeader(java.lang.String)
,
HttpServletResponse.addDateHeader(java.lang.String, long)
public void addDateHeader(String name, long date)
HttpServletResponse
addDateHeader
in interface HttpServletResponse
name
- the name of the header to setdate
- the additional date valueHttpServletResponse.setDateHeader(java.lang.String, long)
public void setHeader(String name, String value)
HttpServletResponse
containsHeader
method can be
used to test for the presence of a header before setting its
value.setHeader
in interface HttpServletResponse
name
- the name of the headervalue
- the header value If it contains octet string,
it should be encoded according to RFC 2047
(http://www.ietf.org/rfc/rfc2047.txt)HttpServletResponse.containsHeader(java.lang.String)
,
HttpServletResponse.addHeader(java.lang.String, java.lang.String)
public void addHeader(String name, String value)
HttpServletResponse
addHeader
in interface HttpServletResponse
name
- the name of the headervalue
- the additional header value If it contains
octet string, it should be encoded
according to RFC 2047
(http://www.ietf.org/rfc/rfc2047.txt)HttpServletResponse.setHeader(java.lang.String, java.lang.String)
public void setIntHeader(String name, int value)
HttpServletResponse
containsHeader
method can be used to test for the presence of a header before
setting its value.setIntHeader
in interface HttpServletResponse
name
- the name of the headervalue
- the assigned integer valueHttpServletResponse.containsHeader(java.lang.String)
,
HttpServletResponse.addIntHeader(java.lang.String, int)
public void addIntHeader(String name, int value)
HttpServletResponse
addIntHeader
in interface HttpServletResponse
name
- the name of the headervalue
- the assigned integer valueHttpServletResponse.setIntHeader(java.lang.String, int)
public void setStatus(int sc)
HttpServletResponse
This method is used to set the return status code when there is no error (for example, for the SC_OK or SC_MOVED_TEMPORARILY status codes).
If this method is used to set an error code, then the container's
error page mechanism will not be triggered. If there is an error and
the caller wishes to invoke an error page defined in the web
application, then HttpServletResponse.sendError(int, java.lang.String)
must be used instead.
This method preserves any cookies and other response headers.
Valid status codes are those in the 2XX, 3XX, 4XX, and 5XX ranges. Other status codes are treated as container specific.
setStatus
in interface HttpServletResponse
sc
- the status codeHttpServletResponse.sendError(int, java.lang.String)
public void setStatus(int sc, String sm)
setStatus(int)
, to send an error with a description
use sendError(int, String)
.
Sets the status code and message for this response.setStatus
in interface HttpServletResponse
sc
- the status codesm
- the status messagepublic int getStatus()
HttpServletResponse
getStatus
in interface HttpServletResponse
public String getHeader(String name)
HttpServletResponse
If a response header with the given name exists and contains multiple values, the value that was added first will be returned.
This method considers only response headers set or added via
HttpServletResponse.setHeader(java.lang.String, java.lang.String)
, HttpServletResponse.addHeader(java.lang.String, java.lang.String)
, HttpServletResponse.setDateHeader(java.lang.String, long)
,
HttpServletResponse.addDateHeader(java.lang.String, long)
, HttpServletResponse.setIntHeader(java.lang.String, int)
, or
HttpServletResponse.addIntHeader(java.lang.String, int)
, respectively.
getHeader
in interface HttpServletResponse
name
- the name of the response header whose value to returnpublic Collection<String> getHeaders(String name)
HttpServletResponse
This method considers only response headers set or added via
HttpServletResponse.setHeader(java.lang.String, java.lang.String)
, HttpServletResponse.addHeader(java.lang.String, java.lang.String)
, HttpServletResponse.setDateHeader(java.lang.String, long)
,
HttpServletResponse.addDateHeader(java.lang.String, long)
, HttpServletResponse.setIntHeader(java.lang.String, int)
, or
HttpServletResponse.addIntHeader(java.lang.String, int)
, respectively.
Any changes to the returned Collection
must not
affect this HttpServletResponse
.
getHeaders
in interface HttpServletResponse
name
- the name of the response header whose values to returnCollection
of the values
of the response header with the given namepublic Collection<String> getHeaderNames()
HttpServletResponse
This method considers only response headers set or added via
HttpServletResponse.setHeader(java.lang.String, java.lang.String)
, HttpServletResponse.addHeader(java.lang.String, java.lang.String)
, HttpServletResponse.setDateHeader(java.lang.String, long)
,
HttpServletResponse.addDateHeader(java.lang.String, long)
, HttpServletResponse.setIntHeader(java.lang.String, int)
, or
HttpServletResponse.addIntHeader(java.lang.String, int)
, respectively.
Any changes to the returned Collection
must not
affect this HttpServletResponse
.
getHeaderNames
in interface HttpServletResponse
Collection
of the names
of the headers of this responseCopyright © 2017 JBoss by Red Hat. All rights reserved.