如何在eXist-db 中注册RESTXQ 模块?
How to register RESTXQ module in eXist-db?
我正在尝试在我的 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 "know" 知道这个新模块在那里?它显然不会自动这样做。如果我调用 "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”(显然已注册),它就可以完美运行。所以我猜新模块只是没有注册。我怎样才能做到这一点?
我会post评论,但我没有足够的积分。我不确定这是否会解决您与 RESTXQ 的整个问题,因为我没有在我的应用程序中使用它,但您似乎将 collection.xconf
文件放在了错误的集合中。
它应该放在系统集合中:/db/system/config
。这意味着您的配置文件应该在 /db/system/config/db/apps/superapp
集合中。
有关您在文档页面上的 exist-db 网站上拥有的触发器的更多信息:Configuring Database Triggers
至少在 eXist-db 5 中有一个带有此触发器的默认 /db/system/config/db/apps/collection.xconf。除非您通过删除此文件或在 /db/system/config/db/apps 下的某处添加不同的配置来覆盖该默认值,否则您无需执行任何操作。我的猜测是,由于您没有看到 restxq.log 中加载的代码,是因为您在某处进行了覆盖,这就是为什么您还需要在 /db/system.
下显式添加 conf
由于您的问题是 3 年前的问题,它可能对您不再有任何影响,但在我自己查找信息时,我偶然发现了这个问题。
我正在尝试在我的 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 "know" 知道这个新模块在那里?它显然不会自动这样做。如果我调用 "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”(显然已注册),它就可以完美运行。所以我猜新模块只是没有注册。我怎样才能做到这一点?
我会post评论,但我没有足够的积分。我不确定这是否会解决您与 RESTXQ 的整个问题,因为我没有在我的应用程序中使用它,但您似乎将 collection.xconf
文件放在了错误的集合中。
它应该放在系统集合中:/db/system/config
。这意味着您的配置文件应该在 /db/system/config/db/apps/superapp
集合中。
有关您在文档页面上的 exist-db 网站上拥有的触发器的更多信息:Configuring Database Triggers
至少在 eXist-db 5 中有一个带有此触发器的默认 /db/system/config/db/apps/collection.xconf。除非您通过删除此文件或在 /db/system/config/db/apps 下的某处添加不同的配置来覆盖该默认值,否则您无需执行任何操作。我的猜测是,由于您没有看到 restxq.log 中加载的代码,是因为您在某处进行了覆盖,这就是为什么您还需要在 /db/system.
下显式添加 conf由于您的问题是 3 年前的问题,它可能对您不再有任何影响,但在我自己查找信息时,我偶然发现了这个问题。