55import com .dtsx .astra .sdk .db .AstraDBOpsClient ;
66import com .dtsx .astra .sdk .db .domain .Database ;
77import com .dtsx .astra .sdk .db .exception .DatabaseNotFoundException ;
8+ import com .dtsx .astra .sdk .utils .ApiLocator ;
89import com .dtsx .astra .sdk .utils .AstraEnvironment ;
910import io .stargate .sdk .ServiceDeployment ;
1011import io .stargate .sdk .api .SimpleTokenProvider ;
@@ -44,6 +45,10 @@ public class AstraDB {
4445 */
4546 private final NamespaceClient nsClient ;
4647
48+ /**
49+ * Url to access the API
50+ */
51+ private final String apiEndpoint ;
4752
4853 /**
4954 * Initialization with endpoint and apikey.
@@ -60,6 +65,7 @@ public AstraDB(String token, String apiEndpoint) {
6065 if (apiEndpoint .endsWith ("com" )) {
6166 apiEndpoint = apiEndpoint + "/api/json" ;
6267 }
68+ this .apiEndpoint = apiEndpoint ;
6369 // Finding Environment based on apiEndpoint (looping to devops)
6470 if (apiEndpoint .contains (AstraEnvironment .PROD .getAppsSuffix ())) {
6571 this .env = AstraEnvironment .PROD ;
@@ -122,18 +128,27 @@ public AstraDB(@NonNull String token, @NonNull UUID databaseId, String region, @
122128 .findById (databaseId .toString ())
123129 .orElseThrow (() -> new DatabaseNotFoundException (databaseId .toString ()));
124130
125- this .apiClient = AstraClient . builder ()
126- .env (env )
127- . withDatabaseRegion ( region == null ? region : db . getInfo (). getRegion ())
128- . withDatabaseId ( databaseId . toString ())
129- . disableCrossRegionFailOver ()
130- . build ()
131- . apiStargateJson ( );
131+ this .apiEndpoint = ApiLocator
132+ .getApiJsonEndpoint (env , databaseId . toString (), region != null ? region : db . getInfo (). getRegion ());
133+ // Create Json Api Client without AstraDB
134+ ServiceDeployment < ServiceHttp > jsonDeploy = new ServiceDeployment <>();
135+ jsonDeploy . addDatacenterTokenProvider ( "default" , new SimpleTokenProvider ( token ));
136+ jsonDeploy . addDatacenterServices ( "default" , new ServiceHttp ( "json" , apiEndpoint , apiEndpoint ));
137+ this . apiClient = new ApiClient ( jsonDeploy );
132138
133139 // will inherit 'default_keyspace' from the database
134140 this .nsClient = apiClient .namespace (db .getInfo ().getKeyspace ());
135141 }
136142
143+ /**
144+ * Gets apiEndpoint
145+ *
146+ * @return value of apiEndpoint
147+ */
148+ public String getApiEndpoint () {
149+ return apiEndpoint ;
150+ }
151+
137152 // --------------------------
138153 // --- Find, FindAll ----
139154 // --------------------------
0 commit comments