summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorDave Borowitz2012-03-26 13:19:40 (EDT)
committer Dave Borowitz2012-03-26 13:19:40 (EDT)
commit55bf06b43d8e8ed2f15357e4ecf26eefbff31e29 (patch)
treebda3b6c955c3fc3bc68c2dadce098a1a2f20a53b
parentd794a4fde3a712d275644c58b21323807845a7fb (diff)
downloadjgit-55bf06b43d8e8ed2f15357e4ecf26eefbff31e29.zip
jgit-55bf06b43d8e8ed2f15357e4ecf26eefbff31e29.tar.gz
jgit-55bf06b43d8e8ed2f15357e4ecf26eefbff31e29.tar.bz2
Allow RepositoryResolver to throw ServiceMayNotContinueExceptionrefs/changes/77/5477/1
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
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonService.java11
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/RepositoryResolver.java8
4 files changed, 23 insertions, 3 deletions
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java
index 5711836..5b336b2 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java
@@ -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);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java
index e301f42..7830676 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java
@@ -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.
//
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonService.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonService.java
index e88b4ab..a9481c4 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonService.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonService.java
@@ -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 {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/RepositoryResolver.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/RepositoryResolver.java
index 611d9a9..c7f0d32 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/RepositoryResolver.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/RepositoryResolver.java
@@ -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;
}