]> source.dussan.org Git - jgit.git/commitdiff
Allow RepositoryResolver to throw ServiceMayNotContinueException 77/5477/1
authorDave Borowitz <dborowitz@google.com>
Mon, 26 Mar 2012 17:19:40 +0000 (10:19 -0700)
committerDave Borowitz <dborowitz@google.com>
Mon, 26 Mar 2012 17:19:40 +0000 (10:19 -0700)
Implementations may want to send an error message to the user, which
doesn't really fit with any of the existing exception types.
ServiceMayNotContinueException, on the other hand, is documented as
always containing a user-visible error string, so use that.

Modify the git and HTTP transport mechanisms to properly relay this
message to the end user.

Change-Id: I362e67ea46102a145bf2c6284d38788537c9735f

org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonService.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/RepositoryResolver.java

index 571183682f4eec6eb5ba0601fffb0a044d8ad02b..5b336b2f93a7da08a2a2a2f1a094a83c0bbf4711 100644 (file)
@@ -65,6 +65,7 @@ import javax.servlet.http.HttpServletResponse;
 
 import org.eclipse.jgit.errors.RepositoryNotFoundException;
 import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.transport.ServiceMayNotContinueException;
 import org.eclipse.jgit.transport.resolver.RepositoryResolver;
 import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
 import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
@@ -141,6 +142,9 @@ public class RepositoryFilter implements Filter {
                } catch (ServiceNotAuthorizedException e) {
                        res.sendError(SC_UNAUTHORIZED);
                        return;
+               } catch (ServiceMayNotContinueException e) {
+                       sendError(req, res, SC_INTERNAL_SERVER_ERROR, e.getMessage());
+                       return;
                }
                try {
                        request.setAttribute(ATTRIBUTE_REPOSITORY, db);
index e301f4242fb88e897e8155bbd16ac1f920c88207..78306766d80ac2d03c921c725821062dcb3e54d2 100644 (file)
@@ -366,7 +366,8 @@ public class Daemon {
                return null;
        }
 
-       Repository openRepository(DaemonClient client, String name) {
+       Repository openRepository(DaemonClient client, String name)
+                       throws ServiceMayNotContinueException {
                // Assume any attempt to use \ was by a Windows client
                // and correct to the more typical / used in Git URIs.
                //
index e88b4abb7a8489c7fa889869d7f1055647cda86a..a9481c4d2237e769ab8f0cb71afc91e8d726624f 100644 (file)
@@ -130,7 +130,16 @@ public abstract class DaemonService {
                        throws IOException, ServiceNotEnabledException,
                        ServiceNotAuthorizedException {
                final String name = commandLine.substring(command.length() + 1);
-               Repository db = client.getDaemon().openRepository(client, name);
+               Repository db;
+               try {
+                       db = client.getDaemon().openRepository(client, name);
+               } catch (ServiceMayNotContinueException e) {
+                       // An error when opening the repo means the client is expecting a ref
+                       // advertisement, so use that style of error.
+                       PacketLineOut pktOut = new PacketLineOut(client.getOutputStream());
+                       pktOut.writeString("ERR " + e.getMessage() + "\n");
+                       db = null;
+               }
                if (db == null)
                        return;
                try {
index 611d9a9216942c242acdb9b2e0581cff9ca82ea2..c7f0d32cb479963ce78a269f5a163a5ee382de31 100644 (file)
@@ -45,6 +45,7 @@ package org.eclipse.jgit.transport.resolver;
 
 import org.eclipse.jgit.errors.RepositoryNotFoundException;
 import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.transport.ServiceMayNotContinueException;
 
 /**
  * Locate a Git {@link Repository} by name from the URL.
@@ -82,7 +83,12 @@ public interface RepositoryResolver<C> {
         * @throws ServiceNotEnabledException
         *             the repository may exist, but HTTP access is not allowed on the
         *             target repository, for the current user.
+        * @throws ServiceMayNotContinueException
+        *             the repository may exist, but HTTP access is not allowed for
+        *             the current request. The exception message contains a detailed
+        *             message that should be shown to the user.
         */
        Repository open(C req, String name) throws RepositoryNotFoundException,
-                       ServiceNotAuthorizedException, ServiceNotEnabledException;
+                       ServiceNotAuthorizedException, ServiceNotEnabledException,
+                       ServiceMayNotContinueException;
 }