Search code examples
androidcouchbase-litecouchbase-sync-gateway

Android Couchbase SyncGateway Cookie


salam
i do this for enable cookie in android project, but in sync-gateway log return :

401 login required

session_id("6e2b5106712c0aa3e0048c5b724b302df63d5fbf") is valid for 20 year
couchbase server is in another local pc(192.168.137.137)

    try {
        syncUrl = new URL("http://192.168.137.137:4984/test");
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }

    boolean isSecure = false;
    boolean httpOnly = false;


    Replication pullReplication = database.createPullReplication(syncUrl);
    pullReplication.setContinuous(true);
    pullReplication.setCookie("SyncGatewaySession",
            "6e2b5106712c0aa3e0048c5b724b302df63d5fbf",
            null, 4125798350463L, isSecure, httpOnly);  

    Replication pushReplication = database.createPushReplication(syncUrl);
    pushReplication.setContinuous(true);
    pushReplication.setCookie("SyncGatewaySession",
            "6e2b5106712c0aa3e0048c5b724b302df63d5fbf",
            null, 4125798350463L, isSecure, httpOnly);

    pullReplication.start();
    pushReplication.start();

    pullReplication.addChangeListener(this);
    pushReplication.addChangeListener(this);

Solution

  • problem solved :

    try {
        syncUrl = new URL("http://192.168.137.137:4984/test");
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
    
    Replication pullReplication = database.createPullReplication(syncUrl);
    pullReplication.setContinuous(true);
    
    Replication pushReplication = database.createPushReplication(syncUrl);
    pushReplication.setContinuous(true);
    
    Authenticator auth = new BasicAuthenticator(username, password);
    pushReplication.setAuthenticator(auth);
    pullReplication.setAuthenticator(auth);
    
    pullReplication.start();
    pushReplication.start();
    
    pullReplication.addChangeListener(this);
    pushReplication.addChangeListener(this);