Class AbstractResource.ResourceResponse
- java.lang.Object
-
- org.apache.wicket.request.resource.AbstractResource.ResourceResponse
-
- Enclosing class:
- AbstractResource
public static class AbstractResource.ResourceResponse extends Object
Represents data used to configure response and write resource data.- Author:
- Matej Knopp
-
-
Constructor Summary
Constructors Constructor Description ResourceResponse()
Construct.
-
Method Summary
-
-
-
Constructor Detail
-
ResourceResponse
public ResourceResponse()
Construct.
-
-
Method Detail
-
setError
public AbstractResource.ResourceResponse setError(Integer errorCode)
Sets the error code for resource. If there is an error code set the data will not be rendered and the code will be sent to client.- Parameters:
errorCode
- error code- Returns:
this
, for chaining.
-
setError
public AbstractResource.ResourceResponse setError(Integer errorCode, String errorMessage)
Sets the error code and message for resource. If there is an error code set the data will not be rendered and the code and message will be sent to client.- Parameters:
errorCode
- error codeerrorMessage
- error message- Returns:
this
, for chaining.
-
getErrorCode
public Integer getErrorCode()
- Returns:
- error code or
null
-
setStatusCode
public AbstractResource.ResourceResponse setStatusCode(Integer statusCode)
Sets the status code for resource.- Parameters:
statusCode
- status code- Returns:
this
, for chaining.
-
getStatusCode
public Integer getStatusCode()
- Returns:
- status code or
null
-
getErrorMessage
public String getErrorMessage()
- Returns:
- error message or
null
-
setFileName
public AbstractResource.ResourceResponse setFileName(String fileName)
Sets the file name of the resource.- Parameters:
fileName
- file name- Returns:
this
, for chaining.
-
getFileName
public String getFileName()
- Returns:
- resource file name
-
setContentDisposition
public AbstractResource.ResourceResponse setContentDisposition(ContentDisposition contentDisposition)
Determines whether the resource will be inline or an attachment.- Parameters:
contentDisposition
- content disposition (attachment or inline)- Returns:
this
, for chaining.- See Also:
ContentDisposition
-
getContentDisposition
public ContentDisposition getContentDisposition()
- Returns:
- whether the resource is inline or attachment
-
setContentType
public AbstractResource.ResourceResponse setContentType(String contentType)
Sets the content type for the resource. If no content type is set it will be determined by the extension.- Parameters:
contentType
- content type (also known as mime type)- Returns:
this
, for chaining.
-
getContentType
public String getContentType()
- Returns:
- resource content type
-
getContentRange
public String getContentRange()
Gets the content range of the resource. If no content range is set the client assumes the whole content.- Returns:
- the content range
-
setContentRange
public void setContentRange(String contentRange)
Sets the content range of the resource. 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
-
getAcceptRange
public AbstractResource.ContentRangeType getAcceptRange()
If the resource accepts ranges- Returns:
- the type of range (e.g. bytes)
-
setAcceptRange
public void setAcceptRange(AbstractResource.ContentRangeType contentRangeType)
Sets the accept range header (e.g. bytes)- Parameters:
contentRangeType
- the content range header information
-
setTextEncoding
public AbstractResource.ResourceResponse setTextEncoding(String textEncoding)
Sets the text encoding for the resource. This setting must only used if the resource response represents text.- Parameters:
textEncoding
- character encoding of text body- Returns:
this
, for chaining.
-
getTextEncoding
protected String getTextEncoding()
- Returns:
- text encoding for resource
-
setContentLength
public AbstractResource.ResourceResponse setContentLength(long contentLength)
Sets the content length (in bytes) of the data. Content length is optional but it's recommended to set it so that the browser can show download progress.- Parameters:
contentLength
- length of response body- Returns:
this
, for chaining.
-
getContentLength
public long getContentLength()
- Returns:
- content length (in bytes)
-
setLastModified
public AbstractResource.ResourceResponse setLastModified(Instant lastModified)
Sets the last modified data of the resource. Even though this method is optional it is recommended to set the date. If the date is set properly Wicket can check theIf-Modified-Since
to determine if the actual data really needs to be sent to client.- Parameters:
lastModified
- last modification timestamp- Returns:
this
, for chaining.
-
getLastModified
public Instant getLastModified()
- Returns:
- last modification timestamp
-
dataNeedsToBeWritten
public boolean dataNeedsToBeWritten(IResource.Attributes attributes)
Check to determine if the resource data needs to be written. This method checks theIf-Modified-Since
request header and compares it to lastModified property. In order for this method to worksetLastModified(Instant)
has to be called first.- Parameters:
attributes
- request attributes- Returns:
true
if the resource data does need to be written,false
otherwise.
-
disableCaching
public AbstractResource.ResourceResponse disableCaching()
Disables caching.- Returns:
this
, for chaining.
-
setCacheDurationToMaximum
public AbstractResource.ResourceResponse setCacheDurationToMaximum()
Sets caching to maximum available duration.- Returns:
this
, for chaining.
-
setCacheDuration
public AbstractResource.ResourceResponse setCacheDuration(Duration duration)
Controls how long this response may be cached.- Parameters:
duration
- caching duration in seconds- Returns:
this
, for chaining.
-
getCacheDuration
public Duration getCacheDuration()
Returns how long this resource may be cached for. The special value Duration.NONE means caching is disabled.- Returns:
- duration for caching
- See Also:
ResourceSettings.setDefaultCacheDuration(Duration)
,ResourceSettings.getDefaultCacheDuration()
-
getCacheScope
public WebResponse.CacheScope getCacheScope()
returns what kind of caches are allowed to cache the resource response resources are only cached at all if caching is enabled by setting a cache duration.- Returns:
- cache scope
- See Also:
getCacheDuration()
,setCacheDuration(Duration)
,WebResponse.CacheScope
-
setCacheScope
public AbstractResource.ResourceResponse setCacheScope(WebResponse.CacheScope scope)
controls what kind of caches are allowed to cache the response resources are only cached at all if caching is enabled by setting a cache duration.- Parameters:
scope
- scope for caching- Returns:
this
, for chaining.- See Also:
getCacheDuration()
,setCacheDuration(Duration)
,WebResponse.CacheScope
-
setWriteCallback
public AbstractResource.ResourceResponse setWriteCallback(AbstractResource.WriteCallback writeCallback)
Sets theAbstractResource.WriteCallback
. The callback is responsible for generating the response data.It is necessary to set the
AbstractResource.WriteCallback
ifdataNeedsToBeWritten(org.apache.wicket.request.resource.IResource.Attributes)
returnstrue
andsetError(Integer)
has not been called.- Parameters:
writeCallback
- write callback- Returns:
this
, for chaining.
-
getWriteCallback
public AbstractResource.WriteCallback getWriteCallback()
- Returns:
- write callback.
-
getHeaders
public HttpHeaderCollection getHeaders()
get custom headers- Returns:
- collection of the response headers
-
-