summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2013-11-29 20:06:09 -0500
committerJames Moger <james.moger@gitblit.com>2013-12-30 16:53:58 -0500
commit14cbbeaf61ce67c1ef5a6445515f3134dd5690ce (patch)
treec90f1e0bec0d65a4e54725b21caff52de5bc8a39 /src/main/java
parentafaab55bf4f309382b55793db44033233dcfb64d (diff)
downloadgitblit-14cbbeaf61ce67c1ef5a6445515f3134dd5690ce.tar.gz
gitblit-14cbbeaf61ce67c1ef5a6445515f3134dd5690ce.zip
New canonical base url setting for repository urls and notifications
Change-Id: I86a1eb61c2351d1cf3f6b3becf00f2a36d5c8ed6
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/gitblit/git/GitblitReceivePack.java6
-rw-r--r--src/main/java/com/gitblit/git/GitblitReceivePackFactory.java10
-rw-r--r--src/main/java/com/gitblit/manager/GitblitManager.java6
-rw-r--r--src/main/java/com/gitblit/servlet/FederationServlet.java12
-rw-r--r--src/main/java/com/gitblit/servlet/RpcServlet.java10
-rw-r--r--src/main/java/com/gitblit/servlet/SyndicationServlet.java5
6 files changed, 32 insertions, 17 deletions
diff --git a/src/main/java/com/gitblit/git/GitblitReceivePack.java b/src/main/java/com/gitblit/git/GitblitReceivePack.java
index e5c0ea45..c3734656 100644
--- a/src/main/java/com/gitblit/git/GitblitReceivePack.java
+++ b/src/main/java/com/gitblit/git/GitblitReceivePack.java
@@ -85,8 +85,6 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
protected String gitblitUrl;
- protected String repositoryUrl;
-
protected GroovyScriptEngine gse;
private final IStoredSettings settings;
@@ -390,10 +388,6 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
this.gitblitUrl = url;
}
- protected void setRepositoryUrl(String url) {
- this.repositoryUrl = url;
- }
-
protected void sendRejection(final ReceiveCommand cmd, final String why, Object... objects) {
String text;
if (ArrayUtils.isEmpty(objects)) {
diff --git a/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java b/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java
index bdf9b1ad..b8b49bcd 100644
--- a/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java
+++ b/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java
@@ -63,7 +63,6 @@ public class GitblitReceivePackFactory<X> implements ReceivePackFactory<X> {
String repositoryName = "";
String origin = "";
String gitblitUrl = "";
- String repositoryUrl = "";
int timeout = 0;
if (req instanceof HttpServletRequest) {
@@ -72,7 +71,6 @@ public class GitblitReceivePackFactory<X> implements ReceivePackFactory<X> {
repositoryName = request.getAttribute("gitblitRepositoryName").toString();
origin = request.getRemoteHost();
gitblitUrl = HttpUtils.getGitblitURL(request);
- repositoryUrl = request.getRequestURI();
// determine pushing user
String username = request.getRemoteUser();
@@ -98,11 +96,15 @@ public class GitblitReceivePackFactory<X> implements ReceivePackFactory<X> {
throw new ServiceNotEnabledException();
}
+ String url = settings.getString(Keys.web.canonicalUrl, null);
+ if (StringUtils.isEmpty(url)) {
+ url = gitblitUrl;
+ }
+
final RepositoryModel repository = gitblit.getRepositoryModel(repositoryName);
final GitblitReceivePack rp = new GitblitReceivePack(gitblit, db, repository, user);
- rp.setGitblitUrl(gitblitUrl);
- rp.setRepositoryUrl(repositoryUrl);
+ rp.setGitblitUrl(url);
rp.setRefLogIdent(new PersonIdent(user.username, user.username + "@" + origin));
rp.setTimeout(timeout);
diff --git a/src/main/java/com/gitblit/manager/GitblitManager.java b/src/main/java/com/gitblit/manager/GitblitManager.java
index 75b258a5..7e788361 100644
--- a/src/main/java/com/gitblit/manager/GitblitManager.java
+++ b/src/main/java/com/gitblit/manager/GitblitManager.java
@@ -337,8 +337,12 @@ public class GitblitManager implements IGitblit {
}
protected String getRepositoryUrl(HttpServletRequest request, String username, RepositoryModel repository) {
+ String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);
+ if (StringUtils.isEmpty(gitblitUrl)) {
+ gitblitUrl = HttpUtils.getGitblitURL(request);
+ }
StringBuilder sb = new StringBuilder();
- sb.append(HttpUtils.getGitblitURL(request));
+ sb.append(gitblitUrl);
sb.append(Constants.R_PATH);
sb.append(repository.name);
diff --git a/src/main/java/com/gitblit/servlet/FederationServlet.java b/src/main/java/com/gitblit/servlet/FederationServlet.java
index 372292de..8dbf0e16 100644
--- a/src/main/java/com/gitblit/servlet/FederationServlet.java
+++ b/src/main/java/com/gitblit/servlet/FederationServlet.java
@@ -138,8 +138,11 @@ public class FederationServlet extends JsonServlet {
return;
}
- String url = HttpUtils.getGitblitURL(request);
- federationManager.submitFederationProposal(proposal, url);
+ String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);
+ if (StringUtils.isEmpty(gitblitUrl)) {
+ gitblitUrl = HttpUtils.getGitblitURL(request);
+ }
+ federationManager.submitFederationProposal(proposal, gitblitUrl);
logger.info(MessageFormat.format(
"Submitted {0} federation proposal to pull {1} repositories from {2}",
proposal.tokenType.name(), proposal.repositories.size(), proposal.url));
@@ -185,7 +188,10 @@ public class FederationServlet extends JsonServlet {
Object result = null;
if (FederationRequest.PULL_REPOSITORIES.equals(reqType)) {
- String gitblitUrl = HttpUtils.getGitblitURL(request);
+ String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);
+ if (StringUtils.isEmpty(gitblitUrl)) {
+ gitblitUrl = HttpUtils.getGitblitURL(request);
+ }
result = federationManager.getRepositories(gitblitUrl, token);
} else {
if (FederationRequest.PULL_SETTINGS.equals(reqType)) {
diff --git a/src/main/java/com/gitblit/servlet/RpcServlet.java b/src/main/java/com/gitblit/servlet/RpcServlet.java
index e7b3ed2c..28f0d5bf 100644
--- a/src/main/java/com/gitblit/servlet/RpcServlet.java
+++ b/src/main/java/com/gitblit/servlet/RpcServlet.java
@@ -101,7 +101,10 @@ public class RpcServlet extends JsonServlet {
result = PROTOCOL_VERSION;
} else if (RpcRequest.LIST_REPOSITORIES.equals(reqType)) {
// Determine the Gitblit clone url
- String gitblitUrl = HttpUtils.getGitblitURL(request);
+ String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);
+ if (StringUtils.isEmpty(gitblitUrl)) {
+ gitblitUrl = HttpUtils.getGitblitURL(request);
+ }
StringBuilder sb = new StringBuilder();
sb.append(gitblitUrl);
sb.append(Constants.R_PATH);
@@ -320,7 +323,10 @@ public class RpcServlet extends JsonServlet {
} else if (RpcRequest.LIST_FEDERATION_SETS.equals(reqType)) {
// return the list of federation sets
if (allowAdmin && gitblit.canFederate()) {
- String gitblitUrl = HttpUtils.getGitblitURL(request);
+ String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);
+ if (StringUtils.isEmpty(gitblitUrl)) {
+ gitblitUrl = HttpUtils.getGitblitURL(request);
+ }
result = gitblit.getFederationSets(gitblitUrl);
} else {
response.sendError(notAllowedCode);
diff --git a/src/main/java/com/gitblit/servlet/SyndicationServlet.java b/src/main/java/com/gitblit/servlet/SyndicationServlet.java
index 8acd0192..66ca4a19 100644
--- a/src/main/java/com/gitblit/servlet/SyndicationServlet.java
+++ b/src/main/java/com/gitblit/servlet/SyndicationServlet.java
@@ -222,7 +222,10 @@ public class SyndicationServlet extends DaggerServlet {
// parameterized parameters
urlPattern = "{0}/commit/?r={1}&h={2}";
}
- String gitblitUrl = HttpUtils.getGitblitURL(request);
+ String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);
+ if (StringUtils.isEmpty(gitblitUrl)) {
+ gitblitUrl = HttpUtils.getGitblitURL(request);
+ }
char fsc = settings.getChar(Keys.web.forwardSlashCharacter, '/');
List<FeedEntryModel> entries = new ArrayList<FeedEntryModel>();