This page last changed on Apr 26, 2006 by cmiller.
Cannot resolve external resource into attachment. How do I get the base URL of a Confluence installation?
What are the base URL and 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://confluence.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.
Confluence attempts to guess the correct base URL for the site during setup. You can change it in the site's General Configuration.
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.
How do I determine the base URL and context path?
First you need the BootstrapManager (see how to retrieve it) then simply call the following method:
String baseUrl = bootstrapManager.getBaseUrl();
 | 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. |
To get the context path, use
String contextPath = bootstrapManager.getWebAppContextPath()
Maybe I'm blind,k but I don't see getBaseUrl() in BootstrapManager... and I really could use the base URL right now. How do I get it?

Posted by jason.dillon@paybytouch.com at Jan 25, 2006 03:01
|
Personally, I get it from the RenderContext/PageContext using something like this:
String contextPath = renderContext.getSiteRoot();
if (contextPath == null)
contextPath = bootstrapManager.getWebAppContextPath();
Usually I just use the first line. I've added the 'if null' test for AJAXified code (eg 'Preview') where the site root may not be set.

Posted by david@randombits.org at Jan 25, 2006 03:15
|
No love My site base URl is set to: http://localhost:8080, and the above both return "".
I've got an Attachment object, and need a full URL so that I can pass it to an applet to load... so its gotta have the full URL.
I'll fiddle around w/it some-more tomorrow and check the code it. Brain shutting down now 

Posted by jason.dillon@paybytouch.com at Jan 25, 2006 04:11
|
What context is this in? A macro? Where's the macro being executed? On a page, a blog post, the dashboard?

Posted by david@randombits.org at Jan 25, 2006 07:01
|
It's in a macro, on a page; code now in svn. See MindmapMacro.
I guess I can always reconstruct the URL from the details in the servlet request context, but would be nice if I didn't have to.

Posted by jason.dillon@paybytouch.com at Jan 25, 2006 12:41
|
Jason - if they return "" it sounds like a bug, should be filed with the Confluence team. Using the request object in Confluence is evil and should be avoided at all possible costs Does your confluence.cfg.xml file in confluence.home have any properties that look like base URL?

Posted by mike@atlassian.com at Jan 25, 2006 16:23
|
The method was renamed to getBaseUrl() from getDomainName() somewhere around Confluence 2.1. Try using getDomainName() instead?

Posted by cmiller at Jan 29, 2006 14:38
|
Hi,
I also need to get baseurl of our confluence installation.
My action declaration is like :
public class UserMgmtConfigAction extends ConfluenceActionSupport implements Administrative
It looks like, I couldn't have BootStrapManager instance easily available through setter method.
Trying to get this instance through ContainerManager.getComponent("bootStrapManager") thrown error that no such bean found.
Atlast after searching in confluence installation directory, I found correct way to get the instance of BootStrapManager as follows:
BootstrapManager bootstrapManager = (BootstrapManager)ContainerManager.getInstance().getContainerContext().getComponent("bootstrapManager");
Just thought of sharing this information. This page has link for how to reterive this object, but doesn't work.
cheers,
Rajendra

Posted by rakadam at Mar 15, 2006 23:54
|
|