String urlString = translateRequestPathQuery(httpRequest);
urlString = UrlOperations.fixupHTTPUrlWithOneSlash(urlString);
boolean handled = true;
ArcResource r = null;
WaybackRequest wbRequest = new WaybackRequest();
wbRequest.setAccessPoint(inner);
wbRequest.setRequestUrl(urlString);
try {
String ref = httpRequest.getHeader("Referer");
PerfStats.clearAll();
if ((ref == null) || !skipHost.matcher(ref).find()) {
wbRequest.setTimestampSearchKey(true);
wbRequest.setReplayDate(new Date());
wbRequest.setReplayRequest();
try {
inner.queryIndex(wbRequest);
// Succeeded, so send redirect to query
httpResponse.sendRedirect(inner.getReplayPrefix() + urlString);
return true;
} catch (ResourceIndexNotAvailableException e) {
throw new LiveDocumentNotAvailableException(e.toString());
} catch (ResourceNotInArchiveException e) {
//Continue
} catch (BadQueryException e) {
throw new LiveDocumentNotAvailableException(e.toString());
} catch (AccessControlException e) {
//Continue
//throw new LiveDocumentNotAvailableException(e.toString());
} catch (ConfigurationException e) {
throw new LiveDocumentNotAvailableException(e.toString());
}
}
wbRequest.setLiveWebRequest(true);
if (inner.isEnablePerfStatsHeader()) {
PerfStats.timeStart(AccessPoint.PerfStat.Total);
httpResponse = new PerfWritingHttpServletResponse(httpRequest, httpResponse, AccessPoint.PerfStat.Total, inner.getPerfStatsHeader());
}
Thread.currentThread().setName("Thread " +
Thread.currentThread().getId() + " " + getBeanName() +
" handling: " + urlString);
CaptureSearchResult result = new FastCaptureSearchResult();
r = this.getLiveWebResource(result, urlString);
if (r != null) {
CaptureSearchResults results = new CaptureSearchResults();
results.addSearchResult(result);
wbRequest.setReplayTimestamp(result.getCaptureTimestamp());
inner.getReplay().getRenderer(wbRequest, result, r).renderResource(httpRequest, httpResponse, wbRequest, result, r,
inner.getUriConverter(), results);
} else {
throw new LiveDocumentNotAvailableException(urlString);
}
} catch(WaybackException e) {
inner.logError(httpResponse, LIVEWEB_RUNTIME_ERROR_HEADER, e, wbRequest);
inner.getException().renderException(httpRequest, httpResponse, wbRequest, e, inner.getUriConverter());
} catch(Exception e) {
inner.logError(httpResponse, LIVEWEB_RUNTIME_ERROR_HEADER, e, wbRequest);
} finally {
if (r != null) {
r.close();
}
}
return handled;
}