Skip to content

Debugging module loading

rjrudin edited this page Nov 14, 2017 · 23 revisions

Under the hood, ml-gradle uses the MarkLogic Client API to connect to a MarkLogic REST API server and load modules. So when you run into errors with loading modules, it's often helpful to run a quick test that uses the Client API to confirm that you can connect to your REST API server outside the scope of ml-gradle.

Here's a task that you can customize and run for loading modules via port 8000 (this includes all "asset" modules - i.e. not REST API services, transforms, or options, which must be loaded via your application-specific REST API server):

task testLoadModule {
    doLast {
	// See https://docs.marklogic.com/javadoc/client/com/marklogic/client/DatabaseClientFactory.html
	def host = "localhost"
	def port = 8000
	def database = "example-modules"
	def username = "admin"
	def password = "admin"

	// See https://docs.marklogic.com/javadoc/client/com/marklogic/client/DatabaseClientFactory.SecurityContext.html
	def context = new com.marklogic.client.DatabaseClientFactory.DigestAuthContext(username, password)
	def client = com.marklogic.client.DatabaseClientFactory.newClient(host, port, database, context)
	try {
		client.newDocumentManager().write("/test/module.xqy", new com.marklogic.client.io.StringHandle("<hello>world</hello>"))
	} finally {
		client.release()
	}
}
}
Clone this wiki locally