Browse Source

Add repository name to failures in HTTP server log

If UploadPack or ReceivePack has an exception record an identifier
associated with the repository as part of the log message. This can
help the HTTP admin track down the offending repository and take
action to repair the root cause.

Change-Id: I58f22b33cdb40994f044a26fba9fe965b45be51d
stable-4.1
Shawn Pearce 10 years ago
parent
commit
ae592cc655
  1. 1
      org.eclipse.jgit.http.server/META-INF/MANIFEST.MF
  2. 4
      org.eclipse.jgit.http.server/resources/org/eclipse/jgit/http/server/HttpServerText.properties
  3. 13
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java
  4. 10
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java
  5. 15
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java
  6. 4
      org.eclipse.jgit/META-INF/MANIFEST.MF

1
org.eclipse.jgit.http.server/META-INF/MANIFEST.MF

@ -18,6 +18,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: javax.servlet;version="[2.5.0,3.0.0)",
javax.servlet.http;version="[2.5.0,3.0.0)",
org.eclipse.jgit.errors;version="[4.0.0,4.1.0)",
org.eclipse.jgit.internal.storage.dfs;version="[4.0.0,4.1.0)",
org.eclipse.jgit.internal.storage.file;version="[4.0.0,4.1.0)",
org.eclipse.jgit.lib;version="[4.0.0,4.1.0)",
org.eclipse.jgit.nls;version="[4.0.0,4.1.0)",

4
org.eclipse.jgit.http.server/resources/org/eclipse/jgit/http/server/HttpServerText.properties

@ -11,8 +11,8 @@ encodingNotSupportedByThisLibrary={0} "{1}": not supported by this library.
expectedRepositoryAttribute=Expected Repository attribute
filterMustNotBeNull=filter must not be null
internalServerError=Internal server error
internalErrorDuringReceivePack=Internal error during receive-pack
internalErrorDuringUploadPack=Internal error during upload-pack
internalErrorDuringReceivePack=Internal error during receive-pack to {0}
internalErrorDuringUploadPack=Internal error during upload-pack from {0}
internalServerErrorRequestAttributeWasAlreadySet=Internal server error, request attribute {0} was already set when {1} was invoked.
invalidBoolean=Invalid boolean {0} = {1}
invalidIndex=Invalid index: {0}

13
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java

@ -62,6 +62,7 @@ import static org.eclipse.jgit.http.server.ServletUtils.getRepository;
import static org.eclipse.jgit.util.HttpSupport.HDR_USER_AGENT;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.List;
import javax.servlet.Filter;
@ -192,14 +193,12 @@ class ReceivePackServlet extends HttpServlet {
out.close();
} catch (UnpackException e) {
// This should be already reported to the client.
getServletContext().log(
HttpServerText.get().internalErrorDuringReceivePack,
e.getCause());
log(rp.getRepository(), e.getCause());
consumeRequestBody(req);
out.close();
} catch (Throwable e) {
getServletContext().log(HttpServerText.get().internalErrorDuringReceivePack, e);
log(rp.getRepository(), e);
if (!rsp.isCommitted()) {
rsp.reset();
sendError(req, rsp, SC_INTERNAL_SERVER_ERROR);
@ -207,4 +206,10 @@ class ReceivePackServlet extends HttpServlet {
return;
}
}
private void log(Repository git, Throwable e) {
getServletContext().log(MessageFormat.format(
HttpServerText.get().internalErrorDuringReceivePack,
ServletUtils.identify(git)), e);
}
}

10
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java

@ -62,6 +62,7 @@ import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jgit.internal.storage.dfs.DfsRepository;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
@ -273,6 +274,15 @@ public final class ServletUtils {
return ObjectId.fromRaw(md.digest()).getName();
}
static String identify(Repository git) {
if (git instanceof DfsRepository) {
return ((DfsRepository) git).getDescription().getRepositoryName();
} else if (git.getDirectory() != null) {
return git.getDirectory().getPath();
}
return "unknown";
}
private ServletUtils() {
// static utility class only
}

15
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java

@ -61,6 +61,7 @@ import static org.eclipse.jgit.http.server.ServletUtils.getRepository;
import static org.eclipse.jgit.util.HttpSupport.HDR_USER_AGENT;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.List;
import javax.servlet.Filter;
@ -76,9 +77,9 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.InternalHttpServerGlue;
import org.eclipse.jgit.transport.RefAdvertiser.PacketLineOutRefAdvertiser;
import org.eclipse.jgit.transport.ServiceMayNotContinueException;
import org.eclipse.jgit.transport.UploadPack;
import org.eclipse.jgit.transport.UploadPackInternalServerErrorException;
import org.eclipse.jgit.transport.ServiceMayNotContinueException;
import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
import org.eclipse.jgit.transport.resolver.UploadPackFactory;
@ -203,14 +204,12 @@ class UploadPackServlet extends HttpServlet {
} catch (UploadPackInternalServerErrorException e) {
// Special case exception, error message was sent to client.
getServletContext().log(
HttpServerText.get().internalErrorDuringUploadPack,
e.getCause());
log(up.getRepository(), e.getCause());
consumeRequestBody(req);
out.close();
} catch (Throwable e) {
getServletContext().log(HttpServerText.get().internalErrorDuringUploadPack, e);
log(up.getRepository(), e);
if (!rsp.isCommitted()) {
rsp.reset();
sendError(req, rsp, SC_INTERNAL_SERVER_ERROR);
@ -218,4 +217,10 @@ class UploadPackServlet extends HttpServlet {
return;
}
}
private void log(Repository git, Throwable e) {
getServletContext().log(MessageFormat.format(
HttpServerText.get().internalErrorDuringUploadPack,
ServletUtils.identify(git)), e);
}
}

4
org.eclipse.jgit/META-INF/MANIFEST.MF

@ -57,7 +57,9 @@ Export-Package: org.eclipse.jgit.api;version="4.0.0";
org.eclipse.jgit.ignore;version="4.0.0",
org.eclipse.jgit.ignore.internal;version="4.0.0";x-friends:="org.eclipse.jgit.test",
org.eclipse.jgit.internal;version="4.0.0";x-friends:="org.eclipse.jgit.test,org.eclipse.jgit.http.test",
org.eclipse.jgit.internal.storage.dfs;version="4.0.0";x-friends:="org.eclipse.jgit.test",
org.eclipse.jgit.internal.storage.dfs;version="4.0.0";
x-friends:="org.eclipse.jgit.test,
org.eclipse.jgit.http.server",
org.eclipse.jgit.internal.storage.file;version="4.0.0";
x-friends:="org.eclipse.jgit.test,
org.eclipse.jgit.junit,

Loading…
Cancel
Save