}
request.setState(STATE_NOCACHE, Boolean.TRUE);
return null;
} else {
// disconnected, abort now!
Reply reply = request.makeReply(HTTP.GATEWAY_TIMEOUT);
reply.setContent("The cache cannot be use for "
+ "<p><code>"+request.getMethod()+"</code> "
+ "<strong>"+request.getURL()+"</strong>"
+ ". <p>It is disconnected.");
return reply;
}
}
// let's try to get the resource!
URL _ru = request.getURL();
String requrl = URLUtils.normalize(_ru).toExternalForm();
// in the pre-cache, wait for full download
// FIXME should be better than this behaviour...
// see EntityCachedResource perform's FIXME ;)
if (precache.containsKey(requrl)) {
if (debug)
System.out.println("*** Already downloading: "+ requrl);
try {
CachedResource cr = (CachedResource)precache.get(requrl);
return cr.perform(request);
} catch (Exception ex) {
// there was a problem with the previous request,
// it may be better to do it by ourself
}
}
CachedResource res = null;
try {
res = store.getCachedResourceReference(requrl);
} catch (InvalidCacheException ex) {
res = null;
}
// are we disconnected?
if (request.checkOnlyIfCached() || !connected ) {
// and no entries...
EntityCachedResource ecr = null;
if (res != null) {
ecr = (EntityCachedResource) res.lookupResource(request);
}
if ((res == null) || (ecr == null)) {
if ( debug )
trace(request, "unavailable (disconnected).");
Reply reply = request.makeReply(HTTP.GATEWAY_TIMEOUT);
reply.setContent("The cache doesn't have an entry for "
+ "<p><strong>"+request.getURL()+"</strong>"
+ ". <p>And it is disconnected.");
return reply;
}
// yeah!
if (debug) {
trace(request, (connected) ? " hit - only if cached" :
" hit while disconneced" );
}
if (!validator.isValid(ecr, request)) {
addWarning(request, WARN_STALE);
}
addWarning(request, WARN_DISCONNECTED);
Reply reply = ecr.perform(request);
// Add any warnings collected during processing to the reply:
setWarnings(request, reply);
//FIXME request.setState(STATE_HOW, HOW_HIT);
return reply;
}
// in connected mode, we should now take care of revalidation and such
if (res != null) {
// if not fully loaded, ask for a revalidation FIXME
if ((res.getLoadState() == CachedResource.STATE_LOAD_PARTIAL) ||
(res.getLoadState() == CachedResource.STATE_LOAD_ERROR)) {
setRequestRevalidation(res, request);
return null;
}
if ( validator.isValid(res, request) ) {
try {
store.updateResourceGeneration(res);
} catch (InvalidCacheException ex) {
// should be ok so...
}
//FIXME request.setState(STATE_HOW, HOW_HIT);
Reply rep = res.perform(request);
return rep;
} else {
if (debug) {
System.out.println("*** Revalidation asked for " + requrl);
}