基本的にMLコンテンツデータベースにアップロードされたファイルを保存するML8で小さな休息拡張機能を作成しました..これを行うと、次の例外が発生します
<error-response xmlns="http://marklogic.com/xdmp/error">
<status-code>500</status-code>
<status>Internal Server Error</status>
<message-code>INTERNAL ERROR</message-code>
<message>XDMP-UPDATEFUNCTIONFROMQUERY: xdmp:function(fn:QName("http://marklogic.com/rest-api/resource/repoLoad","post"), "/marklogic.rest.resource/repoLoad/assets/resource.xqy")($context, $service-params, $input) -- Cannot apply an update function from a query . See the MarkLogic server error log for further detail.</message>
</error-response>
しかし、宣言オプション xdmp:update "true"; を設定しました。以下はコードです..
module namespace repoLoad = "http://marklogic.com/rest-api/resource/repoLoad";
declare namespace rapi = "http://marklogic.com/rest-api";
declare default function namespace "http://www.w3.org/2005/xpath-functions";
declare option xdmp:mapping "false";
declare option xdmp:update "true";
(: Function responding to GET method - must use local name 'get':)
declare function repoLoad:get($context as map:map, $params as map:map) as document-node()*
{
repoLoad:notSuportedMsg($context)
};
(: Function responding to PUT method - must use local name 'put'. :)
declare function repoLoad:put($context as map:map, $params as map:map, $input as document-node()*) as document-node()?
{
repoLoad:notSuportedMsg($context)
};
(: Func responding to DELETE method - must use local name 'delete'. :)
declare function repoLoad:delete($context as map:map,$params as map:map) as document-node()?
{
repoLoad:notSuportedMsg($context)
};
(: Function responding to POST method - must use local name 'post'. :)
declare function repoLoad:post($context as map:map, $params as map:map,$input as document-node()*) as document-node()*
{
let $filename := xdmp:get-request-field-filename("upload")
let $contentType := xdmp:get-request-field-content-type("upload")
let $log := xdmp:log("File Name : " || $filename)
let $log := xdmp:log("Content Type : " || $contentType)
let $uri := "/documents/"||$filename
let $_ := xdmp:document-insert($uri, xdmp:get-request-field("upload"),(xdmp:default-permissions()), ("raw"))
let $output := json:object()
let $_ := (
map:put($output, "Name", $filename),
map:put($output, "Mime-Type", $contentType)
)
return document {xdmp:to-json($output)}
};
declare private function repoLoad:notSuportedMsg($context as map:map) as document-node()*
{
let $_ := map:put($context, "output-status", (501, "Not Supported HTTP method"))
let $output := json:object()
let $errorResponse := json:object()
let $_ := (
map:put($errorResponse, "statusCode", 501),
map:put($errorResponse, "message", "Not Supported HTTP method")
)
let $dummpy := map:put($output, "errorResponse", $errorResponse )
return document {xdmp:to-json($output)}
};
以下は、ログ ファイルのエラー トレースです。
2016-02-15 17:29:32.085 Notice: content-repo: XDMP-UPDATEFUNCTIONFROMQUERY: xdmp:function(fn:QName("http://marklogic.com/rest-api/resource/repoLoad","post"), "/marklogic.rest.resource/repoLoad/assets/resource.xqy")($context, $service-params, $input) -- Cannot apply an update function from a query
2016-02-15 17:29:32.085 Notice: content-repo: in /MarkLogic/rest-api/lib/extensions-util.xqy, at 877:20,
2016-02-15 17:29:32.085 Notice: content-repo: in extut:call-service("repoLoad", "POST", xdmp:function(fn:QName("http://marklogic.com/rest-api/resource/repoLoad","post"), "/marklogic.rest.resource/repoLoad/assets/resource.xqy"), map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:map="http://marklogic.com/xdmp/map"><map:entry key="accept-types"><map:value xsi:type="xs:string">te...</map:map>), map:map(), document{binary{""}}) [1.0-ml]
2016-02-15 17:29:32.085 Notice: content-repo: $extension-name = "repoLoad"
2016-02-15 17:29:32.085 Notice: content-repo: $method = "POST"
2016-02-15 17:29:32.085 Notice: content-repo: $service = xdmp:function(fn:QName("http://marklogic.com/rest-api/resource/repoLoad","post"), "/marklogic.rest.resource/repoLoad/assets/resource.xqy")
2016-02-15 17:29:32.085 Notice: content-repo: $context = map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:map="http://marklogic.com/xdmp/map"><map:entry key="accept-types"><map:value xsi:type="xs:string">te...</map:map>)
2016-02-15 17:29:32.085 Notice: content-repo: $service-params = map:map()
2016-02-15 17:29:32.085 Notice: content-repo: $input = document{binary{""}}
2016-02-15 17:29:32.085 Notice: content-repo: in /MarkLogic/rest-api/lib/extensions-util.xqy, at 792:14,
2016-02-15 17:29:32.085 Notice: content-repo: in extut:invoke-service("repoLoad", "POST", "query", xdmp:function(fn:QName("http://marklogic.com/rest-api/resource/repoLoad","post"), "/marklogic.rest.resource/repoLoad/assets/resource.xqy"), map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:map="http://marklogic.com/xdmp/map"><map:entry key="accept-types"><map:value xsi:type="xs:string">te...</map:map>), map:map(), document{binary{""}}, fn:false()) [1.0-ml]
2016-02-15 17:29:32.085 Notice: content-repo: $extension-name = "repoLoad"
2016-02-15 17:29:32.085 Notice: content-repo: $method = "POST"
2016-02-15 17:29:32.085 Notice: content-repo: $default-txn-mode = "query"
2016-02-15 17:29:32.085 Notice: content-repo: $service = xdmp:function(fn:QName("http://marklogic.com/rest-api/resource/repoLoad","post"), "/marklogic.rest.resource/repoLoad/assets/resource.xqy")
2016-02-15 17:29:32.085 Notice: content-repo: $context = map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:map="http://marklogic.com/xdmp/map"><map:entry key="accept-types"><map:value xsi:type="xs:string">te...</map:map>)
2016-02-15 17:29:32.085 Notice: content-repo: $service-params = map:map()
2016-02-15 17:29:32.085 Notice: content-repo: $input = document{binary{""}}
2016-02-15 17:29:32.085 Notice: content-repo: $in-txn = fn:false()
2016-02-15 17:29:32.085 Notice: content-repo: $txn-curr = "query"
2016-02-15 17:29:32.085 Notice: content-repo: $annotation = ()
2016-02-15 17:29:32.085 Notice: content-repo: $txn-mode = "query"
2016-02-15 17:29:32.085 Notice: content-repo: in /MarkLogic/rest-api/models/resource-model-query.xqy, at 254:8,
2016-02-15 17:29:32.085 Notice: content-repo: in rsrcmodqry:resource-post("repoLoad", map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:map="http://marklogic.com/xdmp/map"><map:entry key="accept-types"><map:value xsi:type="xs:string">te...</map:map>), map:map(), document{binary{""}}, fn:false(), local:rsrcmod-callback#6) [1.0-ml]
2016-02-15 17:29:32.085 Notice: content-repo: $resource-name = "repoLoad"
2016-02-15 17:29:32.085 Notice: content-repo: $context = map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:map="http://marklogic.com/xdmp/map"><map:entry key="accept-types"><map:value xsi:type="xs:string">te...</map:map>)
2016-02-15 17:29:32.085 Notice: content-repo: $resource-params = map:map()
2016-02-15 17:29:32.085 Notice: content-repo: $input = document{binary{""}}
2016-02-15 17:29:32.085 Notice: content-repo: $in-txn = fn:false()
2016-02-15 17:29:32.085 Notice: content-repo: $responder = local:rsrcmod-callback#6
2016-02-15 17:29:32.085 Notice: content-repo: $service = xdmp:function(fn:QName("http://marklogic.com/rest-api/resource/repoLoad","post"), "/marklogic.rest.resource/repoLoad/assets/resource.xqy")
2016-02-15 17:29:32.085 Notice: content-repo: in /MarkLogic/rest-api/models/resource-model-query.xqy, at 219:4,
2016-02-15 17:29:32.085 Notice: content-repo: in rsrcmodqry:exec-post(map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:map="http://marklogic.com/xdmp/map"><map:entry key="content-type"><map:value xsi:type="xs:string">mu...</map:map>), map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:map="http://marklogic.com/xdmp/map"><map:entry key="upload"><map:value/></map:entry></map:map>...XDMP-CHILDNODEKIND: element nodes cannot have binary node children...), document{binary{""}}, local:rsrcmod-callback#6) [1.0-ml]
2016-02-15 17:29:32.085 Notice: content-repo: $headers = map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:map="http://marklogic.com/xdmp/map"><map:entry key="content-type"><map:value xsi:type="xs:string">mu...</map:map>)
2016-02-15 17:29:32.085 Notice: content-repo: $endpoint-params = map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:map="http://marklogic.com/xdmp/map"><map:entry key="upload"><map:value/></map:entry></map:map>...XDMP-CHILDNODEKIND: element nodes cannot have binary node children...)
2016-02-15 17:29:32.085 Notice: content-repo: $input = document{binary{""}}
2016-02-15 17:29:32.085 Notice: content-repo: $responder = local:rsrcmod-callback#6
2016-02-15 17:29:32.085 Notice: content-repo: in /MarkLogic/rest-api/endpoints/resource-service-query.xqy, at 65:8 [1.0-ml]
2016-02-15 17:29:32.085 Notice: content-repo: $params = map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:map="http://marklogic.com/xdmp/map"><map:entry key="upload"><map:value/></map:entry></map:map>...XDMP-CHILDNODEKIND: element nodes cannot have binary node children...)
2016-02-15 17:29:32.085 Notice: content-repo: $headers = map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:map="http://marklogic.com/xdmp/map"><map:entry key="content-type"><map:value xsi:type="xs:string">mu...</map:map>)
2016-02-15 17:29:32.085 Notice: content-repo: $method = "POST"
2016-02-15 17:29:32.085 Notice: content-repo: $body = document{binary{""}}
2016-02-15 17:29:32.216 Info: content-repo: Status 500: XDMP-UPDATEFUNCTIONFROMQUERY: xdmp:function(fn:QName("http://marklogic.com/rest-api/resource/repoLoad","post"), "/marklogic.rest.resource/repoLoad/assets/resource.xqy")($context, $service-params, $input) -- Cannot apply an update function from a query