aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2017-12-07 00:00:52 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2017-12-07 20:02:59 +0900
commitb433f2722fd55e43a764e7d56c29bb037d87fa09 (patch)
treeba4b98034cffbcc7870e5e324d4cc1309c60f318 /org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java
parentcc3cf93eee8a216852179e05330b6c092751ae00 (diff)
downloadjgit-b433f2722fd55e43a764e7d56c29bb037d87fa09.tar.gz
jgit-b433f2722fd55e43a764e7d56c29bb037d87fa09.zip
Move repeated LFS Gson handling to common class
LfsProtocolServlet and FileLfsServlet both implement the same setup of the Gson object. Factor it out to a common class and reuse it. Change-Id: I5696404fad140cbff1b712ebb04a7e8bba60e4b4 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java')
-rw-r--r--org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java28
1 files changed, 4 insertions, 24 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 2473dcdc8c..79f54f1ba7 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
@@ -81,13 +81,10 @@ import org.eclipse.jgit.lfs.errors.LfsUnauthorized;
import org.eclipse.jgit.lfs.errors.LfsUnavailable;
import org.eclipse.jgit.lfs.errors.LfsValidationError;
import org.eclipse.jgit.lfs.internal.LfsText;
+import org.eclipse.jgit.lfs.server.internal.LfsGson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.gson.FieldNamingPolicy;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
/**
* LFS protocol handler implementing the LFS batch API [1]
*
@@ -108,8 +105,6 @@ public abstract class LfsProtocolServlet extends HttpServlet {
private static final int SC_BANDWIDTH_LIMIT_EXCEEDED = 509;
- private Gson gson = createGson();
-
/**
* Get the large file repository for the given request and path.
*
@@ -254,7 +249,7 @@ public abstract class LfsProtocolServlet extends HttpServlet {
Reader r = new BufferedReader(
new InputStreamReader(req.getInputStream(), UTF_8));
- LfsRequest request = gson.fromJson(r, LfsRequest.class);
+ LfsRequest request = LfsGson.fromJson(r, LfsRequest.class);
String path = req.getPathInfo();
res.setContentType(CONTENTTYPE_VND_GIT_LFS_JSON);
@@ -271,7 +266,7 @@ public abstract class LfsProtocolServlet extends HttpServlet {
res.setStatus(SC_OK);
TransferHandler handler = TransferHandler
.forOperation(request.operation, repo, request.objects);
- gson.toJson(handler.process(), w);
+ LfsGson.toJson(handler.process(), w);
} catch (LfsValidationError e) {
sendError(res, w, SC_UNPROCESSABLE_ENTITY, e.getMessage());
} catch (LfsRepositoryNotFound e) {
@@ -295,24 +290,9 @@ public abstract class LfsProtocolServlet extends HttpServlet {
}
}
- static class Error {
- String message;
-
- Error(String m) {
- this.message = m;
- }
- }
-
private void sendError(HttpServletResponse rsp, Writer writer, int status,
String message) {
rsp.setStatus(status);
- gson.toJson(new Error(message), writer);
- }
-
- private Gson createGson() {
- return new GsonBuilder()
- .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
- .disableHtmlEscaping()
- .create();
+ LfsGson.toJson(message, writer);
}
}