- All Implemented Interfaces:
FacesWrapper<Resource>,Externalizable,Serializable
This Resource implementation is a marker class which signals that the given resource is served from a CDN host. It offers a method to return the
local URL which can be used as fallback in case the CDN request errors out.
It is intended to be returned by a ResourceHandler which you write yourself and which uploads your own resources to your own CDN host, so that the
CDN content stays byte for byte identical to the local content. The CombinedResourceHandler will then render an onerror handler which
falls back to the local URL, and the CorsAwareResourceRenderer will then render the integrity attribute.
The CDNResourceHandler does not return this type, it returns a RemappedResource. Its CDN URLs point to third party hosts whose content is not
byte for byte identical to the local content, and an integrity hash computed from the local content would therefore cause the browser to block the resource.
- Since:
- 2.7
- Author:
- Bauke Scholtz
- See Also:
-
Field Summary
Fields inherited from class jakarta.faces.application.Resource
COMPONENT_RESOURCE_KEY -
Constructor Summary
ConstructorsConstructorDescriptionDo not use this constructor.CDNResource(Resource resource, String cdnURL) Constructs a new CDN resource which remaps the given wrapped resource to the given CDN URL. -
Method Summary
Modifier and TypeMethodDescriptionReturns the local URL.Returns the CDN URL.Methods inherited from class org.omnifaces.resourcehandler.RemappedResource
equals, getContentType, getInputStream, getLibraryName, getResourceName, getResponseHeaders, getURL, getWrapped, hashCode, readExternal, setLibraryName, setResourceName, userAgentNeedsUpdate, writeExternalMethods inherited from class jakarta.faces.application.ResourceWrapper
setContentType
-
Constructor Details
-
CDNResource
public CDNResource()Do not use this constructor. It's merely there forExternalizable. -
CDNResource
Constructs a new CDN resource which remaps the given wrapped resource to the given CDN URL. The CDN URL is available bygetRequestPath(). The local URL is available bygetLocalRequestPath().- Parameters:
resource- The resource to be remapped.cdnURL- The CDN URL of the resource.
-
-
Method Details
-
getRequestPath
Returns the CDN URL. I.e. the remapped request path pointing a CDN host.- Overrides:
getRequestPathin classRemappedResource- Returns:
- The CDN URL.
-
getLocalRequestPath
Returns the local URL. I.e. the original request path pointing the local host.- Returns:
- The local URL.
-