From: <bra...@us...> - 2007-07-20 01:23:17
|
Revision: 1848 http://archive-access.svn.sourceforge.net/archive-access/?rev=1848&view=rev Author: bradtofel Date: 2007-07-19 18:23:19 -0700 (Thu, 19 Jul 2007) Log Message: ----------- REFACTOR: changed base class from WaybackServlet to org.archive.wayback.webapp.ServletRequestContext, and added getter/setter for Spring configuration Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/http/ArcProxyServlet.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/http/FileLocationDBServlet.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/http/ArcProxyServlet.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/http/ArcProxyServlet.java 2007-07-20 01:22:25 UTC (rev 1847) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/http/ArcProxyServlet.java 2007-07-20 01:23:19 UTC (rev 1848) @@ -35,9 +35,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.archive.wayback.core.WaybackServlet; -import org.archive.wayback.exception.ConfigurationException; import org.archive.wayback.resourcestore.http.FileLocationDB; +import org.archive.wayback.webapp.ServletRequestContext; import com.sleepycat.je.DatabaseException; @@ -47,7 +46,7 @@ * @author brad * @version $Date$, $Revision$ */ -public class ArcProxyServlet extends WaybackServlet { +public class ArcProxyServlet extends ServletRequestContext { private static final String RANGE_HTTP_HEADER = "Range"; private static final String CONTENT_TYPE_HEADER = "Content-Type"; @@ -56,31 +55,14 @@ * */ private static final long serialVersionUID = 1L; - - private FileLocationDB getLocationDB() throws ServletException { - try { - return (FileLocationDB) wayback.getCachedSingleton( - FileLocationDB.FILE_LOCATION_DB_CLASS); - } catch (ConfigurationException e) { - throw new ServletException(e); - } - } - public void destroy() { - try { - getLocationDB().shutdownDB(); - } catch (DatabaseException e) { - e.printStackTrace(); - } catch (ServletException e) { - e.printStackTrace(); - } - } - public void doGet(HttpServletRequest httpRequest, + private FileLocationDB locationDB = null; + + public boolean handleRequest(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { - FileLocationDB locationDB = getLocationDB(); try { - String arc = httpRequest.getPathTranslated(); + String arc = httpRequest.getRequestURI(); arc = arc.substring(arc.lastIndexOf('/')+1); if(arc.length() == 0) { throw new ParseException("no/invalid arc",0); @@ -123,7 +105,20 @@ httpResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage()); } + return true; } + /** + * @return the locationDB + */ + public FileLocationDB getLocationDB() { + return locationDB; + } + /** + * @param locationDB the locationDB to set + */ + public void setLocationDB(FileLocationDB locationDB) { + this.locationDB = locationDB; + } } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/http/FileLocationDBServlet.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/http/FileLocationDBServlet.java 2007-07-20 01:22:25 UTC (rev 1847) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/http/FileLocationDBServlet.java 2007-07-20 01:23:19 UTC (rev 1848) @@ -34,9 +34,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.archive.wayback.core.WaybackServlet; -import org.archive.wayback.exception.ConfigurationException; import org.archive.wayback.resourcestore.http.FileLocationDB; +import org.archive.wayback.webapp.ServletRequestContext; import com.sleepycat.je.DatabaseException; @@ -46,7 +45,7 @@ * @author brad * @version $Date$, $Revision$ */ -public class FileLocationDBServlet extends WaybackServlet { +public class FileLocationDBServlet extends ServletRequestContext { protected static final String OPERATION_ARGUMENT = "operation"; protected static final String NAME_ARGUMENT = "name"; @@ -61,45 +60,13 @@ protected static final String NO_LOCATION_PREFIX = "ERROR No locations for"; private static final long serialVersionUID = 1L; + private FileLocationDB locationDB = null; - - /** - * Constructor - */ - public FileLocationDBServlet() { - super(); - } - - private FileLocationDB getLocationDB() throws ServletException { - try { - return (FileLocationDB) wayback.getCachedSingleton( - FileLocationDB.FILE_LOCATION_DB_CLASS); - } catch (ConfigurationException e) { - throw new ServletException(e); - } - } - - public void destroy() { - try { - getLocationDB().shutdownDB(); - } catch (DatabaseException e) { - e.printStackTrace(); - } catch (ServletException e) { - e.printStackTrace(); - } - } - - public void doPost(HttpServletRequest httpRequest, + public boolean handleRequest(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { - doGet(httpRequest,httpResponse); - } - - public void doGet(HttpServletRequest httpRequest, - HttpServletResponse httpResponse) throws IOException, - ServletException { - - Map queryMap = httpRequest.getParameterMap(); + @SuppressWarnings("unchecked") + Map<String,String[]> queryMap = httpRequest.getParameterMap(); String message; FileLocationDB locationDB = getLocationDB(); try { @@ -113,9 +80,11 @@ httpResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); } + return true; } - private String handleOperation(FileLocationDB locationDB, Map queryMap) + private String handleOperation(FileLocationDB locationDB, + Map<String,String[]> queryMap) throws ParseException { String operation = getRequiredMapParam(queryMap, OPERATION_ARGUMENT); @@ -177,10 +146,6 @@ } catch (DatabaseException e) { e.printStackTrace(); message = e.getMessage(); - } catch (ServletException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - message = e.getMessage(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -188,4 +153,18 @@ } return message; } + + /** + * @return the locationDB + */ + public FileLocationDB getLocationDB() { + return locationDB; + } + + /** + * @param locationDB the locationDB to set + */ + public void setLocationDB(FileLocationDB locationDB) { + this.locationDB = locationDB; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |