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/PagesServlet.java |   44 ++++++++++++++++++++++++++++++++------------
 1 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/src/com/gitblit/PagesServlet.java b/src/com/gitblit/PagesServlet.java
index 58d67b0..d6304f7 100644
--- a/src/com/gitblit/PagesServlet.java
+++ b/src/com/gitblit/PagesServlet.java
@@ -159,27 +159,47 @@
 				}
 			} else {
 				// specific resource
-				String contentType = context.getMimeType(resource);
-				if (contentType.startsWith("text")) {
-					content = JGitUtils.getStringContent(r, tree, resource).getBytes(
-							Constants.ENCODING);
-				} else {
-					content = JGitUtils.getByteContent(r, tree, resource);
+				try {
+					String contentType = context.getMimeType(resource);
+					if (contentType == null) {
+						contentType = "text/plain";
+					}
+					if (contentType.startsWith("text")) {
+						content = JGitUtils.getStringContent(r, tree, resource).getBytes(
+								Constants.ENCODING);
+					} else {
+						content = JGitUtils.getByteContent(r, tree, resource);
+					}
+					response.setContentType(contentType);
+				} catch (Exception e) {
 				}
-				response.setContentType(contentType);
 			}
 
 			// no content, try custom 404 page
 			if (ArrayUtils.isEmpty(content)) {
-				content = JGitUtils.getStringContent(r, tree, "404.html").getBytes(
-						Constants.ENCODING);
+				String custom404 = JGitUtils.getStringContent(r, tree, "404.html");
+				if (!StringUtils.isEmpty(custom404)) {
+					content = custom404.getBytes(Constants.ENCODING);
+				}
+
 				// still no content
 				if (ArrayUtils.isEmpty(content)) {
-					content = (MessageFormat.format(
+					String str = MessageFormat.format(
 							"# Error\nSorry, the requested resource **{0}** was not found.",
-							resource)).getBytes(Constants.ENCODING);
-					resource = "404.mkd";
+							resource);
+					content = MarkdownUtils.transformMarkdown(str).getBytes(Constants.ENCODING);
 				}
+
+				try {
+					// output the content
+					logger.warn("Pages 404: " + resource);
+					response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+					response.getOutputStream().write(content);
+					response.flushBuffer();
+				} catch (Throwable t) {
+					logger.error("Failed to write page to client", t);
+				}
+				return;
 			}
 
 			// check to see if we should transform markdown files

--
Gitblit v1.9.1