How to register RESTXQ module in eXist-db?

477 Views Asked by At

I am trying to use RESTXQ in my exist-db application - lets call it "superapp". I added the restxq trigger to /db/apps/superapp/collection.xconf:

<collection xmlns="http://exist-db.org/collection-config/1.0">
    <index xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <fulltext default="none" attributes="false"/>
    </index>
    <triggers>
        <trigger class="org.exist.extensions.exquery.restxq.impl.RestXqTrigger"/>
    </triggers>
</collection>

Then I added a file "restxq-test.xql" to the folder /db/apps/superapp/modules:

xquery version "3.0";

module namespace test="http://exist-db.org/apps/restxq/test";


declare namespace rest="http://exquery.org/ns/restxq";
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";


declare
    %rest:GET
    %rest:path("/super")
    %output:media-type("text/html")
    %output:method("html5")
    %rest:query-param("user", "{$user}", "Guest")
function test:hello($user as xs:string*) {
    let $title := 'Hello '
    return
        <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
                <title>{$title}</title>
            </head>
            <body>
                <h1>{$title , $user}</h1>
            </body>
        </html>
};

But how do I make restxq "know" that this new module is there? It obviously does not do so automatically. If I call "xyz.com:8080/exist/restxq/super?user=John" I get

HTTP ERROR 405

Problem accessing /exist/restxq/super. Reason:

    HTTP method GET is not supported by this URL

I restarted eXist and I checked /var/www/exist/webapp/WEB-INF/logs/restxq.log but there is no entry in there... I'm quite sure the function and attribute mapping is correct. If I add the same function to "/db/apps/demo/examples/templating/restxq-demo.xql" (which is obviously registered) it works just perfect. So I guess the new module is just not registered. How can I do that?

2

There are 2 best solutions below

3
On BEST ANSWER

I would post a comment, but I don't have enough points. I am not sure if this is going to solve your whole issue with the RESTXQ because I have not used it in my application, but it seems that you have placed collection.xconf file in the wrong collection. It should be placed in the system collection: /db/system/config. That means that your configuration file should be in /db/system/config/db/apps/superapp collection. More info on triggers you have on the exist-db website on the documentation page: Configuring Database Triggers

0
On

At least in eXist-db 5 there is a default /db/system/config/db/apps/collection.xconf with this trigger. Unless you override that default by removing this file or by adding a different config somewhere under /db/system/config/db/apps, you don't need to do anything. My guess, since you don't see your code loaded in the restxq.log, is that you had an override somewhere which is why you needed to also explicitly add the conf under /db/system.

Since your question was 3 years ago, it might not make a difference to you anymore, but in looking for information myself I stumbled upon this question.