diff options
author | Shawn Pearce <spearce@spearce.org> | 2015-05-06 15:47:34 -0700 |
---|---|---|
committer | Shawn Pearce <spearce@spearce.org> | 2015-05-06 15:47:34 -0700 |
commit | ae592cc65576d1acac2bb6a8ed12c9160b403f0a (patch) | |
tree | ad9319cca5f35efc6b7e18982a3db8df1c7d9f25 /org.eclipse.jgit.http.server/src | |
parent | 72857c52ece8aa4c1dc8f7145c1b0fdbfc82a297 (diff) | |
download | jgit-ae592cc65576d1acac2bb6a8ed12c9160b403f0a.tar.gz jgit-ae592cc65576d1acac2bb6a8ed12c9160b403f0a.zip |
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
Diffstat (limited to 'org.eclipse.jgit.http.server/src')
3 files changed, 29 insertions, 9 deletions
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java index a8e312d3f0..9756feb0b0 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java +++ b/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); + } } diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java index 8d56d84c97..042ccf3dd7 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java +++ b/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 } diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java index 7aefcbd809..443eebb4d4 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java +++ b/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); + } } |