From: <bra...@us...> - 2008-07-22 02:53:41
|
Revision: 2482 http://archive-access.svn.sourceforge.net/archive-access/?rev=2482&view=rev Author: bradtofel Date: 2008-07-22 02:53:50 +0000 (Tue, 22 Jul 2008) Log Message: ----------- INITIAL-REV: two custom ExceptionRenderer implementations which provide the ability to override specific the standard .jsp handlers, via a list of special-case hosts, or by consulting an external Oracle. The AnnotationExceptionRenderer is highly experimental. Added Paths: ----------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/exception/AnnotationExceptionRenderer.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/exception/CustomNotInArchiveExceptionRenderer.java Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/exception/AnnotationExceptionRenderer.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/exception/AnnotationExceptionRenderer.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/exception/AnnotationExceptionRenderer.java 2008-07-22 02:53:50 UTC (rev 2482) @@ -0,0 +1,130 @@ +/* AnnotationExceptionRenderer + * + * $Id$ + * + * Created on 7:17:24 PM Jun 10, 2008. + * + * Copyright (C) 2008 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.exception; + +import java.util.Date; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.archive.accesscontrol.AccessControlClient; +import org.archive.accesscontrol.RuleOracleUnavailableException; +import org.archive.accesscontrol.model.Rule; +import org.archive.wayback.core.WaybackRequest; + +/** + * + * + * @author brad + * @version $Date$, $Revision$ + */ +public class AnnotationExceptionRenderer extends BaseExceptionRenderer { + private AccessControlClient client = null; + private String oracleUrl = null; + private String who = null; + public void init() { + client = new AccessControlClient(oracleUrl); + } + public String getExceptionHandler(HttpServletRequest httpRequest, + HttpServletResponse httpResponse, WaybackRequest wbRequest, + WaybackException exception) { + // the "standard HTML" response handler: + String jspPath = getCustomHandler(exception,wbRequest); + if(jspPath == null) { + jspPath = super.getExceptionHandler(httpRequest, httpResponse, + wbRequest, exception); + } + return jspPath; + } + + private String getCustomHandler(WaybackException e, WaybackRequest wbRequest) { + String jspPath = null; + if((e instanceof ResourceNotInArchiveException) + && wbRequest.isReplayRequest()) { + String url = wbRequest.getRequestUrl(); + Date captureDate = wbRequest.getReplayDate(); + try { + Rule rule = client.getRule(url,captureDate,new Date(),who); + jspPath = ruleToJspPath(rule); + } catch (RuleOracleUnavailableException e1) { + e1.printStackTrace(); + } + } + return jspPath; + } + + private String ruleToJspPath(Rule rule) { + if(rule != null) { + String pc = rule.getPublicComment(); + if(pc.startsWith("/")) { + return pc; + } + } + return null; + } + /** + * @return the client + */ + public AccessControlClient getClient() { + return client; + } + + /** + * @param client the client to set + */ + public void setClient(AccessControlClient client) { + client.setRobotLookupsEnabled(false); + this.client = client; + } + + /** + * @return the oracleUrl + */ + public String getOracleUrl() { + return oracleUrl; + } + + /** + * @param oracleUrl the oracleUrl to set + */ + public void setOracleUrl(String oracleUrl) { + this.oracleUrl = oracleUrl; + setClient(new AccessControlClient(oracleUrl)); + } + + /** + * @return the who + */ + public String getWho() { + return who; + } + + /** + * @param who the who to set + */ + public void setWho(String who) { + this.who = who; + } +} Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/exception/CustomNotInArchiveExceptionRenderer.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/exception/CustomNotInArchiveExceptionRenderer.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/exception/CustomNotInArchiveExceptionRenderer.java 2008-07-22 02:53:50 UTC (rev 2482) @@ -0,0 +1,95 @@ +/* CustomNotInArchiveExceptionRenderer + * + * $Id$ + * + * Created on 1:21:49 PM Jul 8, 2008. + * + * Copyright (C) 2008 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.exception; + +import java.util.HashMap; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.archive.wayback.core.WaybackRequest; +import org.archive.wayback.util.url.UrlOperations; + +/** + * + * + * @author brad + * @version $Date$, $Revision$ + */ +public class CustomNotInArchiveExceptionRenderer extends BaseExceptionRenderer { + private HashMap<String,Object> hosts = null; + private String jspHandler = null; + + + public String getExceptionHandler(HttpServletRequest httpRequest, + HttpServletResponse httpResponse, WaybackRequest wbRequest, + WaybackException exception) { + String jspPath = getCustomHandler(exception,wbRequest); + if(jspPath == null) { + jspPath = super.getExceptionHandler(httpRequest, httpResponse, + wbRequest, exception); + } + return jspPath; + } + + + /** + * @param exception + * @param wbRequest + * @return + */ + private String getCustomHandler(WaybackException exception, + WaybackRequest wbRequest) { + if((exception instanceof ResourceNotInArchiveException) + && wbRequest.isReplayRequest()) { + String url = wbRequest.getRequestUrl(); + String host = UrlOperations.urlToHost(url); + if(hosts.containsKey(host)) { + return jspHandler; + } + } + return null; + } + + + public String getJspHandler() { + return jspHandler; + } + + + public void setJspHandler(String jspHandler) { + this.jspHandler = jspHandler; + } + public List<String> getHosts() { + return null; + } + public void setHosts(List<String> hosts) { + this.hosts = new HashMap<String,Object>(); + for(String host : hosts) { + this.hosts.put(host, null); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |