From: <bra...@us...> - 2009-05-20 02:51:40
|
Revision: 2728 http://archive-access.svn.sourceforge.net/archive-access/?rev=2728&view=rev Author: bradtofel Date: 2009-05-20 02:51:34 +0000 (Wed, 20 May 2009) Log Message: ----------- FEATURE: Now attempts to determine the referring page for badly resolved server-relative URLs within a page, re-resolving against the referring URL, and redirecting to the (hopefully) correct URL. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestFilter.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestFilter.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestFilter.java 2009-05-20 02:49:24 UTC (rev 2727) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestFilter.java 2009-05-20 02:51:34 UTC (rev 2728) @@ -37,12 +37,12 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.httpclient.URIException; +import org.archive.net.UURI; +import org.archive.net.UURIFactory; import org.archive.wayback.exception.ConfigurationException; +import org.archive.wayback.util.url.UrlOperations; -//import org.archive.wayback.core.WaybackRequest; -//import org.archive.wayback.exception.BadQueryException; -//import org.archive.wayback.exception.ConfigurationException; - /** * * @@ -102,9 +102,55 @@ boolean handled = false; RequestContext context = mapper.mapContext(httpRequest); - if(context != null) { + if(context == null) { + try { + handled = + handleServerRelativeArchivalRedirect(httpRequest, httpResponse); + } catch(URIException e) { + // TODO: Log this? + handled = false; + } + } else { handled = context.handleRequest(httpRequest,httpResponse); } return handled; } + + private boolean handleServerRelativeArchivalRedirect( + HttpServletRequest httpRequest, HttpServletResponse httpResponse) + throws IOException { + + boolean handled = false; + // hope that it's a server relative request, with a valid referrer: + String referer = httpRequest.getHeader("Referer"); + if(referer != null) { + UURI uri = UURIFactory.getInstance(referer); + String path = uri.getPath(); + int secondSlash = path.indexOf('/',1); + if(secondSlash > -1) { + String collection = path.substring(0,secondSlash); + String remainder = path.substring(secondSlash+1); + int thirdSlash = remainder.indexOf('/'); + if(thirdSlash > -1) { + String datespec = remainder.substring(0,thirdSlash); + String url = remainder.substring(thirdSlash+1); + String thisPath = httpRequest.getRequestURI(); + String resolved = UrlOperations.resolveUrl(url, thisPath); + String contextPath = httpRequest.getContextPath(); + String finalUrl = uri.getScheme() + "://" + + uri.getAuthority() + contextPath + collection + "/" + + datespec + "/" + resolved; + // cross your fingers!!! + LOGGER.info("Server-Relative-Redirect:\t" + referer + "\t" + + thisPath + "\t" + finalUrl); + httpResponse.sendRedirect(finalUrl); + handled = true; + + } + } + } + + return handled; + + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |