user6419217
user6419217

Reputation: 59

Return link to file stored in eXist db on remote server

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.

Upvotes: 1

Views: 293

Answers (2)

Louis
Louis

Reputation: 151511

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.

Upvotes: 2

GSpringTech
GSpringTech

Reputation: 156

Try the function request:get-server-name()

There are a few other functions which may be useful - Browse the Request module in the XQuery Function Documentation app from your Dashboard.

Upvotes: 1

Related Questions