When you write Confluence plugins, sometimes you need to create an absolute URL, with the full "http://...
" included.
To do that, you need to determine what the URL path is up to the root of the Confluence web application.
Confluence attempts to guess the correct base URL for the site during setup. You can change it in the site's General Configuration.
Starting from Confluence 2.8, you can get it all in one spot. Versions up to Confluence 2.8 will require joining two separate string values.
Starting from Confluence 2.8, you can retrieve the full path from one location.
SettingsManager
object (see how to retrieve it).1 2String baseUrl = settingsManager.getGlobalSettings().getBaseUrl();
Older versions of Confluence store the full base URL split into the base URL, and the context path.
The base URL is the URL for the root of your Confluence site. For example, the base URL for this site is http://developer.atlassian.com. If you have installed Confluence somewhere other than the root directory of the webserver, for example http://www.example.com/confluence, then your base URL would be http://www.example.com/confluence.
Get the BootstrapManager (see how to retrieve it).
Call the following method:
1 2String baseUrl = bootstrapManager.getBaseUrl();
To complete the URL, you will need to add the context path.
The context path is the path to Confluence relative to the root directory of the webserver. For example,
the context path for this site is an empty string, because it is deployed at the root. The context path for a Confluence instance deployed at http://www.example.com/confluence would be /confluence
.
To get context path, use the following:
1 2String contextPath = bootstrapManager.getWebAppContextPath();
To get the full path, just do this:
1 2String fullPath = baseUrl + contextPath;
In Confluence 2.0 and earlier, the method was called bootstrapManager.getDomain()
.
The getDomain()
method was deprecated in favour of getBaseUrl()
in Confluence 2.1, because the latter name better describes the information it returns.
Rate this page: