summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2016-07-22 14:35:18 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2016-07-27 11:07:05 +0900
commite27eab26e2027baba7e96a972b90b17f18843467 (patch)
treea09e4ee74546c131d347255a831fa4f174acfd03 /org.eclipse.jgit.lfs.server/src/org/eclipse/jgit
parent2e652aebab329e805beb8198dea6a064bd64ec1f (diff)
downloadjgit-e27eab26e2027baba7e96a972b90b17f18843467.tar.gz
jgit-e27eab26e2027baba7e96a972b90b17f18843467.zip
FileLfsServlet: Include error message in response body
According to the specification [1], the error response body must include the error message in json format. [1] https://github.com/github/git-lfs/blob/master/docs/api/v1/http-v1-batch.md#response-errors Change-Id: I79e7a841d230fdedefa53b9c6d2d477e81e1f9e6 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.lfs.server/src/org/eclipse/jgit')
-rw-r--r--org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/FileLfsServlet.java32
1 files changed, 29 insertions, 3 deletions
diff --git a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/FileLfsServlet.java b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/FileLfsServlet.java
index 925dea8de5..39aaa91d04 100644
--- a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/FileLfsServlet.java
+++ b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/FileLfsServlet.java
@@ -43,6 +43,7 @@
package org.eclipse.jgit.lfs.server.fs;
import java.io.IOException;
+import java.io.PrintWriter;
import java.text.MessageFormat;
import javax.servlet.AsyncContext;
@@ -59,6 +60,10 @@ import org.eclipse.jgit.lfs.lib.Constants;
import org.eclipse.jgit.lfs.lib.LongObjectId;
import org.eclipse.jgit.lfs.server.internal.LfsServerText;
+import com.google.gson.FieldNamingPolicy;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
/**
* Servlet supporting upload and download of large objects as defined by the
* GitHub Large File Storage extension API extending git to allow separate
@@ -76,6 +81,8 @@ public class FileLfsServlet extends HttpServlet {
private final long timeout;
+ private static Gson gson = createGson();
+
/**
* @param repository
* the repository storing the large objects
@@ -106,7 +113,8 @@ public class FileLfsServlet extends HttpServlet {
if (obj != null) {
if (repository.getSize(obj) == -1) {
sendError(rsp, HttpStatus.SC_NOT_FOUND, MessageFormat
- .format(LfsServerText.get().objectNotFound, obj));
+ .format(LfsServerText.get().objectNotFound,
+ obj.getName()));
return;
}
AsyncContext context = req.startAsync();
@@ -157,11 +165,29 @@ public class FileLfsServlet extends HttpServlet {
}
}
+ static class Error {
+ String message;
+
+ Error(String m) {
+ this.message = m;
+ }
+ }
+
static void sendError(HttpServletResponse rsp, int status, String message)
throws IOException {
rsp.setStatus(status);
- // TODO return message in response body in json format as specified in
- // https://github.com/github/git-lfs/blob/master/docs/api/v1/http-v1-batch.md
+ PrintWriter writer = rsp.getWriter();
+ gson.toJson(new Error(message), writer);
+ writer.flush();
+ writer.close();
rsp.flushBuffer();
}
+
+ private static Gson createGson() {
+ GsonBuilder gb = new GsonBuilder()
+ .setFieldNamingPolicy(
+ FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
+ .setPrettyPrinting().disableHtmlEscaping();
+ return gb.create();
+ }
}