Revision: 2849 http://archive-access.svn.sourceforge.net/archive-access/?rev=2849&view=rev Author: bradtofel Date: 2009-10-28 00:06:30 +0000 (Wed, 28 Oct 2009) Log Message: ----------- FEATURE: Added parsing of ArchivalURL requests within proxy mode, with the main benefit of being able to include a date in the incoming requests. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyArchivalRequestParser.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyArchivalRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyArchivalRequestParser.java 2009-10-28 00:04:43 UTC (rev 2848) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyArchivalRequestParser.java 2009-10-28 00:06:30 UTC (rev 2849) @@ -1,3 +1,27 @@ +/* ProxyArchivalRequestParser + * + * $Id$ + * + * Created on 4:01:04 PM Apr 6, 2009. + * + * Copyright (C) 2009 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.proxy; import java.util.List; @@ -2,2 +26,4 @@ +import javax.servlet.http.HttpServletRequest; + import org.archive.wayback.RequestParser; @@ -7,10 +33,24 @@ import org.archive.wayback.archivalurl.requestparser.PathDateRangeQueryRequestParser; import org.archive.wayback.archivalurl.requestparser.PathPrefixDatePrefixQueryRequestParser; import org.archive.wayback.archivalurl.requestparser.PathPrefixDateRangeQueryRequestParser; +import org.archive.wayback.archivalurl.requestparser.ReplayRequestParser; +import org.archive.wayback.core.WaybackRequest; +import org.archive.wayback.exception.BadQueryException; +import org.archive.wayback.exception.BetterRequestException; +import org.archive.wayback.requestparser.CompositeRequestParser; import org.archive.wayback.requestparser.FormRequestParser; import org.archive.wayback.requestparser.OpenSearchRequestParser; +import org.archive.wayback.util.bdb.BDBMap; +import org.archive.wayback.webapp.AccessPoint; -public class ProxyArchivalRequestParser extends ProxyRequestParser { +/** + * + * + * @author brad + * @version $Date$, $Revision$ + */ + +public class ProxyArchivalRequestParser extends CompositeRequestParser { private ProxyReplayRequestParser prrp = new ProxyReplayRequestParser(this); protected RequestParser[] getRequestParsers() { prrp.init(); @@ -20,6 +60,7 @@ new PathDateRangeQueryRequestParser(this), new PathPrefixDatePrefixQueryRequestParser(this), new PathPrefixDateRangeQueryRequestParser(this), + new ReplayRequestParser(this), new OpenSearchRequestParser(this), new FormRequestParser(this) }; @@ -31,4 +72,37 @@ public void setLocalhostNames(List<String> localhostNames) { prrp.setLocalhostNames(localhostNames); } + + public WaybackRequest parse(HttpServletRequest httpRequest, + AccessPoint wbContext) throws BadQueryException, BetterRequestException { + + WaybackRequest wbRequest = super.parse(httpRequest, wbContext); + if (wbRequest != null) { + String id = httpRequest.getHeader("Proxy-Id"); + if (id == null) + id = httpRequest.getRemoteAddr(); + + // Get the id from the request. + // If no id, use the ip-address instead. + // Check if the parser parsed a replay request and found a + // timestamp. If so, then we need to store the timestamp and + // redirect, which is done with a BetterRequestException: + if(wbRequest.isReplayRequest()) { + String replayTimestamp = wbRequest.getReplayTimestamp(); + if(replayTimestamp != null) { + BDBMap.addTimestampForId(httpRequest.getContextPath(), + id, replayTimestamp); + } + throw new BetterRequestException(wbRequest.getRequestUrl()); + } + + // Then get the timestamp (or rather datestr) matching this id. + // TODO: This is hacky - need generic way to store session data + String replayDateStr = BDBMap.getTimestampForId( + httpRequest.getContextPath(), id); + wbRequest.setReplayTimestamp(replayDateStr); + wbRequest.setAnchorTimestamp(replayDateStr); + } + return wbRequest; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |