Package org.apache.wicket.request.http
Class WebResponse
- java.lang.Object
-
- org.apache.wicket.request.Response
-
- org.apache.wicket.request.http.WebResponse
-
- Direct Known Subclasses:
BufferedWebResponse
,MockWebResponse
,PartialPageUpdate.ResponseBuffer
,ServletWebResponse
,WebSocketResponse
public abstract class WebResponse extends Response
Base class for web-related responses.- Author:
- Matej Knopp
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WebResponse.CacheScope
caching scope for data
-
Field Summary
Fields Modifier and Type Field Description static Duration
MAX_CACHE_DURATION
Recommended value for cache duration
-
Constructor Summary
Constructors Constructor Description WebResponse()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
addCookie(javax.servlet.http.Cookie cookie)
Add a cookie to the web responseabstract void
addHeader(String name, String value)
Add a value to the servlet response stream.abstract void
clearCookie(javax.servlet.http.Cookie cookie)
Convenience method for clearing a cookie.void
disableCaching()
Make this response non-cacheablevoid
enableCaching(Duration duration, WebResponse.CacheScope scope)
Make this response cacheableabstract String
encodeRedirectURL(CharSequence url)
Encodes urls used to redirect.abstract void
flush()
Flushes the response.abstract boolean
isHeaderSupported()
Indicates if the response supports setting headers.abstract boolean
isRedirect()
abstract void
sendError(int sc, String msg)
Send error status code with optional message.abstract void
sendRedirect(String url)
Redirects the response to specified URL.void
setAcceptRange(String acceptRange)
Sets the accept range (e.g.void
setAttachmentHeader(String filename)
Convenience method for setting the content-disposition:attachment header.abstract void
setContentLength(long length)
Set the content length on the response, if appropriate in the subclass.void
setContentRange(String contentRange)
Sets the content range of the response.abstract void
setContentType(String mimeType)
Set the content type on the response, if appropriate in the subclass.abstract void
setDateHeader(String name, Instant date)
Set a header to the date value in the servlet response stream.abstract void
setHeader(String name, String value)
Set a header to the string value in the servlet response stream.void
setInlineHeader(String filename)
Convenience method for setting the content-disposition:inline header.void
setLastModifiedTime(Instant time)
Set the contents last modified time, if appropriate in the subclass.abstract void
setStatus(int sc)
Sets the status code for this response.-
Methods inherited from class org.apache.wicket.request.Response
close, encodeURL, getContainerResponse, getOutputStream, reset, write, write, write
-
-
-
-
Field Detail
-
MAX_CACHE_DURATION
public static final Duration MAX_CACHE_DURATION
Recommended value for cache duration
-
-
Constructor Detail
-
WebResponse
public WebResponse()
-
-
Method Detail
-
addCookie
public abstract void addCookie(javax.servlet.http.Cookie cookie)
Add a cookie to the web response- Parameters:
cookie
-
-
clearCookie
public abstract void clearCookie(javax.servlet.http.Cookie cookie)
Convenience method for clearing a cookie.- Parameters:
cookie
- The cookie to set- See Also:
addCookie(Cookie)
-
isHeaderSupported
public abstract boolean isHeaderSupported()
Indicates if the response supports setting headers. When this method returns false,setHeader(String, String)
and its variations will thrown anUnsupportedOperationException
.- Returns:
- True when this
WebResponse
supports setting headers.
-
setHeader
public abstract void setHeader(String name, String value)
Set a header to the string value in the servlet response stream.- Parameters:
name
-value
-
-
addHeader
public abstract void addHeader(String name, String value)
Add a value to the servlet response stream.- Parameters:
name
-value
-
-
setDateHeader
public abstract void setDateHeader(String name, Instant date)
Set a header to the date value in the servlet response stream.- Parameters:
name
-date
-
-
setContentLength
public abstract void setContentLength(long length)
Set the content length on the response, if appropriate in the subclass. This default implementation does nothing.- Parameters:
length
- The length of the content
-
setContentType
public abstract void setContentType(String mimeType)
Set the content type on the response, if appropriate in the subclass. This default implementation does nothing.- Parameters:
mimeType
- The mime type
-
setContentRange
public void setContentRange(String contentRange)
Sets the content range of the response. If no content range is set the client assumes the whole content. Please note that if the content range is set, the content length, the status code and the accept range must be set right, too.- Parameters:
contentRange
- the content range
-
setAcceptRange
public void setAcceptRange(String acceptRange)
Sets the accept range (e.g. bytes)- Parameters:
acceptRange
- the accept range header information
-
setLastModifiedTime
public void setLastModifiedTime(Instant time)
Set the contents last modified time, if appropriate in the subclass.- Parameters:
time
- The last modified time
-
setAttachmentHeader
public void setAttachmentHeader(String filename)
Convenience method for setting the content-disposition:attachment header. This header is used if the response should prompt the user to download it as a file instead of opening in a browser.The file name will be encoded
- Parameters:
filename
- file name of the attachment
-
setInlineHeader
public void setInlineHeader(String filename)
Convenience method for setting the content-disposition:inline header. This header is used if the response should be shown embedded in browser window while having custom file name when user saves the response. browser.The file name will be encoded
- Parameters:
filename
- file name of the attachment
-
setStatus
public abstract void setStatus(int sc)
Sets the status code for this response.- Parameters:
sc
- status code
-
sendError
public abstract void sendError(int sc, String msg)
Send error status code with optional message.- Parameters:
sc
-msg
-
-
encodeRedirectURL
public abstract String encodeRedirectURL(CharSequence url)
Encodes urls used to redirect. Sometimes rules for encoding URLs for redirecting differ from encoding URLs for links, so this method is broken out away formResponse.encodeURL(CharSequence)
.- Parameters:
url
-- Returns:
- encoded URL
-
sendRedirect
public abstract void sendRedirect(String url)
Redirects the response to specified URL. The implementation is responsible for properly encoding the URL. Implementations of this method should run passed inurl
parameters through theencodeRedirectURL(CharSequence)
method.- Parameters:
url
-
-
isRedirect
public abstract boolean isRedirect()
- Returns:
true
issendRedirect(String)
was called,false
otherwise.
-
flush
public abstract void flush()
Flushes the response.
-
disableCaching
public void disableCaching()
Make this response non-cacheable
-
enableCaching
public void enableCaching(Duration duration, WebResponse.CacheScope scope)
Make this response cacheable when trying to enable caching for web pages check this out: WICKET-4357- Parameters:
duration
- maximum duration before the response must be invalidated by any caches. It should not exceed one year, based on RFC-2616.scope
- controls which caches are allowed to cache the response- See Also:
MAX_CACHE_DURATION
-
-