diff --git a/pom.xml b/pom.xml
index 54e0e555e..34ecdbf24 100644
--- a/pom.xml
+++ b/pom.xml
@@ -193,7 +193,14 @@
com.squareup.okhttp3
okhttp
- 4.4.0
+ 4.8.1
+ test
+
+
+
+ com.squareup.okhttp3
+ okhttp-tls
+ 4.8.1
test
diff --git a/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateQueryCollectionIntegrationTests.java b/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateQueryCollectionIntegrationTests.java
index dcd13b5ab..4c8814f7e 100644
--- a/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateQueryCollectionIntegrationTests.java
+++ b/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateQueryCollectionIntegrationTests.java
@@ -30,7 +30,6 @@
import java.util.UUID;
import java.util.stream.Collectors;
-import com.couchbase.client.core.msg.kv.DurabilityLevel;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
@@ -58,7 +57,7 @@
import com.couchbase.client.core.error.AmbiguousTimeoutException;
import com.couchbase.client.core.error.UnambiguousTimeoutException;
-import com.couchbase.client.core.io.CollectionIdentifier;
+import com.couchbase.client.core.msg.kv.DurabilityLevel;
import com.couchbase.client.java.analytics.AnalyticsOptions;
import com.couchbase.client.java.kv.ExistsOptions;
import com.couchbase.client.java.kv.GetAnyReplicaOptions;
@@ -765,9 +764,6 @@ public void testScopeCollectionAnnotation() {
.withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(scopeName).inCollection(collectionName)
.matching(query).all();
assertEquals(saved, found.get(0), "should have found what was saved");
- List notfound = couchbaseTemplate.findByQuery(UserCol.class).inScope(CollectionIdentifier.DEFAULT_SCOPE)
- .inCollection(CollectionIdentifier.DEFAULT_COLLECTION).matching(query).all();
- assertEquals(0, notfound.size(), "should not have found what was saved");
couchbaseTemplate.removeByQuery(UserCol.class).inScope(scopeName).inCollection(collectionName).matching(query)
.all();
} finally {
@@ -789,9 +785,6 @@ public void testScopeCollectionRepoWith() {
.withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(scopeName).inCollection(collectionName)
.matching(query).all();
assertEquals(saved, found.get(0), "should have found what was saved");
- List notfound = couchbaseTemplate.findByQuery(UserCol.class).inScope(CollectionIdentifier.DEFAULT_SCOPE)
- .inCollection(CollectionIdentifier.DEFAULT_COLLECTION).matching(query).all();
- assertEquals(0, notfound.size(), "should not have found what was saved");
couchbaseTemplate.removeByQuery(UserCol.class).inScope(scopeName).inCollection(collectionName).matching(query)
.all();
} finally {
@@ -810,28 +803,28 @@ void testFluentApi() {
RemoveResult rr;
result = couchbaseTemplate.insertById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName)
.one(user1);
- assertEquals(user1,result);
+ assertEquals(user1, result);
result = couchbaseTemplate.upsertById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName)
.one(user1);
- assertEquals(user1,result);
- result = couchbaseTemplate.replaceById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName)
- .one(user1);
- assertEquals(user1,result);
+ assertEquals(user1, result);
+ result = couchbaseTemplate.replaceById(User.class).withDurability(dl).inScope(scopeName)
+ .inCollection(collectionName).one(user1);
+ assertEquals(user1, result);
rr = couchbaseTemplate.removeById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName)
.one(user1.getId());
assertEquals(rr.getId(), user1.getId());
- assertEquals(user1,result);
- result = reactiveCouchbaseTemplate.insertById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName)
- .one(user1).block();
- assertEquals(user1,result);
- result = reactiveCouchbaseTemplate.upsertById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName)
- .one(user1).block();
- assertEquals(user1,result);
+ assertEquals(user1, result);
+ result = reactiveCouchbaseTemplate.insertById(User.class).withDurability(dl).inScope(scopeName)
+ .inCollection(collectionName).one(user1).block();
+ assertEquals(user1, result);
+ result = reactiveCouchbaseTemplate.upsertById(User.class).withDurability(dl).inScope(scopeName)
+ .inCollection(collectionName).one(user1).block();
+ assertEquals(user1, result);
result = reactiveCouchbaseTemplate.replaceById(User.class).withDurability(dl).inScope(scopeName)
.inCollection(collectionName).one(user1).block();
- assertEquals(user1,result);
- rr = reactiveCouchbaseTemplate.removeById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName)
- .one(user1.getId()).block();
+ assertEquals(user1, result);
+ rr = reactiveCouchbaseTemplate.removeById(User.class).withDurability(dl).inScope(scopeName)
+ .inCollection(collectionName).one(user1.getId()).block();
assertEquals(rr.getId(), user1.getId());
}
diff --git a/src/test/java/org/springframework/data/couchbase/core/CustomTypeKeyIntegrationTests.java b/src/test/java/org/springframework/data/couchbase/core/CustomTypeKeyIntegrationTests.java
index 2ca6bb982..7854cfacb 100644
--- a/src/test/java/org/springframework/data/couchbase/core/CustomTypeKeyIntegrationTests.java
+++ b/src/test/java/org/springframework/data/couchbase/core/CustomTypeKeyIntegrationTests.java
@@ -35,6 +35,9 @@
import org.springframework.data.couchbase.util.IgnoreWhen;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
+import com.couchbase.client.core.deps.io.netty.handler.ssl.util.InsecureTrustManagerFactory;
+import com.couchbase.client.core.env.SecurityConfig;
+import com.couchbase.client.java.env.ClusterEnvironment;
import com.couchbase.client.java.kv.GetResult;
/**
@@ -91,6 +94,14 @@ public String getBucketName() {
return bucketName();
}
+ @Override
+ protected void configureEnvironment(ClusterEnvironment.Builder builder) {
+ if (config().isUsingCloud()) {
+ builder.securityConfig(
+ SecurityConfig.builder().trustManagerFactory(InsecureTrustManagerFactory.INSTANCE).enableTls(true));
+ }
+ }
+
@Override
public String typeKey() {
return CUSTOM_TYPE_KEY;
diff --git a/src/test/java/org/springframework/data/couchbase/domain/CapellaConnectSample.java b/src/test/java/org/springframework/data/couchbase/domain/CapellaConnectSample.java
new file mode 100644
index 000000000..5c9b2101f
--- /dev/null
+++ b/src/test/java/org/springframework/data/couchbase/domain/CapellaConnectSample.java
@@ -0,0 +1,178 @@
+/*
+ * Copyright 2022 the original author or authors.
+ *
+ * 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
+ *
+ * https://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 org.springframework.data.couchbase.domain;
+
+import static com.couchbase.client.java.query.QueryOptions.queryOptions;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
+import okhttp3.tls.HandshakeCertificates;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Base64;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+
+import com.couchbase.client.core.deps.io.netty.handler.ssl.util.InsecureTrustManagerFactory;
+import com.couchbase.client.core.env.IoConfig;
+import com.couchbase.client.core.env.SecurityConfig;
+import com.couchbase.client.java.Bucket;
+import com.couchbase.client.java.Cluster;
+import com.couchbase.client.java.ClusterOptions;
+import com.couchbase.client.java.Collection;
+import com.couchbase.client.java.env.ClusterEnvironment;
+import com.couchbase.client.java.json.JsonArray;
+import com.couchbase.client.java.json.JsonObject;
+import com.couchbase.client.java.manager.query.CreatePrimaryQueryIndexOptions;
+import com.couchbase.client.java.query.QueryResult;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+/**
+ * Sample code for connecting to Capella through both the control-plane and the data-plane. An Access Key and a Secret
+ * Key are required and a bucket named "my_bucket" on the 'last' cluster.
+ */
+public class CapellaConnectSample {
+
+ static final String cbc_access_key = "3gcpgyTBzOetdETYxOAtmLYBe3f9ZSVN";
+ static final String cbc_secret_key = "PWiACuJIZUlv0fCZaIQbhI44NDXVZCDdRBbpdaWlACioN7jkuOINCUVrU2QL1jVO";
+ static final String hostname = "cloudapi.cloud.couchbase.com";
+ static final HandshakeCertificates clientCertificates = new HandshakeCertificates.Builder()
+ .addPlatformTrustedCertificates().addInsecureHost(hostname).build();
+ static final OkHttpClient httpClient = new OkHttpClient.Builder()
+ .sslSocketFactory(clientCertificates.sslSocketFactory(), clientCertificates.trustManager()).build();
+
+ protected static final ObjectMapper MAPPER = new ObjectMapper();
+ static final String authorizationHeaderLabel = "Authorization";
+ static final String timestampHeaderLabel = "Couchbase-Timestamp";
+
+ public static void main(String... args) {
+ String endpoint = null; // "cb.zsibzkbgllfbcj8g.cloud.couchbase.com";
+ List clusterIds = getClustersControlPlane();
+ for (String id : clusterIds) {
+ endpoint = getClusterControlPlane(id);
+ }
+
+ // Update this to your cluster
+ String bucketName = "my_bucket";
+ String username = "user";
+ String password = "Couch0base!";
+ // User Input ends here.
+
+ ClusterEnvironment env = ClusterEnvironment.builder()
+ .securityConfig(SecurityConfig.enableTls(true).trustManagerFactory(InsecureTrustManagerFactory.INSTANCE))
+ .ioConfig(IoConfig.enableDnsSrv(true)).build();
+
+ // Initialize the Connection
+ Cluster cluster = Cluster.connect(endpoint, ClusterOptions.clusterOptions(username, password).environment(env));
+ Bucket bucket = cluster.bucket(bucketName);
+ bucket.waitUntilReady(Duration.parse("PT10S"));
+ Collection collection = bucket.defaultCollection();
+
+ cluster.queryIndexes().createPrimaryIndex(bucketName,
+ CreatePrimaryQueryIndexOptions.createPrimaryQueryIndexOptions().ignoreIfExists(true));
+
+ // Create a JSON Document
+ JsonObject arthur = JsonObject.create().put("name", "Arthur").put("email", "kingarthur@couchbase.com")
+ .put("interests", JsonArray.from("Holy Grail", "African Swallows"));
+
+ // Store the Document
+ collection.upsert("u:king_arthur", arthur);
+
+ // Load the Document and print it
+ // Prints Content and Metadata of the stored Document
+ System.err.println(collection.get("u:king_arthur"));
+
+ // Perform a N1QL Query
+ QueryResult result = cluster.query(String.format("SELECT name FROM `%s` WHERE $1 IN interests", bucketName),
+ queryOptions().parameters(JsonArray.from("African Swallows")));
+
+ // Print each found Row
+ for (JsonObject row : result.rowsAsObject()) {
+ System.err.println(row);
+ }
+
+ cluster.disconnect();
+ }
+
+ public static List getClustersControlPlane() {
+ List clusterIds = new ArrayList<>();
+ Map decoded = doRequest(hostname, "GET", "/v3/clusters");
+ HashMap data = (HashMap) decoded.get("data");
+ List