Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 70d14a2

Browse files
committed
#97 XccTemplate now allows for special characters in the password
1 parent e333fc8 commit 70d14a2

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

src/main/java/com/marklogic/client/ext/spring/BasicConfig.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package com.marklogic.client.ext.spring;
22

3+
import com.marklogic.client.ext.DatabaseClientConfig;
4+
import com.marklogic.client.ext.helper.DatabaseClientProvider;
5+
import com.marklogic.xcc.template.XccTemplate;
36
import org.springframework.beans.factory.annotation.Value;
47
import org.springframework.context.annotation.Bean;
58
import org.springframework.context.annotation.Configuration;
69
import org.springframework.context.annotation.PropertySource;
710
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
811

9-
import com.marklogic.client.ext.DatabaseClientConfig;
10-
import com.marklogic.client.ext.helper.DatabaseClientProvider;
11-
import com.marklogic.xcc.template.XccTemplate;
12-
1312
/**
1413
* Provides a basic configuration for Spring-based applications. Assumes that properties can be found in the
1514
* gradle.properties file, though that file does not need to exist - this can be subclassed and a different property
@@ -55,8 +54,7 @@ public DatabaseClientConfig databaseClientConfig() {
5554

5655
@Bean
5756
public XccTemplate xccTemplate() {
58-
return new XccTemplate(String.format("xcc://%s:%s@%s:8000/%s", getMlUsername(), getMlPassword(), getMlHost(),
59-
buildContentDatabaseName(mlAppName)));
57+
return new XccTemplate(getMlHost(), 8000, getMlUsername(), getMlPassword(), buildContentDatabaseName(mlAppName));
6058
}
6159

6260
/**

src/main/java/com/marklogic/xcc/template/XccTemplate.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class XccTemplate {
2121
private ContentSource contentSource;
2222

2323
public XccTemplate(String uri) {
24+
logger.info("uri: " + uri);
2425
try {
2526
contentSource = ContentSourceFactory.newContentSource(new URI(uri));
2627
if (logger.isInfoEnabled()) {
@@ -35,6 +36,21 @@ public XccTemplate(String uri) {
3536
}
3637
}
3738

39+
public XccTemplate(String host, int port, String username, String password, String contentDatabaseName) {
40+
char[] charPassword;
41+
if (password != null) {
42+
charPassword = password.toCharArray();
43+
} else {
44+
charPassword = new char[]{};
45+
}
46+
47+
if (contentDatabaseName != null) {
48+
this.contentSource = ContentSourceFactory.newContentSource(host, port, username, charPassword, contentDatabaseName);
49+
} else {
50+
this.contentSource = ContentSourceFactory.newContentSource(host, port, username, charPassword);
51+
}
52+
}
53+
3854
public XccTemplate(ContentSource contentSource) {
3955
this.contentSource = contentSource;
4056
}

src/test/java/com/marklogic/client/ext/modulesloader/impl/StaticCheckModulesTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.junit.Test;
77
import org.springframework.core.io.Resource;
88

9-
import java.io.File;
109
import java.nio.file.Paths;
1110
import java.util.Set;
1211

@@ -27,8 +26,8 @@ public void setup() {
2726
client = newClient(database);
2827
client.newServerEval().xquery("cts:uris((), (), cts:true-query()) ! xdmp:document-delete(.)").eval();
2928

30-
xccTemplate = new XccTemplate("xcc://" + clientConfig.getUsername() + ":" + clientConfig.getPassword()
31-
+ "@" + clientConfig.getHost() + ":" + clientConfig.getPort() + "/" + database);
29+
xccTemplate = new XccTemplate(clientConfig.getHost(), clientConfig.getPort(), clientConfig.getUsername(),
30+
clientConfig.getPassword(), database);
3231

3332
staticChecker = new XccStaticChecker(xccTemplate);
3433

0 commit comments

Comments
 (0)