From: <bra...@us...> - 2007-07-16 23:07:01
|
Revision: 1784 http://archive-access.svn.sourceforge.net/archive-access/?rev=1784&view=rev Author: bradtofel Date: 2007-07-16 16:07:00 -0700 (Mon, 16 Jul 2007) Log Message: ----------- REFACTOR: initial rev of new core Wayback object which binds incoming requests to a WaybackContext, using Spring to construct appropriately configured WaybackContexts. Added Paths: ----------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java 2007-07-16 23:07:00 UTC (rev 1784) @@ -0,0 +1,122 @@ +/* RequestMapper + * + * $Id$ + * + * Created on 5:36:36 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.util.logging.Logger; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; + +import org.archive.wayback.exception.ConfigurationException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.xml.XmlBeanFactory; +import org.springframework.core.io.FileSystemResource; +import org.springframework.core.io.Resource; + +/** + * RequestMapper accepts a request, and maps that request to + * a WaybackContext suitable for that request. + * + * This object is a singleton, and the class provides methods for constructing + * and accessing the singleton. + * + * @author brad + * @version $Date$, $Revision$ + */ +public class RequestMapper { + private static final Logger LOGGER = Logger.getLogger(RequestMapper.class + .getName()); + + private final static String PORT_SEPARATOR = ":"; + + + private final static String CONFIG_PATH = "config-path"; +// private WaybackContext defaultContext = null; +// private ServletContext servletContext = null; + + private BeanFactory factory = null; + /** + * @param configPath + * @param servletContext + * @throws ConfigurationException + */ + public RequestMapper(ServletContext servletContext) throws ConfigurationException { + +// this.servletContext = servletContext; + String configPath = servletContext.getInitParameter(CONFIG_PATH); + if(configPath == null) { + throw new ConfigurationException("Missing " + CONFIG_PATH + + " parameter"); + } + String resolvedPath = servletContext.getRealPath(configPath); + Resource resource = new FileSystemResource(resolvedPath); + factory = new XmlBeanFactory(resource); + } + + private String getContextID(HttpServletRequest request) { + String requestPath = request.getRequestURI(); +// String absolutePath = servletContext.getRealPath(requestPath); +// File tmpFile = new File(absolutePath); +// if(tmpFile.exists()) { +// return null; +// } + String collection = ""; + if(requestPath.startsWith("/")) { + int secondSlash = requestPath.indexOf("/",1); + if(secondSlash != -1) { + collection = PORT_SEPARATOR + + requestPath.substring(1,requestPath.indexOf("/",1)); + } + } + return String.valueOf(request.getLocalPort()) + collection; + } + + /** + * @param request + * @return WaybackContext that handles the specific incoming HTTP request + */ + public WaybackContext mapContext(HttpServletRequest request) { + + WaybackContext context = null; + String contextID = String.valueOf(request.getLocalPort()); + if(factory.containsBean(contextID)) { + context = (WaybackContext) factory.getBean(contextID); + } else { + contextID = getContextID(request); + if(factory.containsBean(contextID)) { + context = (WaybackContext) factory.getBean(contextID); + } + } + return context; + } + + /** + * clean up all WaybackContexts, which should release resources gracefully. + */ + public void destroy() { + LOGGER.info("shutting down contexts..."); + //TODO: shut everything down + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bra...@us...> - 2007-07-19 20:55:40
|
Revision: 1819 http://archive-access.svn.sourceforge.net/archive-access/?rev=1819&view=rev Author: bradtofel Date: 2007-07-19 13:55:41 -0700 (Thu, 19 Jul 2007) Log Message: ----------- FEATURE: now instantiates all singletons at startup. This may prove to be a performance hit that we're not happy with. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java 2007-07-19 20:54:25 UTC (rev 1818) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java 2007-07-19 20:55:41 UTC (rev 1819) @@ -30,7 +30,6 @@ import javax.servlet.http.HttpServletRequest; import org.archive.wayback.exception.ConfigurationException; -import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; @@ -56,7 +55,7 @@ // private WaybackContext defaultContext = null; // private ServletContext servletContext = null; - private BeanFactory factory = null; + private XmlBeanFactory factory = null; /** * @param configPath * @param servletContext @@ -73,6 +72,7 @@ String resolvedPath = servletContext.getRealPath(configPath); Resource resource = new FileSystemResource(resolvedPath); factory = new XmlBeanFactory(resource); + factory.preInstantiateSingletons(); } private String getContextID(HttpServletRequest request) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bra...@us...> - 2007-10-17 21:26:28
|
Revision: 2057 http://archive-access.svn.sourceforge.net/archive-access/?rev=2057&view=rev Author: bradtofel Date: 2007-10-17 14:26:32 -0700 (Wed, 17 Oct 2007) Log Message: ----------- BUGFIX: somehow was not removing context deploy name from incoming requests to map to the correct AccessPoint when deploying as non-ROOT context. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java 2007-10-15 22:01:17 UTC (rev 2056) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java 2007-10-17 21:26:32 UTC (rev 2057) @@ -77,11 +77,10 @@ private String getContextID(HttpServletRequest request) { String requestPath = request.getRequestURI(); -// String absolutePath = servletContext.getRealPath(requestPath); -// File tmpFile = new File(absolutePath); -// if(tmpFile.exists()) { -// return null; -// } + String contextPath = request.getContextPath(); + if(requestPath.startsWith(contextPath)) { + requestPath = requestPath.substring(contextPath.length()); + } String collection = ""; if(requestPath.startsWith("/")) { int secondSlash = requestPath.indexOf("/",1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bra...@us...> - 2007-11-28 03:11:09
|
Revision: 2088 http://archive-access.svn.sourceforge.net/archive-access/?rev=2088&view=rev Author: bradtofel Date: 2007-11-27 19:11:14 -0800 (Tue, 27 Nov 2007) Log Message: ----------- FEATURE: allow parsing into base of AccessPoints when trailing slash is omitted from path Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java 2007-11-28 03:08:09 UTC (rev 2087) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java 2007-11-28 03:11:14 UTC (rev 2088) @@ -24,6 +24,7 @@ */ package org.archive.wayback.webapp; +import java.util.ArrayList; import java.util.logging.Logger; import javax.servlet.ServletContext; @@ -50,6 +51,8 @@ private final static String PORT_SEPARATOR = ":"; + private final static String ACCESS_POINT_CLASSNAME = + "org.archive.wayback.webapp.AccessPoint"; private final static String CONFIG_PATH = "config-path"; // private WaybackContext defaultContext = null; @@ -87,6 +90,8 @@ if(secondSlash != -1) { collection = PORT_SEPARATOR + requestPath.substring(1,requestPath.indexOf("/",1)); + } else { + collection = PORT_SEPARATOR + requestPath.substring(1); } } return String.valueOf(request.getLocalPort()) + collection; @@ -99,14 +104,14 @@ public RequestContext mapContext(HttpServletRequest request) { RequestContext context = null; - String contextID = String.valueOf(request.getLocalPort()); - if(factory.containsBean(contextID)) { - Object o = factory.getBean(contextID); + String portStr = String.valueOf(request.getLocalPort()); + if(factory.containsBean(portStr)) { + Object o = factory.getBean(portStr); if(o instanceof RequestContext) { context = (RequestContext) o; } } else { - contextID = getContextID(request); + String contextID = getContextID(request); if(factory.containsBean(contextID)) { Object o = factory.getBean(contextID); if(o instanceof RequestContext) { @@ -114,9 +119,31 @@ } } } + if(context == null) { + ArrayList<String> names = getAccessPointNamesOnPort(portStr); + request.setAttribute("AccessPointNames", names); + } return context; } + @SuppressWarnings("unchecked") + public ArrayList<String> getAccessPointNamesOnPort(String portStr) { + ArrayList<String> names = new ArrayList<String>(); + try { + Class accessPointClass = Class.forName(ACCESS_POINT_CLASSNAME); + String[] apNames = factory.getBeanNamesForType(accessPointClass); + String portStrColon = portStr + ":"; + for(String apName : apNames) { + if(apName.startsWith(portStrColon)) { + names.add(apName.substring(portStrColon.length())); + } + } + } catch (ClassNotFoundException e) { + // boy, we're in trouble now.. + e.printStackTrace(); + } + return names; + } /** * clean up all WaybackContexts, which should release resources gracefully. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bra...@us...> - 2008-04-11 04:10:22
|
Revision: 2235 http://archive-access.svn.sourceforge.net/archive-access/?rev=2235&view=rev Author: bradtofel Date: 2008-04-10 21:10:27 -0700 (Thu, 10 Apr 2008) Log Message: ----------- FEATURE: implemented destroy() method, which locates all AccessPoints in the Spring configuration, and shuts each of them down. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java 2008-04-11 04:09:26 UTC (rev 2234) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/webapp/RequestMapper.java 2008-04-11 04:10:27 UTC (rev 2235) @@ -24,7 +24,11 @@ */ package org.archive.wayback.webapp; +import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; import java.util.logging.Logger; import javax.servlet.ServletContext; @@ -147,8 +151,41 @@ /** * clean up all WaybackContexts, which should release resources gracefully. */ + @SuppressWarnings("unchecked") public void destroy() { LOGGER.info("shutting down contexts..."); - //TODO: shut everything down + Class accessPointClass; + try { + accessPointClass = Class.forName(ACCESS_POINT_CLASSNAME); + Map beanMap = factory.getBeansOfType(accessPointClass); + Iterator beanNameItr = beanMap.keySet().iterator(); + Collection accessPoints = beanMap.values(); + while(beanNameItr.hasNext()) { + String apName = (String) beanNameItr.next(); + AccessPoint ap = (AccessPoint) beanMap.get(apName); + try { + LOGGER.info("Shutting down AccessPoint " + apName); + ap.shutdown(); + LOGGER.info("Successfully shut down " + apName); + } catch (IOException e) { + e.printStackTrace(); + } + } + for(Object o : accessPoints) { + if(o instanceof AccessPoint) { + AccessPoint ap = (AccessPoint) o; + try { + ap.shutdown(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |