changeset 831:30037e93ec2a stream

helper function to show request and response header.
author robcast
date Fri, 25 Feb 2011 12:41:07 +0100
parents f4d3543b6a62
children 8ee72433bb8f
files servlet/src/digilib/image/ImageLoaderDocuImage.java servlet/src/digilib/servlet/AsyncServletWorker.java servlet/src/digilib/servlet/Scaler.java servlet/src/digilib/servlet/ServletOps.java
diffstat 4 files changed, 35 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/servlet/src/digilib/image/ImageLoaderDocuImage.java	Fri Feb 25 11:51:29 2011 +0100
+++ b/servlet/src/digilib/image/ImageLoaderDocuImage.java	Fri Feb 25 12:41:07 2011 +0100
@@ -48,7 +48,6 @@
 import javax.imageio.stream.ImageOutputStream;
 import javax.servlet.ServletException;
 
-import digilib.image.DocuImage.ColorOp;
 import digilib.io.FileOpException;
 import digilib.io.FileOps;
 import digilib.io.ImageInput;
--- a/servlet/src/digilib/servlet/AsyncServletWorker.java	Fri Feb 25 11:51:29 2011 +0100
+++ b/servlet/src/digilib/servlet/AsyncServletWorker.java	Fri Feb 25 12:41:07 2011 +0100
@@ -57,6 +57,7 @@
     public void run() {
         // get fresh response
         HttpServletResponse response = (HttpServletResponse) asyncContext.getResponse();
+        logger.debug("working on response: (" + ServletOps.headersToString(response) + ")");
         try {
             // render the image
             DocuImage img = imageWorker.call();
@@ -84,6 +85,7 @@
         } finally {
             // submit response
             logger.debug("context complete.");
+            logger.debug("response: (" + ServletOps.headersToString(response) + ")");
             asyncContext.complete();
         }
 
--- a/servlet/src/digilib/servlet/Scaler.java	Fri Feb 25 11:51:29 2011 +0100
+++ b/servlet/src/digilib/servlet/Scaler.java	Fri Feb 25 12:41:07 2011 +0100
@@ -31,7 +31,7 @@
     private static final long serialVersionUID = 5289386646192471549L;
 
     /** digilib servlet version (for all components) */
-    public static final String version = "1.9.1a12";
+    public static final String version = "1.9.1a13";
 
     /** servlet error codes */
     public static enum Error {UNKNOWN, AUTH, FILE, IMAGE};
--- a/servlet/src/digilib/servlet/ServletOps.java	Fri Feb 25 11:51:29 2011 +0100
+++ b/servlet/src/digilib/servlet/ServletOps.java	Fri Feb 25 12:41:07 2011 +0100
@@ -26,10 +26,14 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintWriter;
+import java.util.Collection;
+import java.util.Enumeration;
 import java.util.StringTokenizer;
 
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.log4j.Logger;
@@ -298,7 +302,7 @@
     		logger.error("No response!");
     		return;
     	}
-        logger.debug("sending to response:"+ response + " committed=" + response.isCommitted());
+        logger.debug("sending to response: ("+ headersToString(response) + ") committed=" + response.isCommitted());
         try {
             OutputStream outstream = response.getOutputStream();
             // setup output -- if mime type is set use that otherwise
@@ -326,4 +330,31 @@
         // TODO: should we: finally { img.dispose(); }
     }
 
+    /** Returns text representation of headers for debuggging purposes.
+     * @param req
+     * @return
+     */
+    public static String headersToString(HttpServletRequest req) {
+        String s = "";
+        Enumeration<String> hns = req.getHeaderNames();
+        while (hns.hasMoreElements()) {
+            String hn = hns.nextElement();
+            s += hn + "=" + req.getHeader(hn) + "; ";
+        }
+        return s;
+    }
+    
+    /** Returns text representation of headers for debuggging purposes.
+     * @param resp
+     * @return
+     */
+    public static String headersToString(HttpServletResponse resp) {
+        String s = "";
+        Collection<String> hns = resp.getHeaderNames();
+        for (String hn : hns) {
+            s += hn + "=" + resp.getHeader(hn) + "; ";
+        }
+        return s;
+    }
+    
 }
\ No newline at end of file