aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2011-11-22 15:51:11 -0800
committerShawn O. Pearce <spearce@spearce.org>2011-11-22 15:51:14 -0800
commit867087bb1119aa0ed52c01095c121229929c007e (patch)
treee492a1bd7ca54fa6da4a561655970cffda41676a /org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java
parent9d311b333347d13ff2f9e0b7109e6b164a3643cc (diff)
downloadjgit-867087bb1119aa0ed52c01095c121229929c007e.tar.gz
jgit-867087bb1119aa0ed52c01095c121229929c007e.zip
Add utilities for smart HTTP error handling
The GitSmartHttpTools class started as utility functions to help report useful error messages to users of the android.googlesource.com service. Now that the GitServlet and GitFilter classes support filters before a git-upload-pack or git-receive-pack request, server implementors may these routines helpful to report custom messages to clients. Using the sendError() method to return an HTTP 200 OK with error text embedded in the payload prevents native Git clients from retrying the action with a dumb Git or WebDAV HTTP request. Refactor some of the existing code to use these new error functions and protocol constants. The new sendError() function is very close to being identical to the old error handling code in RepositoryFilter, however we now use the POST Content-Type rather than the Accept HTTP header to check if the client will accept the error data in the response body rather than using the HTTP status code. This is a more reliable way of checking for native Git clients, as the Accept header was not always populated with the correct string in older versions of Git smart HTTP. Change-Id: I828ac2deb085af12b6689c10f86662ddd39bd1a2
Diffstat (limited to 'org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java')
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java22
1 files changed, 11 insertions, 11 deletions
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 178473c401..c7891dfc77 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
@@ -45,9 +45,12 @@ package org.eclipse.jgit.http.server;
import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN;
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
-import static javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE;
import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;
import static javax.servlet.http.HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE;
+import static org.eclipse.jgit.http.server.GitSmartHttpTools.UPLOAD_PACK;
+import static org.eclipse.jgit.http.server.GitSmartHttpTools.UPLOAD_PACK_REQUEST_TYPE;
+import static org.eclipse.jgit.http.server.GitSmartHttpTools.UPLOAD_PACK_RESULT_TYPE;
+import static org.eclipse.jgit.http.server.GitSmartHttpTools.sendError;
import static org.eclipse.jgit.http.server.ServletUtils.ATTRIBUTE_HANDLER;
import static org.eclipse.jgit.http.server.ServletUtils.getInputStream;
import static org.eclipse.jgit.http.server.ServletUtils.getRepository;
@@ -76,10 +79,6 @@ import org.eclipse.jgit.transport.resolver.UploadPackFactory;
/** Server side implementation of smart fetch over HTTP. */
class UploadPackServlet extends HttpServlet {
- private static final String REQ_TYPE = "application/x-git-upload-pack-request";
-
- static final String RSP_TYPE = "application/x-git-upload-pack-result";
-
private static final long serialVersionUID = 1L;
static class InfoRefs extends SmartServiceInfoRefs {
@@ -87,7 +86,7 @@ class UploadPackServlet extends HttpServlet {
InfoRefs(UploadPackFactory<HttpServletRequest> uploadPackFactory,
List<Filter> filters) {
- super("git-upload-pack", filters);
+ super(UPLOAD_PACK, filters);
this.uploadPackFactory = uploadPackFactory;
}
@@ -132,7 +131,7 @@ class UploadPackServlet extends HttpServlet {
return;
} catch (ServiceNotEnabledException e) {
- RepositoryFilter.sendError(SC_FORBIDDEN, req, rsp);
+ sendError(req, rsp, SC_FORBIDDEN);
return;
}
@@ -156,7 +155,7 @@ class UploadPackServlet extends HttpServlet {
@Override
public void doPost(final HttpServletRequest req,
final HttpServletResponse rsp) throws IOException {
- if (!REQ_TYPE.equals(req.getContentType())) {
+ if (!UPLOAD_PACK_REQUEST_TYPE.equals(req.getContentType())) {
rsp.sendError(SC_UNSUPPORTED_MEDIA_TYPE);
return;
}
@@ -164,7 +163,7 @@ class UploadPackServlet extends HttpServlet {
UploadPack up = (UploadPack) req.getAttribute(ATTRIBUTE_HANDLER);
try {
up.setBiDirectionalPipe(false);
- rsp.setContentType(RSP_TYPE);
+ rsp.setContentType(UPLOAD_PACK_RESULT_TYPE);
final SmartOutputStream out = new SmartOutputStream(req, rsp) {
@Override
@@ -178,11 +177,12 @@ class UploadPackServlet extends HttpServlet {
} catch (UploadPackMayNotContinueException e) {
if (!e.isOutput() && !rsp.isCommitted()) {
rsp.reset();
- rsp.sendError(SC_SERVICE_UNAVAILABLE);
+ sendError(req, rsp, SC_FORBIDDEN, e.getMessage());
}
return;
} catch (UploadPackInternalServerErrorException e) {
+ // Special case exception, error message was sent to client.
getServletContext().log(
HttpServerText.get().internalErrorDuringUploadPack,
e.getCause());
@@ -191,7 +191,7 @@ class UploadPackServlet extends HttpServlet {
getServletContext().log(HttpServerText.get().internalErrorDuringUploadPack, e);
if (!rsp.isCommitted()) {
rsp.reset();
- rsp.sendError(SC_INTERNAL_SERVER_ERROR);
+ sendError(req, rsp, SC_INTERNAL_SERVER_ERROR);
}
return;
}