From: <bra...@us...> - 2007-07-19 23:30:48
|
Revision: 1842 http://archive-access.svn.sourceforge.net/archive-access/?rev=1842&view=rev Author: bradtofel Date: 2007-07-19 16:30:47 -0700 (Thu, 19 Jul 2007) Log Message: ----------- REMOVED: superceded by WaybackContext and RequestParser refactor Removed Paths: ------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrlParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/QueryFilter.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ReplayFilter.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/parser/ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/RequestFilter.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackContextListener.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ReplayFilter.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/QueryServlet.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/ReplayServlet.java Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrlParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrlParser.java 2007-07-19 21:37:00 UTC (rev 1841) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ArchivalUrlParser.java 2007-07-19 23:30:47 UTC (rev 1842) @@ -1,43 +0,0 @@ -/* ArchivalUrlParser - * - * $Id$ - * - * Created on 3:47:00 PM Oct 24, 2006. - * - * 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; - -import org.archive.wayback.core.WaybackRequest; - -/** - * - * - * @author brad - * @version $Date$, $Revision$ - */ -public interface ArchivalUrlParser { - /** - * attempt to transform a string into a WaybackRequest - * - * @param requestPath - * @return WaybackRequest or null if the String was not parseable - */ - public abstract WaybackRequest parse(String requestPath); -} Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/QueryFilter.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/QueryFilter.java 2007-07-19 21:37:00 UTC (rev 1841) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/QueryFilter.java 2007-07-19 23:30:47 UTC (rev 1842) @@ -1,90 +0,0 @@ -/* QueryFilter - * - * $Id$ - * - * Created on 1:22:14 PM Nov 8, 2005. - * - * Copyright (C) 2005 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; - -import java.util.Properties; - -import javax.servlet.http.HttpServletRequest; - -import org.archive.wayback.WaybackConstants; -import org.archive.wayback.archivalurl.parser.PathDatePrefixParser; -import org.archive.wayback.archivalurl.parser.PathDateRangeParser; -import org.archive.wayback.archivalurl.parser.PathPrefixDatePrefixParser; -import org.archive.wayback.archivalurl.parser.PathPrefixDateRangeParser; -import org.archive.wayback.core.RequestFilter; -import org.archive.wayback.core.WaybackRequest; -import org.archive.wayback.exception.ConfigurationException; - -/** - * - * - * @author brad - * @version $Date$, $Revision$ - */ -public class QueryFilter extends RequestFilter { - - private int defaultResultsPerPage = 10; - - private ArchivalUrlParser parsers[] = { - new PathDatePrefixParser(), - new PathDateRangeParser(), - new PathPrefixDatePrefixParser(), - new PathPrefixDateRangeParser() - }; - - public void init(Properties p) throws ConfigurationException { - super.init(p); - String resultsPerPage = (String) p.get( - WaybackConstants.RESULTS_PER_PAGE_CONFIG_NAME); - if(resultsPerPage != null) { - defaultResultsPerPage = Integer.parseInt(resultsPerPage); - } - } - - public WaybackRequest parseRequest(HttpServletRequest httpRequest) { - String queryString = httpRequest.getQueryString(); - String origRequestPath = httpRequest.getRequestURI(); - if (queryString != null) { - origRequestPath = httpRequest.getRequestURI() + "?" + queryString; - } - String contextPath = httpRequest.getContextPath(); - if (!origRequestPath.startsWith(contextPath)) { - return null; - } - String requestPath = origRequestPath.substring(contextPath.length()); - - WaybackRequest wbRequest = null; - for(int i=0; i< parsers.length; i++) { - wbRequest = parsers[i].parse(requestPath); - if(wbRequest != null) break; - } - - if(wbRequest != null) { - wbRequest.setResultsPerPage(defaultResultsPerPage); - wbRequest.fixup(httpRequest); - } - return wbRequest; - } -} Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ReplayFilter.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ReplayFilter.java 2007-07-19 21:37:00 UTC (rev 1841) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/archivalurl/ReplayFilter.java 2007-07-19 23:30:47 UTC (rev 1842) @@ -1,133 +0,0 @@ -/* ReplayFilter - * - * $Id$ - * - * Created on 1:08:38 PM Nov 8, 2005. - * - * Copyright (C) 2005 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; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.commons.httpclient.URIException; -import org.archive.wayback.WaybackConstants; -import org.archive.wayback.core.RequestFilter; -import org.archive.wayback.core.Timestamp; -import org.archive.wayback.core.WaybackRequest; - - -/** - * - * - * @author brad - * @version $Date$, $Revision$ - */ -public class ReplayFilter extends RequestFilter { - - /** - * Regex which parses Archival URL replay requests into timestamp + url - */ - private final Pattern WB_REQUEST_REGEX = Pattern - .compile("^/(\\d{1,14})/(.*)$"); - - - /** - * Constructor - */ - public ReplayFilter() { - super(); - } - public WaybackRequest parseRequest(HttpServletRequest httpRequest) { - WaybackRequest wbRequest = null; - Matcher matcher = null; - - String queryString = httpRequest.getQueryString(); - String origRequestPath = httpRequest.getRequestURI(); - if (queryString != null && queryString.length() > 0) { - origRequestPath = httpRequest.getRequestURI() + "?" + queryString; - } - String contextPath = httpRequest.getContextPath(); - if (!origRequestPath.startsWith(contextPath)) { - return null; - } - String requestPath = origRequestPath.substring(contextPath.length()); - - matcher = WB_REQUEST_REGEX.matcher(requestPath); - if (matcher != null && matcher.matches()) { - wbRequest = new WaybackRequest(); - String dateStr = matcher.group(1); - String urlStr = matcher.group(2); - if (!urlStr.startsWith("http://")) { - urlStr = "http://" + urlStr; - } - - // The logic of the classic WM wrt timestamp bounding: - // if 14-digits are specified, assume min-max range boundaries - // if less than 14 are specified, assume min-max range boundaries - // based upon amount given (2001 => 20010101... - 20011231...) - // AND assume the user asked for the LATEST possible date - // within that range... - // - // ...don't ask me, I just work here. - - String startDate = null; - String endDate = null; - if(dateStr.length() == 14) { - startDate = Timestamp.earliestTimestamp().getDateStr(); - endDate = Timestamp.currentTimestamp().getDateStr(); - } else { - - // classic behavior: -// startDate = Timestamp.parseBefore(dateStr).getDateStr(); -// endDate = Timestamp.parseAfter(dateStr).getDateStr(); -// dateStr = endDate; - - // "better" behavior: - startDate = Timestamp.earliestTimestamp().getDateStr(); - endDate = Timestamp.currentTimestamp().getDateStr(); - dateStr = Timestamp.parseAfter(dateStr).getDateStr(); - - } - wbRequest.put(WaybackConstants.REQUEST_EXACT_DATE,dateStr); - wbRequest.put(WaybackConstants.REQUEST_START_DATE,startDate); - wbRequest.put(WaybackConstants.REQUEST_END_DATE,endDate); - - wbRequest.put(WaybackConstants.REQUEST_TYPE, - WaybackConstants.REQUEST_REPLAY_QUERY); - - try { - wbRequest.fixup(httpRequest); - String wbPrefix = wbRequest.getContextPrefix(); - if(urlStr.startsWith(wbPrefix)) { - wbRequest.setBetterRequestURI(urlStr); - } - wbRequest.setRequestUrl(urlStr); - - } catch (URIException e) { - e.printStackTrace(); - wbRequest = null; - } - } - return wbRequest; - } -} \ No newline at end of file Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/RequestFilter.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/RequestFilter.java 2007-07-19 21:37:00 UTC (rev 1841) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/RequestFilter.java 2007-07-19 23:30:47 UTC (rev 1842) @@ -1,162 +0,0 @@ -/* RequestFilter - * - * $Id$ - * - * Created on 1:17:08 PM Nov 8, 2005. - * - * Copyright (C) 2005 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.core; - -import java.io.IOException; -import java.util.Enumeration; -import java.util.Properties; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.archive.wayback.exception.ConfigurationException; - -/** - * Common Servlet Filter functionality for parsing incoming URL requests - * into WaybackRequest objects. - * - * @author brad - * @version $Date$, $Revision$ - */ -public abstract class RequestFilter implements Filter { - /** - * name of attribute on Request Object to store filtered WaybackRequest - */ - private static final String WMREQUEST_ATTRIBUTE = "wmrequest.attribute"; - - /** - * name of configuration for context-relative path to servlet that - * can handle the request, if a WaybackRequest is found in the request URL - */ - private static final String HANDLER_URL = "handler.url"; - - /** - * context-relative URL to servlet that handles requests - */ - private String handlerUrl = null; - - /** - * Constructor - */ - public RequestFilter() { - super(); - } - /* (non-Javadoc) - * @see javax.servlet.Filter#destroy() - */ - public void destroy() {} - - /* (non-Javadoc) - * @see javax.servlet.Filter#init(javax.servlet.FilterConfig) - */ - public void init(FilterConfig c) throws ServletException { - - Properties p = new Properties(); - ServletContext sc = c.getServletContext(); - for (Enumeration e = sc.getInitParameterNames(); e.hasMoreElements();) { - String key = (String) e.nextElement(); - p.put(key, sc.getInitParameter(key)); - } - for (Enumeration e = c.getInitParameterNames(); e.hasMoreElements();) { - String key = (String) e.nextElement(); - p.put(key, c.getInitParameter(key)); - } - try { - this.init(p); - } catch (ConfigurationException e) { - //e.printStackTrace(); - throw new ServletException(e); - } - } - - /* (non-Javadoc) - * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) - */ - public void doFilter(ServletRequest request, ServletResponse response, - FilterChain chain) throws IOException, ServletException { - if (!handle(request, response)) { - chain.doFilter(request, response); - } - } - - /** - * initialize this RequestFilter based on a Properties assembled from - * Context and Filter init-params. - * @param p - * @throws ConfigurationException - */ - public void init(Properties p) throws ConfigurationException { - PropertyConfiguration pc = new PropertyConfiguration(p); - handlerUrl = pc.getString(HANDLER_URL); - } - - /** - * @param request - * @param response - * @return boolean, true if a WaybackRequest was parsed from the URL - * @throws IOException - * @throws ServletException - */ - protected boolean handle(final ServletRequest request, - final ServletResponse response) throws IOException, - ServletException { - if (!(request instanceof HttpServletRequest)) { - return false; - } - if (!(response instanceof HttpServletResponse)) { - return false; - } - HttpServletRequest httpRequest = (HttpServletRequest) request; - //HttpServletResponse httpResponse = (HttpServletResponse) response; - WaybackRequest wbRequest = parseRequest(httpRequest); - - if (wbRequest == null) { - return false; - } - - request.setAttribute(WMREQUEST_ATTRIBUTE, wbRequest); - RequestDispatcher dispatcher = request.getRequestDispatcher(handlerUrl); - - dispatcher.forward(request, response); - - return true; - } - - /** attempt to extract a WaybackRequest from a request URL - * @param httpRequest - * @return WaybackRequest if successful, null otherwise - */ - protected abstract WaybackRequest parseRequest( - HttpServletRequest httpRequest); - -} Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackContextListener.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackContextListener.java 2007-07-19 21:37:00 UTC (rev 1841) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackContextListener.java 2007-07-19 23:30:47 UTC (rev 1842) @@ -1,79 +0,0 @@ -/* WaybackContextListener - * - * $Id$ - * - * Created on 5:17:59 PM Oct 16, 2006. - * - * 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.core; - -import java.util.Enumeration; -import java.util.Properties; - -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; -import org.archive.wayback.exception.ConfigurationException; - -/** - * - * - * @author brad - * @version $Date$, $Revision$ - */ -public class WaybackContextListener implements ServletContextListener { - - public void contextInitialized(ServletContextEvent sce) { - // attempt to initialize a ResourceStore and a ResourceIndex, - // so their worker threads can start up... - - - // throwaway WaybackLogic.. - WaybackLogic wayback = new WaybackLogic(); - - Properties p = new Properties(); - ServletContext sc = sce.getServletContext(); - for (Enumeration e = sc.getInitParameterNames(); e.hasMoreElements();) { - String key = (String) e.nextElement(); - p.put(key, sc.getInitParameter(key)); - } - wayback.init(p); - try { - wayback.getResourceStore(); - } catch (ConfigurationException e) { - // Just dump the error and try to barrel on... - e.printStackTrace(); - } - try { - wayback.getResourceIndex(); - } catch (ConfigurationException e) { - // Just dump the error and try to barrel on... - e.printStackTrace(); - } - } - - public void contextDestroyed(ServletContextEvent sce) { - // TODO: kill threads somehow? - - // I think this implies some interface for interogating implementations - // for threads, which seems like more than we need, if the daemon - // threads are just gonna get killed anyways.. - } -} Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ReplayFilter.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ReplayFilter.java 2007-07-19 21:37:00 UTC (rev 1841) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ReplayFilter.java 2007-07-19 23:30:47 UTC (rev 1842) @@ -1,116 +0,0 @@ -/* ProxyReplayFilter - * - * $Id$ - * - * Created on 6:08:59 PM Nov 14, 2005. - * - * Copyright (C) 2005 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; - -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -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.RequestFilter; -import org.archive.wayback.core.WaybackRequest; - -/** - * - * - * @author brad - * @version $Date$, $Revision$ - */ -public class ReplayFilter extends RequestFilter { - - /** - * name of attribute in web.xml 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; - - /** - * Constructor - */ - public ReplayFilter() { - super(); - } - public void init(final FilterConfig c) throws ServletException { - this.localhostNames = InetAddressUtil.getAllLocalHostNames(); - String extraLocalHostname = c.getInitParameter(LOCAL_HOSTNAME); - if ((extraLocalHostname != null) && (extraLocalHostname.length() > 0)) { - localhostNames.add(extraLocalHostname); - } - super.init(c); - } - /* (non-Javadoc) - * @see org.archive.wayback.core.RequestFilter#parseRequest(javax.servlet.http.HttpServletRequest) - */ - protected WaybackRequest parseRequest(HttpServletRequest httpRequest) { - WaybackRequest wbRequest = null; - if(isLocalRequest(httpRequest)) { - return wbRequest; - } - 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)); - - wbRequest.fixup(httpRequest); - - return wbRequest; - } - protected boolean isLocalRequest(HttpServletRequest httpRequest) { - return this.localhostNames.contains(httpRequest.getServerName()); - } - -} Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/QueryServlet.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/QueryServlet.java 2007-07-19 21:37:00 UTC (rev 1841) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/query/QueryServlet.java 2007-07-19 23:30:47 UTC (rev 1842) @@ -1,176 +0,0 @@ -/* QueryServlet - * - * $Id$ - * - * Created on 2:42:50 PM Nov 7, 2005. - * - * Copyright (C) 2005 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.query; - -import java.io.IOException; -import java.text.ParseException; -import java.util.Iterator; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.archive.wayback.WaybackConstants; -import org.archive.wayback.QueryRenderer; -import org.archive.wayback.ResultURIConverter; -import org.archive.wayback.ResourceIndex; -import org.archive.wayback.core.SearchResult; -import org.archive.wayback.core.SearchResults; -import org.archive.wayback.core.Timestamp; -import org.archive.wayback.core.WaybackRequest; -import org.archive.wayback.core.WaybackServlet; -import org.archive.wayback.exception.BadQueryException; -import org.archive.wayback.exception.ConfigurationException; -import org.archive.wayback.exception.WaybackException; - -/** - * - * - * @author brad - * @version $Date$, $Revision$ - */ -public class QueryServlet extends WaybackServlet { - /** - * - */ - private static final String WMREQUEST_ATTRIBUTE = "wmrequest.attribute"; - - private static final long serialVersionUID = 1L; - - /** - * Constructor - */ - public QueryServlet() { - super(); - } - - public void doGet(HttpServletRequest httpRequest, - HttpServletResponse httpResponse) throws IOException, - ServletException { - - WaybackRequest wbRequest = (WaybackRequest) httpRequest - .getAttribute(WMREQUEST_ATTRIBUTE); - QueryRenderer renderer; - try { - renderer = wayback.getQueryRenderer(); - } catch (ConfigurationException e) { - e.printStackTrace(); - throw new ServletException(e.getMessage()); - } - - try { - - if (wbRequest == null) { - wbRequest = wayback.getQueryParser().parseQuery(httpRequest); - } - - ResourceIndex idx = wayback.getResourceIndex(); - ResultURIConverter uriConverter = wayback.getURIConverter(); - - SearchResults results; - - results = idx.query(wbRequest); - - if (wbRequest.get(WaybackConstants.REQUEST_TYPE).equals( - WaybackConstants.REQUEST_URL_QUERY)) { - - // Annotate the closest matching hit so that it can - // be retrieved later from the xml. - try { - annotateClosest(results, wbRequest, httpRequest); - } catch (ParseException e) { - e.printStackTrace(); - } - - renderer.renderUrlResults(httpRequest, httpResponse, - wbRequest, results, uriConverter); - - } else if (wbRequest.get(WaybackConstants.REQUEST_TYPE).equals( - WaybackConstants.REQUEST_REPLAY_QUERY)) { - - // You ask what a REPLAY request is doing in a QueryServlet? - // In one mode, with a remote BDB JE index, and HTTP-XML as - // transport, the whole request is wrapped up as an OpenSearch - // query, and the results are marshalled/unmarshalled to/from - // XML. In this case, a REPLAY request may be recieved and - // handled by this class. - renderer.renderUrlResults(httpRequest, httpResponse, - wbRequest, results, uriConverter); - - } else if (wbRequest.get(WaybackConstants.REQUEST_TYPE).equals( - WaybackConstants.REQUEST_CLOSEST_QUERY)) { - - renderer.renderUrlResults(httpRequest, httpResponse, - wbRequest, results, uriConverter); - - } else if (wbRequest.get(WaybackConstants.REQUEST_TYPE).equals( - WaybackConstants.REQUEST_URL_PREFIX_QUERY)) { - - renderer.renderUrlPrefixResults(httpRequest, httpResponse, - wbRequest, results, uriConverter); - } else { - throw new BadQueryException("Unknown query " + - wbRequest.get(WaybackConstants.REQUEST_TYPE)); - } - - } catch (WaybackException wbe) { - - renderer.renderException(httpRequest, httpResponse, wbRequest, wbe); - - } - } - - // Method annotating the searchresult closest in time to the timestamp - // belonging to this request. - private void annotateClosest(SearchResults results, - WaybackRequest wbRequest, HttpServletRequest request) throws ParseException { - - SearchResult closest = null; - long closestDistance = 0; - SearchResult cur = null; - String id = request.getHeader("Proxy-Id"); - if(id == null) id = request.getRemoteAddr(); - String requestsDate = Timestamp.getTimestampForId(request.getContextPath(),id); - Timestamp wantTimestamp; - wantTimestamp = Timestamp.parseBefore(requestsDate); - - Iterator<SearchResult> itr = results.iterator(); - while (itr.hasNext()) { - cur = itr.next(); - long curDistance; - Timestamp curTimestamp = Timestamp.parseBefore(cur - .get(WaybackConstants.RESULT_CAPTURE_DATE)); - curDistance = curTimestamp.absDistanceFromTimestamp(wantTimestamp); - - if ((closest == null) || (curDistance < closestDistance)) { - closest = cur; - closestDistance = curDistance; - } - } - if(closest != null) { - closest.put("closest", "true"); - } - } -} Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/ReplayServlet.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/ReplayServlet.java 2007-07-19 21:37:00 UTC (rev 1841) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/ReplayServlet.java 2007-07-19 23:30:47 UTC (rev 1842) @@ -1,134 +0,0 @@ -/* WBReplayUIServlet - * - * Created on 2005/10/18 14:00:00 - * - * Copyright (C) 2005 Internet Archive. - * - * This file is part of the Wayback Machine (crawler.archive.org). - * - * Wayback Machine 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 Machine 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 Machine; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -package org.archive.wayback.replay; - -import java.io.IOException; -import java.util.logging.Logger; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.archive.wayback.WaybackConstants; -import org.archive.wayback.ReplayRenderer; -import org.archive.wayback.ResultURIConverter; -import org.archive.wayback.ResourceIndex; -import org.archive.wayback.ResourceStore; -import org.archive.wayback.core.CaptureSearchResults; -import org.archive.wayback.core.Resource; -import org.archive.wayback.core.SearchResult; -import org.archive.wayback.core.SearchResults; -import org.archive.wayback.core.WaybackRequest; -import org.archive.wayback.core.WaybackServlet; -import org.archive.wayback.exception.BetterRequestException; -import org.archive.wayback.exception.ConfigurationException; -import org.archive.wayback.exception.ResourceNotInArchiveException; -import org.archive.wayback.exception.WaybackException; - -/** - * Servlet implementation for Wayback Replay requests. - * - * @author Brad Tofel - * @version $Date$, $Revision$ - */ -public class ReplayServlet extends WaybackServlet { - private static final Logger LOGGER = Logger.getLogger(ReplayServlet.class - .getName()); - - private static final String WMREQUEST_ATTRIBUTE = "wmrequest.attribute"; - - private static final long serialVersionUID = 1L; - - /** - * Constructor - */ - public ReplayServlet() { - super(); - } - - public void doGet(HttpServletRequest httpRequest, - HttpServletResponse httpResponse) throws IOException, - ServletException { - - WaybackRequest wbRequest = (WaybackRequest) httpRequest - .getAttribute(WMREQUEST_ATTRIBUTE); - - ReplayRenderer renderer; - try { - renderer = wayback.getReplayRenderer(); - } catch (ConfigurationException e1) { - throw new ServletException(e1); - } - Resource resource = null; - try { - - if (wbRequest == null) { - wbRequest = wayback.getQueryParser().parseQuery(httpRequest); - } - // maybe redirect to a better URI for the request given: - wbRequest.checkBetterRequest(); - - ResourceIndex idx = wayback.getResourceIndex(); - ResourceStore store = wayback.getResourceStore(); - ResultURIConverter uriConverter = wayback.getURIConverter(); -// uriConverter.setWbRequest(wbRequest); - - SearchResults results = idx.query(wbRequest); - if(!(results instanceof CaptureSearchResults)) { - throw new ConfigurationException("Bad results..."); - } - CaptureSearchResults captureResults = (CaptureSearchResults) results; - - // TODO: check which versions are actually accessible right now? - SearchResult closest = captureResults.getClosest(wbRequest); - resource = store.retrieveResource(closest); - - renderer.renderResource(httpRequest, httpResponse, wbRequest, - closest, resource, uriConverter); - - } catch (ResourceNotInArchiveException nia) { - - LOGGER.info("NotInArchive\t" - + wbRequest.get(WaybackConstants.REQUEST_URL)); - renderer.renderException(httpRequest, httpResponse, wbRequest, nia); - - } catch (BetterRequestException bre) { - - httpResponse.sendRedirect(bre.getBetterURI()); - - } catch (WaybackException wbe) { - - renderer.renderException(httpRequest, httpResponse, wbRequest, wbe); - - } catch (Exception e) { - // TODO show something Wayback'ish to the user rather than letting - // the container deal? - throw new ServletException(e); - } finally { - if (resource != null) { - resource.close(); - } - } - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |