Mercurial > hg > digilib
changeset 1200:80f9d685c890
IIF api works now (even with %2F in id part).
author | robcast |
---|---|
date | Thu, 18 Jul 2013 19:00:08 +0200 |
parents | 22b8e36fcb89 |
children | fda178f73c3f |
files | common/src/main/java/digilib/conf/DigilibConfiguration.java common/src/main/java/digilib/conf/DigilibRequest.java servlet/src/main/java/digilib/conf/DigilibServletConfiguration.java servlet/src/main/java/digilib/conf/DigilibServletRequest.java servlet/src/main/java/digilib/servlet/ServletOps.java servlet3/src/main/java/digilib/conf/DigilibServlet3Configuration.java servlet3/src/main/java/digilib/servlet/Scaler.java |
diffstat | 7 files changed, 40 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/common/src/main/java/digilib/conf/DigilibConfiguration.java Wed Jul 17 19:12:01 2013 +0200 +++ b/common/src/main/java/digilib/conf/DigilibConfiguration.java Thu Jul 18 19:00:08 2013 +0200 @@ -44,6 +44,10 @@ /** Log4J logger */ protected static Logger logger = Logger.getLogger(DigilibConfiguration.class); + public static String getVersion() { + return "2.2.1"; + } + /** * Default constructor defines all parameters and their default values. */ @@ -56,7 +60,7 @@ */ // digilib version - newParameter("digilib.version", "2.2.1", null, 's'); + newParameter("digilib.version", DigilibConfiguration.getVersion(), null, 's'); // sending image files as-is allowed newParameter("sendfile-allowed", Boolean.TRUE, null, 'f'); // Type of DocuImage instance
--- a/common/src/main/java/digilib/conf/DigilibRequest.java Wed Jul 17 19:12:01 2013 +0200 +++ b/common/src/main/java/digilib/conf/DigilibRequest.java Thu Jul 18 19:00:08 2013 +0200 @@ -261,7 +261,7 @@ /** * Populate a request from a string with an IIIF Image API path. * - * path should have no leading slash. + * path should be non-URL-decoded and have no leading slash. * * @param path * String with IIIF Image API path.
--- a/servlet/src/main/java/digilib/conf/DigilibServletConfiguration.java Wed Jul 17 19:12:01 2013 +0200 +++ b/servlet/src/main/java/digilib/conf/DigilibServletConfiguration.java Thu Jul 18 19:00:08 2013 +0200 @@ -82,7 +82,7 @@ /** the time the webapp (i.e. this class) was loaded */ public final Long webappStartTime = System.currentTimeMillis(); - public String getVersion() { + public static String getVersion() { return "2.2.0 srv"; } @@ -109,6 +109,7 @@ newParameter("servlet.filemeta.class", null, null, 's'); newParameter("servlet.dirmeta.class", null, null, 's'); newParameter("servlet.authops.class", null, null, 's'); + newParameter("servlet.version", DigilibServletConfiguration.getVersion(), null, 's'); /* * parameters that can be read from config file have a type 'f'
--- a/servlet/src/main/java/digilib/conf/DigilibServletRequest.java Wed Jul 17 19:12:01 2013 +0200 +++ b/servlet/src/main/java/digilib/conf/DigilibServletRequest.java Thu Jul 18 19:00:08 2013 +0200 @@ -198,9 +198,17 @@ servletRequest = request; setValue("servlet.request", request); // request path (after servlet, before "?") - String path = ((HttpServletRequest) request).getPathInfo(); + String path = request.getPathInfo(); // decide if its IIIF API if (path != null && path.startsWith(iiifPrefix, 1)) { + // for IIIF we need the undecoded path :-( + String uri = request.getRequestURI(); + String ms = request.getServletPath(); + // we try to match servlet name + iiifPrefix in the uri + int mp = uri.indexOf(ms+"/"+iiifPrefix+"/"); + if (mp > -1) { + path = uri.substring(mp + ms.length()); + } setWithIiifPath(path.substring(1)); } else { // decide if it's old-style or new-style digilib
--- a/servlet/src/main/java/digilib/servlet/ServletOps.java Wed Jul 17 19:12:01 2013 +0200 +++ b/servlet/src/main/java/digilib/servlet/ServletOps.java Thu Jul 18 19:00:08 2013 +0200 @@ -347,6 +347,15 @@ } + /** + * Returns IIIF compatible image information as application/json response. + * + * @param dlReq + * @param response + * @param logger + * @throws ServletException + * @see <a href="http://www-sul.stanford.edu/iiif/image-api/1.1/#info">IIIF Image Information Request</a> + */ public static void sendInfo(DigilibServletRequest dlReq, HttpServletResponse response, Logger logger) throws ServletException { if (response == null) { logger.error("No response!"); @@ -356,7 +365,12 @@ // get original image size ImageInput img = dlReq.getJobDescription().getImageSet().getBiggest(); ImageSize size = img.getSize(); - StringBuffer url = dlReq.getServletRequest().getRequestURL(); + String url = dlReq.getServletRequest().getRequestURL().toString(); + if (url.endsWith("/info.json")) { + url = url.substring(0, url.lastIndexOf("/info.json")); + } else if (url.endsWith("/")) { + url = url.substring(0, url.lastIndexOf("/")); + } PrintWriter writer = response.getWriter(); response.setContentType("application/json"); writer.println("{"); @@ -366,7 +380,7 @@ writer.println("\"height\" : \""+size.height+"\","); writer.println("\"formats\" : [\"jpg\", \"png\"],"); writer.println("\"qualities\" : [\"native\", \"color\", \"grey\"],"); - writer.println("\"profile\" : \"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2\","); + writer.println("\"profile\" : \"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2\""); writer.println("}"); } catch (IOException e) { throw new ServletException("Error sending info:", e);
--- a/servlet3/src/main/java/digilib/conf/DigilibServlet3Configuration.java Wed Jul 17 19:12:01 2013 +0200 +++ b/servlet3/src/main/java/digilib/conf/DigilibServlet3Configuration.java Thu Jul 18 19:00:08 2013 +0200 @@ -41,8 +41,8 @@ @WebListener public class DigilibServlet3Configuration extends DigilibServletConfiguration { - public String getVersion() { - return "2.2.0 srv3"; + public static String getVersion() { + return "2.2.1 async"; } /** @@ -62,6 +62,9 @@ public void configure(ServletContext context) { super.configure(context); + // set version + setValue("servlet.version", DigilibServlet3Configuration.getVersion()); + // digilib worker timeout long to = getAsInt("worker-timeout"); AsyncServletWorker.setTimeout(to);
--- a/servlet3/src/main/java/digilib/servlet/Scaler.java Wed Jul 17 19:12:01 2013 +0200 +++ b/servlet3/src/main/java/digilib/servlet/Scaler.java Thu Jul 18 19:00:08 2013 +0200 @@ -43,6 +43,7 @@ import digilib.auth.AuthOpException; import digilib.auth.AuthOps; import digilib.conf.DigilibConfiguration; +import digilib.conf.DigilibServlet3Configuration; import digilib.conf.DigilibServletRequest; import digilib.image.DocuImage; import digilib.image.ImageJobDescription; @@ -58,7 +59,7 @@ private static final long serialVersionUID = 5289386646192471549L; /** digilib servlet version (for all components) */ - public static final String version = "2.2.1 async"; + public static final String version = DigilibServlet3Configuration.getVersion(); /** servlet error codes */ public static enum Error {