manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1670575 - /manifoldcf/branches/CONNECTORS-1177/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java
Date Wed, 01 Apr 2015 07:59:56 GMT
Author: kwright
Date: Wed Apr  1 07:59:55 2015
New Revision: 1670575

URL: http://svn.apache.org/r1670575
Log:
For 401 errors, transmit empty JSON so parsers don't get mad

Modified:
    manifoldcf/branches/CONNECTORS-1177/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java

Modified: manifoldcf/branches/CONNECTORS-1177/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1177/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java?rev=1670575&r1=1670574&r2=1670575&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1177/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java
(original)
+++ manifoldcf/branches/CONNECTORS-1177/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java
Wed Apr  1 07:59:55 2015
@@ -222,6 +222,34 @@ public class APIServlet extends HttpServ
   }
 
   // Protected methods
+
+  protected static void sendUnauthorizedResponse(HttpServletResponse response)
+    throws IOException
+  {
+    response.setStatus(response.SC_UNAUTHORIZED);
+    sendNullJSON(response);
+  }
+  
+  protected static void sendNullJSON(HttpServletResponse response)
+    throws IOException
+  {
+    String loutputText = "{}";
+    byte[] lresponseValue = loutputText.getBytes(StandardCharsets.UTF_8);
+
+    // Set response mime type
+    response.setContentType("text/plain; charset=utf-8");
+    response.setIntHeader("Content-Length", (int)lresponseValue.length);
+    ServletOutputStream out = response.getOutputStream();
+    try
+    {
+      out.write(lresponseValue,0,lresponseValue.length);
+      out.flush();
+    }
+    finally
+    {
+      out.close();
+    }
+  }
   
   /** Perform a general "read" operation.
   */
@@ -231,7 +259,7 @@ public class APIServlet extends HttpServ
     if (!ap.getLoggedOn())
     {
       // Login failed
-      response.sendError(response.SC_UNAUTHORIZED);
+      sendUnauthorizedResponse(response);
       return;
     }
 
@@ -318,7 +346,7 @@ public class APIServlet extends HttpServ
     if (!ap.getLoggedOn())
     {
       // Login failed
-      response.sendError(response.SC_UNAUTHORIZED);
+      sendUnauthorizedResponse(response);
       return;
     }
 
@@ -488,27 +516,12 @@ public class APIServlet extends HttpServ
       ap.login(tc,userID,password);
       if (!ap.getLoggedOn())
       {
-        response.sendError(response.SC_UNAUTHORIZED);
+        sendUnauthorizedResponse(response);
         return;
       }
       else
       {
-        String loutputText = "{}";
-        byte[] lresponseValue = loutputText.getBytes(StandardCharsets.UTF_8);
-
-        // Set response mime type
-        response.setContentType("text/plain; charset=utf-8");
-        response.setIntHeader("Content-Length", (int)lresponseValue.length);
-        ServletOutputStream out = response.getOutputStream();
-        try
-        {
-          out.write(lresponseValue,0,lresponseValue.length);
-          out.flush();
-        }
-        finally
-        {
-          out.close();
-        }
+        sendNullJSON(response);
         return;
       }
     }
@@ -516,7 +529,7 @@ public class APIServlet extends HttpServ
     if (!ap.getLoggedOn())
     {
       // Login failed
-      response.sendError(response.SC_UNAUTHORIZED);
+      sendUnauthorizedResponse(response);
       return;
     }
 
@@ -617,7 +630,7 @@ public class APIServlet extends HttpServ
     if (!ap.getLoggedOn())
     {
       // Login failed
-      response.sendError(response.SC_UNAUTHORIZED);
+      sendUnauthorizedResponse(response);
       return;
     }
 



Mime
View raw message