From 2179fb76bbbd2021c350a7c28d6901389ed50b2b Mon Sep 17 00:00:00 2001 From: James Moger Date: Mon, 26 Sep 2011 17:48:53 -0400 Subject: [PATCH] Fixed broken urls for WAR builds. --- docs/00_index.mkd | 11 ++++++++--- docs/04_releases.mkd | 6 +++--- src/com/gitblit/AccessRestrictionFilter.java | 3 ++- src/com/gitblit/FederationServlet.java | 7 +++---- src/com/gitblit/SyndicationServlet.java | 6 +++--- src/com/gitblit/utils/HttpUtils.java | 5 +++-- src/com/gitblit/wicket/WicketUtils.java | 4 ++-- src/com/gitblit/wicket/pages/CommitPage.java | 6 +++--- src/com/gitblit/wicket/pages/SendProposalPage.java | 2 +- src/com/gitblit/wicket/pages/SummaryPage.java | 2 +- src/com/gitblit/wicket/pages/TreePage.java | 9 +++++---- .../gitblit/wicket/panels/FederationTokensPanel.java | 2 +- src/com/gitblit/wicket/panels/RepositoriesPanel.java | 7 ++++--- 13 files changed, 39 insertions(+), 31 deletions(-) diff --git a/docs/00_index.mkd b/docs/00_index.mkd index e499abe7..5cf81735 100644 --- a/docs/00_index.mkd +++ b/docs/00_index.mkd @@ -15,16 +15,20 @@ Gitblit is available in two variations: All dependencies are bundled. +### Tools + + ### Java Runtime Requirement Gitblit requires a Java 6 Runtime Environment (JRE) or a Java 6 Development Kit (JDK). ### Current Release -**%VERSION%** ([go](http://code.google.com/p/gitblit/downloads/detail?name=%GO%)|[war](http://code.google.com/p/gitblit/downloads/detail?name=%WAR%)) based on [%JGIT%][jgit]   *released %BUILDDATE%* +**%VERSION%** ([go](http://code.google.com/p/gitblit/downloads/detail?name=%GO%)|[war](http://code.google.com/p/gitblit/downloads/detail?name=%WAR%)|[fedclient](http://code.google.com/p/gitblit/downloads/detail?name=%FEDCLIENT%)) based on [%JGIT%][jgit]   *released %BUILDDATE%* -- added: federation feature to allow gitblit instances to pull repositories and, optionally, settings and accounts from other gitblit instances.
-This is something like svn-sync for gitblit. +- added: federation feature to allow gitblit instances (or gitblit federation clients) to pull repositories and, optionally, settings and accounts from other gitblit instances. This is something like [svn-sync](http://svnbook.red-bean.com/en/1.5/svn.ref.svnsync.html) for gitblit.
**New:** *federation.name =*
**New:** *federation.passphrase =*
**New:** *federation.allowProposals = false* @@ -38,6 +42,7 @@ This is something like svn-sync for gitblit. - updated: MarkdownPapers 1.1.1 - updated: Wicket 1.4.18 - updated: JGit 1.1.0 +- fixed: syndication urls for WAR builds issues, binaries, and sources @ [Google Code][googlecode]
sources @ [Github][gitbltsrc] diff --git a/docs/04_releases.mkd b/docs/04_releases.mkd index ead799a7..242af419 100644 --- a/docs/04_releases.mkd +++ b/docs/04_releases.mkd @@ -1,10 +1,9 @@ ## Release History ### Current Release -**%VERSION%** ([go](http://code.google.com/p/gitblit/downloads/detail?name=%GO%)|[war](http://code.google.com/p/gitblit/downloads/detail?name=%WAR%)) based on [%JGIT%][jgit]   *released %BUILDDATE%* +**%VERSION%** ([go](http://code.google.com/p/gitblit/downloads/detail?name=%GO%)|[war](http://code.google.com/p/gitblit/downloads/detail?name=%WAR%)|[fedclient](http://code.google.com/p/gitblit/downloads/detail?name=%FEDCLIENT%)) based on [%JGIT%][jgit]   *released %BUILDDATE%* -- added: federation feature to allow gitblit instances to pull repositories and, optionally, settings and accounts from other gitblit instances.
-This is something like svn-sync for gitblit. +- added: federation feature to allow gitblit instances (or gitblit federation clients) to pull repositories and, optionally, settings and accounts from other gitblit instances. This is something like [svn-sync](http://svnbook.red-bean.com/en/1.5/svn.ref.svnsync.html) for gitblit.
**New:** *federation.name =*
**New:** *federation.passphrase =*
**New:** *federation.allowProposals = false* @@ -18,6 +17,7 @@ This is something like svn-sync for gitblit. - updated: MarkdownPapers 1.1.1 - updated: Wicket 1.4.18 - updated: JGit 1.1.0 +- fixed: syndication urls for WAR builds ### Older Releases diff --git a/src/com/gitblit/AccessRestrictionFilter.java b/src/com/gitblit/AccessRestrictionFilter.java index 6ec70dbd..e309b595 100644 --- a/src/com/gitblit/AccessRestrictionFilter.java +++ b/src/com/gitblit/AccessRestrictionFilter.java @@ -130,7 +130,8 @@ public abstract class AccessRestrictionFilter implements Filter { AccessRestrictionRequest accessRequest = new AccessRestrictionRequest(httpRequest); - String url = httpRequest.getRequestURI().substring(httpRequest.getServletPath().length()); + String servletUrl = httpRequest.getContextPath() + httpRequest.getServletPath(); + String url = httpRequest.getRequestURI().substring(servletUrl.length()); String params = httpRequest.getQueryString(); if (url.length() > 0 && url.charAt(0) == '/') { url = url.substring(1); diff --git a/src/com/gitblit/FederationServlet.java b/src/com/gitblit/FederationServlet.java index 708ca921..784ec33f 100644 --- a/src/com/gitblit/FederationServlet.java +++ b/src/com/gitblit/FederationServlet.java @@ -159,9 +159,8 @@ public class FederationServlet extends HttpServlet { return; } - String hosturl = HttpUtils.getHostURL(request); - String gitblitUrl = hosturl + request.getContextPath(); - GitBlit.self().submitFederationProposal(proposal, gitblitUrl); + String url = HttpUtils.getGitblitURL(request); + GitBlit.self().submitFederationProposal(proposal, url); logger.info(MessageFormat.format( "Submitted {0} federation proposal to pull {1} repositories from {2}", proposal.tokenType.name(), proposal.repositories.size(), proposal.url)); @@ -218,7 +217,7 @@ public class FederationServlet extends HttpServlet { Object result = null; if (FederationRequest.PULL_REPOSITORIES.equals(reqType)) { - String gitblitUrl = HttpUtils.getHostURL(request); + String gitblitUrl = HttpUtils.getGitblitURL(request); result = GitBlit.self().getRepositories(gitblitUrl, token); } else { if (FederationRequest.PULL_SETTINGS.equals(reqType)) { diff --git a/src/com/gitblit/SyndicationServlet.java b/src/com/gitblit/SyndicationServlet.java index 99497544..4ba27891 100644 --- a/src/com/gitblit/SyndicationServlet.java +++ b/src/com/gitblit/SyndicationServlet.java @@ -116,8 +116,8 @@ public class SyndicationServlet extends HttpServlet { javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException { - String hostURL = HttpUtils.getHostURL(request); - String url = request.getRequestURI().substring(request.getServletPath().length()); + String servletUrl = request.getContextPath() + request.getServletPath(); + String url = request.getRequestURI().substring(servletUrl.length()); if (url.charAt(0) == '/' && url.length() > 1) { url = url.substring(1); } @@ -139,7 +139,7 @@ public class SyndicationServlet extends HttpServlet { RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName); List commits = JGitUtils.getRevLog(repository, objectId, 0, length); try { - SyndicationUtils.toRSS(hostURL, getTitle(model.name, objectId), model.description, + SyndicationUtils.toRSS(HttpUtils.getGitblitURL(request), getTitle(model.name, objectId), model.description, model.name, commits, response.getOutputStream()); } catch (Exception e) { logger.error("An error occurred during feed generation", e); diff --git a/src/com/gitblit/utils/HttpUtils.java b/src/com/gitblit/utils/HttpUtils.java index 6f0bedeb..079d1a6b 100644 --- a/src/com/gitblit/utils/HttpUtils.java +++ b/src/com/gitblit/utils/HttpUtils.java @@ -26,12 +26,12 @@ import javax.servlet.http.HttpServletRequest; public class HttpUtils { /** - * Returns the host URL based on the request. + * Returns the Gitblit URL based on the request. * * @param request * @return the host url */ - public static String getHostURL(HttpServletRequest request) { + public static String getGitblitURL(HttpServletRequest request) { StringBuilder sb = new StringBuilder(); sb.append(request.getScheme()); sb.append("://"); @@ -40,6 +40,7 @@ public class HttpUtils { || (request.getScheme().equals("https") && request.getServerPort() != 443)) { sb.append(":" + request.getServerPort()); } + sb.append(request.getContextPath()); return sb.toString(); } } diff --git a/src/com/gitblit/wicket/WicketUtils.java b/src/com/gitblit/wicket/WicketUtils.java index 1a24925b..36f74a15 100644 --- a/src/com/gitblit/wicket/WicketUtils.java +++ b/src/com/gitblit/wicket/WicketUtils.java @@ -217,9 +217,9 @@ public class WicketUtils { return new ContextRelativeResource(file); } - public static String getHostURL(Request request) { + public static String getGitblitURL(Request request) { HttpServletRequest req = ((WebRequest) request).getHttpServletRequest(); - return HttpUtils.getHostURL(req); + return HttpUtils.getGitblitURL(req); } public static HeaderContributor syndicationDiscoveryLink(final String feedTitle, diff --git a/src/com/gitblit/wicket/pages/CommitPage.java b/src/com/gitblit/wicket/pages/CommitPage.java index b49b1d63..7bf78077 100644 --- a/src/com/gitblit/wicket/pages/CommitPage.java +++ b/src/com/gitblit/wicket/pages/CommitPage.java @@ -92,9 +92,9 @@ public class CommitPage extends RepositoryPage { add(new LinkPanel("commitTree", "list", c.getTree().getName(), TreePage.class, newCommitParameter())); add(new BookmarkablePageLink("treeLink", TreePage.class, newCommitParameter())); - add(new ExternalLink("zipLink", DownloadZipServlet.asLink(getRequest() - .getRelativePathPrefixToContextRoot(), repositoryName, objectId, null)) - .setVisible(GitBlit.getBoolean(Keys.web.allowZipDownloads, true))); + final String baseUrl = WicketUtils.getGitblitURL(getRequest()); + add(new ExternalLink("zipLink", DownloadZipServlet.asLink(baseUrl, repositoryName, + objectId, null)).setVisible(GitBlit.getBoolean(Keys.web.allowZipDownloads, true))); // Parent Commits ListDataProvider parentsDp = new ListDataProvider(parents); diff --git a/src/com/gitblit/wicket/pages/SendProposalPage.java b/src/com/gitblit/wicket/pages/SendProposalPage.java index adef0c54..ea91f1b2 100644 --- a/src/com/gitblit/wicket/pages/SendProposalPage.java +++ b/src/com/gitblit/wicket/pages/SendProposalPage.java @@ -52,7 +52,7 @@ public class SendProposalPage extends BasePage { final String token = WicketUtils.getToken(params); - myUrl = WicketUtils.getHostURL(getRequest()); + myUrl = WicketUtils.getGitblitURL(getRequest()); destinationUrl = "https://"; // temporary proposal diff --git a/src/com/gitblit/wicket/pages/SummaryPage.java b/src/com/gitblit/wicket/pages/SummaryPage.java index 07d57144..9fd90c5f 100644 --- a/src/com/gitblit/wicket/pages/SummaryPage.java +++ b/src/com/gitblit/wicket/pages/SummaryPage.java @@ -114,7 +114,7 @@ public class SummaryPage extends RepositoryPage { add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false)); } StringBuilder sb = new StringBuilder(); - sb.append(WicketUtils.getHostURL(getRequestCycle().getRequest())); + sb.append(WicketUtils.getGitblitURL(getRequestCycle().getRequest())); sb.append(Constants.GIT_PATH); sb.append(repositoryName); repositoryUrls.add(sb.toString()); diff --git a/src/com/gitblit/wicket/pages/TreePage.java b/src/com/gitblit/wicket/pages/TreePage.java index 8695621e..7fc91eee 100644 --- a/src/com/gitblit/wicket/pages/TreePage.java +++ b/src/com/gitblit/wicket/pages/TreePage.java @@ -78,6 +78,8 @@ public class TreePage extends RepositoryPage { final ByteFormat byteFormat = new ByteFormat(); + final String baseUrl = WicketUtils.getGitblitURL(getRequest()); + // changed paths list ListDataProvider pathsDp = new ListDataProvider(paths); DataView pathsView = new DataView("changedPath", pathsDp) { @@ -112,10 +114,9 @@ public class TreePage extends RepositoryPage { links.add(new BookmarkablePageLink("history", HistoryPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path))); - links.add(new ExternalLink("zip", DownloadZipServlet.asLink(getRequest() - .getRelativePathPrefixToContextRoot(), repositoryName, objectId, - entry.path)).setVisible(GitBlit.getBoolean( - Keys.web.allowZipDownloads, true))); + links.add(new ExternalLink("zip", DownloadZipServlet.asLink(baseUrl, + repositoryName, objectId, entry.path)).setVisible(GitBlit + .getBoolean(Keys.web.allowZipDownloads, true))); item.add(links); } else { // blob link diff --git a/src/com/gitblit/wicket/panels/FederationTokensPanel.java b/src/com/gitblit/wicket/panels/FederationTokensPanel.java index 5a2e1250..3a771886 100644 --- a/src/com/gitblit/wicket/panels/FederationTokensPanel.java +++ b/src/com/gitblit/wicket/panels/FederationTokensPanel.java @@ -41,7 +41,7 @@ public class FederationTokensPanel extends BasePanel { public FederationTokensPanel(String wicketId, final boolean showFederation) { super(wicketId); - final String baseUrl = getRequest().getRelativePathPrefixToContextRoot(); + final String baseUrl = WicketUtils.getGitblitURL(getRequest()); add(new ExternalLink("federatedUsers", FederationServlet.asFederationLink(baseUrl, GitBlit.self() .getFederationToken(FederationToken.USERS_AND_REPOSITORIES), FederationRequest.PULL_USERS))); diff --git a/src/com/gitblit/wicket/panels/RepositoriesPanel.java b/src/com/gitblit/wicket/panels/RepositoriesPanel.java index f644546b..63b512c2 100644 --- a/src/com/gitblit/wicket/panels/RepositoriesPanel.java +++ b/src/com/gitblit/wicket/panels/RepositoriesPanel.java @@ -125,6 +125,8 @@ public class RepositoriesPanel extends BasePanel { } else { dp = new SortableRepositoriesProvider(models); } + + final String baseUrl = WicketUtils.getGitblitURL(getRequest()); DataView dataView = new DataView("row", dp) { private static final long serialVersionUID = 1L; @@ -271,9 +273,8 @@ public class RepositoriesPanel extends BasePanel { } else { row.add(new Label("repositoryLinks")); } - row.add(new ExternalLink("syndication", SyndicationServlet.asLink(getRequest() - .getRelativePathPrefixToContextRoot(), entry.name, null, 0)) - .setVisible(linksActive)); + row.add(new ExternalLink("syndication", SyndicationServlet.asLink(baseUrl, + entry.name, null, 0)).setVisible(linksActive)); WicketUtils.setAlternatingBackground(item, counter); counter++; } -- 2.39.5