From 0e44acbb2fec928a1606dc60f427a148fff405c9 Mon Sep 17 00:00:00 2001
From: Mohamed Ragab <moragab@gmail.com>
Date: Wed, 02 May 2012 11:15:01 -0400
Subject: [PATCH] Added a script to facilitate setting the proxy host and port and no proxy hosts, and then it concatenates all the java system properties for setting the java proxy configurations and puts the resulting string in an environment variable JAVA_PROXY_CONFIG, modified the scirpts gitblit,  gitblit-ubuntu, and gitblit-centos to source the java-proxy-config.sh script and then include the resulting java proxy configuration in the java command

---
 src/com/gitblit/JsonServlet.java |   42 ++++++++++++++++++++++++++++++++++--------
 1 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/src/com/gitblit/JsonServlet.java b/src/com/gitblit/JsonServlet.java
index b1d1053..3ad2b7d 100644
--- a/src/com/gitblit/JsonServlet.java
+++ b/src/com/gitblit/JsonServlet.java
@@ -17,6 +17,7 @@
 
 import java.io.BufferedReader;
 import java.io.IOException;
+import java.lang.reflect.Type;
 import java.text.MessageFormat;
 
 import javax.servlet.ServletException;
@@ -27,8 +28,8 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
+import com.gitblit.utils.JsonUtils;
+import com.gitblit.utils.StringUtils;
 
 /**
  * Servlet class for interpreting json requests.
@@ -40,6 +41,12 @@
 
 	private static final long serialVersionUID = 1L;
 
+	protected final int forbiddenCode = HttpServletResponse.SC_FORBIDDEN;
+	
+	protected final int notAllowedCode = HttpServletResponse.SC_METHOD_NOT_ALLOWED;
+
+	protected final int failureCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
+	
 	protected final Logger logger;
 
 	public JsonServlet() {
@@ -72,6 +79,28 @@
 
 	protected <X> X deserialize(HttpServletRequest request, HttpServletResponse response,
 			Class<X> clazz) throws IOException {
+		String json = readJson(request, response);
+		if (StringUtils.isEmpty(json)) {
+			return null;
+		}
+
+		X object = JsonUtils.fromJsonString(json.toString(), clazz);
+		return object;
+	}
+
+	protected <X> X deserialize(HttpServletRequest request, HttpServletResponse response, Type type)
+			throws IOException {
+		String json = readJson(request, response);
+		if (StringUtils.isEmpty(json)) {
+			return null;
+		}
+
+		X object = JsonUtils.fromJsonString(json.toString(), type);
+		return object;
+	}
+
+	private String readJson(HttpServletRequest request, HttpServletResponse response)
+			throws IOException {
 		BufferedReader reader = request.getReader();
 		StringBuilder json = new StringBuilder();
 		String line = null;
@@ -86,17 +115,14 @@
 			response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
 			return null;
 		}
-
-		Gson gson = new Gson();
-		X object = gson.fromJson(json.toString(), clazz);
-		return object;
+		return json.toString();
 	}
 
 	protected void serialize(HttpServletResponse response, Object o) throws IOException {
 		if (o != null) {
 			// Send JSON response
-			Gson gson = new GsonBuilder().setPrettyPrinting().create();
-			String json = gson.toJson(o);
+			String json = JsonUtils.toJsonString(o);
+			response.setCharacterEncoding(Constants.ENCODING);
 			response.getWriter().append(json);
 		}
 	}

--
Gitblit v1.9.1