[Mulgara-svn] r1839 - trunk/src/jar/querylang/java/org/mulgara/protocol/http

pag at mulgara.org pag at mulgara.org
Fri Nov 13 19:19:51 UTC 2009


Author: pag
Date: 2009-11-13 11:19:50 -0800 (Fri, 13 Nov 2009)
New Revision: 1839

Added:
   trunk/src/jar/querylang/java/org/mulgara/protocol/http/PartialFailureException.java
Modified:
   trunk/src/jar/querylang/java/org/mulgara/protocol/http/ProtocolServlet.java
Log:
Added better responses to errors in single files when uploading multiple files

Added: trunk/src/jar/querylang/java/org/mulgara/protocol/http/PartialFailureException.java
===================================================================
--- trunk/src/jar/querylang/java/org/mulgara/protocol/http/PartialFailureException.java	                        (rev 0)
+++ trunk/src/jar/querylang/java/org/mulgara/protocol/http/PartialFailureException.java	2009-11-13 19:19:50 UTC (rev 1839)
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2009 Duraspace.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.mulgara.protocol.http;
+
+import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
+
+/**
+ * Encodes the condition of a bad HTTP servlet request.
+ *
+ * @created Sep 8, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.fedora-commons.org/">Fedora Commons</a>
+ */
+public class PartialFailureException extends ServletException {
+
+  /** The serialization ID */
+  private static final long serialVersionUID = 3953416493075214645L;
+
+  /** An default constructor to indicate a problem. */
+  public PartialFailureException() {
+    super(SC_NO_CONTENT);
+  }
+
+  /**
+   * @param message The message to send with a bad request code.
+   */
+  public PartialFailureException(String message) {
+    super(SC_NO_CONTENT, message);
+  }
+
+}

Modified: trunk/src/jar/querylang/java/org/mulgara/protocol/http/ProtocolServlet.java
===================================================================
--- trunk/src/jar/querylang/java/org/mulgara/protocol/http/ProtocolServlet.java	2009-11-13 19:18:33 UTC (rev 1838)
+++ trunk/src/jar/querylang/java/org/mulgara/protocol/http/ProtocolServlet.java	2009-11-13 19:19:50 UTC (rev 1839)
@@ -443,15 +443,27 @@
       }
 
       // upload the data
+      int attempts = 0;
+      int failed = 0;
+      StringBuilder errorBuffer = new StringBuilder();
       for (int partNr = 0; partNr < mime.getCount(); partNr++) {
         BodyPart part = mime.getBodyPart(partNr);
         String partName = mime.getPartName(partNr);
         try {
-          if (!knownParam(partName)) resp.addHeader(HDR_STMT_COUNT, Long.toString(loadData(destGraph, part, conn)));
+          if (!knownParam(partName)) {
+            attempts++;
+            resp.addHeader(HDR_STMT_COUNT, Long.toString(loadData(destGraph, part, conn)));
+          }
         } catch (QueryException e) {
           resp.addHeader(HDR_CANNOT_LOAD, partName);
+          errorBuffer.append("\n").append(partName).append(": ").append(e.getMessage());
+          failed++;
         }
       }
+      if (failed == attempts) {
+        throw new BadRequestException("Unable to load data from " + failed + " file" + (failed == 1 ? "" : "s") + errorBuffer);
+      }
+      if (failed > 0) throw new PartialFailureException("Failed to load " + failed + "/" + attempts + " files" + errorBuffer);
     } catch (MessagingException e) {
       throw new BadRequestException("Unable to process received MIME data: " + e.getMessage());
     }




More information about the Mulgara-svn mailing list