Unable to connect to Couchbase SyncGateway REST API in Java at port 59840


#1

public static void main(String[] args) {
// TODO Auto-generated method stub

	try {
		System.out.println("CouchbaseLiteConnectToSyncGateway");
		
		Manager manager = new Manager(new JavaContext("data"), Manager.DEFAULT_OPTIONS);
		System.out.println("manager "+manager);
		
		Database database = manager.getDatabase("http://192.168.203.45:59840/db");
		
		System.out.println("database "+database);
		
		Query allDocumentsQuery= database.createAllDocumentsQuery();
		 QueryEnumerator queryResult=allDocumentsQuery.run();
		 for (Iterator<QueryRow> it=queryResult;it.hasNext();){
		      QueryRow row=it.next();

		      Document doc=row.getDocument();
		      String id=doc.getId(); // I get the id in here but the result is the default id (UUID):(
		      System.out.println(doc+"  "+id);
		 }
		
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}

While running above code I am getting below exception

CouchbaseLiteConnectToSyncGateway
manager com.couchbase.lite.Manager@33a10788
java.lang.IllegalArgumentException: Invalid database name: http://192.168.203.45:4984/db
at com.couchbase.lite.Manager.getDatabase(Manager.java:558)
at com.couchbase.lite.Manager.openDatabase(Manager.java:334)
at com.couchbase.lite.Manager.getDatabase(Manager.java:300)
at com.karvy.insights.couchbase.remote.entities.test.CouchbaseLiteConnectToSyncGateway.main(CouchbaseLiteConnectToSyncGateway.java:39)


#2

Invalid database name: http://192.168.203.45:4984/db


#3

I have given example database name. Now I modified the database name to “db”. Now also i am getting same exception.


#4

Show the actual exception you get, please.


#5

public class CLSG {

/**
 * @param args
 */
public static void main(String[] args) {
	// TODO Auto-generated method stub

	try {
		System.out.println("CouchbaseLiteConnectToSyncGateway");

		Manager manager = new Manager(new JavaContext("data"), Manager.DEFAULT_OPTIONS);
		System.out.println("manager " + manager);
		Database database = manager.getDatabase("http://192.168.203.45:59840/db");

		System.out.println("database " + database);

		Query allDocumentsQuery = database.createAllDocumentsQuery();
		QueryEnumerator queryResult = allDocumentsQuery.run();
		for (Iterator<QueryRow> it = queryResult; it.hasNext();) {
			QueryRow row = it.next();

			Document doc = row.getDocument();
			String id = doc.getId(); // I get the id in here but the result
										// is the default id (UUID):(
			System.out.println(doc + "  " + id);
		}

	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}

}

CouchbaseLiteConnectToSyncGateway
manager com.couchbase.lite.Manager@33a10788
java.lang.IllegalArgumentException: Invalid database name: http://192.168.203.45:59840/db
at com.couchbase.lite.Manager.getDatabase(Manager.java:558)
at com.couchbase.lite.Manager.openDatabase(Manager.java:334)
at com.couchbase.lite.Manager.getDatabase(Manager.java:300)
at com.karvy.insights.couchbase.remote.entities.test.CLSG.main(CLSG.java:33)


#6

Database names can’t contain slashes. Just name it “db”.

I think you’re mixing up the name of the database, with the URL of the remote database you sync with. The URL is used when creating the Replication object.


#7

Hi,

I am trying to connect sync gateway from Java web application using REST API, not Android project.

We are implementing a java web application connect to sync gateway rest api and make CURD operation through sync gateway rest api only.

If any sample logic to connect to sync gateway rest api from java web application, please share it.


#8

The REST API should be called using HTTP requests. Your code is showing you using the Java native APIs. You need to form your own HTTP requests to the REST endpoints documented here: http://developer.couchbase.com/documentation/mobile/1.2/develop/references/sync-gateway/index.html