diff --git a/examples/build.gradle b/examples/build.gradle index ab920f99e..037937ff9 100644 --- a/examples/build.gradle +++ b/examples/build.gradle @@ -30,5 +30,4 @@ dependencies { api 'com.opencsv:opencsv:4.6' api 'org.springframework:spring-jdbc:5.3.29' api 'org.apache.commons:commons-lang3:3.12.0' - api 'org.apache.httpcomponents:httpclient:4.5.14' } diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/ClientCreator.java b/examples/src/main/java/com/marklogic/client/example/cookbook/ClientCreator.java index 7863ee454..479fecd0a 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/ClientCreator.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/ClientCreator.java @@ -34,10 +34,7 @@ public static void main(String[] args) throws IOException { public static void run(ExampleProperties props) { System.out.println("example: "+ClientCreator.class.getName()); - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); // make use of the client connection TextDocumentManager docMgr = client.newTextDocumentManager(); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentDelete.java b/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentDelete.java index 484ccacd8..5a202e25f 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentDelete.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentDelete.java @@ -38,10 +38,7 @@ public static void run(ExampleProperties props) throws IOException { String filename = "flipper.xml"; - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); // create a manager for XML documents XMLDocumentManager docMgr = client.newXMLDocumentManager(); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentFormats.java b/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentFormats.java index 00c9c896d..cd073018b 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentFormats.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentFormats.java @@ -15,17 +15,16 @@ */ package com.marklogic.client.example.cookbook; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; import com.marklogic.client.document.GenericDocumentManager; import com.marklogic.client.example.cookbook.Util.ExampleProperties; import com.marklogic.client.io.BytesHandle; import com.marklogic.client.io.InputStreamHandle; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + /** * DocumentFormats illustrates working with documents in multiple or unknown formats. */ @@ -45,10 +44,7 @@ public static void run(ExampleProperties props) throws IOException { {"flipper.xml", "XML"} }; - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); // iterate over the files for (String[] fileEntry: fileEntries) { diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentMetadataRead.java b/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentMetadataRead.java index 4a0716515..e351183a6 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentMetadataRead.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentMetadataRead.java @@ -15,14 +15,7 @@ */ package com.marklogic.client.example.cookbook; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - -import org.w3c.dom.Document; - import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; import com.marklogic.client.document.XMLDocumentManager; import com.marklogic.client.example.cookbook.Util.ExampleProperties; import com.marklogic.client.io.DOMHandle; @@ -31,6 +24,11 @@ import com.marklogic.client.io.DocumentMetadataHandle.DocumentCollections; import com.marklogic.client.io.DocumentMetadataHandle.DocumentMetadataValues; import com.marklogic.client.io.InputStreamHandle; +import org.w3c.dom.Document; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; /** * DocumentMetadataReader illustrates how to read the metadata and content of a database document @@ -46,10 +44,7 @@ public static void run(ExampleProperties props) throws IOException { String filename = "flipper.xml"; - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); // create a manager for XML documents XMLDocumentManager docMgr = client.newXMLDocumentManager(); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentMetadataWrite.java b/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentMetadataWrite.java index 1596d7e27..e7cf59c20 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentMetadataWrite.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentMetadataWrite.java @@ -15,20 +15,19 @@ */ package com.marklogic.client.example.cookbook; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; import com.marklogic.client.document.XMLDocumentManager; import com.marklogic.client.example.cookbook.Util.ExampleProperties; import com.marklogic.client.io.DocumentMetadataHandle; import com.marklogic.client.io.DocumentMetadataHandle.Capability; import com.marklogic.client.io.InputStreamHandle; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + /** - * DocumentMetadataWriter illustrates how to write metadata and content to a database document + * DocumentMetadataWriter illustrates how to write metadata and content to a database document * in a single request. */ public class DocumentMetadataWrite { @@ -41,10 +40,7 @@ public static void run(ExampleProperties props) throws IOException { String filename = "flipper.xml"; - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); // acquire the content InputStream docStream = Util.openStream("data"+File.separator+filename); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentOutputStream.java b/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentOutputStream.java index 465ff2ec9..48ee044c7 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentOutputStream.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentOutputStream.java @@ -15,18 +15,17 @@ */ package com.marklogic.client.example.cookbook; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; import com.marklogic.client.document.XMLDocumentManager; import com.marklogic.client.example.cookbook.Util.ExampleProperties; import com.marklogic.client.io.OutputStreamHandle; import com.marklogic.client.io.OutputStreamSender; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + /** * DocumentOutputStream illustrates how to write content to a document * using an OutputStream. You provide the content during execution of @@ -43,10 +42,7 @@ public static void run(ExampleProperties props) throws IOException { final int MAX_BUF = 8192; final String FILENAME = "flipper.xml"; - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); // create a manager for XML documents XMLDocumentManager docMgr = client.newXMLDocumentManager(); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentRead.java b/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentRead.java index 1ce1167f6..e370db2b8 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentRead.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentRead.java @@ -15,20 +15,17 @@ */ package com.marklogic.client.example.cookbook; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - -import javax.xml.xpath.XPathExpressionException; - -import org.w3c.dom.Document; - import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; import com.marklogic.client.document.XMLDocumentManager; import com.marklogic.client.example.cookbook.Util.ExampleProperties; import com.marklogic.client.io.DOMHandle; import com.marklogic.client.io.InputStreamHandle; +import org.w3c.dom.Document; + +import javax.xml.xpath.XPathExpressionException; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; /** * DocumentReader illustrates how to read the content of a database document. @@ -41,10 +38,7 @@ public static void main(String[] args) throws IOException, XPathExpressionExcept public static void run(ExampleProperties props) throws IOException, XPathExpressionException { System.out.println("example: "+DocumentRead.class.getName()); - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); setUpExample(client); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentReadTransform.java b/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentReadTransform.java index 664a43d9f..7c205c518 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentReadTransform.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentReadTransform.java @@ -15,17 +15,7 @@ */ package com.marklogic.client.example.cookbook; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - -import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; -import com.marklogic.client.DatabaseClientFactory.Authentication; -import com.marklogic.client.FailedRequestException; -import com.marklogic.client.ForbiddenUserException; -import com.marklogic.client.ResourceNotFoundException; -import com.marklogic.client.ResourceNotResendableException; +import com.marklogic.client.*; import com.marklogic.client.admin.ExtensionMetadata; import com.marklogic.client.admin.TransformExtensionsManager; import com.marklogic.client.document.ServerTransform; @@ -35,6 +25,10 @@ import com.marklogic.client.io.InputStreamHandle; import com.marklogic.client.io.StringHandle; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + /** * DocumentReadTransform installs a server transform for converting XML documents * with a known vocabulary to HTML documents for presentation. @@ -54,22 +48,15 @@ public static void run(ExampleProperties props) { System.out.println("example: "+DocumentReadTransform.class.getName()); - installTransform(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); - - readDocument(props.host, props.port, - props.writerUser, props.writerPassword, props.authType); - - tearDownExample(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); + installTransform(props); + readDocument(props); + tearDownExample(props); } - public static void installTransform(String host, int port, String user, String password, Authentication authType) + public static void installTransform(ExampleProperties props) throws IOException, ResourceNotFoundException, ResourceNotResendableException, ForbiddenUserException, FailedRequestException { - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - host, port, user, password, authType); + DatabaseClient client = Util.newAdminClient(props); // create a manager for transform extensions TransformExtensionsManager transMgr = client.newServerConfigManager().newTransformExtensionsManager(); @@ -100,14 +87,12 @@ public static void installTransform(String host, int port, String user, String p client.release(); } - public static void readDocument(String host, int port, String user, String password, Authentication authType) + public static void readDocument(ExampleProperties props) throws IOException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException { String filename = "flipper.xml"; - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - host, port, user, password, authType); + DatabaseClient client = Util.newClient(props); // create an identifier for the document String docId = "/example/"+filename; @@ -153,12 +138,10 @@ public static void setUpExample(DatabaseClient client, String docId, String file } // clean up by deleting the read document and the example transform - public static void tearDownExample( - String host, int port, String user, String password, Authentication authType) + public static void tearDownExample(ExampleProperties props) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { - DatabaseClient client = DatabaseClientFactory.newClient( - host, port, user, password, authType); + DatabaseClient client = Util.newAdminClient(props); XMLDocumentManager docMgr = client.newXMLDocumentManager(); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentWrite.java b/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentWrite.java index 17546fd88..89fbe9c64 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentWrite.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentWrite.java @@ -15,16 +15,15 @@ */ package com.marklogic.client.example.cookbook; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; import com.marklogic.client.document.XMLDocumentManager; import com.marklogic.client.example.cookbook.Util.ExampleProperties; import com.marklogic.client.io.InputStreamHandle; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + /** * DocumentWriter illustrates how to write content to a database document. */ @@ -36,10 +35,7 @@ public static void main(String[] args) throws IOException { public static void run(ExampleProperties props) throws IOException { System.out.println("example: "+DocumentWrite.class.getName()); - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); // use either shortcut or strong typed IO runShortcut(client); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentWriteServerURI.java b/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentWriteServerURI.java index cd2f66542..6d5147a61 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentWriteServerURI.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentWriteServerURI.java @@ -15,18 +15,17 @@ */ package com.marklogic.client.example.cookbook; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; import com.marklogic.client.document.DocumentDescriptor; import com.marklogic.client.document.DocumentUriTemplate; import com.marklogic.client.document.XMLDocumentManager; import com.marklogic.client.example.cookbook.Util.ExampleProperties; import com.marklogic.client.io.InputStreamHandle; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + /** * DocumentWriterServerURI illustrates how to write content, letting MarkLogic assign a server URI */ @@ -40,10 +39,7 @@ public static void run(ExampleProperties props) throws IOException { String filename = "flipper.xml"; - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); // acquire the content InputStream docStream = Util.openStream("data"+File.separator+filename); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentWriteTransform.java b/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentWriteTransform.java index ff0ff479e..9b0114cb0 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentWriteTransform.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/DocumentWriteTransform.java @@ -15,17 +15,7 @@ */ package com.marklogic.client.example.cookbook; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - -import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; -import com.marklogic.client.DatabaseClientFactory.Authentication; -import com.marklogic.client.FailedRequestException; -import com.marklogic.client.ForbiddenUserException; -import com.marklogic.client.ResourceNotFoundException; -import com.marklogic.client.ResourceNotResendableException; +import com.marklogic.client.*; import com.marklogic.client.admin.ExtensionMetadata; import com.marklogic.client.admin.TransformExtensionsManager; import com.marklogic.client.document.ServerTransform; @@ -35,6 +25,10 @@ import com.marklogic.client.io.InputStreamHandle; import com.marklogic.client.io.StringHandle; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + /** * DocumentWriteTransform installs a server transform for converting HTML documents * to XHTML documents so HTML documents can be written to the database, indexed, @@ -54,22 +48,15 @@ public static void run(ExampleProperties props) throws IOException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException, ResourceNotResendableException { System.out.println("example: "+DocumentWriteTransform.class.getName()); - - installTransform(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); - - writeDocument(props.host, props.port, - props.writerUser, props.writerPassword, props.authType); - - tearDownExample(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); + installTransform(props); + writeDocument(props); + tearDownExample(props); } - public static void installTransform(String host, int port, String user, String password, Authentication authType) + public static void installTransform(ExampleProperties props) throws IOException, ResourceNotFoundException, ResourceNotResendableException, ForbiddenUserException, FailedRequestException { - // create the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newAdminClient(props); // create a manager for transform extensions TransformExtensionsManager transMgr = client.newServerConfigManager().newTransformExtensionsManager(); @@ -100,13 +87,12 @@ public static void installTransform(String host, int port, String user, String p client.release(); } - public static void writeDocument(String host, int port, String user, String password, Authentication authType) + public static void writeDocument(ExampleProperties props) throws IOException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException { String filename = "sentiment.html"; - // create the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newClient(props); // acquire the content InputStream docStream = Util.openStream("data"+File.separator+filename); @@ -152,11 +138,10 @@ public static void writeDocument(String host, int port, String user, String pass } // clean up by deleting the written document and the example transform - public static void tearDownExample( - String host, int port, String user, String password, Authentication authType) + public static void tearDownExample(ExampleProperties props) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newAdminClient(props); TextDocumentManager docMgr = client.newTextDocumentManager(); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/JAXBDocument.java b/examples/src/main/java/com/marklogic/client/example/cookbook/JAXBDocument.java index 040cb882e..9f498612d 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/JAXBDocument.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/JAXBDocument.java @@ -15,18 +15,17 @@ */ package com.marklogic.client.example.cookbook; -import java.io.IOException; - -import jakarta.xml.bind.JAXBContext; -import jakarta.xml.bind.JAXBException; -import jakarta.xml.bind.annotation.XmlRootElement; - import com.marklogic.client.DatabaseClient; import com.marklogic.client.DatabaseClientFactory; import com.marklogic.client.document.XMLDocumentManager; import com.marklogic.client.example.cookbook.Util.ExampleProperties; import com.marklogic.client.io.JAXBHandle; import com.marklogic.client.io.StringHandle; +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.annotation.XmlRootElement; + +import java.io.IOException; /** * JAXBDocument illustrates how to write and read a POJO structure as a database document. @@ -82,10 +81,7 @@ public static void runShortcut(ExampleProperties props) throws JAXBException { JAXBHandle.newFactory(Product.class) ); - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); // create a manager for XML documents XMLDocumentManager docMgr = client.newXMLDocumentManager(); @@ -118,10 +114,7 @@ public static void runShortcut(ExampleProperties props) throws JAXBException { client.release(); } public static void runStrongTyped(ExampleProperties props) throws JAXBException { - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); JAXBContext context = JAXBContext.newInstance(Product.class); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/JavascriptResourceExtension.java b/examples/src/main/java/com/marklogic/client/example/cookbook/JavascriptResourceExtension.java index d49040b70..1a7b5b91b 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/JavascriptResourceExtension.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/JavascriptResourceExtension.java @@ -15,16 +15,7 @@ */ package com.marklogic.client.example.cookbook; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - - import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; -import com.marklogic.client.DatabaseClientFactory.Authentication; import com.marklogic.client.FailedRequestException; import com.marklogic.client.ForbiddenUserException; import com.marklogic.client.ResourceNotFoundException; @@ -40,6 +31,12 @@ import com.marklogic.client.io.StringHandle; import com.marklogic.client.util.RequestParameters; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + /** * JavascriptResourceExtension installs an extension for managing spelling dictionary resources. */ @@ -55,15 +52,9 @@ public static void run(ExampleProperties props) throws IOException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException { System.out.println("example: "+JavascriptResourceExtension.class.getName()); - - installResourceExtension(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); - - useResource(props.host, props.port, - props.writerUser, props.writerPassword, props.authType); - - tearDownExample(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); + installResourceExtension(props); + useResource(props); + tearDownExample(props); } /** @@ -115,9 +106,8 @@ public String sayHello() { } // install the resource extension on the server - public static void installResourceExtension(String host, int port, String user, String password, Authentication authType) throws IOException { - // create the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + public static void installResourceExtension(ExampleProperties props) throws IOException { + DatabaseClient client = Util.newAdminClient(props); // use either shortcut or strong typed IO installResourceExtension(client); @@ -125,6 +115,7 @@ public static void installResourceExtension(String host, int port, String user, // release the client client.release(); } + public static void installResourceExtension(DatabaseClient client) throws IOException { // create a manager for resource extensions ResourceExtensionsManager resourceMgr = client.newServerConfigManager().newResourceExtensionsManager(); @@ -151,11 +142,10 @@ public static void installResourceExtension(DatabaseClient client) throws IOExce } // use the resource manager - public static void useResource(String host, int port, String user, String password, Authentication authType) + public static void useResource(ExampleProperties props) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { - // create the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newClient(props); // create the resource extension client HelloWorld hello = new HelloWorld(client); @@ -168,8 +158,8 @@ public static void useResource(String host, int port, String user, String passwo } // clean up by deleting the example resource extension - public static void tearDownExample(String host, int port, String user, String password, Authentication authType) { - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + public static void tearDownExample(ExampleProperties props) { + DatabaseClient client = Util.newAdminClient(props); ResourceExtensionsManager resourceMgr = client.newServerConfigManager().newResourceExtensionsManager(); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/KerberosSSLClientCreator.java b/examples/src/main/java/com/marklogic/client/example/cookbook/KerberosSSLClientCreator.java index ab736e6b5..e70970318 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/KerberosSSLClientCreator.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/KerberosSSLClientCreator.java @@ -67,7 +67,8 @@ public X509Certificate[] getAcceptedIssuers() { // create the client // (note: a real application should use a COMMON, STRICT, or implemented hostname verifier) DatabaseClient client = null; - client = DatabaseClientFactory.newClient(props.host, props.port, new KerberosAuthContext().withSSLContext(sslContext).withSSLHostnameVerifier(SSLHostnameVerifier.ANY)); + client = DatabaseClientFactory.newClient(props.host, props.port, new KerberosAuthContext() + .withSSLContext(sslContext, null).withSSLHostnameVerifier(SSLHostnameVerifier.ANY)); // make use of the client connection TextDocumentManager docMgr = client.newTextDocumentManager(); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/MultiStatementTransaction.java b/examples/src/main/java/com/marklogic/client/example/cookbook/MultiStatementTransaction.java index 3cb425015..07eb88b05 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/MultiStatementTransaction.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/MultiStatementTransaction.java @@ -15,17 +15,16 @@ */ package com.marklogic.client.example.cookbook; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; import com.marklogic.client.Transaction; import com.marklogic.client.document.XMLDocumentManager; import com.marklogic.client.example.cookbook.Util.ExampleProperties; import com.marklogic.client.io.InputStreamHandle; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + /** * MultiStatementTransaction illustrates how to open a transaction, execute * multiple statements under the transaction, and commit the transaction. @@ -41,10 +40,7 @@ public static void run(ExampleProperties props) throws IOException { String beforeFilename = "flipper.xml"; String afterFilename = "flapped.xml"; - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); // create a manager for XML documents XMLDocumentManager docMgr = client.newXMLDocumentManager(); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/OpticUpdateExample.java b/examples/src/main/java/com/marklogic/client/example/cookbook/OpticUpdateExample.java index 4a08fbc53..356cb0b2e 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/OpticUpdateExample.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/OpticUpdateExample.java @@ -21,8 +21,7 @@ public class OpticUpdateExample { public static void main(String[] args) throws Exception { System.out.println("example: " + OpticUpdateExample.class.getName()); Util.ExampleProperties props = Util.loadProperties(); - DatabaseClient client = DatabaseClientFactory.newClient(props.host, props.port, - new DatabaseClientFactory.DigestAuthContext(props.writerUser, props.writerPassword)); + DatabaseClient client = Util.newClient(props); // Load a TDE template that establishes a tabular view of zip codes loadTdeTemplate(props); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/OptimisticLocking.java b/examples/src/main/java/com/marklogic/client/example/cookbook/OptimisticLocking.java index 5ff72ac0a..b74b3f1f6 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/OptimisticLocking.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/OptimisticLocking.java @@ -15,19 +15,7 @@ */ package com.marklogic.client.example.cookbook; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - -import org.w3c.dom.Document; - -import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; -import com.marklogic.client.DatabaseClientFactory.Authentication; -import com.marklogic.client.FailedRequestException; -import com.marklogic.client.ForbiddenUserException; -import com.marklogic.client.ResourceNotFoundException; -import com.marklogic.client.ResourceNotResendableException; +import com.marklogic.client.*; import com.marklogic.client.admin.ServerConfigurationManager; import com.marklogic.client.admin.ServerConfigurationManager.UpdatePolicy; import com.marklogic.client.document.DocumentDescriptor; @@ -35,6 +23,11 @@ import com.marklogic.client.example.cookbook.Util.ExampleProperties; import com.marklogic.client.io.DOMHandle; import com.marklogic.client.io.InputStreamHandle; +import org.w3c.dom.Document; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; /** * Optimistic Locking creates a document only when the document doesn't exist and @@ -52,22 +45,15 @@ public static void run(ExampleProperties props) throws IOException, FailedRequestException, ResourceNotFoundException, ResourceNotResendableException, ForbiddenUserException { System.out.println("example: "+OptimisticLocking.class.getName()); - - requireOptimisticLocking(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); - - modifyDatabase(props.host, props.port, - props.writerUser, props.writerPassword, props.authType); - - tearDownExample(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); + requireOptimisticLocking(props); + modifyDatabase(props); + tearDownExample(props); } - public static void requireOptimisticLocking(String host, int port, String user, String password, Authentication authType) + public static void requireOptimisticLocking(ExampleProperties props) throws FailedRequestException, ResourceNotFoundException, ResourceNotResendableException, ForbiddenUserException { - // create the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newAdminClient(props); // create a manager for the server configuration ServerConfigurationManager configMgr = client.newServerConfigManager(); @@ -88,13 +74,12 @@ public static void requireOptimisticLocking(String host, int port, String user, client.release(); } - public static void modifyDatabase(String host, int port, String user, String password, Authentication authType) + public static void modifyDatabase(ExampleProperties props) throws IOException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException { String filename = "flipper.xml"; - // create the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newClient(props); // acquire the content InputStream docStream = Util.openStream("data"+File.separator+filename); @@ -148,11 +133,10 @@ public static void modifyDatabase(String host, int port, String user, String pas } // clean up by resetting the server configuration - public static void tearDownExample( - String host, int port, String user, String password, Authentication authType) + public static void tearDownExample(ExampleProperties props) throws FailedRequestException, ResourceNotFoundException, ResourceNotResendableException, ForbiddenUserException { - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newAdminClient(props); ServerConfigurationManager configMgr = client.newServerConfigManager(); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/QueryOptions.java b/examples/src/main/java/com/marklogic/client/example/cookbook/QueryOptions.java index e4a8c20c1..2b074128f 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/QueryOptions.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/QueryOptions.java @@ -43,9 +43,7 @@ public static void run(ExampleProperties props) { System.out.println("example: "+QueryOptions.class.getName()); - // create the client - DatabaseClient client = DatabaseClientFactory.newClient(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); + DatabaseClient client = Util.newAdminClient(props); // use either shortcut or strong typed IO runShortcut(client); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/RawClientAlert.java b/examples/src/main/java/com/marklogic/client/example/cookbook/RawClientAlert.java index 1a88863e3..8a14e0ece 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/RawClientAlert.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/RawClientAlert.java @@ -15,13 +15,7 @@ */ package com.marklogic.client.example.cookbook; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.Iterator; - import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; import com.marklogic.client.alerting.RuleDefinition; import com.marklogic.client.alerting.RuleDefinitionList; import com.marklogic.client.alerting.RuleManager; @@ -32,6 +26,11 @@ import com.marklogic.client.query.QueryManager; import com.marklogic.client.query.StringQueryDefinition; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.Iterator; + /** * RawClientAlert illustrates defining and finding rules that match documents. */ @@ -47,10 +46,7 @@ public static void main(String[] args) throws IOException { public static void run(ExampleProperties props) throws IOException { System.out.println("example: "+RawClientAlert.class.getName()); - // connect the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); setUpExample(client); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/RawCombinedSearch.java b/examples/src/main/java/com/marklogic/client/example/cookbook/RawCombinedSearch.java index ef1941aa6..16b72c23d 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/RawCombinedSearch.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/RawCombinedSearch.java @@ -15,22 +15,17 @@ */ package com.marklogic.client.example.cookbook; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; import com.marklogic.client.document.XMLDocumentManager; import com.marklogic.client.example.cookbook.Util.ExampleProperties; import com.marklogic.client.io.Format; import com.marklogic.client.io.InputStreamHandle; import com.marklogic.client.io.SearchHandle; -import com.marklogic.client.query.MatchDocumentSummary; -import com.marklogic.client.query.MatchLocation; -import com.marklogic.client.query.MatchSnippet; -import com.marklogic.client.query.QueryManager; -import com.marklogic.client.query.RawCombinedQueryDefinition; +import com.marklogic.client.query.*; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; /** * RawCombinedSearch illustrates searching for documents and iterating over results @@ -46,10 +41,7 @@ public static void main(String[] args) throws IOException { public static void run(ExampleProperties props) throws IOException { System.out.println("example: "+RawCombinedSearch.class.getName()); - // connect the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); setUpExample(client); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/ResourceExtension.java b/examples/src/main/java/com/marklogic/client/example/cookbook/ResourceExtension.java index 1fe62edad..ae0d967f4 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/ResourceExtension.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/ResourceExtension.java @@ -15,22 +15,7 @@ */ package com.marklogic.client.example.cookbook; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import javax.xml.XMLConstants; -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.w3c.dom.Document; - import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; -import com.marklogic.client.DatabaseClientFactory.Authentication; import com.marklogic.client.FailedRequestException; import com.marklogic.client.ForbiddenUserException; import com.marklogic.client.ResourceNotFoundException; @@ -43,12 +28,19 @@ import com.marklogic.client.extensions.ResourceManager; import com.marklogic.client.extensions.ResourceServices.ServiceResult; import com.marklogic.client.extensions.ResourceServices.ServiceResultIterator; -import com.marklogic.client.io.DOMHandle; -import com.marklogic.client.io.InputStreamHandle; -import com.marklogic.client.io.ReaderHandle; -import com.marklogic.client.io.StringHandle; -import com.marklogic.client.io.XMLStreamReaderHandle; +import com.marklogic.client.io.*; import com.marklogic.client.util.RequestParameters; +import org.w3c.dom.Document; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; /** * ResourceExtension installs an extension for managing spelling dictionary resources. @@ -65,15 +57,9 @@ public static void run(ExampleProperties props) throws IOException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException { System.out.println("example: "+ResourceExtension.class.getName()); - - installResourceExtension(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); - - useResource(props.host, props.port, - props.writerUser, props.writerPassword, props.authType); - - tearDownExample(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); + installResourceExtension(props); + useResource(props); + tearDownExample(props); } /** @@ -220,9 +206,8 @@ public void deleteDictionary(String uri) } // install the resource extension on the server - public static void installResourceExtension(String host, int port, String user, String password, Authentication authType) throws IOException { - // create the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + public static void installResourceExtension(ExampleProperties props) throws IOException { + DatabaseClient client = Util.newAdminClient(props); // use either shortcut or strong typed IO installResourceExtensionShortcut(client); @@ -283,11 +268,10 @@ public static void installResourceExtensionStrongTyped(DatabaseClient client) th } // use the resource manager - public static void useResource(String host, int port, String user, String password, Authentication authType) + public static void useResource(ExampleProperties props) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { - // create the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newClient(props); // create the resource extension client DictionaryManager dictionaryMgr = new DictionaryManager(client); @@ -336,8 +320,8 @@ public static void useResource(String host, int port, String user, String passwo } // clean up by deleting the example resource extension - public static void tearDownExample(String host, int port, String user, String password, Authentication authType) { - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + public static void tearDownExample(ExampleProperties props) { + DatabaseClient client = Util.newAdminClient(props); ResourceExtensionsManager resourceMgr = client.newServerConfigManager().newResourceExtensionsManager(); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/SearchResponseTransform.java b/examples/src/main/java/com/marklogic/client/example/cookbook/SearchResponseTransform.java index 2515859c5..5ac16d6ef 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/SearchResponseTransform.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/SearchResponseTransform.java @@ -15,17 +15,7 @@ */ package com.marklogic.client.example.cookbook; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - -import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; -import com.marklogic.client.DatabaseClientFactory.Authentication; -import com.marklogic.client.FailedRequestException; -import com.marklogic.client.ForbiddenUserException; -import com.marklogic.client.ResourceNotFoundException; -import com.marklogic.client.ResourceNotResendableException; +import com.marklogic.client.*; import com.marklogic.client.admin.ExtensionMetadata; import com.marklogic.client.admin.QueryOptionsManager; import com.marklogic.client.admin.TransformExtensionsManager; @@ -37,6 +27,10 @@ import com.marklogic.client.query.QueryManager; import com.marklogic.client.query.StringQueryDefinition; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + /** * Search illustrates adding a result transformation to * a search. The transformed result here is output as serialized HTML @@ -58,26 +52,16 @@ public static void run(ExampleProperties props) { System.out.println("example: "+SearchResponseTransform.class.getName()); - configure(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); - - // install the server transform - installTransform(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); - - search(props.host, props.port, - props.writerUser, props.writerPassword, props.authType); - - tearDownExample(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); + configure(props); + installTransform(props); + search(props); + tearDownExample(props); } - public static void installTransform(String host, int port, String user, String password, Authentication authType) + public static void installTransform(ExampleProperties props) throws IOException, ResourceNotFoundException, ResourceNotResendableException, ForbiddenUserException, FailedRequestException { - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - host, port, user, password, authType); + DatabaseClient client = Util.newAdminClient(props); // create a manager for transform extensions TransformExtensionsManager transMgr = client.newServerConfigManager().newTransformExtensionsManager(); @@ -107,11 +91,10 @@ public static void installTransform(String host, int port, String user, String p client.release(); } - public static void configure(String host, int port, String user, String password, Authentication authType) + public static void configure(ExampleProperties props) throws FailedRequestException, ForbiddenUserException, ResourceNotFoundException, ResourceNotResendableException { - // create the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newAdminClient(props); // create a manager for writing query options @@ -138,11 +121,10 @@ public static void configure(String host, int port, String user, String password client.release(); } - public static void search(String host, int port, String user, String password, Authentication authType) + public static void search(ExampleProperties props) throws IOException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException { - // create the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newClient(props); setUpExample(client); @@ -194,11 +176,10 @@ public static void setUpExample(DatabaseClient client) } // clean up by deleting the documents and query options used in the example query - public static void tearDownExample( - String host, int port, String user, String password, Authentication authType) + public static void tearDownExample(ExampleProperties props) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newAdminClient(props); XMLDocumentManager docMgr = client.newXMLDocumentManager(); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/StringSearch.java b/examples/src/main/java/com/marklogic/client/example/cookbook/StringSearch.java index 4520fb093..e68b526cf 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/StringSearch.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/StringSearch.java @@ -15,28 +15,18 @@ */ package com.marklogic.client.example.cookbook; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - -import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; -import com.marklogic.client.DatabaseClientFactory.Authentication; -import com.marklogic.client.FailedRequestException; -import com.marklogic.client.ForbiddenUserException; -import com.marklogic.client.ResourceNotFoundException; -import com.marklogic.client.ResourceNotResendableException; +import com.marklogic.client.*; import com.marklogic.client.admin.QueryOptionsManager; import com.marklogic.client.document.XMLDocumentManager; import com.marklogic.client.example.cookbook.Util.ExampleProperties; import com.marklogic.client.io.InputStreamHandle; import com.marklogic.client.io.SearchHandle; import com.marklogic.client.io.StringHandle; -import com.marklogic.client.query.MatchDocumentSummary; -import com.marklogic.client.query.MatchLocation; -import com.marklogic.client.query.MatchSnippet; -import com.marklogic.client.query.QueryManager; -import com.marklogic.client.query.StringQueryDefinition; +import com.marklogic.client.query.*; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; /** * StringSearch illustrates searching for documents and iterating over results @@ -57,22 +47,15 @@ public static void run(ExampleProperties props) throws IOException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException, ResourceNotResendableException { System.out.println("example: "+StringSearch.class.getName()); - - configure(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); - - search(props.host, props.port, - props.writerUser, props.writerPassword, props.authType); - - tearDownExample(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); + configure(props); + search(props); + tearDownExample(props); } - public static void configure(String host, int port, String user, String password, Authentication authType) + public static void configure(ExampleProperties props) throws FailedRequestException, ForbiddenUserException, ResourceNotFoundException, ResourceNotResendableException { - // create the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newAdminClient(props); // create a manager for writing query options QueryOptionsManager optionsMgr = client.newServerConfigManager().newQueryOptionsManager(); @@ -98,11 +81,10 @@ public static void configure(String host, int port, String user, String password client.release(); } - public static void search(String host, int port, String user, String password, Authentication authType) + public static void search(ExampleProperties props) throws IOException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException { - // create the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newClient(props); setUpExample(client); @@ -173,11 +155,10 @@ public static void setUpExample(DatabaseClient client) } // clean up by deleting the documents and query options used in the example query - public static void tearDownExample( - String host, int port, String user, String password, Authentication authType) + public static void tearDownExample(ExampleProperties props) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newAdminClient(props); XMLDocumentManager docMgr = client.newXMLDocumentManager(); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/StructuredSearch.java b/examples/src/main/java/com/marklogic/client/example/cookbook/StructuredSearch.java index 30684b2e1..7e990cde6 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/StructuredSearch.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/StructuredSearch.java @@ -15,29 +15,18 @@ */ package com.marklogic.client.example.cookbook; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - -import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; -import com.marklogic.client.DatabaseClientFactory.Authentication; -import com.marklogic.client.FailedRequestException; -import com.marklogic.client.ForbiddenUserException; -import com.marklogic.client.ResourceNotFoundException; -import com.marklogic.client.ResourceNotResendableException; +import com.marklogic.client.*; import com.marklogic.client.admin.QueryOptionsManager; import com.marklogic.client.document.XMLDocumentManager; import com.marklogic.client.example.cookbook.Util.ExampleProperties; import com.marklogic.client.io.InputStreamHandle; import com.marklogic.client.io.SearchHandle; import com.marklogic.client.io.StringHandle; -import com.marklogic.client.query.MatchDocumentSummary; -import com.marklogic.client.query.MatchLocation; -import com.marklogic.client.query.MatchSnippet; -import com.marklogic.client.query.QueryManager; -import com.marklogic.client.query.StructuredQueryBuilder; -import com.marklogic.client.query.StructuredQueryDefinition; +import com.marklogic.client.query.*; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; /** * StructuredSearch illustrates searching for documents and iterating over results @@ -58,22 +47,15 @@ public static void run(ExampleProperties props) throws IOException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException, ResourceNotResendableException { System.out.println("example: "+StructuredSearch.class.getName()); - - configure(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); - - search(props.host, props.port, - props.writerUser, props.writerPassword, props.authType); - - tearDownExample(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); + configure(props); + search(props); + tearDownExample(props); } - public static void configure(String host, int port, String user, String password, Authentication authType) + public static void configure(ExampleProperties props) throws FailedRequestException, ForbiddenUserException, ResourceNotFoundException, ResourceNotResendableException { - // connect the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newAdminClient(props); // create a manager for writing query options QueryOptionsManager optionsMgr = client.newServerConfigManager().newQueryOptionsManager(); @@ -99,11 +81,10 @@ public static void configure(String host, int port, String user, String password client.release(); } - public static void search(String host, int port, String user, String password, Authentication authType) + public static void search(ExampleProperties props) throws IOException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException { - // connect the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newClient(props); setUpExample(client); @@ -177,10 +158,10 @@ public static void setUpExample(DatabaseClient client) } // clean up by deleting the documents and query options used in the example query - public static void tearDownExample(String host, int port, String user, String password, Authentication authType) + public static void tearDownExample(ExampleProperties props) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newAdminClient(props); XMLDocumentManager docMgr = client.newXMLDocumentManager(); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/Suggest.java b/examples/src/main/java/com/marklogic/client/example/cookbook/Suggest.java index 2624d11aa..f62b6e1ec 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/Suggest.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/Suggest.java @@ -15,17 +15,7 @@ */ package com.marklogic.client.example.cookbook; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - -import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; -import com.marklogic.client.DatabaseClientFactory.Authentication; -import com.marklogic.client.FailedRequestException; -import com.marklogic.client.ForbiddenUserException; -import com.marklogic.client.ResourceNotFoundException; -import com.marklogic.client.ResourceNotResendableException; +import com.marklogic.client.*; import com.marklogic.client.admin.QueryOptionsManager; import com.marklogic.client.document.XMLDocumentManager; import com.marklogic.client.example.cookbook.Util.ExampleProperties; @@ -34,6 +24,10 @@ import com.marklogic.client.query.QueryManager; import com.marklogic.client.query.SuggestDefinition; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + /** * Suggest illustrates getting suggestions for words to find in an element. * @@ -54,21 +48,15 @@ public static void main(String[] args) public static void run(ExampleProperties props) throws IOException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException, ResourceNotResendableException { System.out.println("example: "+Suggest.class.getName()); - - configure(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); - - suggest(props.host, props.port, - props.writerUser, props.writerPassword, props.authType); - - tearDownExample(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); + configure(props); + suggest(props); + tearDownExample(props); } - public static void configure(String host, int port, String user, String password, Authentication authType) + public static void configure(ExampleProperties props) throws FailedRequestException, ForbiddenUserException, ResourceNotFoundException, ResourceNotResendableException { - // create the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + + DatabaseClient client = Util.newAdminClient(props); // create a manager for writing query options QueryOptionsManager optionsMgr = client.newServerConfigManager().newQueryOptionsManager(); @@ -94,10 +82,9 @@ public static void configure(String host, int port, String user, String password client.release(); } - public static void suggest(String host, int port, String user, String password, Authentication authType) + public static void suggest(ExampleProperties props) throws IOException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException { - // create the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newClient(props); setUpExample(client); @@ -144,10 +131,9 @@ public static void setUpExample(DatabaseClient client) } // clean up by deleting the documents and query options used in the example query - public static void tearDownExample( - String host, int port, String user, String password, Authentication authType) + public static void tearDownExample(ExampleProperties props) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newAdminClient(props); XMLDocumentManager docMgr = client.newXMLDocumentManager(); diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/Util.java b/examples/src/main/java/com/marklogic/client/example/cookbook/Util.java index 32a98e0bf..a8fceb1d0 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/Util.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/Util.java @@ -15,12 +15,13 @@ */ package com.marklogic.client.example.cookbook; +import com.marklogic.client.DatabaseClient; +import com.marklogic.client.DatabaseClientFactory; + import java.io.IOException; import java.io.InputStream; import java.util.Properties; -import com.marklogic.client.DatabaseClientFactory.Authentication; - /** * Utilities to support and simplify examples. */ @@ -37,7 +38,6 @@ static public class ExampleProperties { public String readerPassword; public String writerUser; public String writerPassword; - public Authentication authType; public String jdbcUrl; public String jdbcUser; public String jdbcPassword; @@ -52,15 +52,24 @@ public ExampleProperties(Properties props) { readerPassword = props.getProperty("example.reader_password"); writerUser = props.getProperty("example.writer_user"); writerPassword = props.getProperty("example.writer_password"); - authType = Authentication.valueOf( - props.getProperty("example.authentication_type").toUpperCase() - ); jdbcUrl = props.getProperty("example.jdbc.url"); jdbcUser = props.getProperty("example.jdbc.user"); jdbcPassword = props.getProperty("example.jdbc.password"); } } + public static DatabaseClient newClient(ExampleProperties props) { + return DatabaseClientFactory.newClient(props.host, props.port, + new DatabaseClientFactory.DigestAuthContext(props.writerUser, props.writerPassword) + ); + } + + public static DatabaseClient newAdminClient(ExampleProperties props) { + return DatabaseClientFactory.newClient(props.host, props.port, + new DatabaseClientFactory.DigestAuthContext(props.adminUser, props.adminPassword) + ); + } + /** * Read the configuration properties for the example from the file * Example.properties. diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/datamovement/MoveDataBetweenMarklogicDBs.java b/examples/src/main/java/com/marklogic/client/example/cookbook/datamovement/MoveDataBetweenMarklogicDBs.java index a1e420c0a..9ad1cf9fe 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/datamovement/MoveDataBetweenMarklogicDBs.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/datamovement/MoveDataBetweenMarklogicDBs.java @@ -1,14 +1,6 @@ package com.marklogic.client.example.cookbook.datamovement; -import java.io.IOException; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Random; - import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; -import com.marklogic.client.DatabaseClientFactory.DigestAuthContext; import com.marklogic.client.admin.ServerConfigurationManager; import com.marklogic.client.admin.TransformExtensionsManager; import com.marklogic.client.datamovement.DataMovementManager; @@ -16,9 +8,9 @@ import com.marklogic.client.datamovement.QueryBatcher; import com.marklogic.client.datamovement.WriteBatcher; import com.marklogic.client.document.DocumentManager; +import com.marklogic.client.document.DocumentManager.Metadata; import com.marklogic.client.document.DocumentWriteSet; import com.marklogic.client.document.ServerTransform; -import com.marklogic.client.document.DocumentManager.Metadata; import com.marklogic.client.example.cookbook.Util; import com.marklogic.client.io.DocumentMetadataHandle; import com.marklogic.client.io.Format; @@ -26,6 +18,12 @@ import com.marklogic.client.query.QueryManager; import com.marklogic.client.query.RawCombinedQueryDefinition; +import java.io.IOException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Random; + /** * This example demonstrates how to move data from one Marklogic Database to * another Marklogic Database. In this example, we can provide in a Cts query @@ -46,7 +44,7 @@ public class MoveDataBetweenMarklogicDBs { private int threadCount = 3; private String transformName = "moveDataBetweenMLDBs"; private String ctsQuery = ""; - + public void run() { setup(); loadDataIntoSourceDB(); @@ -125,15 +123,14 @@ private void setup() { sourceMoveMgr = sourceClient.newDataMovementManager(); try { Util.ExampleProperties props = Util.loadProperties(); - destMoveMgr = DatabaseClientFactory.newClient(props.host, props.port, new DigestAuthContext(props.adminUser, props.adminPassword)) - .newDataMovementManager(); + destMoveMgr = Util.newAdminClient(props).newDataMovementManager(); } catch (IOException ex) { throw new RuntimeException(ex); } } /* - * Load the documents into source DB for running this example + * Load the documents into source DB for running this example */ private void loadDataIntoSourceDB() { String[] customers = { "{ \"name\" : \"Alice\", \"id\": 1, \"phone\" : 8793993333, \"state\":\"CA\"}", diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/datamovement/RecordJobInformation.java b/examples/src/main/java/com/marklogic/client/example/cookbook/datamovement/RecordJobInformation.java index 8554774a8..135077309 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/datamovement/RecordJobInformation.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/datamovement/RecordJobInformation.java @@ -21,8 +21,7 @@ public class RecordJobInformation { public static void main( String args[] ) throws IOException { Util.ExampleProperties props = Util.loadProperties(); - DatabaseClient client = DatabaseClientFactory.newClient(props.host, props.port, - new DatabaseClientFactory.DigestAuthContext(props.adminUser, props.adminPassword)); + DatabaseClient client = Util.newAdminClient(props); DataMovementManager dm = client.newDataMovementManager(); // Create a WriteBatcher for which job information needs to be recorded diff --git a/examples/src/main/java/com/marklogic/client/example/extension/BatchManagerExample.java b/examples/src/main/java/com/marklogic/client/example/extension/BatchManagerExample.java index bf0e9d6d2..09d3d9e09 100644 --- a/examples/src/main/java/com/marklogic/client/example/extension/BatchManagerExample.java +++ b/examples/src/main/java/com/marklogic/client/example/extension/BatchManagerExample.java @@ -15,13 +15,7 @@ */ package com.marklogic.client.example.extension; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; -import com.marklogic.client.DatabaseClientFactory.Authentication; import com.marklogic.client.FailedRequestException; import com.marklogic.client.ForbiddenUserException; import com.marklogic.client.ResourceNotFoundException; @@ -38,6 +32,10 @@ import com.marklogic.client.io.InputStreamHandle; import com.marklogic.client.io.StringHandle; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + /** * BatchManagerExample illustrates executing a batch of document read, write, * or delete requests using the BatchManager example of a Resource Extension. @@ -54,23 +52,16 @@ public static void run(ExampleProperties props) throws IOException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException { System.out.println("example: "+BatchManagerExample.class.getName()); - - installResourceExtension(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); - - useResource(props.host, props.port, - props.writerUser, props.writerPassword, props.authType); - - tearDownExample(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); + installResourceExtension(props); + useResource(props); + tearDownExample(props); } // install the resource extension on the server - public static void installResourceExtension(String host, int port, String user, String password, Authentication authType) + public static void installResourceExtension(ExampleProperties props) throws IOException { - // create the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newAdminClient(props); // create a manager for resource extensions ResourceExtensionsManager resourceMgr = client.newServerConfigManager().newResourceExtensionsManager(); @@ -102,11 +93,10 @@ public static void installResourceExtension(String host, int port, String user, } // use the resource manager - public static void useResource(String host, int port, String user, String password, Authentication authType) + public static void useResource(ExampleProperties props) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { - // create the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newClient(props); setUpExample(client); @@ -183,11 +173,10 @@ public static void setUpExample(DatabaseClient client) docMgr.write("/batch/delete1.xml", handle.with("")); } - // clean up by deleting the example resource extension - public static void tearDownExample(String host, int port, String user, String password, Authentication authType) + public static void tearDownExample(ExampleProperties props) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newAdminClient(props); XMLDocumentManager docMgr = client.newXMLDocumentManager(); docMgr.delete("/batch/read1.xml"); diff --git a/examples/src/main/java/com/marklogic/client/example/extension/GraphSPARQLExample.java b/examples/src/main/java/com/marklogic/client/example/extension/GraphSPARQLExample.java index d3b48771e..73fd98194 100644 --- a/examples/src/main/java/com/marklogic/client/example/extension/GraphSPARQLExample.java +++ b/examples/src/main/java/com/marklogic/client/example/extension/GraphSPARQLExample.java @@ -37,12 +37,8 @@ public class GraphSPARQLExample { public static void main(String... args) throws IOException { ExampleProperties props = Util.loadProperties(); - DatabaseClient appClient = DatabaseClientFactory.newClient( - props.host, props.port, - props.writerUser, props.writerPassword, props.authType); - DatabaseClient adminClient = DatabaseClientFactory.newClient( - props.host, props.port, - props.adminUser, props.adminPassword, props.authType); + DatabaseClient appClient = Util.newClient(props); + DatabaseClient adminClient = Util.newAdminClient(props); run(appClient, adminClient); appClient.release(); adminClient.release(); diff --git a/examples/src/main/java/com/marklogic/client/example/extension/OpenCSVBatcherExample.java b/examples/src/main/java/com/marklogic/client/example/extension/OpenCSVBatcherExample.java index 77895eaed..fb47ed3eb 100644 --- a/examples/src/main/java/com/marklogic/client/example/extension/OpenCSVBatcherExample.java +++ b/examples/src/main/java/com/marklogic/client/example/extension/OpenCSVBatcherExample.java @@ -15,16 +15,7 @@ */ package com.marklogic.client.example.extension; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -import javax.xml.parsers.ParserConfigurationException; - import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; -import com.marklogic.client.DatabaseClientFactory.Authentication; import com.marklogic.client.FailedRequestException; import com.marklogic.client.ForbiddenUserException; import com.marklogic.client.ResourceNotFoundException; @@ -38,6 +29,12 @@ import com.marklogic.client.io.InputStreamHandle; import com.marklogic.client.io.StringHandle; +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + /** * OpenCSVBatcherExample illustrates splitting a CSV stream * using the OpenCSVBatcher class and the DocumentSplitter example @@ -55,23 +52,16 @@ public static void run(ExampleProperties props) throws IOException, ParserConfigurationException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException { System.out.println("example: "+OpenCSVBatcherExample.class.getName()); - - installResourceExtension(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); - - useResource(props.host, props.port, - props.writerUser, props.writerPassword, props.authType); - - tearDownExample(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); + installResourceExtension(props); + useResource(props); + tearDownExample(props); } // install the resource extension on the server - public static void installResourceExtension(String host, int port, String user, String password, Authentication authType) + public static void installResourceExtension(ExampleProperties props) throws IOException { - // create the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newAdminClient(props); // create a manager for resource extensions ResourceExtensionsManager resourceMgr = client.newServerConfigManager().newResourceExtensionsManager(); @@ -104,11 +94,10 @@ public static void installResourceExtension(String host, int port, String user, } // use the resource manager - public static void useResource(String host, int port, String user, String password, Authentication authType) + public static void useResource(ExampleProperties props) throws IOException, ParserConfigurationException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException { - // create the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newClient(props); // create the CSV splitter OpenCSVBatcher splitter = new OpenCSVBatcher(client); @@ -139,10 +128,10 @@ public static void useResource(String host, int port, String user, String passwo } // clean up by deleting the example resource extension - public static void tearDownExample(String host, int port, String user, String password, Authentication authType) + public static void tearDownExample(ExampleProperties props) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newAdminClient(props); XMLDocumentManager docMgr = client.newXMLDocumentManager(); for (int i=1; i <= 4; i++) { diff --git a/examples/src/main/java/com/marklogic/client/example/extension/SearchCollectorExample.java b/examples/src/main/java/com/marklogic/client/example/extension/SearchCollectorExample.java index 009a1f46d..945fbec51 100644 --- a/examples/src/main/java/com/marklogic/client/example/extension/SearchCollectorExample.java +++ b/examples/src/main/java/com/marklogic/client/example/extension/SearchCollectorExample.java @@ -15,25 +15,9 @@ */ package com.marklogic.client.example.extension; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - -import javax.xml.parsers.ParserConfigurationException; - -import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; -import com.marklogic.client.DatabaseClientFactory.Authentication; -import com.marklogic.client.FailedRequestException; -import com.marklogic.client.ForbiddenUserException; -import com.marklogic.client.ResourceNotFoundException; -import com.marklogic.client.ResourceNotResendableException; -import com.marklogic.client.admin.ExtensionMetadata; -import com.marklogic.client.admin.MethodType; -import com.marklogic.client.admin.QueryOptionsManager; -import com.marklogic.client.admin.ResourceExtensionsManager; +import com.marklogic.client.*; +import com.marklogic.client.admin.*; import com.marklogic.client.admin.ResourceExtensionsManager.MethodParameters; -import com.marklogic.client.admin.ServerConfigurationManager; import com.marklogic.client.document.XMLDocumentManager; import com.marklogic.client.example.cookbook.Util; import com.marklogic.client.example.cookbook.Util.ExampleProperties; @@ -41,6 +25,11 @@ import com.marklogic.client.io.InputStreamHandle; import com.marklogic.client.io.StringHandle; +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + /** * SearchCollectorExample illustrates reading a page of documents * qualified by a query using the SearchCollector class example @@ -62,25 +51,17 @@ public static void run(ExampleProperties props) throws IOException, ParserConfigurationException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException, ResourceNotResendableException { System.out.println("example: "+SearchCollectorExample.class.getName()); - - configureExample(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); - - useResource(props.host, props.port, - props.writerUser, props.writerPassword, props.authType); - - tearDownExample(props.host, props.port, - props.adminUser, props.adminPassword, props.authType); + configureExample(props); + useResource(props); + tearDownExample(props); } // set up the query options for the collecting search - public static void configureExample(String host, int port, String user, String password, Authentication authType) + public static void configureExample(ExampleProperties props) throws IOException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException, ResourceNotResendableException { - // create the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); - - installResourceExtension(client); + DatabaseClient client = Util.newAdminClient(props); + installResourceExtension(client); configureQueryOptions(client); @@ -195,11 +176,8 @@ public static void setUpExample(DatabaseClient client) } // use the resource manager - public static void useResource(String host, int port, String user, String password, Authentication authType) - throws IOException, ParserConfigurationException - { - // create the client - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + public static void useResource(ExampleProperties props) { + DatabaseClient client = Util.newClient(props); // create the search collector SearchCollector collector = new SearchCollector(client); @@ -229,11 +207,10 @@ public static void useResource(String host, int port, String user, String passwo } // clean up by deleting the example resource extension - public static void tearDownExample( - String host, int port, String user, String password, Authentication authType) + public static void tearDownExample(ExampleProperties props) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { - DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType); + DatabaseClient client = Util.newAdminClient(props); XMLDocumentManager docMgr = client.newXMLDocumentManager(); for (String filename: filenames) { diff --git a/examples/src/main/java/com/marklogic/client/example/handle/DOM4JHandleExample.java b/examples/src/main/java/com/marklogic/client/example/handle/DOM4JHandleExample.java index 4b969c744..fa0f8fdca 100644 --- a/examples/src/main/java/com/marklogic/client/example/handle/DOM4JHandleExample.java +++ b/examples/src/main/java/com/marklogic/client/example/handle/DOM4JHandleExample.java @@ -15,21 +15,20 @@ */ package com.marklogic.client.example.handle; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -import org.dom4j.Document; -import org.dom4j.DocumentException; -import org.dom4j.io.SAXReader; - import com.marklogic.client.DatabaseClient; import com.marklogic.client.DatabaseClientFactory; import com.marklogic.client.document.XMLDocumentManager; import com.marklogic.client.example.cookbook.Util; import com.marklogic.client.example.cookbook.Util.ExampleProperties; import com.marklogic.client.extra.dom4j.DOM4JHandle; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.io.SAXReader; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; /** * DOM4JHandleExample illustrates writing and reading content as a dom4j structure @@ -60,10 +59,7 @@ public static void runShortcut(ExampleProperties props) DOM4JHandle.newFactory() ); - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); // create a manager for documents of any format XMLDocumentManager docMgr = client.newXMLDocumentManager(); @@ -107,10 +103,7 @@ public static void runStrongTyped(ExampleProperties props) { String filename = "flipper.xml"; - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); // create a manager for documents of any format XMLDocumentManager docMgr = client.newXMLDocumentManager(); diff --git a/examples/src/main/java/com/marklogic/client/example/handle/GSONHandleExample.java b/examples/src/main/java/com/marklogic/client/example/handle/GSONHandleExample.java index 88a4f7ec2..a16c7308e 100644 --- a/examples/src/main/java/com/marklogic/client/example/handle/GSONHandleExample.java +++ b/examples/src/main/java/com/marklogic/client/example/handle/GSONHandleExample.java @@ -15,11 +15,6 @@ */ package com.marklogic.client.example.handle; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - import com.google.gson.JsonElement; import com.google.gson.JsonParser; import com.marklogic.client.DatabaseClient; @@ -29,6 +24,11 @@ import com.marklogic.client.example.cookbook.Util.ExampleProperties; import com.marklogic.client.extra.gson.GSONHandle; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + /** * GSONHandleExample illustrates writing and reading content as a JSON structure * using the GSON extra library. You must install the library first. @@ -53,10 +53,7 @@ public static void runShortcut(ExampleProperties props) throws IOException { GSONHandle.newFactory() ); - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); // create a manager for JSON documents JSONDocumentManager docMgr = client.newJSONDocumentManager(); @@ -97,10 +94,7 @@ public static void runShortcut(ExampleProperties props) throws IOException { public static void runStrongTyped(ExampleProperties props) throws IOException { String filename = "flipper.json"; - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); // create a manager for JSON documents JSONDocumentManager docMgr = client.newJSONDocumentManager(); diff --git a/examples/src/main/java/com/marklogic/client/example/handle/HTMLCleanerHandleExample.java b/examples/src/main/java/com/marklogic/client/example/handle/HTMLCleanerHandleExample.java index 7432da0b3..53614622b 100644 --- a/examples/src/main/java/com/marklogic/client/example/handle/HTMLCleanerHandleExample.java +++ b/examples/src/main/java/com/marklogic/client/example/handle/HTMLCleanerHandleExample.java @@ -15,20 +15,18 @@ */ package com.marklogic.client.example.handle; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.Set; - -import org.htmlcleaner.ITagInfoProvider; -import org.htmlcleaner.TagInfo; - import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; import com.marklogic.client.document.XMLDocumentManager; import com.marklogic.client.example.cookbook.Util; import com.marklogic.client.example.cookbook.Util.ExampleProperties; import com.marklogic.client.io.StringHandle; +import org.htmlcleaner.ITagInfoProvider; +import org.htmlcleaner.TagInfo; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.Set; /** * HTMLCleanerHandleExample illustrates writing HTML content as @@ -47,10 +45,7 @@ public static void run(ExampleProperties props) throws IOException { String fileroot = "sentiment"; - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); // create a manager for documents of any format XMLDocumentManager docMgr = client.newXMLDocumentManager(); diff --git a/examples/src/main/java/com/marklogic/client/example/handle/JDOMHandleExample.java b/examples/src/main/java/com/marklogic/client/example/handle/JDOMHandleExample.java index cd5eba2e0..096348202 100644 --- a/examples/src/main/java/com/marklogic/client/example/handle/JDOMHandleExample.java +++ b/examples/src/main/java/com/marklogic/client/example/handle/JDOMHandleExample.java @@ -15,22 +15,21 @@ */ package com.marklogic.client.example.handle; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -import org.jdom2.Document; -import org.jdom2.JDOMException; -import org.jdom2.input.SAXBuilder; -import org.jdom2.input.sax.XMLReaders; - import com.marklogic.client.DatabaseClient; import com.marklogic.client.DatabaseClientFactory; import com.marklogic.client.document.XMLDocumentManager; import com.marklogic.client.example.cookbook.Util; import com.marklogic.client.example.cookbook.Util.ExampleProperties; import com.marklogic.client.extra.jdom.JDOMHandle; +import org.jdom2.Document; +import org.jdom2.JDOMException; +import org.jdom2.input.SAXBuilder; +import org.jdom2.input.sax.XMLReaders; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; /** * JDOMHandleExample illustrates writing and reading content as a JDOM structure @@ -60,10 +59,7 @@ public static void runShortcut(ExampleProperties props) JDOMHandle.newFactory() ); - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); // create a manager for documents of any format XMLDocumentManager docMgr = client.newXMLDocumentManager(); @@ -104,10 +100,7 @@ public static void runStrongTyped(ExampleProperties props) { String filename = "flipper.xml"; - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); // create a manager for documents of any format XMLDocumentManager docMgr = client.newXMLDocumentManager(); diff --git a/examples/src/main/java/com/marklogic/client/example/handle/JacksonHandleExample.java b/examples/src/main/java/com/marklogic/client/example/handle/JacksonHandleExample.java index 4c53357fd..8c14c992f 100644 --- a/examples/src/main/java/com/marklogic/client/example/handle/JacksonHandleExample.java +++ b/examples/src/main/java/com/marklogic/client/example/handle/JacksonHandleExample.java @@ -15,11 +15,6 @@ */ package com.marklogic.client.example.handle; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.marklogic.client.DatabaseClient; @@ -29,6 +24,11 @@ import com.marklogic.client.example.cookbook.Util.ExampleProperties; import com.marklogic.client.io.JacksonHandle; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + /** * JacksonHandleExample illustrates writing and reading content as a JSON structure * using the Jackson extra library. You must install the library first. @@ -53,10 +53,7 @@ public static void runShortcut(ExampleProperties props) throws IOException { JacksonHandle.newFactory() ); - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); // create a manager for JSON documents JSONDocumentManager docMgr = client.newJSONDocumentManager(); @@ -96,10 +93,7 @@ public static void runShortcut(ExampleProperties props) throws IOException { public static void runStrongTyped(ExampleProperties props) throws IOException { String filename = "flipper.json"; - // create the client - DatabaseClient client = DatabaseClientFactory.newClient( - props.host, props.port, props.writerUser, props.writerPassword, - props.authType); + DatabaseClient client = Util.newClient(props); // create a manager for JSON documents JSONDocumentManager docMgr = client.newJSONDocumentManager(); diff --git a/examples/src/main/java/com/marklogic/client/example/util/Bootstrapper.java b/examples/src/main/java/com/marklogic/client/example/util/Bootstrapper.java deleted file mode 100644 index db9f419ac..000000000 --- a/examples/src/main/java/com/marklogic/client/example/util/Bootstrapper.java +++ /dev/null @@ -1,473 +0,0 @@ -/* - * Copyright (c) 2022 MarkLogic Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.marklogic.client.example.util; - -import java.io.IOException; -import java.io.InputStream; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import javax.xml.stream.FactoryConfigurationError; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamWriter; - -import org.apache.http.HttpResponse; -import org.apache.http.StatusLine; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.auth.params.AuthPNames; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.params.AuthPolicy; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.protocol.BasicHttpContext; - -import com.marklogic.client.DatabaseClientFactory.Authentication; - -/** - * Bootstrapper provides an example of how to create a REST server - * using an HTTP client. - */ -public class Bootstrapper { - /** - * Command-line invocation. - * @param args command-line arguments specifying the configuration and REST server - * @throws IOException if a communication error occurs - */ - public static void main(String[] args) - throws IOException - { - Properties properties = new Properties(); - for (int i=0; i < args.length; i++) { - String name = args[i]; - if (name.startsWith("-") && name.length() > 1 && ++i < args.length) { - name = name.substring(1); - if ("properties".equals(name)) { - try ( InputStream propsStream = Bootstrapper.class.getClassLoader().getResourceAsStream(name) ) { - if (propsStream == null) throw new IOException("Could not read bootstrapper properties"); - Properties props = new Properties(); - props.load(propsStream); - props.putAll(properties); - properties = props; - } - } else { - properties.put(name, args[i]); - } - } else { - System.err.println("invalid argument: "+name); - System.err.println(getUsage()); - System.exit(1); - } - } - - String invalid = joinList(listInvalidKeys(properties)); - if (invalid != null && invalid.length() > 0) { - System.err.println("invalid arguments: "+invalid); - System.err.println(getUsage()); - System.exit(1); - } - -// TODO: catch invalid argument exceptions and provide feedback - new Bootstrapper().makeServer(properties); - - System.out.println( - "Created "+properties.getProperty("restserver")+ - " server on "+properties.getProperty("restport")+ - " port for "+properties.getProperty("restdb")+ - " database" - ); - } - - /** - * Invocation based on properties. - * @param properties the specification of the configuration and REST server - * @throws IOException if a communication error occurs - */ - public void makeServer(Properties properties) - throws IOException - { - makeServer(new ConfigServer(properties), new RESTServer(properties)); - } - /** - * Programmatic invocation. - * @param configServer the configuration server for creating the REST server - * @param restServer the specification of the REST server - * @throws IOException if a communication error occurs - */ - public void makeServer(ConfigServer configServer, RESTServer restServer) - throws IOException - { - - DefaultHttpClient client = new DefaultHttpClient(); - - String host = configServer.getHost(); - int configPort = configServer.getPort(); - -// TODO: SSL - Authentication authType = configServer.getAuthType(); - if (authType != null) { - List prefList = new ArrayList<>(); - if (authType == Authentication.BASIC) - prefList.add(AuthPolicy.BASIC); - else if (authType == Authentication.DIGEST) - prefList.add(AuthPolicy.DIGEST); - else - throw new IllegalArgumentException( - "Unknown authentication type: "+authType.name() - ); - client.getParams().setParameter( - AuthPNames.PROXY_AUTH_PREF, prefList - ); - - String configUser = configServer.getUser(); - String configPassword = configServer.getPassword(); - client.getCredentialsProvider().setCredentials( - new AuthScope(host, configPort), - new UsernamePasswordCredentials(configUser, configPassword) - ); - } - - BasicHttpContext context = new BasicHttpContext(); - - StringEntity content; - try { - content = new StringEntity(restServer.toXMLString()); - } catch (XMLStreamException e) { - throw new IOException("Could not create payload to bootstrap server."); - } - content.setContentType("application/xml"); - - HttpPost poster = new HttpPost("http://"+host+":"+configPort+"/v1/rest-apis"); - poster.setEntity(content); - - HttpResponse response = client.execute(poster, context); - //poster.releaseConnection(); - - StatusLine status = response.getStatusLine(); - - int statusCode = status.getStatusCode(); - String statusPhrase = status.getReasonPhrase(); - - client.getConnectionManager().shutdown(); - - if (statusCode >= 300) { - throw new RuntimeException( - "Failed to create REST server using host=" + host + - " and port=" + configPort + ": "+ - statusCode+" "+ - statusPhrase+"\n"+ - "Please check the server log for detail" - ); - } - } - - static public String getUsage() { - Map propNames = getPropNames(); - - StringBuilder buffer = new StringBuilder(); - buffer.append("usage:\n"); - for (Map.Entry entry: propNames.entrySet()) { - buffer.append(entry.getKey()); - buffer.append("\t= "); - buffer.append(entry.getValue()); - buffer.append("\n"); - } - - return buffer.toString(); - } - static public void checkProperties(Properties properties) { - String invalid = joinList(listInvalidKeys(properties)); - if (invalid != null && invalid.length() > 0) { - throw new IllegalArgumentException( - "invalid bootstrapping names: "+invalid - ); - } - } - static public List listInvalidKeys(Properties properties) { - Map propNames = getPropNames(); - - List invalid = null; - for (String key: properties.stringPropertyNames()) { - if (propNames.containsKey(key)) - continue; - - if (invalid == null) - invalid = new ArrayList<>(); - - invalid.add(key); - } - - return invalid; - } - static public String joinList(List list) { - return joinList(list, ", "); - } - static public String joinList(List list, String sep) { - if (list == null || list.size() == 0) - return null; - - StringBuilder buffer = null; - for (String key: list) { - if (buffer == null) - buffer = new StringBuilder(); - else - buffer.append(sep); - buffer.append(key); - } - - return buffer.toString(); - } - static private Map getPropNames() { - Map propNames = new HashMap<>(); - propNames.put("confighost", - "the host for configuring a new REST server"); - propNames.put("configport", - "the port (typically 8002) for the configuration server"); - propNames.put("configuser", - "the user (typically admin) for the configuration server"); - propNames.put("configpassword", - "the password for the configuration user"); - propNames.put("configauth", - "the type of authentication (digest or basic) for the configuration server"); - propNames.put("restdb", - "the name of the database exposed by the new REST server"); - propNames.put("restmodulesdb", - "the name of the modules database (if any) for new REST server"); - propNames.put("restgroup", - "the name of the group (on a cluster with many groups) for new REST server"); - propNames.put("restserver", - "the name of the new REST server"); - propNames.put("restport", - "the port for the new REST server"); - - return propNames; - } - - /** - * ConfigServer specifies a configuration server supporting - * requests to create a REST server. - */ - static public class ConfigServer { - private String host = "localhost"; - private int port = 8002; - private String user = null; - private String password = null; - private Authentication authType = Authentication.DIGEST; - - /** - * Construct the configuration server specification based on properties. - * @param properties specifies the configuration server - */ - public ConfigServer(Properties properties) { - for (String key: properties.stringPropertyNames()) { - String value = properties.getProperty(key); - if ("confighost".equals(key)) - host = value; - else if ("configport".equals(key)) - port = Integer.parseInt(value); - else if ("configuser".equals(key)) - user = value; -// TODO: secure password configuration - else if ("configpassword".equals(key)) - password = value; - else if ("configauth".equals(key)) - authType = Authentication.valueOf(value.toUpperCase()); - } - validate(); - } - /** - * Construct the configuration server specification programmatically. - * @param host the host (often localhost) for the configuration and REST server - * @param port the port (usually 8002) for the configuration server - * @param user the user (often admin) for the configuration server - * @param password the password for the configuration server - * @param authType the authentication type (usually DIGEST) for the configuration server - */ - public ConfigServer( - String host, int port, String user, String password, Authentication authType - ) { - if (host != null) - this.host = host; - if (port != -1) - this.port = port; - if (user != null) - this.user = user; - if (password != null) - this.password = password; - if (authType != null) - this.authType = authType; - validate(); - } - private void validate() { - if ( - (authType != null || user != null || password != null) && - (authType == null || user == null || password == null) - ) - throw new IllegalArgumentException( - "requires all or no user, password, and authentication type" - ); - } - - public String getHost() { - return host; - } - public int getPort() { - return port; - } - public String getUser() { - return user; - } - public String getPassword() { - return password; - } - public Authentication getAuthType() { - return authType; - } - } - - /** - * RESTServer specifies an application providing access to a database - * using built-in RESTful services. - */ - static public class RESTServer { - private String database; - private String modulesDatabase; - private String group; - private String server; - private int port = -1; - - /** - * Construct the REST server specification based on properties. - * @param properties specifies the REST server - */ - public RESTServer(Properties properties) { - for (String key: properties.stringPropertyNames()) { - String value = properties.getProperty(key); - if ("restdb".equals(key)) - database = value; - else if ("restmodulesdb".equals(key)) - modulesDatabase = value; - else if ("restgroup".equals(key)) - group = value; - else if ("restserver".equals(key)) - server = value; - else if ("restport".equals(key)) - port = Integer.parseInt(value); - } - validate(); - } - /** - * Construct the REST server specification programmatically. - * @param database the database exposed by the REST server - * @param modulesDatabase the modules database for the REST server - * @param group the group containing the REST server - * @param server the name of the REST server - * @param port the port for the REST server - */ - public RESTServer( - String database, String modulesDatabase, - String group, String server, int port - ) { - this.database = database; - if (modulesDatabase != null) - this.modulesDatabase = modulesDatabase; - if (group != null) - this.group = group; - this.server = server; - this.port = port; - validate(); - } - private void validate() { - if (database == null) - throw new IllegalArgumentException("database required"); - if (server == null) - throw new IllegalArgumentException("server required"); - if (port == -1) - throw new IllegalArgumentException("port required"); - } - - public String getDatabase() { - return database; - } - public String getModulesDatabase() { - return modulesDatabase; - } - public String getGroup() { - return group; - } - public String getServer() { - return server; - } - public int getPort() { - return port; - } - - public String toXMLString() - throws XMLStreamException, FactoryConfigurationError - { - StringWriter buffer = new StringWriter(); - - XMLStreamWriter writer = - XMLOutputFactory.newFactory().createXMLStreamWriter(buffer); - - String server = getServer(); - int port = getPort(); - String group = getGroup(); - String database = getDatabase(); - String modulesDatabase = getModulesDatabase(); - - writer.writeStartDocument(); - writer.writeStartElement("rest-api"); - writer.writeDefaultNamespace("http://marklogic.com/rest-api"); - - writer.writeStartElement("name"); - if(server != null) - writer.writeCharacters(server); - writer.writeEndElement(); - - if (group != null && group.length() > 0) { - writer.writeStartElement("group"); - writer.writeCharacters(group); - writer.writeEndElement(); - } - - writer.writeStartElement("database"); - if(database != null) - writer.writeCharacters(database); - writer.writeEndElement(); - - if (modulesDatabase != null && modulesDatabase.length() > 0) { - writer.writeStartElement("modules-database"); - writer.writeCharacters(modulesDatabase); - writer.writeEndElement(); - } - - writer.writeStartElement("port"); - writer.writeCharacters(String.valueOf(port)); - writer.writeEndElement(); - - writer.writeEndElement(); - writer.writeEndDocument(); - - return buffer.toString(); - } - } -} diff --git a/examples/src/main/java/com/marklogic/client/example/util/BootstrapperExample.java b/examples/src/main/java/com/marklogic/client/example/util/BootstrapperExample.java deleted file mode 100644 index 815cd7b4f..000000000 --- a/examples/src/main/java/com/marklogic/client/example/util/BootstrapperExample.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2022 MarkLogic Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.marklogic.client.example.util; - -import java.io.IOException; - -import javax.xml.stream.FactoryConfigurationError; -import javax.xml.stream.XMLStreamException; - -import org.apache.http.client.ClientProtocolException; - -import com.marklogic.client.DatabaseClientFactory.Authentication; -import com.marklogic.client.example.util.Bootstrapper.ConfigServer; -import com.marklogic.client.example.util.Bootstrapper.RESTServer; - -/** - * Sample main method for a REST bootstrapper. - * - */ -public class BootstrapperExample { - public static void main(String[] args) - throws ClientProtocolException, IOException, XMLStreamException, FactoryConfigurationError - { - new BootstrapperExample().makeSampleServer(); - } - public void makeSampleServer() - throws ClientProtocolException, IOException, XMLStreamException, FactoryConfigurationError - { - new Bootstrapper().makeServer( - new ConfigServer( - "localhost", 8002, "admin", "admin", Authentication.DIGEST - ), - new RESTServer( - "Documents", "Modules", "Default", "DocuREST", 8014 - ) - ); - - System.out.println( - "Created DocuREST server on 8014 port for Documents database" - ); - } -} diff --git a/examples/src/main/java/com/marklogic/client/example/util/package-info.java b/examples/src/main/java/com/marklogic/client/example/util/package-info.java deleted file mode 100644 index b96ff881b..000000000 --- a/examples/src/main/java/com/marklogic/client/example/util/package-info.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * The package provides utilities for bootstrapping and tearing down a MarkLogic REST instance. - */ -/* - * Copyright (c) 2022 MarkLogic Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.marklogic.client.example.util; diff --git a/examples/src/main/resources/Example.properties b/examples/src/main/resources/Example.properties index 64972a73e..3628fa400 100644 --- a/examples/src/main/resources/Example.properties +++ b/examples/src/main/resources/Example.properties @@ -1,4 +1,4 @@ -# properties to configure the examples +# properties to configure the examples example.reader_user=rest-reader example.reader_password=x example.writer_user=rest-writer @@ -7,7 +7,6 @@ example.admin_user=admin example.admin_password=admin example.host=localhost example.port=8000 -example.authentication_type=digest example.jdbc.url=jdbc:hsqldb:hsql://localhost:9002/employees example.jdbc.user=sa diff --git a/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/fastfunctest/TestDatabaseClientConnection.java b/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/fastfunctest/TestDatabaseClientConnection.java index 4e6281fdf..a4fa3b876 100644 --- a/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/fastfunctest/TestDatabaseClientConnection.java +++ b/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/fastfunctest/TestDatabaseClientConnection.java @@ -17,35 +17,19 @@ package com.marklogic.client.fastfunctest; import com.marklogic.client.DatabaseClient; -import com.marklogic.client.DatabaseClientFactory; import com.marklogic.client.DatabaseClientFactory.SSLHostnameVerifier; import com.marklogic.client.DatabaseClientFactory.SecurityContext; import com.marklogic.client.MarkLogicIOException; -import com.marklogic.client.ResourceNotFoundException; import com.marklogic.client.Transaction; import com.marklogic.client.alerting.RuleDefinition; import com.marklogic.client.alerting.RuleDefinitionList; import com.marklogic.client.alerting.RuleManager; -import com.marklogic.client.document.DocumentDescriptor; import com.marklogic.client.document.DocumentManager.Metadata; import com.marklogic.client.document.DocumentPage; -import com.marklogic.client.document.DocumentUriTemplate; import com.marklogic.client.document.DocumentWriteSet; import com.marklogic.client.document.TextDocumentManager; -import com.marklogic.client.fastfunctest.AbstractFunctionalTest; -import com.marklogic.client.io.DocumentMetadataHandle; -import com.marklogic.client.io.DocumentMetadataHandle.DocumentMetadataValues; -import com.marklogic.client.io.InputStreamHandle; -import com.marklogic.client.io.StringHandle; -import com.marklogic.client.io.TuplesHandle; -import com.marklogic.client.io.ValuesHandle; -import com.marklogic.client.io.ValuesListHandle; -import com.marklogic.client.query.AggregateResult; -import com.marklogic.client.query.QueryManager; -import com.marklogic.client.query.StringQueryDefinition; -import com.marklogic.client.query.SuggestDefinition; -import com.marklogic.client.query.ValuesDefinition; -import com.marklogic.client.query.ValuesListDefinition; +import com.marklogic.client.io.*; +import com.marklogic.client.query.*; import org.custommonkey.xmlunit.exceptions.XpathException; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -56,13 +40,7 @@ import javax.net.ssl.X509TrustManager; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.security.KeyManagementException; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; @@ -72,12 +50,10 @@ import java.text.DecimalFormat; import java.util.Iterator; import java.util.Map; -import java.util.Scanner; import java.util.TreeMap; import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; public class TestDatabaseClientConnection extends AbstractFunctionalTest { @@ -761,133 +737,6 @@ public void testRMMatchAsWithCandidates() throws IOException, ParserConfiguratio client.release(); } - @Test - public void testDatabaseClientFactoryBean() throws IOException, ParserConfigurationException, SAXException, XpathException, KeyManagementException, - NoSuchAlgorithmException - { - DatabaseClient client = null; - try { - DatabaseClientFactory.Bean clientFactoryBean = new DatabaseClientFactory.Bean(); - clientFactoryBean.setHost(getRestAppServerHostName()); - clientFactoryBean.setPort(getRestAppServerPort()); - clientFactoryBean.setBasePath(basePath); - clientFactoryBean.setConnectionType(getConnType()); - SecurityContext secContext = newSecurityContext("rest-admin", "x"); - - clientFactoryBean.setSecurityContext(secContext); - client = clientFactoryBean.newClient(); - - String docId[] = { "/foo/test/myFoo1.txt", "/foo/test/myFoo2.txt", "/foo/test/myFoo3.txt" }; - - TextDocumentManager docMgr = client.newTextDocumentManager(); - DocumentWriteSet writeset = docMgr.newWriteSet(); - - writeset.add(docId[0], new StringHandle().with("This is so foo1")); - writeset.add(docId[1], new StringHandle().with("This is so foo2")); - writeset.add(docId[2], new StringHandle().with("This is so foo3")); - - docMgr.write(writeset); - assertEquals( "This is so foo1", docMgr.read(docId[0], new StringHandle()).get()); - assertEquals( "This is so foo2", docMgr.read(docId[1], new StringHandle()).get()); - assertEquals( "This is so foo3", docMgr.read(docId[2], new StringHandle()).get()); - docMgr.delete(docId[0], docId[1], docId[2]); - } catch (ResourceNotFoundException e) { - e.printStackTrace(); - } - finally { - client.release(); - } - } - - // Verify that DatabaseClient from Bean handles transactions - @Test - public void testDBClientFactoryBeanTransaction() throws Exception { - DatabaseClient client = null; - - String filename = "facebook-10443244874876159931"; - DatabaseClientFactory.Bean clientFactoryBean = new DatabaseClientFactory.Bean(); - clientFactoryBean.setHost(getRestAppServerHostName()); - clientFactoryBean.setPort(getRestAppServerPort()); - clientFactoryBean.setBasePath(basePath); - clientFactoryBean.setConnectionType(getConnType()); - SecurityContext secContext = newSecurityContext("rest-writer", "x"); - - clientFactoryBean.setSecurityContext(secContext); - client = clientFactoryBean.newClient(); - - DocumentMetadataHandle metadataHandle = new DocumentMetadataHandle(); - DocumentMetadataHandle readMetadataHandle = new DocumentMetadataHandle(); - DocumentMetadataValues metadatavalues = readMetadataHandle.getMetadataValues(); - Transaction t1 = null; - Transaction t2 = null; - metadataHandle.getMetadataValues().add("key1", "value1"); - metadataHandle.getMetadataValues().add("key2", "value2"); - metadataHandle.getMetadataValues().add("key3", "value3"); - - TextDocumentManager docMgr = client.newTextDocumentManager(); - String uri = "/trx-jsonhandle-metadatavalues/"; - String docId = uri + filename; - FileInputStream fis = null; - Scanner scanner = null; - String readContent; - File file = null; - - try { - file = new File("src/test/java/com/marklogic/client/functionaltest/data/" + filename); - fis = new FileInputStream(file); - scanner = new Scanner(fis).useDelimiter("\\Z"); - readContent = scanner.next(); - } finally { - fis.close(); - scanner.close(); - } - StringHandle contentHandle = new StringHandle(); - contentHandle.set(readContent); - // write the doc - docMgr.writeAs(docId, metadataHandle, contentHandle); - DocumentUriTemplate template = docMgr.newDocumentUriTemplate("Text").withDirectory("/trx-jsonhandle-metadatavalues-template/"); - - try { - // Trx with metadata values rollback scenario - t1 = client.openTransaction(); - metadataHandle.getMetadataValues().add("keyTrx1", "valueTrx1"); - docMgr.writeMetadata(docId, metadataHandle, t1); - docMgr.readMetadata(docId, readMetadataHandle, t1); - assertTrue( metadatavalues.containsValue("valueTrx1")); - t1.rollback(); - docMgr.readMetadata(docId, readMetadataHandle); - metadatavalues = readMetadataHandle.getMetadataValues(); - assertFalse(metadatavalues.containsValue("valueTrx1")); - - // Trx with metadata values commit scenario - t2 = client.openTransaction(); - metadataHandle.getMetadataValues().add("keyTrx2", "valueTrx2"); - DocumentDescriptor desc = docMgr.create(template, metadataHandle, contentHandle, t2); - String docId1 = desc.getUri(); - docMgr.read(docId1, readMetadataHandle, contentHandle, t2); - assertTrue( metadatavalues.containsValue("valueTrx2")); - t2.commit(); - docMgr.readAs(docId1, readMetadataHandle, String.class); - metadatavalues = readMetadataHandle.getMetadataValues(); - assertTrue( metadatavalues.containsValue("valueTrx2")); - waitForPropertyPropagate(); - - t1 = t2 = null; - } catch (Exception e) { - e.printStackTrace(); - } finally { - if (t1 != null) { - t1.rollback(); - t1 = null; - - } else if (t2 != null) { - t2.rollback(); - t2 = null; - } - client.release(); - } - } - @Test public void testRuleManagerMatchAs() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException, KeyManagementException, NoSuchAlgorithmException diff --git a/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/BasicJavaClientREST.java b/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/BasicJavaClientREST.java index 143975752..530da80c0 100644 --- a/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/BasicJavaClientREST.java +++ b/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/BasicJavaClientREST.java @@ -16,61 +16,6 @@ package com.marklogic.client.functionaltest; -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import java.nio.channels.FileChannel; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; -import java.util.Iterator; -import java.util.Map; -import java.util.Scanner; -import java.util.Set; - -import org.apache.http.HttpResponse; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.ResponseHandler; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.BasicResponseHandler; -import org.apache.http.impl.client.DefaultHttpClient; - -import jakarta.xml.bind.JAXBContext; -import jakarta.xml.bind.JAXBException; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.stream.XMLEventReader; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Result; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.sax.SAXSource; -import javax.xml.transform.stream.StreamResult; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParser; @@ -78,38 +23,41 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.marklogic.client.DatabaseClientFactory; -import com.marklogic.client.document.DocumentManager; import com.marklogic.client.DatabaseClient; -import com.marklogic.client.io.Format; -import com.marklogic.client.query.QueryManager; import com.marklogic.client.admin.QueryOptionsManager; -import com.marklogic.client.Transaction; -import com.marklogic.client.DatabaseClientFactory.Authentication; -import com.marklogic.client.query.MatchDocumentSummary; -import com.marklogic.client.query.MatchLocation; -import com.marklogic.client.query.StringQueryDefinition; -import com.marklogic.client.io.BaseHandle; -import com.marklogic.client.io.BytesHandle; -import com.marklogic.client.io.DOMHandle; -import com.marklogic.client.io.DocumentMetadataHandle; +import com.marklogic.client.document.DocumentManager; +import com.marklogic.client.io.*; import com.marklogic.client.io.DocumentMetadataHandle.DocumentCollections; import com.marklogic.client.io.DocumentMetadataHandle.DocumentPermissions; import com.marklogic.client.io.DocumentMetadataHandle.DocumentProperties; -import com.marklogic.client.io.FileHandle; -import com.marklogic.client.io.InputSourceHandle; -import com.marklogic.client.io.InputStreamHandle; -import com.marklogic.client.io.JAXBHandle; -import com.marklogic.client.io.OutputStreamHandle; -import com.marklogic.client.io.OutputStreamSender; -import com.marklogic.client.io.ReaderHandle; -import com.marklogic.client.io.SearchHandle; -import com.marklogic.client.io.SourceHandle; -import com.marklogic.client.io.StringHandle; -import com.marklogic.client.io.XMLEventReaderHandle; -import com.marklogic.client.io.XMLStreamReaderHandle; -import com.marklogic.client.io.marker.GenericReadHandle; -import com.marklogic.client.io.marker.GenericWriteHandle; +import com.marklogic.client.query.MatchDocumentSummary; +import com.marklogic.client.query.MatchLocation; +import com.marklogic.client.query.QueryManager; +import com.marklogic.client.query.StringQueryDefinition; +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.JAXBException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.transform.*; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stream.StreamResult; +import java.io.*; +import java.nio.channels.FileChannel; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.util.Iterator; +import java.util.Map; +import java.util.Scanner; +import java.util.Set; public abstract class BasicJavaClientREST extends ConnectedRESTQA { diff --git a/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/TestDatabaseClientKerberosFromFile.java b/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/TestDatabaseClientKerberosFromFile.java index 8565cb590..59c1bda07 100644 --- a/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/TestDatabaseClientKerberosFromFile.java +++ b/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/TestDatabaseClientKerberosFromFile.java @@ -167,7 +167,7 @@ public void setUp() throws KeyManagementException, NoSuchAlgorithmException, Exc .withKeyTab(keytabFile); client = DatabaseClientFactory.newClient( appServerHostName, appServerHostPort, - new DatabaseClientFactory.KerberosAuthContext(krbConfig).withSSLContext(sslcontext)); + new DatabaseClientFactory.KerberosAuthContext(krbConfig).withSSLContext(sslcontext, null)); } else { /*Pass this file's location for the gradle (thru Jenkins job) QA functional test project's build.gradle file has << systemProperty "keytabFile", System.getProperty("keytabFile") >> diff --git a/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/TestDatabaseClientWithKerberos.java b/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/TestDatabaseClientWithKerberos.java index 2f3e883f8..d242abb3c 100644 --- a/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/TestDatabaseClientWithKerberos.java +++ b/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/TestDatabaseClientWithKerberos.java @@ -134,7 +134,7 @@ public void setUp() throws KeyManagementException, NoSuchAlgorithmException, Exc sslcontext = getSslContext(); client = DatabaseClientFactory.newClient( appServerHostName, appServerHostPort, - new KerberosAuthContext(kdcPrincipalUser).withSSLContext(sslcontext)); + new KerberosAuthContext(kdcPrincipalUser).withSSLContext(sslcontext, null)); } else client = DatabaseClientFactory.newClient(appServerHostName, appServerHostPort, new KerberosAuthContext(kdcPrincipalUser)); diff --git a/marklogic-client-api/src/main/java/com/marklogic/client/DatabaseClientFactory.java b/marklogic-client-api/src/main/java/com/marklogic/client/DatabaseClientFactory.java index 622805f08..a9a88bc15 100644 --- a/marklogic-client-api/src/main/java/com/marklogic/client/DatabaseClientFactory.java +++ b/marklogic-client-api/src/main/java/com/marklogic/client/DatabaseClientFactory.java @@ -15,14 +15,21 @@ */ package com.marklogic.client; +import com.marklogic.client.extra.httpclient.HttpClientConfigurator; +import com.marklogic.client.extra.okhttpclient.OkHttpClientConfigurator; +import com.marklogic.client.impl.*; +import com.marklogic.client.io.marker.ContentHandle; +import com.marklogic.client.io.marker.ContentHandleFactory; +import okhttp3.OkHttpClient; + +import javax.naming.InvalidNameException; +import javax.naming.ldap.LdapName; +import javax.naming.ldap.Rdn; +import javax.net.ssl.*; import java.io.FileInputStream; import java.io.IOException; import java.io.Serializable; -import java.security.KeyManagementException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.UnrecoverableKeyException; +import java.security.*; import java.security.cert.Certificate; import java.security.cert.CertificateException; import java.security.cert.CertificateParsingException; @@ -31,26 +38,6 @@ import java.util.*; import java.util.function.Function; -import javax.naming.InvalidNameException; -import javax.naming.ldap.LdapName; -import javax.naming.ldap.Rdn; -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.KeyManager; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLException; -import javax.net.ssl.SSLSession; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; - -import com.marklogic.client.impl.*; -import okhttp3.OkHttpClient; - -import com.marklogic.client.extra.okhttpclient.OkHttpClientConfigurator; -import com.marklogic.client.extra.httpclient.HttpClientConfigurator; -import com.marklogic.client.io.marker.ContentHandle; -import com.marklogic.client.io.marker.ContentHandleFactory; - /** * A Database Client Factory configures a database client for making * database requests. @@ -62,43 +49,6 @@ public class DatabaseClientFactory { static private HandleFactoryRegistry handleRegistry = HandleFactoryRegistryImpl.newDefault(); - /** - * Authentication enumerates the methods for verifying a user and - * password with the database. - * @deprecated (as of 4.0.1) use BasicAuthContext, DigestAuthContext and KerberosAuthContext classes - */ - @Deprecated - public enum Authentication { - /** - * Minimal security unless used with SSL. - */ - BASIC, - /** - * Moderate security without SSL. - */ - DIGEST, - /** - * Authentication using Kerberos. - */ - KERBEROS, - /** - * Authentication using Certificates; - */ - CERTIFICATE, - /** - * Authentication using SAML; - */ - SAML; - /** - * Returns the enumerated value for the case-insensitive name. - * @param name the name of the enumerated value - * @return the enumerated value - */ - static public Authentication valueOfUncased(String name) { - return Authentication.valueOf(name.toUpperCase()); - } - } - /** * An SSLHostnameVerifier checks whether a hostname is acceptable during SSL * authentication. By default, {@link #COMMON} is used, allowing any level @@ -325,15 +275,7 @@ public interface SecurityContext { */ X509TrustManager getTrustManager(); - /** - * Set the context without a trust manager - * @param context - the SSLContext object required for the SSL connection - * @deprecated (as of 4.0.1) use SecurityContext.withSSLContext(SSLContext,X509TrustManager) - */ - @Deprecated - void setSSLContext(SSLContext context); - - /* + /* * Returns the host verifier. * @return the host verifier */ @@ -346,15 +288,6 @@ public interface SecurityContext { */ void setSSLHostnameVerifier(SSLHostnameVerifier verifier); - /** - * Set the context without a trust manager - * @param context - the SSLContext object required for the SSL connection - * @deprecated (as of 4.0.1) use SecurityContext.withSSLContext(SSLContext,X509TrustManager) - * @return a context containing authentication information - */ - @Deprecated - SecurityContext withSSLContext(SSLContext context); - /** * The SSLContext should be initialized with KeyManager and TrustManager * using a KeyStore.
@@ -400,12 +333,6 @@ public SSLContext getSSLContext() { return sslContext; } - @Override - @Deprecated - public void setSSLContext(SSLContext context) { - this.sslContext = context; - } - @Override public SSLHostnameVerifier getSSLHostnameVerifier() { return sslVerifier; @@ -420,13 +347,6 @@ public X509TrustManager getTrustManager() { return this.trustManager; } - @Override - @Deprecated - public SecurityContext withSSLContext(SSLContext context) { - this.sslContext = context; - return this; - } - @Override public SecurityContext withSSLHostnameVerifier(SSLHostnameVerifier verifier) { this.sslVerifier = verifier; @@ -564,13 +484,6 @@ public String getPassword() { return password; } - @Override - @Deprecated - public BasicAuthContext withSSLContext(SSLContext context) { - this.sslContext = context; - return this; - } - @Override public BasicAuthContext withSSLContext(SSLContext context, X509TrustManager trustManager) { this.sslContext = context; @@ -602,13 +515,6 @@ public String getPassword() { return password; } - @Override - @Deprecated - public DigestAuthContext withSSLContext(SSLContext context) { - this.sslContext = context; - return this; - } - @Override public DigestAuthContext withSSLContext(SSLContext context, X509TrustManager trustManager) { this.sslContext = context; @@ -645,13 +551,6 @@ public KerberosAuthContext(KerberosConfig krbConfig) { krbOptions = Collections.unmodifiableMap(krbConfig.toOptions()); } - @Override - @Deprecated - public KerberosAuthContext withSSLContext(SSLContext context) { - this.sslContext = context; - return this; - } - @Override public KerberosAuthContext withSSLContext(SSLContext context, X509TrustManager trustManager) { this.sslContext = context; @@ -829,13 +728,6 @@ public SSLContext getSSLContext() { return sslContext; } - @Override - @Deprecated - public void setSSLContext(SSLContext context) { - this.sslContext = context; - - } - /** * Gets the hostname verifier when using SSL. * @return the hostname verifier used for authentication @@ -848,14 +740,6 @@ public SSLHostnameVerifier getSSLHostnameVerifier() { @Override public void setSSLHostnameVerifier(SSLHostnameVerifier verifier) { this.sslVerifier = verifier; - - } - - @Override - @Deprecated - public SecurityContext withSSLContext(SSLContext context) { - this.sslContext = context; - return this; } } @@ -1043,21 +927,8 @@ public Map toOptions() { public static class CertificateAuthContext extends AuthContext { String certFile; String certPassword; - /** - * Creates a CertificateAuthContext by initializing the SSLContext - * of the HTTPS channel with the SSLContext object passed. The KeyManager of - * the SSLContext should be initialized with the appropriate client - * certificate and client's private key - * @param context the SSLContext with which we initialize the - * CertificateAuthContext - * @deprecated (as of 4.0.1) use CertificateAuthContext(SSLContext,X509TrustManager) - */ - @Deprecated - public CertificateAuthContext(SSLContext context) { - this.sslContext = context; - } - /** + /** * Creates a CertificateAuthContext by initializing the SSLContext of the * HTTPS channel with the SSLContext object passed and using the TrustManger * passed. The KeyManager of the SSLContext should be initialized with the @@ -1073,23 +944,6 @@ public CertificateAuthContext(SSLContext context, X509TrustManager trustManager) this.trustManager = trustManager; } - /** - * Creates a CertificateAuthContext by initializing the SSLContext - * of the HTTPS channel with the SSLContext object passed and assigns the - * SSLHostnameVerifier passed to be used for checking host names. The KeyManager of - * the SSLContext should be initialized with the appropriate client - * certificate and client's private key - * @param context the SSLContext with which we initialize the - * CertificateAuthContext - * @param verifier a callback for checking host names - * @deprecated (as of 4.0.1) use CertificateAuthContext(SSLContext,SSLHostnameVerifier,X509TrustManager) - */ - @Deprecated - public CertificateAuthContext(SSLContext context, SSLHostnameVerifier verifier) { - this.sslContext = context; - this.sslVerifier = verifier; - } - /** * Creates a CertificateAuthContext by initializing the SSLContext of the * HTTPS channel with the SSLContext object passed and assigns the @@ -1109,34 +963,6 @@ public CertificateAuthContext(SSLContext context, SSLHostnameVerifier verifier, this.trustManager = trustManager; } - /** - * Creates a CertificateAuthContext with a PKCS12 file. The SSLContext is - * created from the information in the PKCS12 file. This constructor should - * be called when the export password of the PKCS12 file is empty. - * - * @param certFile the p12 file which contains the client's private key and - * the client's certificate chain - * @throws CertificateException if any of the certificates in the certFile - * cannot be loaded - * @throws UnrecoverableKeyException if the certFile has an export password - * @throws KeyManagementException if initializing the SSLContext with the - * KeyManager fails - * @throws IOException if there is an I/O or format problem with the - * keystore data, if a password is required but not given, or if - * the given password was incorrect or if the certFile path is - * invalid or if the file is not found If the error is due to a - * wrong password, the cause of the IOException should be an - * UnrecoverableKeyException. - */ - @Deprecated - public CertificateAuthContext(String certFile) - throws CertificateException, IOException, - UnrecoverableKeyException, KeyManagementException { - this.certFile = certFile; - this.certPassword = ""; - this.sslContext = createSSLContext(); - } - /** * Creates a CertificateAuthContext with a PKCS12 file. The SSLContext is * created from the information in the PKCS12 file. This constructor should @@ -1167,30 +993,6 @@ public CertificateAuthContext(String certFile, X509TrustManager trustManager) this.sslContext = createSSLContext(); } - /** - * Creates a CertificateAuthContext with a PKCS12 file. The SSLContext - * is created from the information in the PKCS12 file. This constructor - * should be called when the export password of the PKCS12 file is non-empty. - * @param certFile the p12 file which contains the client's private key - * and the client's certificate chain - * @param certPassword the export password of the p12 file - * @throws CertificateException if any of the certificates in the certFile cannot be loaded - * @throws UnrecoverableKeyException if the certFile has an export password - * @throws KeyManagementException if initializing the SSLContext with the KeyManager fails - * @throws IOException if there is an I/O or format problem with the keystore data, - * if a password is required but not given, or if the given password was - * incorrect or if the certFile path is invalid or if the file is not found - * If the error is due to a wrong password, the cause of the IOException - * should be an UnrecoverableKeyException. - */ - @Deprecated - public CertificateAuthContext(String certFile, String certPassword) - throws CertificateException, IOException, - UnrecoverableKeyException, KeyManagementException { - this.certFile = certFile; - this.certPassword = certPassword; - this.sslContext = createSSLContext(); - } /** * Creates a CertificateAuthContext with a PKCS12 file. The SSLContext * is created from the information in the PKCS12 file. This constructor @@ -1457,133 +1259,6 @@ static public DatabaseClient newClient(String host, int port, String basePath, S return client; } - - static private SecurityContext makeSecurityContext(String user, String password, Authentication type, SSLContext context, SSLHostnameVerifier verifier) { - if ( Authentication.BASIC == type ) { - return new BasicAuthContext(user, password) - .withSSLContext(context) - .withSSLHostnameVerifier(verifier); - } else if ( Authentication.DIGEST == type ) { - return new DigestAuthContext(user, password) - .withSSLContext(context) - .withSSLHostnameVerifier(verifier); - } else { - throw new IllegalStateException("makeSecurityContext should only be called with BASIC or DIGEST Authentication"); - } - } - - /** - * Creates a client to access the database by means of a REST server. - * - * @param host the host with the REST server - * @param port the port for the REST server - * @param user the user with read, write, or administrative privileges - * @param password the password for the user - * @param type the type of authentication applied to the request - * @return a new client for making database requests - * @deprecated (as of 4.0.1) use {@link #newClient(String host, int port, SecurityContext securityContext)} - */ - @Deprecated - static public DatabaseClient newClient(String host, int port, String user, String password, Authentication type) { - return newClient(host, port, null, makeSecurityContext(user, password, type, null, null), null); - } - /** - * Creates a client to access the database by means of a REST server. - * - * A data service interface can only call an endpoint for the configured content database - * of the appserver. You cannot specify the database when constructing a client for working - * with a data service. - * - * @param host the host with the REST server - * @param port the port for the REST server - * @param database the database to access (default: configured database for the REST server) - * @param user the user with read, write, or administrative privileges - * @param password the password for the user - * @param type the type of authentication applied to the request - * @return a new client for making database requests - * @deprecated (as of 4.0.1) use {@link #newClient(String host, int port, String database, SecurityContext securityContext)} - */ - @Deprecated - static public DatabaseClient newClient(String host, int port, String database, String user, String password, Authentication type) { - return newClient(host, port, database, makeSecurityContext(user, password, type, null, null), null); - } - /** - * Creates a client to access the database by means of a REST server. - * - * @param host the host with the REST server - * @param port the port for the REST server - * @param user the user with read, write, or administrative privileges - * @param password the password for the user - * @param type the type of authentication applied to the request - * @param context the SSL context for authenticating with the server - * @return a new client for making database requests - * @deprecated (as of 4.0.1) use {@link #newClient(String host, int port, SecurityContext securityContext)} - */ - @Deprecated - static public DatabaseClient newClient(String host, int port, String user, String password, Authentication type, SSLContext context) { - return newClient(host, port, null, makeSecurityContext(user, password, type, context, SSLHostnameVerifier.COMMON), null); - } - /** - * Creates a client to access the database by means of a REST server. - * - * A data service interface can only call an endpoint for the configured content database - * of the appserver. You cannot specify the database when constructing a client for working - * with a data service. - * - * @param host the host with the REST server - * @param port the port for the REST server - * @param database the database to access (default: configured database for the REST server) - * @param user the user with read, write, or administrative privileges - * @param password the password for the user - * @param type the type of authentication applied to the request - * @param context the SSL context for authenticating with the server - * @return a new client for making database requests - * @deprecated (as of 4.0.1) use {@link #newClient(String host, int port, String database, SecurityContext securityContext)} - */ - @Deprecated - static public DatabaseClient newClient(String host, int port, String database, String user, String password, Authentication type, SSLContext context) { - return newClient(host, port, database, makeSecurityContext(user, password, type, context, SSLHostnameVerifier.COMMON), null); - } - /** - * Creates a client to access the database by means of a REST server. - * - * @param host the host with the REST server - * @param port the port for the REST server - * @param user the user with read, write, or administrative privileges - * @param password the password for the user - * @param type the type of authentication applied to the request - * @param context the SSL context for authenticating with the server - * @param verifier a callback for checking hostnames - * @return a new client for making database requests - * @deprecated (as of 4.0.1) use {@link #newClient(String host, int port, SecurityContext securityContext)} - */ - @Deprecated - static public DatabaseClient newClient(String host, int port, String user, String password, Authentication type, SSLContext context, SSLHostnameVerifier verifier) { - return newClient(host, port, null, makeSecurityContext(user, password, type, context, verifier), null); - } - /** - * Creates a client to access the database by means of a REST server. - * - * A data service interface can only call an endpoint for the configured content database - * of the appserver. You cannot specify the database when constructing a client for working - * with a data service. - * - * @param host the host with the REST server - * @param port the port for the REST server - * @param database the database to access (default: configured database for the REST server) - * @param user the user with read, write, or administrative privileges - * @param password the password for the user - * @param type the type of authentication applied to the request - * @param context the SSL context for authenticating with the server - * @param verifier a callback for checking hostnames - * @return a new client for making database requests - * @deprecated (as of 4.0.1) use {@link #newClient(String host, int port, String database, SecurityContext securityContext)} - */ - @Deprecated - static public DatabaseClient newClient(String host, int port, String database, String user, String password, Authentication type, SSLContext context, SSLHostnameVerifier verifier) { - return newClient(host, port, database, makeSecurityContext(user, password, type, context, verifier), null); - } - /** * Returns the default registry with factories for creating handles * as adapters for IO representations. To create custom registries, @@ -1642,24 +1317,6 @@ static public void removeConfigurators() { /** * A Database Client Factory Bean provides an object for specifying configuration * before creating a client to make database requests. - * - *

For instance, a Spring configuration file might resemble the following - * example:

- *
-   * <bean name="databaseClientFactory"
-   * 	   class="com.marklogic.client.DatabaseClientFactory.Bean">
-   *   <property name="host"                value="localhost"/>
-   *   <property name="port"                value="8012"/>
-   *   <property name="user"                value="rest-writer-user"/>
-   *   <property name="password"            value="rest-writer-password"/>
-   *   <property name="authenticationValue" value="digest"/>
-   * </bean>
-   *
-   * <bean name="databaseClient"
-   * 	   class="com.marklogic.client.DatabaseClient"
-   * 	   factory-bean="databaseClientFactory"
-   * 	   factory-method="newClient"/>
-   * 
*/ static public class Bean implements Serializable { private static final long serialVersionUID = 1L; @@ -1668,18 +1325,10 @@ static public class Bean implements Serializable { private int port; private String basePath; private String database; - private String user; - private String password; - private Authentication authentication; - private String externalName; private DatabaseClient.ConnectionType connectionType; - transient private SecurityContext securityContext; transient private HandleFactoryRegistry handleRegistry = HandleFactoryRegistryImpl.newDefault(); - transient private SSLContext context; - transient private SSLHostnameVerifier verifier; - /** * Zero-argument constructor for bean applications. Other @@ -1744,96 +1393,6 @@ public void setBasePath(String basePath) { } /** - * Returns the user authentication for clients created with a - * DatabaseClientFactory.Bean object. - * @return the user - * @deprecated (as of 4.0.1) use SecurityContext.getUser() with BasicAuthContext or DigestAuthContext - */ - @Deprecated - public String getUser() { - return user; - } - /** - * Specifies the user authentication for clients created with a - * DatabaseClientFactory.Bean object. - * @param user the user - * @deprecated (as of 4.0.1) use constructors for BasicAuthContext or DigestAuthContext - */ - @Deprecated - public void setUser(String user) { - this.user = user; - } - /** - * Returns the password authentication for clients created with a - * DatabaseClientFactory.Bean object. - * @return the password - * @deprecated (as of 4.0.1) use SecurityContext.getUser() with BasicAuthContext or DigestAuthContext - */ - @Deprecated - public String getPassword() { - return password; - } - /** - * Specifies the password authentication for clients created with a - * DatabaseClientFactory.Bean object. - * @param password the password - * @deprecated (as of 4.0.1) use constructors for BasicAuthContext or DigestAuthContext - */ - @Deprecated - public void setPassword(String password) { - this.password = password; - } - /** - * Returns the external name for Kerberos clients created with a - * DatabaseClientFactory.Bean object. - * @return the external name - * @deprecated (as of 6.1.0, though has never had any impact) - */ - @Deprecated - public String getExternalName() { - return externalName; - } - /** - * Specifies the external name for Kerberos clients created with a - * DatabaseClientFactory.Bean object. - * @param externalName the external name - * @deprecated (as of 6.1.0, though has never had any impact) - */ - @Deprecated - public void setExternalName(String externalName) { - this.externalName = externalName; - } - /** - * Returns the authentication type for clients created with a - * DatabaseClientFactory.Bean object. - * @return the authentication type - * @deprecated (as of 4.0.1) use instanceof on any SecurityContext to get its type - */ - @Deprecated - public Authentication getAuthentication() { - return authentication; - } - /** - * Specifies the authentication type for clients created with a - * DatabaseClientFactory.Bean object. - * @param authentication the authentication type - * @deprecated (as of 4.0.1) use constructor for any SecurityContext - */ - @Deprecated - public void setAuthentication(Authentication authentication) { - this.authentication = authentication; - } - /** - * Specifies the authentication type for clients created with a - * DatabaseClientFactory.Bean object based on a string value. - * @param authentication the authentication type - * @deprecated (as of 4.0.1) use constructor for any SecurityContext - */ - @Deprecated - public void setAuthenticationValue(String authentication) { - this.authentication = Authentication.valueOfUncased(authentication); - } - /** * Returns the database for clients created with a * DatabaseClientFactory.Bean object. * @return the database @@ -1854,48 +1413,6 @@ public String getDatabase() { public void setDatabase(String database) { this.database = database; } - /** - * Returns the SSLContext for SSL clients created with a - * DatabaseClientFactory.Bean object. - * @return the SSL context - * @deprecated (as of 4.0.1) use SecurityContext.getSSLContext() - */ - @Deprecated - public SSLContext getContext() { - return context; - } - /** - * Specifies the SSLContext for clients created with a - * DatabaseClientFactory.Bean object that authenticate with SSL. - * @param context the SSL context - * @deprecated (as of 4.0.1) use SecurityContext.withSSLContext(SSLContext,X509TrustManager) - */ - @Deprecated - public void setContext(SSLContext context) { - this.context = context; - } - /** - * Returns the host verifier for clients created with a - * DatabaseClientFactory.Bean object. - * @return the host verifier - * @deprecated (as of 4.0.1) use SecurityContext.getSSLHostnameVerifier() - */ - @Deprecated - public SSLHostnameVerifier getVerifier() { - return verifier; - } - /** - * Specifies the host verifier for clients created with a - * DatabaseClientFactory.Bean object that verify hosts for - * additional security. - * @param verifier the host verifier - * @deprecated (as of 4.0.1) use SecurityContext.setSSLHostnameVerifier(SSLHostnameVerifier) - * or SecurityContext.withSSLHostnameVerifier(SSLHostnameVerifier) - */ - @Deprecated - public void setVerifier(SSLHostnameVerifier verifier) { - this.verifier = verifier; - } /** * Returns the security context for clients created with a * DatabaseClientFactory.Bean object - BasicAuthContext, DigestAuthContext @@ -1965,9 +1482,7 @@ public void registerDefaultHandles() { */ public DatabaseClient newClient() { DatabaseClientImpl client = (DatabaseClientImpl) DatabaseClientFactory.newClient( - host, port, basePath, database, - (securityContext != null ? securityContext : makeSecurityContext(user, password, authentication, context, verifier)), - connectionType); + host, port, basePath, database, securityContext, connectionType); client.setHandleRegistry(getHandleRegistry().copy()); return client; } diff --git a/marklogic-client-api/src/test/resources/boot-test-cygwin.sh b/marklogic-client-api/src/test/resources/boot-test-cygwin.sh deleted file mode 100644 index cfa400450..000000000 --- a/marklogic-client-api/src/test/resources/boot-test-cygwin.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -DEFAULT_M2=$USERPROFILE/.m2/repository -M2_REPO=${1:-$DEFAULT_M2} - -java -cp "target/test-classes;target/classes;$M2_REPO/org/apache/httpcomponents/httpclient/4.5.3/httpclient-4.5.3.jar;$M2_REPO/org/apache/httpcomponents/httpcore/4.4.6/httpcore-4.4.6.jar;$M2_REPO/commons-logging/commons-logging/1.2/commons-logging-1.2.jar;$M2_REPO/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar" com.marklogic.client.test.util.TestServerBootstrapper diff --git a/marklogic-client-api/src/test/resources/boot-test.sh b/marklogic-client-api/src/test/resources/boot-test.sh deleted file mode 100755 index 48f785b51..000000000 --- a/marklogic-client-api/src/test/resources/boot-test.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -DEFAULT_M2=$HOME/.m2/repository -M2_REPO=${1:-$DEFAULT_M2} - -java -cp target/test-classes:target/classes:$M2_REPO/org/apache/httpcomponents/httpclient/4.5.3/httpclient-4.5.3.jar:$M2_REPO/org/apache/httpcomponents/httpcore/4.4.6/httpcore-4.4.6.jar:$M2_REPO/commons-logging/commons-logging/1.2/commons-logging-1.2.jar:$M2_REPO/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar com.marklogic.client.test.util.TestServerBootstrapper diff --git a/marklogic-client-api/src/test/resources/teardown-test-cygwin.sh b/marklogic-client-api/src/test/resources/teardown-test-cygwin.sh deleted file mode 100644 index b1ab470ea..000000000 --- a/marklogic-client-api/src/test/resources/teardown-test-cygwin.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -DEFAULT_M2=$USERPROFILE/.m2/repository -M2_REPO=${1:-$DEFAULT_M2} - -java -cp "target/test-classes;target/classes;$M2_REPO/org/apache/httpcomponents/httpclient/4.5.3/httpclient-4.5.3.jar;$M2_REPO/org/apache/httpcomponents/httpcore/4.4.6/httpcore-4.4.6.jar;$M2_REPO/commons-logging/commons-logging/1.2/commons-logging-1.2.jar;$M2_REPO/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar" com.marklogic.client.test.util.TestServerBootstrapper teardown - diff --git a/marklogic-client-api/src/test/resources/teardown-test.sh b/marklogic-client-api/src/test/resources/teardown-test.sh deleted file mode 100644 index 1515ae1d5..000000000 --- a/marklogic-client-api/src/test/resources/teardown-test.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -DEFAULT_M2=$HOME/.m2/repository -M2_REPO=${1:-$DEFAULT_M2} - -java -cp target/test-classes:target/classes:$M2_REPO/org/apache/httpcomponents/httpclient/4.5.3/httpclient-4.5.3.jar:$M2_REPO/org/apache/httpcomponents/httpcore/4.4.6/httpcore-4.4.6.jar:$M2_REPO/commons-logging/commons-logging/1.2/commons-logging-1.2.jar:$M2_REPO/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar com.marklogic.client.test.util.TestServerBootstrapper teardown -