Browse Source

UploadPackServlet: Use uploadWithExceptionPropagation

As UploadPackErrorHandler's Javadoc says, UploadPackServlet should have
called uploadWithExceptionPropagation and let UploadPackErrorHandler to
handle the exception. Fix UploadPackServlet.

Change-Id: I1f9686495fcf3ef28598ccdff3e6f76a16c8bca3
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
stable-5.7
Masaya Suzuki 5 years ago
parent
commit
d72d6a6b4b
  1. 9
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java
  2. 2
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java

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

@ -70,7 +70,9 @@ import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.eclipse.jgit.annotations.Nullable; import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.errors.PackProtocolException;
import org.eclipse.jgit.http.server.UploadPackErrorHandler.UploadPackRunnable; import org.eclipse.jgit.http.server.UploadPackErrorHandler.UploadPackRunnable;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.InternalHttpServerGlue; import org.eclipse.jgit.transport.InternalHttpServerGlue;
@ -212,7 +214,8 @@ class UploadPackServlet extends HttpServlet {
rsp.setContentType(UPLOAD_PACK_RESULT_TYPE); rsp.setContentType(UPLOAD_PACK_RESULT_TYPE);
try { try {
up.upload(getInputStream(req), out, null); up.uploadWithExceptionPropagation(getInputStream(req), out,
null);
out.close(); out.close();
} catch (ServiceMayNotContinueException e) { } catch (ServiceMayNotContinueException e) {
if (e.isOutput()) { if (e.isOutput()) {
@ -245,7 +248,9 @@ class UploadPackServlet extends HttpServlet {
log(up.getRepository(), e); log(up.getRepository(), e);
if (!rsp.isCommitted()) { if (!rsp.isCommitted()) {
rsp.reset(); rsp.reset();
sendError(req, rsp, SC_INTERNAL_SERVER_ERROR); String msg = e instanceof PackProtocolException ? e.getMessage()
: null;
sendError(req, rsp, SC_INTERNAL_SERVER_ERROR, msg);
} }
} }
} }

2
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java

@ -1214,7 +1214,7 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
Collections.<ObjectId> emptySet()); Collections.<ObjectId> emptySet());
fail("Successfully served ref with value " + c.getRef(master)); fail("Successfully served ref with value " + c.getRef(master));
} catch (TransportException err) { } catch (TransportException err) {
assertEquals("internal server error", err.getMessage()); assertEquals("Internal server error", err.getMessage());
} }
} finally { } finally {
noRefServer.tearDown(); noRefServer.tearDown();

Loading…
Cancel
Save