/** * 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 securityContext the security context created depending upon the * authentication type - BasicAuthContext, DigestAuthContext or KerberosAuthContext * and communication channel type (SSL) * @return a new client for making database requests */ static public DatabaseClient newClient(String host, int port, SecurityContext securityContext) { return newClient(host, port, null, securityContext, null); }
/** * Creates a client to access the database by means of a REST server * without any authentication. Such clients can be convenient for * experimentation but should not be used in production. * * @param host the host with the REST server * @param port the port for the REST server * @return a new client for making database requests */ static public DatabaseClient newClient(String host, int port) { return newClient(host, port, null, null, null, null, null, null); }
/** * Creates a client to access the database by means of a REST server * without any authentication. Such clients can be convenient for * experimentation but should not be used in production. * * @param host the host with the REST server * @param port the port for the REST server * @return a new client for making database requests */ static public DatabaseClient newClient(String host, int port) { return newClient(host, port, null, null, null, null, null); }
/** * Creates a client to access the database by means of a REST server * without any authentication. Such clients can be convenient for * experimentation but should not be used in production. * * @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) * @return a new client for making database requests */ static public DatabaseClient newClient(String host, int port, String database) { return newClient(host, port, database, null, null, 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 * @return a new client for making database requests */ static public DatabaseClient newClient(String host, int port, String user, String password, Authentication type) { return newClient(host, port, user, password, type, 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 */ static public DatabaseClient newClient(String host, int port, String user, String password, Authentication type, SSLContext context) { return newClient(host, port, user, password, type, context, SSLHostnameVerifier.COMMON); } /**
/** * 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 database the database to access (default: configured database for * the REST server) * @param securityContext the security context created depending upon the * authentication type - BasicAuthContext, DigestAuthContext or KerberosAuthContext * and communication channel type (SSL) * @return a new client for making database requests */ static public DatabaseClient newClient(String host, int port, String database, SecurityContext securityContext) { return newClient(host, port, database, securityContext, 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 * @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); } /**
public static DatabaseClient newAdminClient() { return DatabaseClientFactory.newClient( Common.HOST, Common.PORT, new DigestAuthContext(Common.REST_ADMIN_USER, Common.REST_ADMIN_PASS), CONNECTION_TYPE); } public static DatabaseClient newServerAdminClient() {
public static DatabaseClient newEvalClient(String databaseName) { return DatabaseClientFactory.newClient( Common.HOST, Common.PORT, databaseName, new DigestAuthContext(Common.EVAL_USER, Common.EVAL_PASS), CONNECTION_TYPE); } public static DatabaseClient newReadOnlyClient() {
public static DatabaseClient newServerAdminClient() { return DatabaseClientFactory.newClient( Common.HOST, Common.PORT, new DigestAuthContext(Common.SERVER_ADMIN_USER, Common.SERVER_ADMIN_PASS), CONNECTION_TYPE); } public static DatabaseClient newEvalClient() {
public static DatabaseClient newClient(String databaseName) { return DatabaseClientFactory.newClient(Common.HOST, Common.PORT, databaseName, new DatabaseClientFactory.DigestAuthContext(Common.USER, Common.PASS), CONNECTION_TYPE); } public static DatabaseClient newAdminClient() {
public static DatabaseClient newReadOnlyClient() { return DatabaseClientFactory.newClient( Common.HOST, Common.PORT, new DigestAuthContext(Common.READ_ONLY_USER, Common.READ_ONLY_PASS), CONNECTION_TYPE); }
/** * Creates a client for bean applications based on the properties. * Other applications can use the static newClient() factory methods * of DatabaseClientFactory. * The client accesses the database by means of a REST server. * @return a new client for making database requests */ public DatabaseClient newClient() { DatabaseClientImpl client = (DatabaseClientImpl) DatabaseClientFactory.newClient( host, port, database, (securityContext!=null? securityContext:makeSecurityContext(user, password, authentication, context, verifier)), connectionType); client.setHandleRegistry(getHandleRegistry().copy()); return client; } }
@SuppressWarnings("deprecation") @Test public void testUserBlah() throws Exception { final String query1 = "fn:count(fn:doc())"; DatabaseClient client = DatabaseClientFactory.newClient(localHostname, port, new CertificateAuthContext(temp + "blah.p12", "abc")); try { client.newServerEval().xquery(query1).eval().next().getNumber().intValue(); } catch (Exception e) { e.printStackTrace(); System.out.println("Exception is " + e.getClass().getName()); Assert.assertTrue(e.getClass().getName().equals("com.marklogic.client.FailedRequestException")); Assert.assertTrue(e.getMessage().equals("Local message: failed to apply resource at eval: Unauthorized. Server Message: Unauthorized")); } }
@Before public void setUp() throws KeyManagementException, NoSuchAlgorithmException, Exception { SSLContext sslcontext = null; if (IsSecurityEnabled()) { sslcontext = getSslContext(); client = DatabaseClientFactory.newClient( appServerHostName, appServerHostPort, new KerberosAuthContext(kdcPrincipalUser).withSSLContext(sslcontext)); } else client = DatabaseClientFactory.newClient(appServerHostName, appServerHostPort, new KerberosAuthContext(kdcPrincipalUser)); }
@Test(expected = FailedRequestException.class) public void testJSONParserException() throws IOException { System.out.println("Running testPartialUpdateJSON"); String[] filenames = { "json-original.json" }; SecurityContext secContext = new DatabaseClientFactory.DigestAuthContext("bad-eval-user", "x"); DatabaseClient client = DatabaseClientFactory.newClient(appServerHostname, uberPort, dbName, secContext, getConnType()); // write docs for (String filename : filenames) { writeDocumentUsingInputStreamHandle(client, filename, "/partial-update/", "JSON"); } // release client client.release(); }
@Before public void setUp() throws KeyManagementException, NoSuchAlgorithmException, Exception { // create new connection for each test below createUserRolesWithPrevilages("test-eval", "xdbc:eval", "xdbc:eval-in", "xdmp:eval-in", "any-uri", "xdbc:invoke"); createRESTUser("eval-user", "x", "test-eval", "rest-admin", "rest-writer", "rest-reader"); if (isLBHost()) client = getDatabaseClient("eval-user", "x", getConnType()); else { SecurityContext secContext = new DatabaseClientFactory.DigestAuthContext("eval-user", "x"); client = DatabaseClientFactory.newClient(appServerHostname, uberPort, dbName, secContext, getConnType()); } }
@Test public void testConfigurator() { ConfiguratorImpl configurator = new ConfiguratorImpl(); DatabaseClientFactory.addConfigurator(configurator); DatabaseClient client = DatabaseClientFactory.newClient( Common.HOST, Common.PORT, new DigestAuthContext(Common.USER, Common.PASS)); try { assertTrue("Factory did not apply custom configurator", configurator.isConfigured); OkHttpClient okClient = (OkHttpClient) client.getClientImplementation(); assertEquals(testConnectTimeoutMillis, okClient.connectTimeoutMillis()); } finally { client.release(); } }
@Test public void testWriteTextDoc() { SecurityContext secContext = new DatabaseClientFactory.DigestAuthContext("admin", "admin"); DatabaseClient client = DatabaseClientFactory.newClient(appServerHostname, 8015, secContext, getConnType()); String docId = "/foo/test/myFoo.txt"; TextDocumentManager docMgr = client.newTextDocumentManager(); docMgr.write(docId, new StringHandle().with("This is so foo")); assertEquals("Text document write difference", "This is so foo", docMgr.read(docId, new StringHandle()).get()); }