void revalidate(final IValidationHandler hdl) throws IOException {
IHttpRequest requestCopy = HttpUtils.copy(request);
if (response.getHeader("Etag") != null) {
requestCopy.setHeader("IF-None-Match", response.getHeader("Etag"));
} else {
requestCopy.setHeader("If-Modified-Since", response.getHeader("Last-Modified"));
}
requestCopy.setAttribute(CacheHandler.SKIP_CACHE_HANDLING, "true");
IHttpResponseHandler respHdl = new IHttpResponseHandler() {
@Execution(Execution.NONTHREADED)
@InvokeOn(InvokeOn.MESSAGE_RECEIVED)
public void onResponse(IHttpResponse response) throws IOException {
if (response.getStatus() == 304) {
CacheEntry entry = updateCacheEntryOnRevaildation(request, response.getResponseHeader());
register(entry);
hdl.onRevalidated(true, CacheEntry.this);
} else {
if (isCacheableSuccess(response.getStatus())) {
CacheEntry entry = updateCacheEntry(request, response);
register(entry);
} else {
deregister(request);
}
hdl.onRevalidated(false, CacheEntry.this);
}
}
public void onException(IOException ioe) throws IOException {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("got exception by revalidating "+ ioe.toString());
}
deregister(request);
hdl.onException(ioe);
}
};
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("revalidating request " + requestCopy.getRequestUrl().toString());
}
httpClient.send(requestCopy, respHdl);
}