use of org.apache.wicket.request.resource.caching.IStaticCacheableResource in project wicket by apache.
the class ConcatBundleResource method getCacheKey.
@Override
public Serializable getCacheKey() {
ArrayList<Serializable> key = new ArrayList<>(providedResources.size());
for (IReferenceHeaderItem curItem : providedResources) {
Serializable curKey = ((IStaticCacheableResource) curItem.getReference().getResource()).getCacheKey();
if (curKey == null) {
reportError(curItem.getReference(), "Unable to get cache key for ");
return null;
}
key.add(curKey);
}
return key;
}
use of org.apache.wicket.request.resource.caching.IStaticCacheableResource in project wicket by apache.
the class AbstractResource method respond.
/**
* @see org.apache.wicket.request.resource.IResource#respond(org.apache.wicket.request.resource.IResource.Attributes)
*/
@Override
public void respond(final Attributes attributes) {
// Sets the request attributes
setRequestMetaData(attributes);
// Get a "new" ResourceResponse to write a response
ResourceResponse data = newResourceResponse(attributes);
// is resource supposed to be cached?
if (this instanceof IStaticCacheableResource) {
final IStaticCacheableResource cacheable = (IStaticCacheableResource) this;
// is caching enabled?
if (cacheable.isCachingEnabled()) {
// apply caching strategy to response
getCachingStrategy().decorateResponse(data, cacheable);
}
}
// set response header
setResponseHeaders(data, attributes);
if (!data.dataNeedsToBeWritten(attributes) || data.getErrorCode() != null || needsBody(data.getStatusCode()) == false) {
return;
}
if (data.getWriteCallback() == null) {
throw new IllegalStateException("ResourceResponse#setWriteCallback() must be set.");
}
try {
data.getWriteCallback().writeData(attributes);
} catch (IOException iox) {
throw new WicketRuntimeException(iox);
}
}
use of org.apache.wicket.request.resource.caching.IStaticCacheableResource in project wicket by apache.
the class RequestCycleUrlForTest method urlForResourceReference.
/**
* ResourceReference with IStaticCacheableResource should not have the jsessionid encoded in the url
*
* @throws Exception
*/
@Test
public void urlForResourceReference() throws Exception {
final IStaticCacheableResource resource = mock(IStaticCacheableResource.class);
ResourceReference reference = new ResourceReference("dummy") {
@Override
public IResource getResource() {
return resource;
}
};
ResourceReferenceRequestHandler handler = new ResourceReferenceRequestHandler(reference);
CharSequence url = requestCycle.urlFor(handler);
assertEquals("./" + RES_REF_URL, url);
}
use of org.apache.wicket.request.resource.caching.IStaticCacheableResource in project wicket by apache.
the class RequestCycleUrlForTest method urlForStaticResource.
/**
* IStaticCacheableResource should not have the jsessionid encoded in the url
*
* @throws Exception
*/
@Test
public void urlForStaticResource() throws Exception {
IStaticCacheableResource resource = mock(IStaticCacheableResource.class);
ResourceRequestHandler handler = new ResourceRequestHandler(resource, new PageParameters());
CharSequence url = requestCycle.urlFor(handler);
assertEquals("./" + RESOURCE_URL, url);
}
use of org.apache.wicket.request.resource.caching.IStaticCacheableResource in project wicket by apache.
the class ResourceMapper method addCachingDecoration.
protected void addCachingDecoration(Url url, PageParameters parameters) {
final List<String> segments = url.getSegments();
final int lastSegmentAt = segments.size() - 1;
final String filename = segments.get(lastSegmentAt);
if (Strings.isEmpty(filename) == false) {
final IResource resource = resourceReference.getResource();
if (resource instanceof IStaticCacheableResource) {
final IStaticCacheableResource cacheable = (IStaticCacheableResource) resource;
if (cacheable.isCachingEnabled()) {
final ResourceUrl cacheUrl = new ResourceUrl(filename, parameters);
getCachingStrategy().decorateUrl(cacheUrl, cacheable);
if (Strings.isEmpty(cacheUrl.getFileName())) {
if (Application.exists() && Application.get().usesDeploymentConfig()) {
throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "caching strategy returned empty name for " + resource);
} else {
throw new IllegalStateException("caching strategy returned empty name for " + resource);
}
}
segments.set(lastSegmentAt, cacheUrl.getFileName());
}
}
}
}
Aggregations