Question

I'm trying to follow the replication guide on github for cloudant to prototype a basic one way connection between a local couchdb and and a locally running j2se app utilizing the cloudant sync library.

The local datastore file is being created, however almost immediately after running my application, I'm getting a runtime error - which at a glance I'm a little unsure of how to resolve: Asside from the cloudant code and dependancies;

This is the entire code for my app - I have apache couchdb installed on my machine and the database called 'baseball' exists already:

import com.cloudant.sync.datastore.DatastoreManager;
import com.cloudant.sync.datastore.Datastore;
import com.cloudant.sync.replication.*;
import com.cloudant.sync.notifications.*;
import com.google.common.eventbus.Subscribe;
import java.util.concurrent.CountDownLatch;
import java.io.*;
import java.net.*;
//https://github.com/cloudant/sync-android/blob/master/doc/replication.md
public class CloudApp{
    public static void main(String [] args) throws Exception{
        File path = new File("datastores");
        System.out.println(path.getAbsolutePath());
        DatastoreManager manager = new DatastoreManager(path.getAbsolutePath());

        URI uri = new URI("http://127.0.0.1:5984/baseball");
        Datastore ds = manager.openDatastore("my_datastore");

        // Create a replictor that replicates changes from the remote
        // database to the local datastore.
        Replicator replicator = ReplicatorFactory.oneway(uri, ds);

        // Use a CountDownLatch to provide a lightweight way to wait for completion
        CountDownLatch latch = new CountDownLatch(1);
        Listener listener = new Listener(latch);
        replicator.getEventBus().register(listener);
        replicator.start();
        latch.await();
        replicator.getEventBus().unregister(listener);
        if (replicator.getState() != Replicator.State.COMPLETE) {
            System.out.println("Error replicating FROM remote");
            System.out.println(listener.error);
        }
    }

}

class Listener {

    private final CountDownLatch latch;
    public ErrorInfo error = null;

    Listener(CountDownLatch latch) {
        this.latch = latch;
    }

    @Subscribe
    public void complete(ReplicationCompleted event) {
        latch.countDown();
    }

    @Subscribe
    public void error(ReplicationErrored event) {
        this.error = event.errorInfo;
        latch.countDown();
    }
}

And this is the runtime error as well as log outputs:

    [I]DatastoreManager: path: /Users/reecegriffin/Documents/workspace/Cloudant 2/datastores
    [I]DatastoreManager: dbDirectory: /Users/reecegriffin/Documents/workspace/Cloudant 2/datastores/my_datastore
    Mar 10, 2014 9:29:02 AM com.almworks.sqlite4java.Internal log
    INFO: [sqlite] DB[1]: instantiated [/Users/reecegriffin/Documents/workspace/Cloudant 2/datastores/my_datastore/db.sync]
    Mar 10, 2014 9:29:02 AM com.almworks.sqlite4java.Internal log
    INFO: [sqlite] Internal: loaded sqlite4java-osx from /Users/reecegriffin/Documents/workspace/Cloudant 2/src/libsqlite4java-osx.jnilib
    Mar 10, 2014 9:29:02 AM com.almworks.sqlite4java.Internal log
    INFO: [sqlite] Internal: loaded sqlite 3.7.10, wrapper 0.2
    Mar 10, 2014 9:29:02 AM com.almworks.sqlite4java.Internal log
    INFO: [sqlite] DB[1]: opened
    Exception in thread "main" java.lang.IllegalStateException: java.lang.RuntimeException: Stub!
        at com.cloudant.mazha.HttpRequests.createHttpClient(HttpRequests.java:185)
        at com.cloudant.mazha.HttpRequests.<init>(HttpRequests.java:69)
        at com.cloudant.mazha.CouchClient.<init>(CouchClient.java:47)
        at com.cloudant.sync.replication.CouchClientWrapper.<init>(CouchClientWrapper.java:45)
        at com.cloudant.sync.replication.BasicPullStrategy.<init>(BasicPullStrategy.java:90)
        at com.cloudant.sync.replication.PullReplication.createReplicationStrategy(PullReplication.java:40)
        at com.cloudant.sync.replication.BasicReplicator.getReplicationStrategy(BasicReplicator.java:41)
        at com.cloudant.sync.replication.BasicReplicator.start(BasicReplicator.java:61)
        at CloudApp.main(CloudApp.java:27)
    Caused by: java.lang.RuntimeException: Stub!
        at org.apache.http.params.AbstractHttpParams.<init>(AbstractHttpParams.java:5)
        at org.apache.http.params.BasicHttpParams.<init>(BasicHttpParams.java:6)
        at com.cloudant.mazha.HttpRequests.getHttpConnectionParams(HttpRequests.java:199)
        at com.clou

dant.mazha.HttpRequests.createHttpClient(HttpRequests.java:173)
    ... 8 more

Many thanks for any help. Regards, Reece.

Was it helpful?

Solution

I noticed in some other threads regarding Stub related apache commons HTTPclient related stuff, that the android library build path order can have an effect. I was trying to run from within eclipse & sure enough - after I opened up the build path editor and moved android.jar to be last on my build path, the run time error went away.

OTHER TIPS

There's some more information on the "stub!" issue in Using android.jar in Java project - RuntimeException Stub?.

We'll take a look into whether we can mitigate the effects of the build path order in code, but I'm not sure whether we'll be able to fix the issue.

This problem hasn't come up for us in tests. Perhaps this is because the Android dependency is specified last in our build.gradle file, meaning it ends up in a position in the path ordering that works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top