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/utils/JsonUtils.java | 48 ++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 44 insertions(+), 4 deletions(-)
diff --git a/src/com/gitblit/utils/JsonUtils.java b/src/com/gitblit/utils/JsonUtils.java
index 3cb43eb..bc9a1e0 100644
--- a/src/com/gitblit/utils/JsonUtils.java
+++ b/src/com/gitblit/utils/JsonUtils.java
@@ -38,6 +38,8 @@
import com.gitblit.GitBlitException.UnknownRequestException;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
+import com.google.gson.ExclusionStrategy;
+import com.google.gson.FieldAttributes;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
@@ -114,6 +116,19 @@
*
* @param url
* @param type
+ * @return the deserialized object
+ * @throws {@link IOException}
+ */
+ public static <X> X retrieveJson(String url, Class<? extends X> clazz) throws IOException,
+ UnauthorizedException {
+ return retrieveJson(url, clazz, null, null);
+ }
+
+ /**
+ * Reads a gson object from the specified url.
+ *
+ * @param url
+ * @param type
* @param username
* @param password
* @return the deserialized object
@@ -156,10 +171,11 @@
*/
public static String retrieveJsonString(String url, String username, char[] password)
throws IOException {
- try {
+ try {
URLConnection conn = ConnectionUtils.openReadConnection(url, username, password);
InputStream is = conn.getInputStream();
- BufferedReader reader = new BufferedReader(new InputStreamReader(is, ConnectionUtils.CHARSET));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(is,
+ ConnectionUtils.CHARSET));
StringBuilder json = new StringBuilder();
char[] buffer = new char[4096];
int len = 0;
@@ -247,10 +263,13 @@
// build custom gson instance with GMT date serializer/deserializer
// http://code.google.com/p/google-gson/issues/detail?id=281
- private static Gson gson() {
+ public static Gson gson(ExclusionStrategy... strategies) {
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(Date.class, new GmtDateTypeAdapter());
builder.setPrettyPrinting();
+ if (!ArrayUtils.isEmpty(strategies)) {
+ builder.setExclusionStrategies(strategies);
+ }
return builder.create();
}
@@ -276,11 +295,32 @@
JsonDeserializationContext jsonDeserializationContext) {
try {
synchronized (dateFormat) {
- return dateFormat.parse(jsonElement.getAsString());
+ Date date = dateFormat.parse(jsonElement.getAsString());
+ return new Date((date.getTime() / 1000) * 1000);
}
} catch (ParseException e) {
throw new JsonSyntaxException(jsonElement.getAsString(), e);
}
}
}
+
+ public static class ExcludeField implements ExclusionStrategy {
+
+ private Class<?> c;
+ private String fieldName;
+
+ public ExcludeField(String fqfn) throws SecurityException, NoSuchFieldException,
+ ClassNotFoundException {
+ this.c = Class.forName(fqfn.substring(0, fqfn.lastIndexOf(".")));
+ this.fieldName = fqfn.substring(fqfn.lastIndexOf(".") + 1);
+ }
+
+ public boolean shouldSkipClass(Class<?> arg0) {
+ return false;
+ }
+
+ public boolean shouldSkipField(FieldAttributes f) {
+ return (f.getDeclaringClass() == c && f.getName().equals(fieldName));
+ }
+ }
}
--
Gitblit v1.9.1