From: <bra...@us...> - 2007-07-16 22:36:04
|
Revision: 1774 http://archive-access.svn.sourceforge.net/archive-access/?rev=1774&view=rev Author: bradtofel Date: 2007-07-16 15:36:05 -0700 (Mon, 16 Jul 2007) Log Message: ----------- REFACTOR: moved request parsing code for proxy mode into these classes. Added Paths: ----------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyReplayRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyRequestParser.java Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyReplayRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyReplayRequestParser.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyReplayRequestParser.java 2007-07-16 22:36:05 UTC (rev 1774) @@ -0,0 +1,133 @@ +/* ProxyReplayRequestParser + * + * $Id$ + * + * Created on 3:43:24 PM Apr 26, 2007. + * + * Copyright (C) 2007 Internet Archive. + * + * This file is part of wayback-core. + * + * wayback-core 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-core 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-core; 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; +import java.util.Properties; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.httpclient.URIException; +import org.archive.util.InetAddressUtil; +import org.archive.wayback.WaybackConstants; +import org.archive.wayback.core.Timestamp; +import org.archive.wayback.core.WaybackRequest; +import org.archive.wayback.exception.BadQueryException; +import org.archive.wayback.exception.ConfigurationException; +import org.archive.wayback.requestparser.BaseRequestParser; +import org.archive.wayback.webapp.WaybackContext; + +/** + * + * + * @author brad + * @version $Date$, $Revision$ + */ +public class ProxyReplayRequestParser extends BaseRequestParser { + /** + * name of attribute in config Properties for specifying an additional + * hostname that should be considered "local" for discriminating between + * Replays and Queries + */ + private static final String LOCAL_HOSTNAME = "query.localhostname"; + + private List<String> localhostNames = null; + + public void init(final Properties p) throws ConfigurationException { + this.localhostNames = InetAddressUtil.getAllLocalHostNames(); + String extraLocalHostname = p.getProperty(LOCAL_HOSTNAME); + if ((extraLocalHostname != null) && (extraLocalHostname.length() > 0)) { + localhostNames.add(extraLocalHostname); + } + super.init(p); + } + /** + * @param list + */ + public void init(List<String> list) { + this.localhostNames = InetAddressUtil.getAllLocalHostNames(); + if((list != null) && (list.size() > 0)) { + localhostNames.addAll(list); + } + } + /** + * + */ + public void init() { + List<String> empty = null; + init(empty); + } + private boolean isLocalRequest(HttpServletRequest httpRequest) { + return this.localhostNames.contains(httpRequest.getServerName()); + } + + /* (non-Javadoc) + * @see org.archive.wayback.requestparser.BaseRequestParser#parse(javax.servlet.http.HttpServletRequest, org.archive.wayback.webapp.WaybackContext) + */ + @Override + public WaybackRequest parse(HttpServletRequest httpRequest, + WaybackContext wbContext) throws BadQueryException { + + if (isLocalRequest(httpRequest)) { + // local means query: let the following RequestParsers have a go + // at it. + return null; + } + + WaybackRequest wbRequest = null; + String requestServer = httpRequest.getServerName(); + String requestPath = httpRequest.getRequestURI(); + //int port = httpRequest.getServerPort(); + String requestQuery = httpRequest.getQueryString(); + String requestScheme = httpRequest.getScheme(); + if (requestQuery != null) { + requestPath = requestPath + "?" + requestQuery; + } + + String requestUrl = requestScheme + "://" + requestServer + requestPath; + + wbRequest = new WaybackRequest(); + try { + wbRequest.setRequestUrl(requestUrl); + } catch (URIException e) { + e.printStackTrace(); + return null; + } + wbRequest.put(WaybackConstants.REQUEST_TYPE, + WaybackConstants.REQUEST_REPLAY_QUERY); + + // Get the id from the request. If no id, use the ip-address instead. + // Then get the timestamp (or rather datestr) matching this id. + String id = httpRequest.getHeader("Proxy-Id"); + if (id == null) + id = httpRequest.getRemoteAddr(); + wbRequest.put(WaybackConstants.REQUEST_EXACT_DATE, Timestamp + .getTimestampForId(httpRequest.getContextPath(), id)); + addHttpHeaderFields(wbRequest, httpRequest); + + return wbRequest; + } + +} Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyRequestParser.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyRequestParser.java 2007-07-16 22:36:05 UTC (rev 1774) @@ -0,0 +1,49 @@ +/* ProxyRequestParser + * + * $Id$ + * + * Created on 3:42:13 PM Apr 26, 2007. + * + * Copyright (C) 2007 Internet Archive. + * + * This file is part of wayback-core. + * + * wayback-core 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-core 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-core; 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 org.archive.wayback.RequestParser; +import org.archive.wayback.requestparser.CompositeRequestParser; +import org.archive.wayback.requestparser.FormRequestParser; +import org.archive.wayback.requestparser.OpenSearchRequestParser; + +/** + * + * + * @author brad + * @version $Date$, $Revision$ + */ +public class ProxyRequestParser extends CompositeRequestParser { + protected RequestParser[] getRequestParsers() { + ProxyReplayRequestParser prrp = new ProxyReplayRequestParser(); + prrp.init(); + RequestParser[] theParsers = { + prrp, + new OpenSearchRequestParser(), + new FormRequestParser() + }; + return theParsers; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bra...@us...> - 2007-09-11 01:00:43
|
Revision: 1988 http://archive-access.svn.sourceforge.net/archive-access/?rev=1988&view=rev Author: bradtofel Date: 2007-09-10 18:00:47 -0700 (Mon, 10 Sep 2007) Log Message: ----------- FEATURE: added missing capability to explicitly set localhostNames List via Spring. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyReplayRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyRequestParser.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyReplayRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyReplayRequestParser.java 2007-09-11 00:59:47 UTC (rev 1987) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyReplayRequestParser.java 2007-09-11 01:00:47 UTC (rev 1988) @@ -48,20 +48,14 @@ private List<String> localhostNames = null; /** - * @param list - */ - public void init(List<String> list) { - this.localhostNames = InetAddressUtil.getAllLocalHostNames(); - if((list != null) && (list.size() > 0)) { - localhostNames.addAll(list); - } - } - /** * */ public void init() { - List<String> empty = null; - init(empty); + if(localhostNames == null) { + localhostNames = InetAddressUtil.getAllLocalHostNames(); + } else { + localhostNames.addAll(InetAddressUtil.getAllLocalHostNames()); + } } private boolean isLocalRequest(HttpServletRequest httpRequest) { return this.localhostNames.contains(httpRequest.getServerName()); @@ -113,5 +107,11 @@ return wbRequest; } + public List<String> getLocalhostNames() { + return localhostNames; + } + public void setLocalhostNames(List<String> localhostNames) { + this.localhostNames = localhostNames; + } } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyRequestParser.java 2007-09-11 00:59:47 UTC (rev 1987) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyRequestParser.java 2007-09-11 01:00:47 UTC (rev 1988) @@ -24,6 +24,8 @@ */ package org.archive.wayback.proxy; +import java.util.List; + import org.archive.wayback.RequestParser; import org.archive.wayback.requestparser.CompositeRequestParser; import org.archive.wayback.requestparser.FormRequestParser; @@ -36,8 +38,8 @@ * @version $Date$, $Revision$ */ public class ProxyRequestParser extends CompositeRequestParser { + private ProxyReplayRequestParser prrp = new ProxyReplayRequestParser(); protected RequestParser[] getRequestParsers() { - ProxyReplayRequestParser prrp = new ProxyReplayRequestParser(); prrp.init(); RequestParser[] theParsers = { prrp, @@ -46,4 +48,10 @@ }; return theParsers; } + public List<String> getLocalhostNames() { + return prrp.getLocalhostNames(); + } + public void setLocalhostNames(List<String> localhostNames) { + prrp.setLocalhostNames(localhostNames); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bra...@us...> - 2008-02-21 01:55:33
|
Revision: 2203 http://archive-access.svn.sourceforge.net/archive-access/?rev=2203&view=rev Author: bradtofel Date: 2008-02-20 17:55:36 -0800 (Wed, 20 Feb 2008) Log Message: ----------- BUGFIX: (ACC-11) now associates last requested timestamp for the current user with query as well as replay requests, allowing the closest indicator to be set properly on XML query requests. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyReplayRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyRequestParser.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyReplayRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyReplayRequestParser.java 2008-02-20 23:50:37 UTC (rev 2202) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyReplayRequestParser.java 2008-02-21 01:55:36 UTC (rev 2203) @@ -31,7 +31,6 @@ import org.apache.commons.httpclient.URIException; import org.archive.util.InetAddressUtil; import org.archive.wayback.WaybackConstants; -import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.BadQueryException; import org.archive.wayback.requestparser.BaseRequestParser; @@ -96,15 +95,6 @@ wbRequest.put(WaybackConstants.REQUEST_TYPE, WaybackConstants.REQUEST_REPLAY_QUERY); - // Get the id from the request. If no id, use the ip-address instead. - // Then get the timestamp (or rather datestr) matching this id. - String id = httpRequest.getHeader("Proxy-Id"); - if (id == null) - id = httpRequest.getRemoteAddr(); - wbRequest.put(WaybackConstants.REQUEST_EXACT_DATE, Timestamp - .getTimestampForId(httpRequest.getContextPath(), id)); - wbRequest.fixup(httpRequest); - return wbRequest; } public List<String> getLocalhostNames() { Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyRequestParser.java 2008-02-20 23:50:37 UTC (rev 2202) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyRequestParser.java 2008-02-21 01:55:36 UTC (rev 2203) @@ -26,10 +26,17 @@ import java.util.List; +import javax.servlet.http.HttpServletRequest; + import org.archive.wayback.RequestParser; +import org.archive.wayback.WaybackConstants; +import org.archive.wayback.core.Timestamp; +import org.archive.wayback.core.WaybackRequest; +import org.archive.wayback.exception.BadQueryException; import org.archive.wayback.requestparser.CompositeRequestParser; import org.archive.wayback.requestparser.FormRequestParser; import org.archive.wayback.requestparser.OpenSearchRequestParser; +import org.archive.wayback.webapp.AccessPoint; /** * @@ -54,4 +61,20 @@ public void setLocalhostNames(List<String> localhostNames) { prrp.setLocalhostNames(localhostNames); } + public WaybackRequest parse(HttpServletRequest httpRequest, + AccessPoint wbContext) throws BadQueryException { + + WaybackRequest wbRequest = super.parse(httpRequest, wbContext); + if (wbRequest != null) { + // Get the id from the request. If no id, use the ip-address instead. + // Then get the timestamp (or rather datestr) matching this id. + String id = httpRequest.getHeader("Proxy-Id"); + if (id == null) + id = httpRequest.getRemoteAddr(); + wbRequest.put(WaybackConstants.REQUEST_EXACT_DATE, Timestamp + .getTimestampForId(httpRequest.getContextPath(), id)); + wbRequest.fixup(httpRequest); + } + return wbRequest; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |