From: <bra...@us...> - 2010-04-27 22:06:36
|
Revision: 3073 http://archive-access.svn.sourceforge.net/archive-access/?rev=3073&view=rev Author: bradtofel Date: 2010-04-27 22:06:30 +0000 (Tue, 27 Apr 2010) Log Message: ----------- INITIAL REV: new Archival URL RequestParser component implementation, which allows requests without a datespec, and redirects the client to a replay request for the supplied URL, for the current timestamp Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrlRequestParser.java Added Paths: ----------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/DatelessReplayRequestParser.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrlRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrlRequestParser.java 2010-04-27 22:03:42 UTC (rev 3072) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrlRequestParser.java 2010-04-27 22:06:30 UTC (rev 3073) @@ -25,6 +25,7 @@ package org.archive.wayback.archivalurl; import org.archive.wayback.RequestParser; +import org.archive.wayback.archivalurl.requestparser.DatelessReplayRequestParser; import org.archive.wayback.archivalurl.requestparser.PathDatePrefixQueryRequestParser; import org.archive.wayback.archivalurl.requestparser.PathDateRangeQueryRequestParser; import org.archive.wayback.archivalurl.requestparser.PathPrefixDatePrefixQueryRequestParser; @@ -76,7 +77,8 @@ new PathPrefixDatePrefixQueryRequestParser(this), new PathPrefixDateRangeQueryRequestParser(this), new OpenSearchRequestParser(this), - new FormRequestParser(this) + new FormRequestParser(this), + new DatelessReplayRequestParser(this) }; return theParsers; } Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/DatelessReplayRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/DatelessReplayRequestParser.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/DatelessReplayRequestParser.java 2010-04-27 22:06:30 UTC (rev 3073) @@ -0,0 +1,106 @@ +/* DatelessReplayRequestParser + * + * $Id$: + * + * Created on Apr 26, 2010. + * + * Copyright (C) 2006 Internet Archive. + * + * This file is part of Wayback. + * + * Wayback is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * any later version. + * + * Wayback is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser Public License for more details. + * + * You should have received a copy of the GNU Lesser Public License + * along with Wayback; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package org.archive.wayback.archivalurl.requestparser; + +import java.net.MalformedURLException; +import java.net.URL; + +import org.archive.wayback.core.WaybackRequest; +import org.archive.wayback.exception.BadQueryException; +import org.archive.wayback.exception.BetterRequestException; +import org.archive.wayback.requestparser.BaseRequestParser; +import org.archive.wayback.requestparser.PathRequestParser; +import org.archive.wayback.util.Timestamp; +import org.archive.wayback.util.url.UrlOperations; +import org.archive.wayback.webapp.AccessPoint; + + +/** + * @author brad + * + */ +public class DatelessReplayRequestParser extends PathRequestParser { + + /** + * @param wrapped the BaseRequestParser being wrapped + */ + public DatelessReplayRequestParser(BaseRequestParser wrapped) { + super(wrapped); + } + + public WaybackRequest parse(String requestPath, AccessPoint accessPoint) + throws BetterRequestException, BadQueryException { + /* + * + * We're trying to catch requests without a datespec, in which case, + * we just redirect to the same request, inserting today's datespec, + * and then we'll let the normal redirection occur. + * + * The one tricky point is that we don't want to defeat the + * server-relative redirection handling, so we want to do some + * inspection to make sure it actually looks like an URL, and not like: + * + * images/foo.gif + * redirect.php?blargity=blargblarg + * + * What would be perfect is if the user supplied http:// at the front. + * + * So, we'll assume that if we see that, we either match, or throw a + * BadQueryException. + * + */ + + String scheme = UrlOperations.urlToScheme(requestPath); + if(scheme == null) { + try { + URL u = new URL(UrlOperations.HTTP_SCHEME + requestPath); + // does the authority look legit? + if(u.getUserInfo() != null) { + throw new BadQueryException("Unable to handle URLs with user information"); + } + if(UrlOperations.isAuthority(u.getAuthority())) { + // ok, we're going to assume this is good: + String nowTS = Timestamp.currentTimestamp().getDateStr(); + String newUrl = + accessPoint.getUriConverter().makeReplayURI(nowTS, requestPath); + throw new BetterRequestException(newUrl); + } + } catch(MalformedURLException e) { + // eat it silently + } + } else { + // OK, we're going to assume this is a replay request, sans timestamp, + // ALWAYS redirect: + + String nowTS = Timestamp.currentTimestamp().getDateStr(); + String newUrl = + accessPoint.getUriConverter().makeReplayURI(nowTS, requestPath); + throw new BetterRequestException(newUrl); + } + return null; + } + +} Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/requestparser/DatelessReplayRequestParser.java ___________________________________________________________________ Added: svn:keywords + Author Date Revision Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |