From: <bra...@us...> - 2007-09-28 18:43:29
|
Revision: 2014 http://archive-access.svn.sourceforge.net/archive-access/?rev=2014&view=rev Author: bradtofel Date: 2007-09-28 11:43:31 -0700 (Fri, 28 Sep 2007) Log Message: ----------- REFACTOR: changed name of WaybackContext >> AccessPoint Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/RequestParser.java 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/domainprefix/DomainPrefixRequestParser.java 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/requestparser/BaseRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/CompositeRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/FormRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/OpenSearchRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/PathRequestParser.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/NutchResourceIndex.java Added Paths: ----------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/AccessPoint.java Removed Paths: ------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/WaybackContext.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/RequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/RequestParser.java 2007-09-28 00:55:20 UTC (rev 2013) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/RequestParser.java 2007-09-28 18:43:31 UTC (rev 2014) @@ -28,7 +28,7 @@ import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.BadQueryException; -import org.archive.wayback.webapp.WaybackContext; +import org.archive.wayback.webapp.AccessPoint; /** * @@ -47,7 +47,7 @@ * @throws BadQueryException */ public abstract WaybackRequest parse(HttpServletRequest httpRequest, - WaybackContext wbContext) throws BadQueryException; + AccessPoint wbContext) throws BadQueryException; /** * @param maxRecords */ 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 2007-09-28 00:55:20 UTC (rev 2013) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/UIResults.java 2007-09-28 18:43:31 UTC (rev 2014) @@ -29,7 +29,7 @@ import javax.servlet.http.HttpServletRequest; import org.archive.wayback.util.StringFormatter; -import org.archive.wayback.webapp.WaybackContext; +import org.archive.wayback.webapp.AccessPoint; /** * @@ -189,7 +189,7 @@ */ public String getContextConfig(final String configName) { String configValue = null; - WaybackContext context = getWbRequest().getContext(); + AccessPoint context = getWbRequest().getContext(); if(context != null) { Properties configs = context.getConfigs(); if(configs != null) { 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 2007-09-28 00:55:20 UTC (rev 2013) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackRequest.java 2007-09-28 18:43:31 UTC (rev 2014) @@ -39,7 +39,7 @@ import org.archive.wayback.requestparser.OpenSearchRequestParser; import org.archive.wayback.util.ObjectFilter; import org.archive.wayback.util.StringFormatter; -import org.archive.wayback.webapp.WaybackContext; +import org.archive.wayback.webapp.AccessPoint; /** * Abstraction of all the data associated with a users request to the Wayback @@ -56,7 +56,7 @@ private String contextPrefix = null; private String serverPrefix = null; - private WaybackContext context = null; + private AccessPoint context = null; private ObjectFilter<SearchResult> exclusionFilter = null; private HashMap<String,String> filters = new HashMap<String,String>(); @@ -383,14 +383,14 @@ /** * @return the context */ - public WaybackContext getContext() { + public AccessPoint getContext() { return context; } /** * @param context the context to set */ - public void setContext(WaybackContext context) { + public void setContext(AccessPoint context) { this.context = context; } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixRequestParser.java 2007-09-28 00:55:20 UTC (rev 2013) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/domainprefix/DomainPrefixRequestParser.java 2007-09-28 18:43:31 UTC (rev 2014) @@ -35,7 +35,7 @@ import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.BadQueryException; -import org.archive.wayback.webapp.WaybackContext; +import org.archive.wayback.webapp.AccessPoint; /** * @@ -75,7 +75,7 @@ * @see org.archive.wayback.RequestParser#parse(javax.servlet.http.HttpServletRequest, org.archive.wayback.webapp.WaybackContext) */ public WaybackRequest parse(HttpServletRequest httpRequest, - WaybackContext wbContext) throws BadQueryException { + AccessPoint wbContext) throws BadQueryException { WaybackRequest wbRequest = null; String server = httpRequest.getServerName() + 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-28 00:55:20 UTC (rev 2013) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/proxy/ProxyReplayRequestParser.java 2007-09-28 18:43:31 UTC (rev 2014) @@ -35,7 +35,7 @@ import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.BadQueryException; import org.archive.wayback.requestparser.BaseRequestParser; -import org.archive.wayback.webapp.WaybackContext; +import org.archive.wayback.webapp.AccessPoint; /** * @@ -66,7 +66,7 @@ */ @Override public WaybackRequest parse(HttpServletRequest httpRequest, - WaybackContext wbContext) throws BadQueryException { + AccessPoint wbContext) throws BadQueryException { if (isLocalRequest(httpRequest)) { // local means query: let the following RequestParsers have a go Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/BaseRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/BaseRequestParser.java 2007-09-28 00:55:20 UTC (rev 2013) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/BaseRequestParser.java 2007-09-28 18:43:31 UTC (rev 2014) @@ -33,7 +33,7 @@ import org.archive.wayback.core.Timestamp; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.BadQueryException; -import org.archive.wayback.webapp.WaybackContext; +import org.archive.wayback.webapp.AccessPoint; /** * Class that implements the RequestParser interface, and also understands how @@ -133,7 +133,7 @@ * @see org.archive.wayback.RequestParser#parse(javax.servlet.http.HttpServletRequest) */ public abstract WaybackRequest parse(HttpServletRequest httpRequest, - WaybackContext wbContext) throws BadQueryException; + AccessPoint wbContext) throws BadQueryException; /** * @return the maxRecords Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/CompositeRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/CompositeRequestParser.java 2007-09-28 00:55:20 UTC (rev 2013) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/CompositeRequestParser.java 2007-09-28 18:43:31 UTC (rev 2014) @@ -29,7 +29,7 @@ import org.archive.wayback.RequestParser; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.BadQueryException; -import org.archive.wayback.webapp.WaybackContext; +import org.archive.wayback.webapp.AccessPoint; /** * @@ -64,7 +64,7 @@ * @see org.archive.wayback.RequestParser#parse(javax.servlet.http.HttpServletRequest) */ public WaybackRequest parse(HttpServletRequest httpRequest, - WaybackContext wbContext) throws BadQueryException { + AccessPoint wbContext) throws BadQueryException { WaybackRequest wbRequest = null; Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/FormRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/FormRequestParser.java 2007-09-28 00:55:20 UTC (rev 2013) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/FormRequestParser.java 2007-09-28 18:43:31 UTC (rev 2014) @@ -32,7 +32,7 @@ import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.WaybackRequest; -import org.archive.wayback.webapp.WaybackContext; +import org.archive.wayback.webapp.AccessPoint; /** * @@ -51,7 +51,7 @@ * WaybackRequest object, except the Submit button argument. */ public WaybackRequest parse(HttpServletRequest httpRequest, - WaybackContext wbContext) { + AccessPoint wbContext) { WaybackRequest wbRequest = null; @SuppressWarnings("unchecked") Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/OpenSearchRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/OpenSearchRequestParser.java 2007-09-28 00:55:20 UTC (rev 2013) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/OpenSearchRequestParser.java 2007-09-28 18:43:31 UTC (rev 2014) @@ -32,7 +32,7 @@ import org.archive.wayback.WaybackConstants; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.BadQueryException; -import org.archive.wayback.webapp.WaybackContext; +import org.archive.wayback.webapp.AccessPoint; /** * @@ -74,7 +74,7 @@ * info from the httpRequest object. */ public WaybackRequest parse(HttpServletRequest httpRequest, - WaybackContext wbContext) throws BadQueryException { + AccessPoint wbContext) throws BadQueryException { WaybackRequest wbRequest = null; @SuppressWarnings("unchecked") Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/PathRequestParser.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/PathRequestParser.java 2007-09-28 00:55:20 UTC (rev 2013) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/requestparser/PathRequestParser.java 2007-09-28 18:43:31 UTC (rev 2014) @@ -28,7 +28,7 @@ import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.BadQueryException; -import org.archive.wayback.webapp.WaybackContext; +import org.archive.wayback.webapp.AccessPoint; /** * Subclass of RequestParser that acquires key request information from the @@ -51,7 +51,7 @@ */ @Override public WaybackRequest parse(HttpServletRequest httpRequest, - WaybackContext wbContext) throws BadQueryException { + AccessPoint wbContext) throws BadQueryException { String queryString = httpRequest.getQueryString(); String origRequestPath = httpRequest.getRequestURI(); Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/NutchResourceIndex.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/NutchResourceIndex.java 2007-09-28 00:55:20 UTC (rev 2013) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/NutchResourceIndex.java 2007-09-28 18:43:31 UTC (rev 2014) @@ -36,10 +36,10 @@ import org.archive.wayback.ResourceIndex; import org.archive.wayback.WaybackConstants; +import org.archive.wayback.core.CaptureSearchResults; import org.archive.wayback.core.SearchResult; import org.archive.wayback.core.SearchResults; import org.archive.wayback.core.Timestamp; -import org.archive.wayback.core.UrlSearchResults; import org.archive.wayback.core.WaybackRequest; import org.archive.wayback.exception.AccessControlException; import org.archive.wayback.exception.BadQueryException; @@ -68,11 +68,12 @@ private static final String NUTCH_NS = "http://www.nutch.org/opensearchrss/1.0/"; private String searchUrlBase; - private DocumentBuilderFactory factory; + private DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); private DocumentBuilder builder; private static final String NUTCH_ARCNAME = "arcname"; private static final String NUTCH_ARCOFFSET = "arcoffset"; private static final String NUTCH_ARCDATE = "tstamp"; + private static final String NUTCH_ARCDATE_ALT = "arcdate"; private static final String NUTCH_DIGEST = "digest"; private static final String NUTCH_PRIMARY_TYPE = "primaryType"; private static final String NUTCH_SUB_TYPE = "subType"; @@ -95,7 +96,7 @@ LOGGER.info("initializing NutchResourceIndex..."); LOGGER.info("Using base search url " + this.searchUrlBase); - this.factory = DocumentBuilderFactory.newInstance(); +// this.factory = DocumentBuilderFactory.newInstance(); this.factory.setNamespaceAware(true); try { this.builder = this.factory.newDocumentBuilder(); @@ -129,7 +130,15 @@ e.getMessage()); } - SearchResults results = new UrlSearchResults(); + SearchResults results; + String type = wbRequest.get(WaybackConstants.REQUEST_TYPE); + if(type.equals(WaybackConstants.REQUEST_REPLAY_QUERY) || + type.equals(WaybackConstants.REQUEST_URL_QUERY)) { + results = new CaptureSearchResults(); + } else { + // TODO: this is wrong, but needs exploration into what NutchWax can actually do. + throw new BadQueryException("Unable to perform path prefix requests with this index type"); + } NodeList channel = getSearchChannel(document); NodeList nodes = getSearchItems(document); @@ -174,7 +183,8 @@ return results; } - private SearchResult elementToSearchResult(Element e) { + private SearchResult elementToSearchResult(Element e) + throws ResourceIndexNotAvailableException { SearchResult result = new SearchResult(); @@ -184,6 +194,12 @@ // The date in nutchwax is now named 'tstamp' and its // 17 characters rather than 14. Pass first 14 only. String d = getNodeNutchContent(e,NUTCH_ARCDATE); + if(d == null) { + d = getNodeNutchContent(e,NUTCH_ARCDATE_ALT); + } + if(d == null) { + throw new ResourceIndexNotAvailableException("Missing arcdate field in search results"); + } if (d.length() == 17) { d = d.substring(0, 14); } @@ -289,8 +305,8 @@ } // when searching for exacturl, we are mostly // interested in the different versions over the time - ms.append("&sort=date"); - ms.append("&reverse=true"); +// ms.append("&sort=date"); +// ms.append("&reverse=true"); } ms.append("&hitsPerPage=").append(hitsPerPage); ms.append("&start=").append(start); Copied: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/AccessPoint.java (from rev 1996, trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/WaybackContext.java) =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/AccessPoint.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/AccessPoint.java 2007-09-28 18:43:31 UTC (rev 2014) @@ -0,0 +1,447 @@ +/* WaybackContext + * + * $Id$ + * + * Created on 5:37:31 PM Apr 20, 2007. + * + * Copyright (C) 2007 Internet Archive. + * + * This file is part of wayback-webapp. + * + * wayback-webapp 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-webapp 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-webapp; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package org.archive.wayback.webapp; + +import java.io.IOException; +import java.util.Properties; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.archive.wayback.QueryRenderer; +import org.archive.wayback.ReplayDispatcher; +import org.archive.wayback.RequestParser; +import org.archive.wayback.ResourceIndex; +import org.archive.wayback.ResourceStore; +import org.archive.wayback.ResultURIConverter; +import org.archive.wayback.WaybackConstants; +import org.archive.wayback.accesscontrol.ExclusionFilterFactory; +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.UIResults; +import org.archive.wayback.core.WaybackRequest; +import org.archive.wayback.exception.AuthenticationControlException; +import org.archive.wayback.exception.BadQueryException; +import org.archive.wayback.exception.ResourceNotAvailableException; +import org.archive.wayback.exception.WaybackException; +import org.archive.wayback.util.operator.BooleanOperator; +import org.springframework.beans.factory.BeanNameAware; + +/** + * Retains all information about a particular Wayback configuration + * within a ServletContext, including holding references to the + * implementation instances of the primary Wayback classes: + * + * ResourceIndex + * ResourceStore + * QueryUI + * ReplayUI + * + * @author brad + * @version $Date$, $Revision$ + */ +public class AccessPoint implements RequestContext, BeanNameAware { + + private boolean useServerName = false; + private int contextPort = 0; + private String contextName = null; + private ResourceIndex index = null; + private ResourceStore store = null; + private ReplayDispatcher replay = null; + private QueryRenderer query = null; + private RequestParser parser = null; + private ResultURIConverter uriConverter = null; + private Properties configs = null; + private ExclusionFilterFactory exclusionFactory = null; + private BooleanOperator<WaybackRequest> authentication = null; + + /** + * + */ + public AccessPoint() { + + } + + /* (non-Javadoc) + * @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String) + */ + public void setBeanName(String beanName) { + // TODO Auto-generated method stub + this.contextName = ""; + int idx = beanName.indexOf(":"); + if(idx > -1) { + contextPort = Integer.valueOf(beanName.substring(0,idx)); + contextName = beanName.substring(idx + 1); + } else { + try { + this.contextPort = Integer.valueOf(beanName); + } catch(NumberFormatException e) { + e.printStackTrace(); + } + } + } + /** + * @param httpRequest + * @return the prefix of paths recieved by this server that are handled by + * this WaybackContext, including the trailing '/' + */ + public String getContextPath(HttpServletRequest httpRequest) { +// if(contextPort != 0) { +// return httpRequest.getContextPath(); +// } + String httpContextPath = httpRequest.getContextPath(); + if(contextName.length() == 0) { + return httpContextPath + "/"; + } + return httpContextPath + "/" + contextName + "/"; + } + + /** + * @param httpRequest + * @param includeQuery + * @return the portion of the request following the path to this context + * without leading '/' + */ + private String translateRequest(HttpServletRequest httpRequest, + boolean includeQuery) { + + String origRequestPath = httpRequest.getRequestURI(); + if(includeQuery) { + String queryString = httpRequest.getQueryString(); + if (queryString != null) { + origRequestPath += "?" + queryString; + } + } + String contextPath = getContextPath(httpRequest); + if (!origRequestPath.startsWith(contextPath)) { + return null; + } + return origRequestPath.substring(contextPath.length()); + } + + /** + * @param httpRequest + * @return the portion of the request following the path to this context, + * including any query information,without leading '/' + */ + public String translateRequestPathQuery(HttpServletRequest httpRequest) { + return translateRequest(httpRequest,true); + } + + /** + * @param httpRequest + * @return the portion of the request following the path to this context, + * excluding any query information, without leading '/' + */ + public String translateRequestPath(HttpServletRequest httpRequest) { + return translateRequest(httpRequest,false); + } + + /** + * Construct an absolute URL that points to the root of the context that + * recieved the request, including a trailing "/". + * + * @return String absolute URL pointing to the Context root where the + * request was revieved. + */ + private String getAbsoluteContextPrefix(HttpServletRequest httpRequest, + boolean useRequestServer) { + + StringBuilder prefix = new StringBuilder(); + prefix.append(WaybackConstants.HTTP_URL_PREFIX); + String waybackPort = null; + if(useRequestServer) { + prefix.append(httpRequest.getLocalName()); + waybackPort = String.valueOf(httpRequest.getLocalPort()); + } else { + prefix.append(httpRequest.getServerName()); + waybackPort = String.valueOf(httpRequest.getServerPort()); + } + if (!waybackPort.equals(WaybackConstants.HTTP_DEFAULT_PORT)) { + prefix.append(":").append(waybackPort); + } + String contextPath = getContextPath(httpRequest); +// if(contextPath.length() > 1) { +// prefix.append(contextPath); +// } else { +// prefix.append(contextPath); +// } + prefix.append(contextPath); + return prefix.toString(); + } + + /** + * @param httpRequest + * @return absolute URL pointing to the base of this WaybackContext, using + * Server and port information from the HttpServletRequest argument. + */ + public String getAbsoluteServerPrefix(HttpServletRequest httpRequest) { + return getAbsoluteContextPrefix(httpRequest, true); + } + + /** + * @param httpRequest + * @return absolute URL pointing to the base of this WaybackContext, using + * Canonical server and port information. + */ + public String getAbsoluteLocalPrefix(HttpServletRequest httpRequest) { + return getAbsoluteContextPrefix(httpRequest, useServerName); + } + + private boolean dispatchLocal(HttpServletRequest httpRequest, + HttpServletResponse httpResponse) + throws ServletException, IOException { + + WaybackRequest wbRequest = new WaybackRequest(); + wbRequest.setContextPrefix(getAbsoluteLocalPrefix(httpRequest)); + wbRequest.setContext(this); + UIResults uiResults = new UIResults(wbRequest); + String translated = "/" + translateRequestPathQuery(httpRequest); + uiResults.storeInRequest(httpRequest,translated); + RequestDispatcher dispatcher = null; +// // special case for the front '/' page: +// if(translated.length() == 0) { +// translated = "/"; +// } else { +// translated = "/" + translated; +// } + dispatcher = httpRequest.getRequestDispatcher(translated); + if(dispatcher != null) { + dispatcher.forward(httpRequest, httpResponse); + return true; + } + return false; + } + + /** + * @param httpRequest + * @param httpResponse + * @return true if the request was actually handled + * @throws ServletException + * @throws IOException + */ + public boolean handleRequest(HttpServletRequest httpRequest, + HttpServletResponse httpResponse) + throws ServletException, IOException { + + WaybackRequest wbRequest = null; + boolean handled = false; + + try { + wbRequest = parser.parse(httpRequest, this); + + if(wbRequest != null) { + wbRequest.setContext(this); + handled = true; + wbRequest.setContextPrefix(getAbsoluteLocalPrefix(httpRequest)); + if(authentication != null) { + if(!authentication.isTrue(wbRequest)) { + throw new AuthenticationControlException("Not authorized"); + } + } + + if(exclusionFactory != null) { + wbRequest.setExclusionFilter(exclusionFactory.get()); + } + if(wbRequest.isReplayRequest()) { + + handleReplay(wbRequest,httpRequest,httpResponse); + + } else { + + handleQuery(wbRequest,httpRequest,httpResponse); + } + } else { + handled = dispatchLocal(httpRequest,httpResponse); + } + + } catch (BadQueryException e) { + query.renderException(httpRequest, httpResponse, wbRequest, e); + } catch (AuthenticationControlException e) { + query.renderException(httpRequest, httpResponse, wbRequest, e); + } + + return handled; + } + + private void handleReplay(WaybackRequest wbRequest, + HttpServletRequest httpRequest, HttpServletResponse httpResponse) + throws IOException, ServletException { + Resource resource = null; + try { + SearchResults results = index.query(wbRequest); + if(!(results instanceof CaptureSearchResults)) { + throw new ResourceNotAvailableException("Bad results..."); + } + CaptureSearchResults captureResults = (CaptureSearchResults) results; + + // TODO: check which versions are actually accessible right now? + SearchResult closest = captureResults.getClosest(wbRequest); + resource = store.retrieveResource(closest); + + replay.renderResource(httpRequest, httpResponse, wbRequest, + closest, resource, uriConverter, captureResults); + } catch(WaybackException e) { + replay.renderException(httpRequest, httpResponse, wbRequest, e); + } finally { + if(resource != null) { + resource.close(); + } + } + } + + private void handleQuery(WaybackRequest wbRequest, + HttpServletRequest httpRequest, HttpServletResponse httpResponse) + throws ServletException, IOException { + + try { + SearchResults results = index.query(wbRequest); + if(results.getResultsType().equals( + WaybackConstants.RESULTS_TYPE_CAPTURE)) { + + query.renderUrlResults(httpRequest,httpResponse,wbRequest, + results,uriConverter); + + } else { + query.renderUrlPrefixResults(httpRequest,httpResponse,wbRequest, + results,uriConverter); + } + } catch(WaybackException e) { + query.renderException(httpRequest, httpResponse, wbRequest, e); + } + } + + /** + * @param contextPort the contextPort to set + */ + public void setContextPort(int contextPort) { + this.contextPort = contextPort; + } + + /** + * @param contextName the contextName to set + */ + public void setContextName(String contextName) { + this.contextName = contextName; + } + + /** + * @param index the index to set + */ + public void setIndex(ResourceIndex index) { + this.index = index; + } + + /** + * @param store the store to set + */ + public void setStore(ResourceStore store) { + this.store = store; + } + + /** + * @param replay the replay to set + */ + public void setReplay(ReplayDispatcher replay) { + this.replay = replay; + } + + /** + * @param query the query to set + */ + public void setQuery(QueryRenderer query) { + this.query = query; + } + + /** + * @param parser the parser to set + */ + public void setParser(RequestParser parser) { + this.parser = parser; + } + + /** + * @param uriConverter the uriConverter to set + */ + public void setUriConverter(ResultURIConverter uriConverter) { + this.uriConverter = uriConverter; + } + + + /** + * @return the contextPort + */ + public int getContextPort() { + return contextPort; + } + + /** + * @return the configs + */ + public Properties getConfigs() { + return configs; + } + + /** + * @param configs the configs to set + */ + public void setConfigs(Properties configs) { + this.configs = configs; + } + + /** + * @return the useServerName + */ + public boolean isUseServerName() { + return useServerName; + } + + /** + * @param useServerName the useServerName to set + */ + public void setUseServerName(boolean useServerName) { + this.useServerName = useServerName; + } + + public ExclusionFilterFactory getExclusionFactory() { + return exclusionFactory; + } + + public void setExclusionFactory(ExclusionFilterFactory exclusionFactory) { + this.exclusionFactory = exclusionFactory; + } + + public BooleanOperator<WaybackRequest> getAuthentication() { + return authentication; + } + + public void setAuthentication(BooleanOperator<WaybackRequest> authentication) { + this.authentication = authentication; + } +} Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/WaybackContext.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/WaybackContext.java 2007-09-28 00:55:20 UTC (rev 2013) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/WaybackContext.java 2007-09-28 18:43:31 UTC (rev 2014) @@ -1,447 +0,0 @@ -/* WaybackContext - * - * $Id$ - * - * Created on 5:37:31 PM Apr 20, 2007. - * - * Copyright (C) 2007 Internet Archive. - * - * This file is part of wayback-webapp. - * - * wayback-webapp 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-webapp 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-webapp; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -package org.archive.wayback.webapp; - -import java.io.IOException; -import java.util.Properties; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.archive.wayback.QueryRenderer; -import org.archive.wayback.ReplayDispatcher; -import org.archive.wayback.RequestParser; -import org.archive.wayback.ResourceIndex; -import org.archive.wayback.ResourceStore; -import org.archive.wayback.ResultURIConverter; -import org.archive.wayback.WaybackConstants; -import org.archive.wayback.accesscontrol.ExclusionFilterFactory; -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.UIResults; -import org.archive.wayback.core.WaybackRequest; -import org.archive.wayback.exception.AuthenticationControlException; -import org.archive.wayback.exception.BadQueryException; -import org.archive.wayback.exception.ResourceNotAvailableException; -import org.archive.wayback.exception.WaybackException; -import org.archive.wayback.util.operator.BooleanOperator; -import org.springframework.beans.factory.BeanNameAware; - -/** - * Retains all information about a particular Wayback configuration - * within a ServletContext, including holding references to the - * implementation instances of the primary Wayback classes: - * - * ResourceIndex - * ResourceStore - * QueryUI - * ReplayUI - * - * @author brad - * @version $Date$, $Revision$ - */ -public class WaybackContext implements RequestContext, BeanNameAware { - - private boolean useServerName = false; - private int contextPort = 0; - private String contextName = null; - private ResourceIndex index = null; - private ResourceStore store = null; - private ReplayDispatcher replay = null; - private QueryRenderer query = null; - private RequestParser parser = null; - private ResultURIConverter uriConverter = null; - private Properties configs = null; - private ExclusionFilterFactory exclusionFactory = null; - private BooleanOperator<WaybackRequest> authentication = null; - - /** - * - */ - public WaybackContext() { - - } - - /* (non-Javadoc) - * @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String) - */ - public void setBeanName(String beanName) { - // TODO Auto-generated method stub - this.contextName = ""; - int idx = beanName.indexOf(":"); - if(idx > -1) { - contextPort = Integer.valueOf(beanName.substring(0,idx)); - contextName = beanName.substring(idx + 1); - } else { - try { - this.contextPort = Integer.valueOf(beanName); - } catch(NumberFormatException e) { - e.printStackTrace(); - } - } - } - /** - * @param httpRequest - * @return the prefix of paths recieved by this server that are handled by - * this WaybackContext, including the trailing '/' - */ - public String getContextPath(HttpServletRequest httpRequest) { -// if(contextPort != 0) { -// return httpRequest.getContextPath(); -// } - String httpContextPath = httpRequest.getContextPath(); - if(contextName.length() == 0) { - return httpContextPath + "/"; - } - return httpContextPath + "/" + contextName + "/"; - } - - /** - * @param httpRequest - * @param includeQuery - * @return the portion of the request following the path to this context - * without leading '/' - */ - private String translateRequest(HttpServletRequest httpRequest, - boolean includeQuery) { - - String origRequestPath = httpRequest.getRequestURI(); - if(includeQuery) { - String queryString = httpRequest.getQueryString(); - if (queryString != null) { - origRequestPath += "?" + queryString; - } - } - String contextPath = getContextPath(httpRequest); - if (!origRequestPath.startsWith(contextPath)) { - return null; - } - return origRequestPath.substring(contextPath.length()); - } - - /** - * @param httpRequest - * @return the portion of the request following the path to this context, - * including any query information,without leading '/' - */ - public String translateRequestPathQuery(HttpServletRequest httpRequest) { - return translateRequest(httpRequest,true); - } - - /** - * @param httpRequest - * @return the portion of the request following the path to this context, - * excluding any query information, without leading '/' - */ - public String translateRequestPath(HttpServletRequest httpRequest) { - return translateRequest(httpRequest,false); - } - - /** - * Construct an absolute URL that points to the root of the context that - * recieved the request, including a trailing "/". - * - * @return String absolute URL pointing to the Context root where the - * request was revieved. - */ - private String getAbsoluteContextPrefix(HttpServletRequest httpRequest, - boolean useRequestServer) { - - StringBuilder prefix = new StringBuilder(); - prefix.append(WaybackConstants.HTTP_URL_PREFIX); - String waybackPort = null; - if(useRequestServer) { - prefix.append(httpRequest.getLocalName()); - waybackPort = String.valueOf(httpRequest.getLocalPort()); - } else { - prefix.append(httpRequest.getServerName()); - waybackPort = String.valueOf(httpRequest.getServerPort()); - } - if (!waybackPort.equals(WaybackConstants.HTTP_DEFAULT_PORT)) { - prefix.append(":").append(waybackPort); - } - String contextPath = getContextPath(httpRequest); -// if(contextPath.length() > 1) { -// prefix.append(contextPath); -// } else { -// prefix.append(contextPath); -// } - prefix.append(contextPath); - return prefix.toString(); - } - - /** - * @param httpRequest - * @return absolute URL pointing to the base of this WaybackContext, using - * Server and port information from the HttpServletRequest argument. - */ - public String getAbsoluteServerPrefix(HttpServletRequest httpRequest) { - return getAbsoluteContextPrefix(httpRequest, true); - } - - /** - * @param httpRequest - * @return absolute URL pointing to the base of this WaybackContext, using - * Canonical server and port information. - */ - public String getAbsoluteLocalPrefix(HttpServletRequest httpRequest) { - return getAbsoluteContextPrefix(httpRequest, useServerName); - } - - private boolean dispatchLocal(HttpServletRequest httpRequest, - HttpServletResponse httpResponse) - throws ServletException, IOException { - - WaybackRequest wbRequest = new WaybackRequest(); - wbRequest.setContextPrefix(getAbsoluteLocalPrefix(httpRequest)); - wbRequest.setContext(this); - UIResults uiResults = new UIResults(wbRequest); - String translated = "/" + translateRequestPathQuery(httpRequest); - uiResults.storeInRequest(httpRequest,translated); - RequestDispatcher dispatcher = null; -// // special case for the front '/' page: -// if(translated.length() == 0) { -// translated = "/"; -// } else { -// translated = "/" + translated; -// } - dispatcher = httpRequest.getRequestDispatcher(translated); - if(dispatcher != null) { - dispatcher.forward(httpRequest, httpResponse); - return true; - } - return false; - } - - /** - * @param httpRequest - * @param httpResponse - * @return true if the request was actually handled - * @throws ServletException - * @throws IOException - */ - public boolean handleRequest(HttpServletRequest httpRequest, - HttpServletResponse httpResponse) - throws ServletException, IOException { - - WaybackRequest wbRequest = null; - boolean handled = false; - - try { - wbRequest = parser.parse(httpRequest, this); - - if(wbRequest != null) { - wbRequest.setContext(this); - handled = true; - wbRequest.setContextPrefix(getAbsoluteLocalPrefix(httpRequest)); - if(authentication != null) { - if(!authentication.isTrue(wbRequest)) { - throw new AuthenticationControlException("Not authorized"); - } - } - - if(exclusionFactory != null) { - wbRequest.setExclusionFilter(exclusionFactory.get()); - } - if(wbRequest.isReplayRequest()) { - - handleReplay(wbRequest,httpRequest,httpResponse); - - } else { - - handleQuery(wbRequest,httpRequest,httpResponse); - } - } else { - handled = dispatchLocal(httpRequest,httpResponse); - } - - } catch (BadQueryException e) { - query.renderException(httpRequest, httpResponse, wbRequest, e); - } catch (AuthenticationControlException e) { - query.renderException(httpRequest, httpResponse, wbRequest, e); - } - - return handled; - } - - private void handleReplay(WaybackRequest wbRequest, - HttpServletRequest httpRequest, HttpServletResponse httpResponse) - throws IOException, ServletException { - Resource resource = null; - try { - SearchResults results = index.query(wbRequest); - if(!(results instanceof CaptureSearchResults)) { - throw new ResourceNotAvailableException("Bad results..."); - } - CaptureSearchResults captureResults = (CaptureSearchResults) results; - - // TODO: check which versions are actually accessible right now? - SearchResult closest = captureResults.getClosest(wbRequest); - resource = store.retrieveResource(closest); - - replay.renderResource(httpRequest, httpResponse, wbRequest, - closest, resource, uriConverter, captureResults); - } catch(WaybackException e) { - replay.renderException(httpRequest, httpResponse, wbRequest, e); - } finally { - if(resource != null) { - resource.close(); - } - } - } - - private void handleQuery(WaybackRequest wbRequest, - HttpServletRequest httpRequest, HttpServletResponse httpResponse) - throws ServletException, IOException { - - try { - SearchResults results = index.query(wbRequest); - if(results.getResultsType().equals( - WaybackConstants.RESULTS_TYPE_CAPTURE)) { - - query.renderUrlResults(httpRequest,httpResponse,wbRequest, - results,uriConverter); - - } else { - query.renderUrlPrefixResults(httpRequest,httpResponse,wbRequest, - results,uriConverter); - } - } catch(WaybackException e) { - query.renderException(httpRequest, httpResponse, wbRequest, e); - } - } - - /** - * @param contextPort the contextPort to set - */ - public void setContextPort(int contextPort) { - this.contextPort = contextPort; - } - - /** - * @param contextName the contextName to set - */ - public void setContextName(String contextName) { - this.contextName = contextName; - } - - /** - * @param index the index to set - */ - public void setIndex(ResourceIndex index) { - this.index = index; - } - - /** - * @param store the store to set - */ - public void setStore(ResourceStore store) { - this.store = store; - } - - /** - * @param replay the replay to set - */ - public void setReplay(ReplayDispatcher replay) { - this.replay = replay; - } - - /** - * @param query the query to set - */ - public void setQuery(QueryRenderer query) { - this.query = query; - } - - /** - * @param parser the parser to set - */ - public void setParser(RequestParser parser) { - this.parser = parser; - } - - /** - * @param uriConverter the uriConverter to set - */ - public void setUriConverter(ResultURIConverter uriConverter) { - this.uriConverter = uriConverter; - } - - - /** - * @return the contextPort - */ - public int getContextPort() { - return contextPort; - } - - /** - * @return the configs - */ - public Properties getConfigs() { - return configs; - } - - /** - * @param configs the configs to set - */ - public void setConfigs(Properties configs) { - this.configs = configs; - } - - /** - * @return the useServerName - */ - public boolean isUseServerName() { - return useServerName; - } - - /** - * @param useServerName the useServerName to set - */ - public void setUseServerName(boolean useServerName) { - this.useServerName = useServerName; - } - - public ExclusionFilterFactory getExclusionFactory() { - return exclusionFactory; - } - - public void setExclusionFactory(ExclusionFilterFactory exclusionFactory) { - this.exclusionFactory = exclusionFactory; - } - - public BooleanOperator<WaybackRequest> getAuthentication() { - return authentication; - } - - public void setAuthentication(BooleanOperator<WaybackRequest> authentication) { - this.authentication = authentication; - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |