如何在 eXist-db 中注册 RESTXQ 模块



我正在尝试在我的exist-db应用程序中使用RESTXQ - 我们称之为"superapp"。我将restxq触发器添加到/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>

然后我添加了一个文件"restxq-test.xql"到文件夹/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>
};

但是我如何让 restxq "知道"这个新模块的存在呢?它显然不会自动这样做。如果我打电话给"xyz.com:8080/exist/restxq/super?user=John",我会得到

HTTP ERROR 405
Problem accessing /exist/restxq/super. Reason:
    HTTP method GET is not supported by this URL

重新启动了eXist,我检查了/var/www/exist/webapp/WEB-INF/logs/restxq.log但里面没有条目......我很确定函数和属性映射是正确的。如果我将相同的函数添加到"/db/apps/demo/examples/templating/restxq-demo.xql"(显然已注册(,它就可以完美地工作了。所以我想新模块只是没有注册。我该怎么做?

我会发表评论,但我没有足够的积分。我不确定这是否会解决您对 RESTXQ 的整个问题,因为我没有在我的应用程序中使用它,但似乎您将collection.xconf文件放在错误的集合中。它应该放在系统集合中:/db/system/config 。这意味着您的配置文件应该在集合/db/system/config/db/apps/superapp中。有关现有数据库网站文档页面上的触发器的更多信息:配置数据库触发器

至少在 eXist-db 5 中,有一个带有此触发器的默认/db/system/config/db/apps/collection.xconf。除非您通过删除此文件或在/db/system/config/db/apps 下的某处添加其他配置来覆盖该默认值,否则您无需执行任何操作。我的猜测,因为你没有看到你的代码加载在restxq.log中,是你在某处有一个覆盖,这就是为什么你还需要在/db/system下显式添加conf

由于您的问题是 3 年前的问题,因此对您来说可能不再有什么不同,但在自己寻找信息时,我偶然发现了这个问题。

最新更新