Suganya Kannan
Suganya Kannan

Reputation: 21

Marklogic 6 , Calling Resource Extension in java

I need to upload and use a xquery module to marklogic 6 like check-docAvailable.xqy. I tried using the dictionary.xqy sample given by ML6, it works well. But when I try to import my own xquery I'm getting below error.

ERROR :
Exception in thread "main" com.marklogic.client.FailedRequestException: Local message: config/resources write failed: Internal Server Error. Server Message: XDMP-IMPORTMOD: Cannot import Main Module /marklogic.rest.resource/dictionary/lib/resource.xqy.  See the MarkLogic server error log for further detail.
    at com.marklogic.client.impl.JerseyServices.putPostValueImpl(JerseyServices.java:2033)
    at com.marklogic.client.impl.JerseyServices.putValue(JerseyServices.java:1918)
    at com.marklogic.client.impl.ResourceExtensionsImpl.writeServices(ResourceExtensionsImpl.java:114)
    at com.mobius.ln.ml.util.MLUtil$DictionaryManager.installResourceExtensionShortcut(MLUtil.java:279)
    at com.mobius.ln.ml.util.MLUtil.main(MLUtil.java:202)

My Xquery Module:

xquery version "1.0-ml";
declare namespace xs = "http://www.w3.org/2001/XMLSchema";
declare variable $uri as xs:string external;

let $uri := $uri
return (
fn:doc-available($uri)
)

Please suggest me how to achieve this. Is there any mistake in Xquery?

Upvotes: 1

Views: 348

Answers (2)

Dave Cassel
Dave Cassel

Reputation: 8422

This part of the error message looks significant:

XDMP-IMPORTMOD: Cannot import Main Module /marklogic.rest.resource/dictionary/lib/resource.xqy.

That looks like you deployed dictionary.xqy as a service extension, using the REST API, then tried to import that module into another. dictionary.xqy is apparently a main module, but only library modules can be imported. See XQuery Library Modules and Main Modules in the Application Developer's Guide for more info about that.

I think what's happening is that you're deploying a main module as a service extension, but such extensions are required to be library modules. Take a look at Guidelines for Writing XQuery Resource Service Extensions in the REST Application Developer's Guide, taking note of the Resource Extension Interface section.

Solution: rewrite your extension as a library module, using the required interface.

Upvotes: 3

Sam Mefford
Sam Mefford

Reputation: 2475

I would suggest a read through Extending the REST API. Your XQuery module doesn't look like a REST extension. When I attempt to install your module via curl

curl --anyauth --user admin:admin -i \
  -H "Content-type: application/xquery" \
  --data-binary @/c/temp/a.xqy \
  -X PUT http://localhost:8000/LATEST/config/resources/a

I get the following error:

{"errorResponse":{"statusCode":400, "status":"Bad Request", "messageCode":"RESTAPI-INVALIDCONTENT", "message":"RESTAPI-INVALIDCONTENT: (err:FOER0000) Invalid content: invalid a extension: could not parse XQuery extension a; please see the server error log for detail XDMP-IMPORTMOD: Cannot import Main Module /marklogic.rest.resource/a/assets/resource.xqy; a either is not a valid module or does not provide extension functions (delete, get, put, post) in the http://marklogic.com/rest-api/resource/a namespace"}}

Upvotes: 4

Related Questions