Browse Source

Allow RepositoryResolver to throw ServiceMayNotContinueException

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
stable-2.0
Dave Borowitz 13 years ago
parent
commit
55bf06b43d
  1. 4
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java
  2. 3
      org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java
  3. 11
      org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonService.java
  4. 8
      org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/RepositoryResolver.java

4
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);

3
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.
//

11
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 {

8
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;
}

Loading…
Cancel
Save