From d5623a235d54b308280d90920238bf75a2880b84 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Mon, 24 Oct 2011 16:32:57 -0400
Subject: [PATCH] Combined-md5 password storage option

---
 src/com/gitblit/utils/JsonUtils.java |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/src/com/gitblit/utils/JsonUtils.java b/src/com/gitblit/utils/JsonUtils.java
index 3834c8e..0c78df9 100644
--- a/src/com/gitblit/utils/JsonUtils.java
+++ b/src/com/gitblit/utils/JsonUtils.java
@@ -47,6 +47,7 @@
 
 import com.gitblit.GitBlitException.ForbiddenException;
 import com.gitblit.GitBlitException.UnauthorizedException;
+import com.gitblit.GitBlitException.UnknownRequestException;
 import com.gitblit.models.RepositoryModel;
 import com.gitblit.models.UserModel;
 import com.google.gson.Gson;
@@ -157,6 +158,25 @@
 		}
 		return gson().fromJson(json, type);
 	}
+	
+	/**
+	 * Reads a gson object from the specified url.
+	 * 
+	 * @param url
+	 * @param clazz
+	 * @param username
+	 * @param password
+	 * @return the deserialized object
+	 * @throws {@link IOException}
+	 */
+	public static <X> X retrieveJson(String url, Class<X> clazz, String username, char[] password)
+			throws IOException {
+		String json = retrieveJsonString(url, username, password);
+		if (StringUtils.isEmpty(json)) {
+			return null;
+		}
+		return gson().fromJson(json, clazz);
+	}
 
 	/**
 	 * Retrieves a JSON message.
@@ -258,6 +278,9 @@
 			} else if (e.getMessage().indexOf("403") > -1) {
 				// requested url is forbidden by the requesting user
 				throw new ForbiddenException(url);
+			} else if (e.getMessage().indexOf("501") > -1) {
+				// requested url is not recognized by the server
+				throw new UnknownRequestException(url);
 			}
 			throw e;
 		}

--
Gitblit v1.9.1