]> source.dussan.org Git - archiva.git/commitdiff
fix failing tests
authorJames William Dumay <jdumay@apache.org>
Wed, 18 Feb 2009 03:56:23 +0000 (03:56 +0000)
committerJames William Dumay <jdumay@apache.org>
Wed, 18 Feb 2009 03:56:23 +0000 (03:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-with-new-repoapi@745373 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/api/InvalidOperationException.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-repository/src/main/java/org/apache/archiva/repository/DefaultRepositoryManager.java
archiva-modules/archiva-base/archiva-repository/src/main/java/org/apache/archiva/repository/GroupRepositoryManager.java
archiva-modules/archiva-web/archiva-repository-servlet/src/main/java/org/apache/archiva/web/servlet/RepositoryServlet.java

diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/api/InvalidOperationException.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/api/InvalidOperationException.java
new file mode 100644 (file)
index 0000000..cc13f98
--- /dev/null
@@ -0,0 +1,41 @@
+package org.apache.archiva.repository.api;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * InvalidOperationException
+ */
+public class InvalidOperationException extends RepositoryManagerException
+{
+    public InvalidOperationException(String message)
+    {
+        super(message);
+    }
+
+    public InvalidOperationException(String message, Throwable cause)
+    {
+        super(message, cause);
+    }
+
+    public InvalidOperationException(Throwable cause)
+    {
+        super(cause.getMessage(), cause);
+    }
+}
index e78c2c1768a177e0219ac85c3bfeebfd0eef6900..75954883b3839ccf502639ae8be470d5a59800c3 100644 (file)
@@ -137,8 +137,7 @@ public class DefaultRepositoryManager implements SystemRepositoryManager
                 }
                 return result;
             }
-            return Collections.EMPTY_LIST;
         }
-        return null;
+        return Collections.EMPTY_LIST;
     }
 }
index 0062aee6036955b36834da7cb903315e8ef5d70f..5f463f68fafb648782b07b9de21f4bc586e4eb83 100644 (file)
@@ -25,9 +25,9 @@ import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import org.apache.archiva.repository.api.InvalidOperationException;
 import org.apache.archiva.repository.api.MutableResourceContext;
 import org.apache.archiva.repository.api.RepositoryManager;
-import org.apache.archiva.repository.api.RepositoryManagerException;
 import org.apache.archiva.repository.api.RepositoryManagerWeight;
 import org.apache.archiva.repository.api.ResourceContext;
 import org.apache.archiva.repository.api.Status;
@@ -82,7 +82,7 @@ public class GroupRepositoryManager implements RepositoryManager
     
     public boolean write(ResourceContext context, InputStream is)
     {
-        throw new RepositoryManagerException("Repository Groups are not writable: " + context.getRepositoryId());
+        throw new InvalidOperationException("Repository Groups are not writable: " + context.getRepositoryId());
     }
 
     public List<Status> stat(ResourceContext context)
index b7939143a11738f769e6e7add30507c4d1b1b75c..8d2b703b3b7740e59f50f6ffb804f3e05de1f2d0 100644 (file)
@@ -35,6 +35,7 @@ import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import org.apache.archiva.repository.api.InvalidOperationException;
 import org.apache.archiva.repository.api.ResourceType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -123,14 +124,21 @@ public class RepositoryServlet extends HttpServlet
     }
 
     private void handleRequest(final HttpServletRequest req, final HttpServletResponse resp)
-        throws IOException
+        throws IOException, ServletException
     {
         log.debug("Request started");
         HttpRepositoryContext context = new HttpRepositoryContext(req, resp);
         log.debug("Running PreRepositoryInterceptors");
         executePreRepositoryInterceptors(context);
         log.debug("Executing Repository Manager");
-        runRepositoryManager(context, req, resp);
+        try
+        {
+            runRepositoryManager(context, req, resp);
+        }
+        catch (InvalidOperationException e)
+        {
+            resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, e.getMessage());
+        }
         log.debug("Running PostRepositoryInterceptors");
         executePostRepositoryInterceptors(context);
         log.debug("Request Completed");
@@ -207,7 +215,10 @@ public class RepositoryServlet extends HttpServlet
 
                 if (withBody)
                 {
-                    repositoryManager.read(context, resp.getOutputStream());
+                    if (!repositoryManager.read(context, resp.getOutputStream()))
+                    {
+                        resp.sendError(HttpServletResponse.SC_NOT_FOUND);
+                    }
                 }
             }
         }