I'd like to know how to get/create a url to a file stored in exist-db. I can get a file with link similar to this one if eXist-db is running on my localhost: http://localhost:8080/exist/rest/db/junitReports/Report1.xml
But how can I do it if it exist-db is on the remote host? I can hardcode that host's IP address in xQuery, but I do not want to do it. Is there a function which would return me remote's hostname or ip address in xquery?
Thank you.
I'm able to build a URL I can use with curl
with the following expression:
concat(request:get-scheme(), "://", request:get-server-name(), ":",
request:get-server-port(), request:get-context-path(),
request:get-servlet-path(), document-uri(root($m)))
$m
is a node from some document.
Here is an example of a complete query:
xquery version "3.0";
declare namespace config='http://exist-db.org/collection-config/1.0';
for $m in //config:collection
return concat(request:get-scheme(), "://", request:get-server-name(),
":", request:get-server-port(), request:get-context-path(),
request:get-servlet-path(), document-uri(root($m)))
On a normal eXist database the above query would produce one URL per .xconf
file that is present in the database. (A default eXist installation has a bunch of them.) Here's an example of a URL I get from this:
http://localhost:8080/exist/rest/db/system/config/db/collection.xconf
And I can use curl
directly on that URL to get the document. Or I can plop it in my browser.