marklogic / marklogic-jena

Adapter for using MarkLogic with the Jena RDF Framework
Other
5 stars 11 forks source link

Previous digest authentication with same nonce failed, returning null #72

Closed AlexTo closed 5 years ago

AlexTo commented 6 years ago

Hi, I am using marklogic-jena:3.0.5 with Spring Boot

My Spring service looks like this

@Service
public class TripleStoreMarkLogicImpl implements TripleStore {

    private MarkLogicDatasetGraph dg;

    public TripleStoreMarkLogicImpl(MarkLogicConfig cfg) {
        DatabaseClient client = DatabaseClientFactory.newClient(
                cfg.getHost(),
                cfg.getPort(),
                new DatabaseClientFactory.DigestAuthContext(cfg.getUser(), cfg.getPassword()));

        this.dg = MarkLogicDatasetGraphFactory.createDatasetGraph(client);
    }

    public void insert(String graph, Model model) {
        Dataset ds = dg.toDataset();
        if (!ds.containsNamedModel(graph)) {
            ds.addNamedModel(graph, ModelFactory.createDefaultModel());
        }
        Model g = ds.getNamedModel(graph);
        g.add(model);
    }
    // more code
}

If I use Postman to post to my Controller which then calls my Service, it works fine. However, when I deploy in the test environment with higher load, then I have the below error message. It seems to be related to this issue java-client-api-#770 but according to the status, the issue has been fixed. :(

2018-09-13 10:04:02.105 Exception in thread "Timer-1"  WARN 18276 --- [        Timer-1] okhttp3.OkHttpClient                     : previous digest authentication with same nonce failed, returning null
com.marklogic.client.FailedRequestException: Local message: failed to apply resource at /graphs/sparql: Unauthorized. Server Message: Unauthorized
    at com.marklogic.client.impl.OkHttpServices.checkStatus(OkHttpServices.java:4317)
    at com.marklogic.client.impl.OkHttpServices.postResource(OkHttpServices.java:3291)
    at com.marklogic.client.impl.OkHttpServices.postResource(OkHttpServices.java:3237)
    at com.marklogic.client.impl.OkHttpServices.postResource(OkHttpServices.java:3228)
    at com.marklogic.client.impl.OkHttpServices.executeSparql(OkHttpServices.java:5248)
    at com.marklogic.client.impl.SPARQLQueryManagerImpl.executeQueryImpl(SPARQLQueryManagerImpl.java:107)
    at com.marklogic.client.impl.SPARQLQueryManagerImpl.executeQueryImpl(SPARQLQueryManagerImpl.java:100)
    at com.marklogic.client.impl.SPARQLQueryManagerImpl.executeUpdate(SPARQLQueryManagerImpl.java:170)
    at com.marklogic.semantics.jena.client.JenaDatabaseClient.executeUpdate(JenaDatabaseClient.java:142)
    at com.marklogic.semantics.jena.client.TriplesWriteBuffer.flush(TriplesWriteBuffer.java:76)
    at com.marklogic.semantics.jena.client.TripleBuffer.run(TripleBuffer.java:75)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)

Btw, how do I properly create and close the connection? Do I create and close inside the insert() method or should I create the connection in the service constructor like what I am doing now?

Thanks

grechaw commented 6 years ago

Hello, you need a release of marklogic-jena that has an upgraded java client. I'll raise this issue and see about cutting a release as soon as is convenient. Feel free to ping back if you don't hear a reply.

Your connection method should be good. It's intended to be a long-lived object.

AlexTo commented 6 years ago

Thanks a lot for a quick update, I look forwards to the next release. Regards

Kridev commented 5 years ago

Any update on release? Having similar problem with similar setup. But instead of fail I see:

o.OkHttpClient : previous digest authentication with same nonce failed, returning null o.OkHttpClient : Cached authentication expired. Sending a new request.

AlexTo commented 5 years ago

if you can't wait for MarkLogic to release the new version, simply clone the Git and update this file

https://github.com/marklogic/marklogic-jena/blob/master/marklogic-jena/build.gradle

  1. Update marklogic-client-api version from 4.0.3 to 4.1.1
  2. Update version from 3.0.5 to 3.0.5.1 (just to avoid conflicting in Maven repo)
  3. Rebuild the project or install into local Maven repo according to the instructions

I no longer have errors after bumping marklogic-client-api to latest version

Kridev commented 5 years ago

Thanks for reply!