]> source.dussan.org Git - gitblit.git/commitdiff
Improve logging granularity of raw page missing commit, object, or blob
authorJames Moger <james.moger@gitblit.com>
Fri, 28 Feb 2014 17:14:48 +0000 (12:14 -0500)
committerJames Moger <james.moger@gitblit.com>
Fri, 28 Feb 2014 17:14:48 +0000 (12:14 -0500)
src/main/java/com/gitblit/wicket/pages/RawPage.java

index 7b4eb0457b2139625c502470313de6c653f16a36..c4357478248fe44eef1af5d556cfb204e4e918db 100644 (file)
@@ -70,9 +70,6 @@ public class RawPage extends SessionPage {
                                final String objectId = WicketUtils.getObject(params);\r
                                final String blobPath = WicketUtils.getPath(params);\r
 \r
-                               final String notFound = MessageFormat.format("Raw page failed to find {0} in {1} @ {2}",\r
-                                               blobPath, repositoryName, objectId);\r
-\r
                                String[] encodings = getEncodings();\r
                                GitBlitWebSession session = GitBlitWebSession.get();\r
                                UserModel user = session.getUser();\r
@@ -96,8 +93,10 @@ public class RawPage extends SessionPage {
                                        // objectid referenced raw view\r
                                        byte [] binary = JGitUtils.getByteContent(r, objectId);\r
                                        if (binary == null) {\r
-                                               logger.error(notFound);\r
-                                               throw new AbortWithWebErrorCodeException(HttpServletResponse.SC_NOT_FOUND, notFound);\r
+                                               final String objectNotFound = MessageFormat.format("Raw page failed to find object {0} in {1}",\r
+                                                               objectId, repositoryName);\r
+                                               logger.error(objectNotFound);\r
+                                               throw new AbortWithWebErrorCodeException(HttpServletResponse.SC_NOT_FOUND, objectNotFound);\r
                                        }\r
                                        contentType = "application/octet-stream";\r
                                        response.setContentType(contentType);\r
@@ -110,6 +109,12 @@ public class RawPage extends SessionPage {
                                } else {\r
                                        // standard raw blob view\r
                                        RevCommit commit = JGitUtils.getCommit(r, objectId);\r
+                                       if (commit == null) {\r
+                                               final String commitNotFound = MessageFormat.format("Raw page failed to find commit {0} in {1}",\r
+                                                               objectId, repositoryName);\r
+                                               logger.error(commitNotFound);\r
+                                               throw new AbortWithWebErrorCodeException(HttpServletResponse.SC_NOT_FOUND, commitNotFound);\r
+                                       }\r
 \r
                                        String filename = blobPath;\r
                                        if (blobPath.indexOf('/') > -1) {\r
@@ -130,6 +135,9 @@ public class RawPage extends SessionPage {
                                                map.put(ext.toLowerCase(), 3);\r
                                        }\r
 \r
+                                       final String blobNotFound = MessageFormat.format("Raw page failed to find blob {0} in {1} @ {2}",\r
+                                                       blobPath, repositoryName, objectId);\r
+\r
                                        if (extension != null) {\r
                                                int type = 0;\r
                                                if (map.containsKey(extension)) {\r
@@ -140,8 +148,8 @@ public class RawPage extends SessionPage {
                                                        // image blobs\r
                                                        byte[] image = JGitUtils.getByteContent(r, commit.getTree(), blobPath, true);\r
                                                        if (image == null) {\r
-                                                               logger.error(notFound);\r
-                                                               throw new AbortWithWebErrorCodeException(HttpServletResponse.SC_NOT_FOUND, notFound);\r
+                                                               logger.error(blobNotFound);\r
+                                                               throw new AbortWithWebErrorCodeException(HttpServletResponse.SC_NOT_FOUND, blobNotFound);\r
                                                        }\r
                                                        contentType = "image/" + extension.toLowerCase();\r
                                                        response.setContentType(contentType);\r
@@ -156,8 +164,8 @@ public class RawPage extends SessionPage {
                                                        // binary blobs (download)\r
                                                        byte[] binary = JGitUtils.getByteContent(r, commit.getTree(), blobPath, true);\r
                                                        if (binary == null) {\r
-                                                               logger.error(notFound);\r
-                                                               throw new AbortWithWebErrorCodeException(HttpServletResponse.SC_NOT_FOUND, notFound);\r
+                                                               logger.error(blobNotFound);\r
+                                                               throw new AbortWithWebErrorCodeException(HttpServletResponse.SC_NOT_FOUND, blobNotFound);\r
                                                        }\r
                                                        contentType = "application/octet-stream";\r
                                                        response.setContentLength(binary.length);\r
@@ -193,8 +201,8 @@ public class RawPage extends SessionPage {
                                                        String content = JGitUtils.getStringContent(r, commit.getTree(),\r
                                                                        blobPath, encodings);\r
                                                        if (content == null) {\r
-                                                               logger.error(notFound);\r
-                                                               throw new AbortWithWebErrorCodeException(HttpServletResponse.SC_NOT_FOUND, notFound);\r
+                                                               logger.error(blobNotFound);\r
+                                                               throw new AbortWithWebErrorCodeException(HttpServletResponse.SC_NOT_FOUND, blobNotFound);\r
                                                        }\r
                                                        contentType = "text/plain; charset=UTF-8";\r
                                                        response.setContentType(contentType);\r
@@ -210,8 +218,8 @@ public class RawPage extends SessionPage {
                                                String content = JGitUtils.getStringContent(r, commit.getTree(), blobPath,\r
                                                                encodings);\r
                                                if (content == null) {\r
-                                                       logger.error(notFound);\r
-                                                       throw new AbortWithWebErrorCodeException(HttpServletResponse.SC_NOT_FOUND, notFound);\r
+                                                       logger.error(blobNotFound);\r
+                                                       throw new AbortWithWebErrorCodeException(HttpServletResponse.SC_NOT_FOUND, blobNotFound);\r
                                                }\r
                                                contentType = "text/plain; charset=UTF-8";\r
                                                response.setContentType(contentType);\r