Deepan Chelliah
Deepan Chelliah

Reputation: 81

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

I was trying to load the xquery transformation into Modules DB using Marklogic Java API. Initially, I used to load Javascript transformation(.sjs) using the same piece of code which works fine. Now, when I try to load xquery transformation with the same code, it doesn't work.

My Xquery transformation:

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  

};

My Java code to load Transformation:

    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:

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)

Upvotes: 0

Views: 492

Answers (1)

Wagner Michael
Wagner Michael

Reputation: 2192

Seems like you have a syntax error in your code. Change to this and it should work:

...
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
...

I added let $_ := in front of the map:put expressions.

Also your namespace name (sec) and transformation name (deepan) do not match:

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

declare function test:transform
...

Further the interface of the transform function must match this one:

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

Change yours to the following:

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

More information here.

Upvotes: 1

Related Questions