|
From: <bra...@us...> - 2010-05-18 23:24:51
|
Revision: 3112
http://archive-access.svn.sourceforge.net/archive-access/?rev=3112&view=rev
Author: bradtofel
Date: 2010-05-18 23:24:45 +0000 (Tue, 18 May 2010)
Log Message:
-----------
REFACTOR: AccessPoint fields: contextPrefix and serverPrefix are now replaced with staticPrefix, replayPrefix, and queryPrefix.
Modified Paths:
--------------
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/UIResults.java
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackRequest.java
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/AccessPoint.java
Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/UIResults.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/UIResults.java 2010-05-18 23:19:04 UTC (rev 3111)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/UIResults.java 2010-05-18 23:24:45 UTC (rev 3112)
@@ -224,7 +224,7 @@
}
/**
- * @return the original URL as recieved by Wayback, before forwarding to
+ * @return the original URL as received by Wayback, before forwarding to
* a .jsp
*/
public String getOriginalRequestURL() {
@@ -246,7 +246,7 @@
newWBR.setCaptureQueryRequest();
newWBR.setRequestUrl(url);
- return newWBR.getContextPrefix() + "query?" +
+ return newWBR.getAccessPoint().getQueryPrefix() + "query?" +
newWBR.getQueryArguments(1);
}
@@ -291,10 +291,46 @@
*/
public String urlForPage(int pageNum) {
WaybackRequest wbRequest = getWbRequest();
- return wbRequest.getContextPrefix() + "query?" +
+ return wbRequest.getAccessPoint().getQueryPrefix() + "query?" +
wbRequest.getQueryArguments(pageNum);
}
+ /**
+ * @return the defined staticPrefix for the AccessPoint
+ */
+ public String getStaticPrefix() {
+ if(wbRequest != null) {
+ if(wbRequest.getAccessPoint() != null) {
+ return wbRequest.getAccessPoint().getStaticPrefix();
+ }
+ }
+ return "/";
+ }
+
+ /**
+ * @return the defined queryPrefix for the AccessPoint
+ */
+ public String getQueryPrefix() {
+ if(wbRequest != null) {
+ if(wbRequest.getAccessPoint() != null) {
+ return wbRequest.getAccessPoint().getQueryPrefix();
+ }
+ }
+ return "/";
+ }
+
+ /**
+ * @return the defined replayPrefix for the AccessPoint
+ */
+ public String getReplayPrefix() {
+ if(wbRequest != null) {
+ if(wbRequest.getAccessPoint() != null) {
+ return wbRequest.getAccessPoint().getReplayPrefix();
+ }
+ }
+ return "/";
+ }
+
/*
* FORWARD TO A .JSP
*/
@@ -475,7 +511,6 @@
}
-
/*
* STATIC CONVENIENCE METHODS
*/
Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackRequest.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackRequest.java 2010-05-18 23:19:04 UTC (rev 3111)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackRequest.java 2010-05-18 23:24:45 UTC (rev 3112)
@@ -37,8 +37,6 @@
import org.archive.wayback.requestparser.OpenSearchRequestParser;
import org.archive.wayback.resourceindex.filters.ExclusionFilter;
-import org.archive.wayback.resourceindex.filters.HostMatchFilter;
-import org.archive.wayback.resourceindex.filters.SchemeMatchFilter;
import org.archive.wayback.util.ObjectFilter;
import org.archive.wayback.util.ObjectFilterChain;
import org.archive.wayback.util.StringFormatter;
@@ -441,6 +439,8 @@
/**
* @param prefix
+ * @deprecated use getAccessPoint.getStaticPrefix() or
+ * getAccessPoint.getReplayPrefix()
*/
public void setContextPrefix(String prefix) {
contextPrefix = prefix;
@@ -452,16 +452,18 @@
*
* @return String absolute URL pointing to the Context root where the
* request was received.
+ * @deprecated use AccessPoint.setReplayPrefix or setQueryPrefix
*/
public String getContextPrefix() {
- if(contextPrefix == null) {
+ if(accessPoint == null) {
return "";
}
- return contextPrefix;
+ return accessPoint.getQueryPrefix();
}
/**
* @param prefix
+ * @deprecated use AccessPoint.set*Prefix
*/
public void setServerPrefix(String prefix) {
serverPrefix = prefix;
@@ -471,13 +473,15 @@
* @param prefix
* @return an absolute String URL that will point to the root of the
* server that is handling the request.
+ * @deprecated use AccessPoint.get*Prefix
*/
public String getServerPrefix() {
- if(serverPrefix == null) {
+ if(accessPoint == null) {
return "";
}
- return serverPrefix;
+ return accessPoint.getQueryPrefix();
}
+
/**
* @return the accessPoint
*/
@@ -500,25 +504,6 @@
this.exclusionFilter = exclusionFilter;
}
- @Deprecated
- public ObjectFilter<CaptureSearchResult> getResultFilters() {
- ObjectFilterChain<CaptureSearchResult> tmpFilters =
- new ObjectFilterChain<CaptureSearchResult>();
- if(isExactHost()) {
- tmpFilters.addFilter(new HostMatchFilter(
- UrlOperations.urlToHost(getRequestUrl())));
- }
-
- if(isExactScheme()) {
- tmpFilters.addFilter(new SchemeMatchFilter(
- UrlOperations.urlToScheme(getRequestUrl())));
- }
- if(resultFilters != null) {
- tmpFilters.addFilters(resultFilters.getFilters());
- }
- return tmpFilters;
- }
-
public void setResultFilters(ObjectFilterChain<CaptureSearchResult> resultFilters) {
this.resultFilters = resultFilters;
}
@@ -1008,6 +993,7 @@
wbRequest.serverPrefix = serverPrefix;
wbRequest.formatter = formatter;
+ wbRequest.accessPoint = accessPoint;
wbRequest.filters = new HashMap<String,String>();
Iterator<String> itr = filters.keySet().iterator();
Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/AccessPoint.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/AccessPoint.java 2010-05-18 23:19:04 UTC (rev 3111)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/AccessPoint.java 2010-05-18 23:24:45 UTC (rev 3112)
@@ -24,7 +24,10 @@
*/
package org.archive.wayback.webapp;
+import java.io.File;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
@@ -79,18 +82,31 @@
*/
public class AccessPoint extends AbstractRequestHandler
implements ShutdownListener {
+ /** webapp relative location of Interstitial.jsp */
+ public final static String INTERSTITIAL_JSP = "jsp/Interstitial.jsp";
+ /** argument for Interstitial.jsp target URL */
+ public final static String INTERSTITIAL_TARGET = "target";
+ /** argument for Interstitial.jsp seconds to delay */
+ public final static String INTERSTITIAL_SECONDS = "seconds";
private static final Logger LOGGER = Logger.getLogger(
AccessPoint.class.getName());
-
+
private boolean exactHostMatch = false;
private boolean exactSchemeMatch = true;
private boolean useAnchorWindow = false;
private boolean useServerName = false;
+ private boolean serveStatic = true;
+ private boolean bounceToReplayPrefix = false;
+ private boolean bounceToQueryPrefix = false;
private String liveWebPrefix = null;
- private String urlRoot = null;
+ private String staticPrefix = null;
+ private String queryPrefix = null;
+ private String replayPrefix = null;
+ private String refererAuth = null;
+
private Locale locale = null;
private Properties configs = null;
@@ -112,20 +128,30 @@
protected boolean dispatchLocal(HttpServletRequest httpRequest,
HttpServletResponse httpResponse)
throws ServletException, IOException {
-
- String translated = "/" + translateRequestPathQuery(httpRequest);
-
- WaybackRequest wbRequest = new WaybackRequest();
- wbRequest.setContextPrefix(getUrlRoot());
- wbRequest.setAccessPoint(this);
- wbRequest.fixup(httpRequest);
- UIResults uiResults = new UIResults(wbRequest,uriConverter);
- try {
- uiResults.forward(httpRequest, httpResponse, translated);
- return true;
- } catch(IOException e) {
- // TODO: figure out if we got IO because of a missing dispatcher
+ if(!serveStatic) {
+ return false;
}
+// String contextRelativePath = httpRequest.getServletPath();
+ String translated = "/" + translateRequestPath(httpRequest);
+// String absPath = getServletContext().getRealPath(contextRelativePath);
+ String absPath = getServletContext().getRealPath(translated);
+ File test = new File(absPath);
+ if(test.exists()) {
+
+ String translated2 = "/" + translateRequestPathQuery(httpRequest);
+
+ WaybackRequest wbRequest = new WaybackRequest();
+// wbRequest.setContextPrefix(getUrlRoot());
+ wbRequest.setAccessPoint(this);
+ wbRequest.fixup(httpRequest);
+ UIResults uiResults = new UIResults(wbRequest,uriConverter);
+ try {
+ uiResults.forward(httpRequest, httpResponse, translated2);
+ return true;
+ } catch(IOException e) {
+ // TODO: figure out if we got IO because of a missing dispatcher
+ }
+ }
return false;
}
@@ -152,7 +178,7 @@
// TODO: refactor this code into RequestParser implementations
wbRequest.setAccessPoint(this);
// wbRequest.setContextPrefix(getAbsoluteLocalPrefix(httpRequest));
- wbRequest.setContextPrefix(getUrlRoot());
+// wbRequest.setContextPrefix(getUrlRoot());
wbRequest.fixup(httpRequest);
// end of refactor
@@ -179,11 +205,26 @@
wbRequest.setExactScheme(isExactSchemeMatch());
if(wbRequest.isReplayRequest()) {
-
+ if(bounceToReplayPrefix) {
+ // we don't accept replay requests on this AccessPoint
+ // bounce the user to the right place:
+ String suffix = translateRequestPathQuery(httpRequest);
+ String replayUrl = replayPrefix + suffix;
+ httpResponse.sendRedirect(replayUrl);
+ return true;
+ }
handleReplay(wbRequest,httpRequest,httpResponse);
} else {
+ if(bounceToQueryPrefix) {
+ // we don't accept replay requests on this AccessPoint
+ // bounce the user to the right place:
+ String suffix = translateRequestPathQuery(httpRequest);
+ String replayUrl = queryPrefix + suffix;
+ httpResponse.sendRedirect(replayUrl);
+ return true;
+ }
wbRequest.setExactHost(isExactHostMatch());
handleQuery(wbRequest,httpRequest,httpResponse);
}
@@ -198,7 +239,9 @@
} catch(WaybackException e) {
boolean drawError = true;
if(e instanceof ResourceNotInArchiveException) {
- if(getLiveWebPrefix() != null) {
+ if((getLiveWebPrefix() != null)
+ && (getLiveWebPrefix().length() > 0)) {
+
String liveUrl =
getLiveWebPrefix() + wbRequest.getRequestUrl();
httpResponse.sendRedirect(liveUrl);
@@ -220,18 +263,48 @@
String url = r.getRequestUrl();
StringBuilder sb = new StringBuilder(100);
sb.append("NotInArchive\t");
- sb.append(getUrlRoot()).append("\t");
+ sb.append(getBeanName()).append("\t");
sb.append(url);
LOGGER.info(sb.toString());
}
}
+ private void checkInterstitialRedirect(HttpServletRequest httpRequest)
+ throws BetterRequestException {
+ if(refererAuth != null) {
+ String referer = httpRequest.getHeader("Referer");
+ if((referer == null) || (!referer.contains(refererAuth))) {
+ StringBuffer sb = httpRequest.getRequestURL();
+ if(httpRequest.getQueryString() != null) {
+ sb.append("?").append(httpRequest.getQueryString());
+ }
+ StringBuilder u = new StringBuilder();
+ u.append(getQueryPrefix());
+ u.append(INTERSTITIAL_JSP);
+ u.append("?");
+ u.append(INTERSTITIAL_SECONDS).append("=").append(5);
+ u.append("&");
+ u.append(INTERSTITIAL_TARGET).append("=");
+ try {
+ u.append(URLEncoder.encode(sb.toString(), "UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ // not gonna happen...
+ u.append(sb.toString());
+ }
+ throw new BetterRequestException(u.toString());
+ }
+ }
+ }
+
private void handleReplay(WaybackRequest wbRequest,
HttpServletRequest httpRequest, HttpServletResponse httpResponse)
throws IOException, ServletException, WaybackException {
Resource resource = null;
try {
+
+ checkInterstitialRedirect(httpRequest);
+
PerformanceLogger p = new PerformanceLogger("replay");
SearchResults results =
getCollection().getResourceIndex().query(wbRequest);
@@ -241,7 +314,7 @@
}
CaptureSearchResults captureResults =
(CaptureSearchResults) results;
-
+
// TODO: check which versions are actually accessible right now?
CaptureSearchResult closest = captureResults.getClosest(wbRequest,
isUseAnchorWindow());
@@ -308,6 +381,16 @@
}
}
+ private String getBestPrefix(String best, String next, String last) {
+ if(best != null) {
+ return best;
+ }
+ if(next != null) {
+ return next;
+ }
+ return last;
+ }
+
/*
* *******************************************************************
* *******************************************************************
@@ -369,7 +452,7 @@
/**
* @return the useServerName
- * @deprecated no longer used, use urlPrefix
+ * @deprecated no longer used, use {replay,query,static}Prefix
*/
public boolean isUseServerName() {
return useServerName;
@@ -377,13 +460,28 @@
/**
* @param useServerName the useServerName to set
- * @deprecated no longer used, use urlPrefix
+ * @deprecated no longer used, use {replay,query,static}Prefix
*/
public void setUseServerName(boolean useServerName) {
this.useServerName = useServerName;
}
/**
+ * @return true if this AccessPoint serves static content
+ */
+ public boolean isServeStatic() {
+ return serveStatic;
+ }
+
+ /**
+ * @param serveStatic if set to true, this AccessPoint will serve static
+ * content, and .jsp files
+ */
+ public void setServeStatic(boolean serveStatic) {
+ this.serveStatic = serveStatic;
+ }
+
+ /**
* @return the liveWebPrefix String to use, or null, if this AccessPoint
* does not use the Live Web to fill in documents missing from the archive
*/
@@ -401,21 +499,73 @@
/**
* @return the String url prefix to use when generating self referencing
- * URLs
+ * static URLs
*/
- public String getUrlRoot() {
- return urlRoot;
+ public String getStaticPrefix() {
+ return getBestPrefix(staticPrefix,queryPrefix,replayPrefix);
}
/**
- * @param urlRoot explicit URL prefix to use when creating self referencing
- * URLs
+ * @param staticPrefix explicit URL prefix to use when creating self referencing
+ * static URLs
*/
+ public void setStaticPrefix(String staticPrefix) {
+ this.staticPrefix = staticPrefix;
+ }
+
+ /**
+ * @return the String url prefix to use when generating self referencing
+ * replay URLs
+ */
+ public String getReplayPrefix() {
+ return getBestPrefix(replayPrefix,queryPrefix,staticPrefix);
+ }
+
+ /**
+ * @param replayPrefix explicit URL prefix to use when creating self referencing
+ * replay URLs
+ */
+ public void setReplayPrefix(String replayPrefix) {
+ this.replayPrefix = replayPrefix;
+ }
+
+ /**
+ * @param queryPrefix explicit URL prefix to use when creating self referencing
+ * query URLs
+ */
+ public void setQueryPrefix(String queryPrefix) {
+ this.queryPrefix = queryPrefix;
+ }
+
+ /**
+ * @return the String url prefix to use when generating self referencing
+ * replay URLs
+ */
+ public String getQueryPrefix() {
+ return getBestPrefix(queryPrefix,staticPrefix,replayPrefix);
+ }
+
+ /**
+ * @param urlRoot explicit URL prefix to use when creating ANY self
+ * referencing URLs
+ * @deprecated use setQueryPrefix, setReplayPrefix, setStaticPrefix
+ */
public void setUrlRoot(String urlRoot) {
- this.urlRoot = urlRoot;
+ this.queryPrefix = urlRoot;
+ this.replayPrefix = urlRoot;
+ this.staticPrefix = urlRoot;
}
/**
+ * @return the String url prefix used when generating self referencing
+ * URLs
+ * @deprecated use getQueryPrefix, getReplayPrefix, getStaticPrefix
+ */
+ public String getUrlRoot() {
+ return getBestPrefix(queryPrefix,staticPrefix,replayPrefix);
+ }
+
+ /**
* @return explicit Locale to use within this AccessPoint.
*/
public Locale getLocale() {
@@ -605,4 +755,45 @@
public void setAuthentication(BooleanOperator<WaybackRequest> auth) {
this.authentication = auth;
}
+
+ /**
+ * @return the refererAuth
+ */
+ public String getRefererAuth() {
+ return refererAuth;
+ }
+
+ /**
+ * @param refererAuth the refererAuth to set
+ */
+ public void setRefererAuth(String refererAuth) {
+ this.refererAuth = refererAuth;
+ }
+
+ /**
+ * @return the bounceToReplayPrefix
+ */
+ public boolean isBounceToReplayPrefix() {
+ return bounceToReplayPrefix;
+ }
+
+ /**
+ * @param bounceToReplayPrefix the bounceToReplayPrefix to set
+ */
+ public void setBounceToReplayPrefix(boolean bounceToReplayPrefix) {
+ this.bounceToReplayPrefix = bounceToReplayPrefix;
+ }
+ /**
+ * @return the bounceToQueryPrefix
+ */
+ public boolean isBounceToQueryPrefix() {
+ return bounceToQueryPrefix;
+ }
+
+ /**
+ * @param bounceToQueryPrefix the bounceToQueryPrefix to set
+ */
+ public void setBounceToQueryPrefix(boolean bounceToQueryPrefix) {
+ this.bounceToQueryPrefix = bounceToQueryPrefix;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|