aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs')
-rw-r--r--org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java46
1 files changed, 19 insertions, 27 deletions
diff --git a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java
index e6a5ef90fc..1aa8c04058 100644
--- a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java
+++ b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java
@@ -54,7 +54,6 @@ import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.List;
@@ -139,37 +138,34 @@ public abstract class LfsProtocolServlet extends HttpServlet {
Writer w = new BufferedWriter(
new OutputStreamWriter(res.getOutputStream(), UTF_8));
- Reader r = new BufferedReader(new InputStreamReader(req.getInputStream(), UTF_8));
+ Reader r = new BufferedReader(
+ new InputStreamReader(req.getInputStream(), UTF_8));
LfsRequest request = gson.fromJson(r, LfsRequest.class);
String path = req.getPathInfo();
LargeFileRepository repo = null;
try {
repo = getLargeFileRepository(request, path);
+ if (repo == null) {
+ res.setStatus(SC_SERVICE_UNAVAILABLE);
+ } else {
+ res.setStatus(SC_OK);
+ res.setContentType(CONTENTTYPE_VND_GIT_LFS_JSON);
+ TransferHandler handler = TransferHandler
+ .forOperation(request.operation, repo, request.objects);
+ gson.toJson(handler.process(), w);
+ }
} catch (LfsValidationError e) {
- sendError(res, SC_UNPROCESSABLE_ENTITY, e.getMessage());
- return;
+ sendError(res, w, SC_UNPROCESSABLE_ENTITY, e.getMessage());
} catch (LfsRepositoryNotFound e) {
- sendError(res, SC_NOT_FOUND, e.getMessage());
- return;
+ sendError(res, w, SC_NOT_FOUND, e.getMessage());
} catch (LfsRepositoryReadOnly e) {
- sendError(res, SC_FORBIDDEN, e.getMessage());
- return;
+ sendError(res, w, SC_FORBIDDEN, e.getMessage());
} catch (LfsException e) {
- sendError(res, SC_SERVICE_UNAVAILABLE, e.getMessage());
- return;
+ sendError(res, w, SC_SERVICE_UNAVAILABLE, e.getMessage());
+ } finally {
+ w.flush();
}
- if (repo == null) {
- res.setStatus(SC_SERVICE_UNAVAILABLE);
- return;
- }
-
- res.setStatus(SC_OK);
- res.setContentType(CONTENTTYPE_VND_GIT_LFS_JSON);
- TransferHandler handler = TransferHandler
- .forOperation(request.operation, repo, request.objects);
- gson.toJson(handler.process(), w);
- w.flush();
}
static class Error {
@@ -180,14 +176,10 @@ public abstract class LfsProtocolServlet extends HttpServlet {
}
}
- private void sendError(HttpServletResponse rsp, int status, String message)
- throws IOException {
+ private void sendError(HttpServletResponse rsp, Writer writer, int status,
+ String message) {
rsp.setStatus(status);
- PrintWriter writer = rsp.getWriter();
gson.toJson(new Error(message), writer);
- writer.flush();
- writer.close();
- rsp.flushBuffer();
}
private Gson createGson() {