I'm trying to execute a search on my Data Hub Service using Java API. Unfortunately, the server returns the Unauthorized
response.
Here is the code:
public Object doSearch() throws NoSuchAlgorithmException, KeyManagementException {
String user = *****;
String password = ******;
String db = "data-hub-FINAL";
String host = "***********.marklogicsvc.com";
int port = 8011;
SecurityContext auth = new DatabaseClientFactory.DigestAuthContext(user, password).withSSLContext(SSLContext.getDefault());
DatabaseClient client = DatabaseClientFactory.newClient(host, port, db, auth);
try {
QueryManager qm = client.newQueryManager();
StructuredQueryBuilder qb = qm.newStructuredQueryBuilder();
qm.setPageLength(100);
var query = qb.collection("listings");
return qm.search(query, new SearchHandle());
} finally {
client.release();
}
}
I suspected that I've used wrong credentials but when I tried them in Visual Studio Code Marklogic Extension it worked fine, here are my VS Code settings and query:
"marklogic.modulesDb": "data-hub-MODULES", "marklogic.host": "*******.marklogicsvc.com", "marklogic.password": *******, "marklogic.username": *******, "marklogic.ssl": true, "marklogic.port": 8011
query:
xquery version "3.0";
declare namespace cts = "http://marklogic.com/cts";
cts:search(fn:collection(("listings")), cts:and-query(()))
I would be very happy if you tell me what is wrong with my Java code that I can not connect to DHS.