1
votes

I am trying to connect to MarkLogic with JAVA using XCC.

URI uri = new URI("xcc://admin:admin123@localhost:8011/Documents");
ContentSource contentSource = ContentSourceFactory.newContentSource(uri);
Session session = contentSource.newSession();
Request request = session.newAdhocQuery("\"Hello World\"");
ResultSequence rs = session.submitRequest(request);
System.out.println(rs.asString());
session.close();

I get the below exception.

Exception in thread "main" com.marklogic.xcc.exceptions.ServerConnectionException: Premature End-Of-Stream on flush.  Server connection lost?

The error seems to because of XDBC server congiration. I am not able to figure out what I am doing wrong here.

Few of the XDBC parameters are,

authentication = basic,
threads = 100,
timeout = 1000
keep alive time count = 5
1
Your code worked for me with MarkLogic 8.0-3, the current XCC jar file, and Java 1.7. Just to check the easy thing, can you confirm that your application server on port 8011 is an XDBC server, not an HTTP one? - Dave Cassel
In MarkLogic 8 it can be an HTTP one as well, actually. Can you tell us the versions you are using? MarkLogic, Java as well as the XCC library that is used. MarkLogic 8 requires the latest XCC library. - grtjn
re: "HTTP Server" - XCC can only be used on "HTTP" server ports which are configured via the XML rewriter to support XDBC protocol. Servers created as "REST" servers add this support, HTTP servers created in other means do not. re: "requires the latest xcc library" -- this is not completely true, earlier versions of the XCC library should work against ML 8 providing you are only using features supported by that version of the XCC library. I.e. if your client app worked in V7, you should be able to use the same XCC library in V8 as you did in V7. - DALDEI
I use marklogic 8.0-3 and the XCC jar version is 5.0.6. XDBC runs on 8011 and not HTTP. - s_u_f
In theory version 5.0.6 should work, but is there a reason you're not using the 8.0-3 library? You can download it from developer.marklogic.com/maven2/com/marklogic/marklogic-xcc/… . Also, if you're using Gradle (I highly recommend it), here's an example of a Gradle script that depends on XCC - github.com/rjrudin/ml-xcc-util/blob/master/build.gradle . - rjrudin

1 Answers

2
votes

Yes. The issue was with the version of XCC jar. I updated the jar to the latest version 8 and the issue has been resolved.

Thanks all for your help.