JAL-1575 no-cache headers added to (empty) rest response
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 13 May 2015 09:44:28 +0000 (10:44 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 13 May 2015 09:44:28 +0000 (10:44 +0100)
src/jalview/httpserver/AbstractRequestHandler.java
src/jalview/httpserver/HttpServer.java
src/jalview/rest/RestHandler.java

index 9642508..8030c1d 100644 (file)
@@ -73,9 +73,10 @@ public abstract class AbstractRequestHandler extends AbstractHandler
    * 
    * @param request
    * @param response
+   * @throws IOException
    */
   protected abstract void processRequest(HttpServletRequest request,
-          HttpServletResponse response);
+          HttpServletResponse response) throws IOException;
 
   /**
    * For debug - writes HTTP request details to stdout
index fcfefaa..34b39cd 100644 (file)
@@ -131,7 +131,6 @@ public class HttpServer
       // "HttpServer started with %d threads", server.getThreadPool()
       // .getThreads()));
       contextRoot = server.getURI();
-      System.out.println("Jalview endpoint " + contextRoot);
     } catch (Exception e)
     {
       System.err.println("Error trying to start HttpServer: "
index 88f23f4..3f00c07 100644 (file)
@@ -64,7 +64,7 @@ public class RestHandler extends AbstractRequestHandler
    */
   @Override
   protected void processRequest(HttpServletRequest request,
-          HttpServletResponse response)
+          HttpServletResponse response) throws IOException
   {
     /*
      * Currently just echoes the request; add helper classes as required to
@@ -72,19 +72,15 @@ public class RestHandler extends AbstractRequestHandler
      */
     final String queryString = request.getQueryString();
     final String reply = "REST not yet implemented; received "
-            + request.getRequestURL()
+            + request.getMethod() + ": " + request.getRequestURL()
             + (queryString == null ? "" : "?" + queryString);
     System.out.println(reply);
 
-    try
-    {
-      final PrintWriter writer = response.getWriter();
-      writer.write(reply);
-      writer.close();
-    } catch (IOException e)
-    {
-      System.err.println("Error writing REST response: " + e.getMessage());
-    }
+    response.setHeader("Cache-Control", "no-cache/no-store");
+    response.setHeader("Content-type", "text/plain");
+    final PrintWriter writer = response.getWriter();
+    writer.write(reply);
+    writer.close();
   }
 
   /**