Class 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 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 code
        errorMessage - error message
        Returns:
        this, for chaining.
      • getErrorCode

        public Integer getErrorCode()
        Returns:
        error code or null
      • getStatusCode

        public Integer getStatusCode()
        Returns:
        status code or null
      • getErrorMessage

        public String getErrorMessage()
        Returns:
        error message or null
      • getFileName

        public String getFileName()
        Returns:
        resource file name
      • 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
      • 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 the If-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 the If-Modified-Since request header and compares it to lastModified property. In order for this method to work #setLastModified(Time) has to be called first.
        Parameters:
        attributes - request attributes
        Returns:
        true if the resource data does need to be written, false otherwise.
      • 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:
        org.apache.wicket.settings.ResourceSettings#setDefaultCacheDuration(org.apache.wicket.util.time.Duration), ResourceSettings.getDefaultCacheDuration()
      • getCacheScope

        public org.apache.wicket.request.http.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(), org.apache.wicket.request.resource.AbstractResource.ResourceResponse#setCacheDuration(org.apache.wicket.util.time.Duration), WebResponse.CacheScope
      • setCacheScope

        public AbstractResource.ResourceResponse setCacheScope​(org.apache.wicket.request.http.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(), org.apache.wicket.request.resource.AbstractResource.ResourceResponse#setCacheDuration(org.apache.wicket.util.time.Duration), WebResponse.CacheScope
      • getHeaders

        public org.apache.wicket.request.HttpHeaderCollection getHeaders()
        get custom headers
        Returns:
        collection of the response headers