如何在 Marklogic 中修复 "Server Message: RESTAPI-INVALIDCONTENT: (err:FOER0000) Invalid content:"?

How to fix "Server Message: RESTAPI-INVALIDCONTENT: (err:FOER0000) Invalid content:" in Marklogic?

我试图使用 Marklogic Java API 将 xquery 转换加载到模块数据库中。最初,我曾经使用工作正常的同一段代码加载 Javascript transformation(.sjs)。 现在,当我尝试使用相同的代码加载 xquery 转换时,它不起作用。

我的 Xquery 转换:

xquery version "1.0-ml";

module namespace test =
  "http://marklogic.com/rest-api/transform/deepan";

declare function test:transform(
  $context as map:map,
  $params as map:map,
  $content as map:map
) as map:map*
{
    let $jsoncont := xdmp:from-json-string($content)

    let $inputval := "fname,lname"
    let $orig-value := map:get($jsoncont, "value")

    let $jscode := "var simple = require('/wdsUtils.sjs');
                    var content, input;
                    simple.createUri(content,input);"

    let $uri := xdmp:javascript-eval($jscode,('content',$orig-value,'input',$inputval))
    map:put($content, "uri",$uri)
    map:put($content, "value",$orig-value)
    return $content  

};

我的 Java 加载转换的代码:

    private static final String TRANSFORM_NAME = "sec";
    static String HOST = "localhost";
    static int PORT = 8136;
    static String USER = "admin";
    static String PASSWORD = "admin";
    private static DatabaseClient client = 
            DatabaseClientFactory.newClient(
                HOST, PORT, new DigestAuthContext(USER, PASSWORD));


    public static void loadLookup() throws FileNotFoundException 
    {

        TransformExtensionsManager extensionsManager=client.newServerConfigManager().newTransformExtensionsManager();
        FileInputStream fileInputStream=new FileInputStream("C:/Users/deepan/Desktop/sec.xqy");
        //System.out.println(fileInputStream.toString());
        InputStreamHandle handle=new InputStreamHandle(fileInputStream);
        //extensionsManager.writeJavascriptTransform(TRANSFORM_NAME, handle);
        extensionsManager.writeXQueryTransform(TRANSFORM_NAME, handle);
        client.release();

    }

异常:

Exception in thread "main" com.marklogic.client.FailedRequestException: Local message: config/transforms write failed: Bad Request. Server Message: RESTAPI-INVALIDCONTENT: (err:FOER0000) Invalid content: invalid sec extension: could not parse XQuery extension sec; please see the server error log for detail XDMP-UNEXPECTED: (err:XPST0003) Unexpected token syntax error, unexpected Dollar_; sec either is not a valid module or does not provide extension functions (transform) in the http://marklogic.com/rest-api/transform/sec namespace
    at com.marklogic.client.impl.OkHttpServices.putPostValueImpl(OkHttpServices.java:2890)
    at com.marklogic.client.impl.OkHttpServices.putValue(OkHttpServices.java:2757)
    at com.marklogic.client.impl.TransformExtensionsImpl.writeTransform(TransformExtensionsImpl.java:356)
    at com.marklogic.client.impl.TransformExtensionsImpl.writeXQueryTransform(TransformExtensionsImpl.java:255)
    at com.marklogic.client.impl.TransformExtensionsImpl.writeXQueryTransform(TransformExtensionsImpl.java:249)
    at com.example.batch.Transform.loadLookup(Transform.java:33)
    at com.example.batch.Transform.main(Transform.java:40)

您的代码似乎有语法错误。对此进行更改,它应该可以工作:

...
let $uri := xdmp:javascript-eval($jscode, ('content', $orig-value, 'input', $inputval))
let $_ := map:put($content, "uri", $uri)
let $_ := map:put($content, "value", $orig-value)
return $content
...

我在 map:put 表达式前添加了 let $_ :=

您的命名空间名称 (sec) 和转换名称 (deepan) 也不匹配:

module namespace test =
  "http://marklogic.com/rest-api/transform/sec";

declare function test:transform
...

另外转换函数的接口必须匹配这个:

declare function yourNS:transform(
  $context as map:map,
  $params as map:map,
  $content as document-node())
as document-node()

将您的更改为以下内容:

declare function test:transform(
  $context as map:map,
  $params as map:map,
  $content as document-node()
) as document-node()

更多信息here