howto compute external URL to Vaadin UI

I need to compute a URL to a Vaadin UI so when this URL is launched from the client, the UI is processed (for example to feed ckeditor with a filebrowser URL - the filebrowser is a Vaadin UI then). I know that com.vaadin.server.UIProvider does the trick but the question is what is the best way to compute the URL?

Page.getLocation() provides the URI as seen from the browser (which is really good!) but usually it returns something like “/a/b” (where ‘a’ is the context and ‘b’ is the vaadin servlet path) so that URI.resolve(“resourceBrowser”) ends up in “/a/resourceBrowser” and not “/a/b/resourceBrowser”. Furthermore the page location URI might contain some path-info segments (who knows what URLs end-users do type in their address bar…), thus one has to peek into the page location uri and check whether it ends with slash or contains extra path segments etc.

Thus I thought that there might be a more elegant way to compute an external URL to a Vaadin UI.
FileDownloader and BrowserFrame must have the same problem. I looked at the source code and found that they use an ExternalResource with “app://” (ApplicationConstants.APP_PROTOCOL_PREFIX) but I don’t know how to use this.

Any ideas?