Skip to content

Javascript extension doesn't work since it is inserted with source format as xquery #168

@sravanr

Description

@sravanr

Here is my code for inserting a javascript resource

 client = DatabaseClientFactory.newClient("localhost", restPort, "rest-admin", "x", Authentication.DIGEST);
         resourceMgr = client.newServerConfigManager().newResourceExtensionsManager();
         ExtensionMetadata resextMetadata = new ExtensionMetadata();
         resextMetadata.setTitle("BasicJSTest");
         resextMetadata.setDescription("Testing resource extension for java script");
         System.out.println(resextMetadata.getScriptLanguage());
         resextMetadata.setScriptLanguage(ScriptLanguage.JAVASCRIPT);
         System.out.println(resextMetadata.getScriptLanguage());
         resextMetadata.setVersion("1.0");
         MethodParameters getParams = new MethodParameters(MethodType.GET);
         getParams.add("my-uri", "xs:string?");
         FileInputStream myStream = new FileInputStream("src/test/java/com/marklogic/javaclient/data/JSResource.js");
         InputStreamHandle handle = new InputStreamHandle(myStream);
         handle.set (myStream);
         resourceMgr.writeServices("simpleJSResourceModule", handle, resextMetadata,getParams);

Http wire:
[DEBUG] wire - << "Keep-Alive: timeout=5[\r][\n]"
[DEBUG] wire - << "[\r][\n]"
[DEBUG] wire - >> "PUT /v1/config/resources/simpleJSResourceModule?title=BasicJSTest&description=Testing%20resource%20extension%20for%20java%20script&get:my-uri=xs:string?&method=get&version=1.0 HTTP/1.1[\r][\n]"
[DEBUG] wire - >> "Content-Type: application/xquery[\r][\n]"
[DEBUG] wire - >> "Authorization: Digest username="rest-admin",realm="public",nonce="8ca7691f5182439b02834a35e226275a",opaque="635ddcbe1efc49f4",qop=auth,uri="/v1/config/resources/simpleJSResourceModule",cnonce="6f481e82",nc=00000002,response="7063ca4e9e87f57d79db53f79e75ccfb"[\r][\n]"
[DEBUG] wire - >> "Transfer-Encoding: chunked[\r][\n]"
[DEBUG] wire - >> "Host: localhost:8011[\r][\n]"
[DEBUG] wire - >> "Connection: Keep-Alive[\r][\n]"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - >> "38d[\r][\n]"
[DEBUG] wire - >> "// module that exports get, post, put and delete [\r][\n]"
[DEBUG] wire - >> "function get(context, params) { [\r][\n]"
[DEBUG] wire - >> " context.outputTypes = ["application/json"];[\r][\n]"
[DEBUG] wire - >> " var arg1 = params.arg1;[\r][\n]"
[DEBUG] wire - >> "return {[\r][\n]"
[DEBUG] wire - >> "[0x9]"argument1": arg1,[\r][\n]"
[DEBUG] wire - >> "    "content": "This is a JSON document",[\r][\n]"
[DEBUG] wire - >> "    "response": xdmp.getResponseCode(),[\r][\n]"
[DEBUG] wire - >> "[0x9]"outputTypes": context.outputTypes,[\r][\n]"
[DEBUG] wire - >> "[0x9]"acceptTypes": context.acceptTypes[\r][\n]"
[DEBUG] wire - >> "  }[\r][\n]"
[DEBUG] wire - >> "};[\r][\n]"
[DEBUG] wire - >> "function post(context, params, input) { [\r][\n]"
[DEBUG] wire - >> "   jsInput = input.toObject();  // create an object from node[\r][\n]"
[DEBUG] wire - >> "   return(xdmp.log("post!"))[\r][\n]"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - >> " };[\r][\n]"
[DEBUG] wire - >> " [\r][\n]"
[DEBUG] wire - >> "// Function responding to PUT method - must use local name 'put'.[\r][\n]"
[DEBUG] wire - >> "function put(context, params, input) {[\r][\n]"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - >> "[0x9]return {"argument1": context.acceptTypes}[\r][\n]"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - >> "};[\r][\n]"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - >> "// Function responding to DELETE method - must use local name 'delete'.[\r][\n]"
[DEBUG] wire - >> "function deleteFunction(context, params) {[\r][\n]"
[DEBUG] wire - >> "[0x9]return(xdmp.log("delete!"))[\r][\n]"
[DEBUG] wire - >> "};[\r][\n]"
[DEBUG] wire - >> "exports.GET = get;[\r][\n]"
[DEBUG] wire - >> "exports.POST = post;[\r][\n]"
[DEBUG] wire - >> "exports.PUT = put;[\r][\n]"
[DEBUG] wire - >> "exports.DELETE = deleteFunction;[\r][\n]"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - >> "0[\r][\n]"
[DEBUG] wire - >> "[\r][\n]"
[DEBUG] wire - << "HTTP/1.1 400 Bad Request[\r][\n]"
[DEBUG] wire - << "Content-type: application/json; charset=UTF-8[\r][\n]"
[DEBUG] wire - << "Server: MarkLogic[\r][\n]"
[DEBUG] wire - << "Content-Length: 620[\r][\n]"
[DEBUG] wire - << "Connection: Keep-Alive[\r][\n]"
[DEBUG] wire - << "Keep-Alive: timeout=5[\r][\n]"
[DEBUG] wire - << "[\r][\n]"
[DEBUG] wire - << "{"errorResponse":{"statusCode":400, "status":"Bad Request", "messageCode":"RESTAPI-INVALIDCONTENT", "message":"RESTAPI-INVALIDCONTENT: (err:FOER0000) Invalid content: invalid simpleJSResourceModule extension: could not parse XQuery extension simpleJSResourceModule; please see the server error log for detail XDMP-UNEXPECTED: (err:XPST0003) Unexpected token syntax error, unexpected QName_, expecting $end or SemiColon_; simpleJSResourceModule either is not a valid module or does not provide extension functions (delete, get, put, post) in the http://marklogic.com/rest-api/resource/simpleJSResourceModule namespace"}}[\n]"

I see 2 documents in the modules database

/marklogic.rest.resource/simpleJSResourceModule/assets/metadata.xml 
```xml
<?xml version="1.0" encoding="UTF-8"?>
<rapi:resource-metadata xmlns:rapi="http://marklogic.com/rest-api">
<rapi:name>
simpleJSResourceModule
</rapi:name>
<rapi:source-format>
xquery
</rapi:source-format>
<rapi:version>
1.0
</rapi:version>
<rapi:description>
Testing resource extension for java script
</rapi:description>
<rapi:title>
BasicJSTest
</rapi:title>
<rapi:methods>
</rapi:methods>
<rapi:errors>
<rapi:error>
could not parse XQuery extension simpleJSResourceModule; please see the server error log for detail XDMP-UNEXPECTED: (err:XPST0003) Unexpected token syntax error, unexpected QName_, expecting $end or SemiColon_
</rapi:error>
<rapi:error>
simpleJSResourceModule either is not a valid module or does not provide extension functions (delete, get, put, post) in the http://marklogic.com/rest-api/resource/simpleJSResourceModule namespace
</rapi:error>
</rapi:errors>
</rapi:resource-metadata>

/marklogic.rest.resource/simpleJSResourceModule/assets/resource.xqy

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions