Reputation: 1179
Is there a way to execute xquery code, using marklogic java api.. Basically I want to get the size of a given file and in xquery I could just do the following
return xdmp:binary-size(fn:doc($uri)/binary())
Is there an easy way to do this using Java API ? or can we execute random xquery code using java API ?
Upvotes: 0
Views: 838
Reputation: 7770
You are probably looking for this: Execute ad-hoc code on the server- with data mapped automatically to/from MarkLogic. https://docs.marklogic.com/guide/java/resourceservices#id_47102
Take it for a test drive - looks like it suits your needs.
You also have the robust resource service extension options: https://docs.marklogic.com/guide/java/resourceservices#id_27702
My absolute favourite is this: https://docs.marklogic.com/guide/java/resourceservices#id_84134 Full module execution on MarkLogic with injected variables - with data mapped automatically to/from MarkLogic
We use this option as follows:
Its a bit more complex in real life(including security and per/post execution auditing), but certainly a pattern that can help you by keeping control over your xQuery/JS code and not allow injection of arbitrary code execution (because you execute only functions for which the connected user has rights to use).
Upvotes: 1
Reputation: 2475
Yes, you have the ServerEvaluationCall which enables both eval and invoke. However, they require special privileges. Eval is particularly dangerous because it opens up security risks when you send ad-hoc code from the client that might contain an injection attack.
Instead we recommend that you install and use a custom resource extension.
Upvotes: 3