question

saffy avatar image
saffy asked Jitesh commented

Getting IO exception connecting to Astra DB

I am getting below error while trying to connect astra through java driver . code is same as given in java doc

Path given for secure-connect bundle is correct and I have passed client id and client secret.

Please find the code

public class ConnectDatabase {

   public static void main(String[] args) {
       // Create the CqlSession object:
       try (CqlSession session = CqlSession.builder()
           .withCloudSecureConnectBundle(Paths.get("<</PATH/TO/>>secure-connect-books.zip"))
           .withAuthCredentials("<<CLIENT ID>>","<<CLIENT SECRET>>")
           .build()) {
           // Select the release_version from the system.local table:
           ResultSet rs = session.execute("select release_version from system.local");
           Row row = rs.one();
           //Print the results of the CQL query to the console:
           if (row != null) {
               System.out.println(row.getString("release_version"));
           } else {
               System.out.println("An error occurred.");
           }
       }
       System.exit(0);
   }
}

Getting below error

Exception in thread "main" com.datastax.oss.driver.api.core.DriverExecutionException
    at com.datastax.oss.driver.internal.core.util.concurrent.CompletableFutures.getUninterruptibly(CompletableFutures.java:152)
    at com.datastax.oss.driver.api.core.session.SessionBuilder.build(SessionBuilder.java:835)
    at com.booksrepo.betterreads.test.main(test.java:15)
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: https://1a8875b8-5b49-4c13-8c9d-21a7f7bbb37f-us-east-2.db.astra.datastax.com:29080/metadata
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1913)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1509)
    at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:245)
    at com.datastax.oss.driver.internal.core.config.cloud.CloudConfigFactory.fetchProxyMetadata(CloudConfigFactory.java:232)
    at com.datastax.oss.driver.internal.core.config.cloud.CloudConfigFactory.createCloudConfig(CloudConfigFactory.java:133)
    at com.datastax.oss.driver.api.core.session.SessionBuilder.buildDefaultSessionAsync(SessionBuilder.java:876)
    at com.datastax.oss.driver.api.core.session.SessionBuilder.buildAsync(SessionBuilder.java:817)
... 2 more
java driverastra db
3 comments
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

smadhavan avatar image smadhavan ♦ commented ·
@saffy I am unable to reproduce this either. Could you please update your question with details about the Java Driver version (a maven POM dependency section would be good here) along with the complete stacktrace here? If you want, you could check-in your codebase (of course, without any username/passwords) into a GitHub repo and share us that link to help speed up the triage.
0 Likes 0 ·
Jitesh avatar image Jitesh commented ·

Well, I also have been encountered the same issue many times, unsure of the reason.

Exception in thread "main" com.datastax.oss.driver.api.core.DriverExecutionException
at com.datastax.oss.driver.internal.core.util.concurrent.CompletableFutures.getUninterruptibly(CompletableFutures.java:152)
at com.datastax.oss.driver.api.core.session.SessionBuilder.build(SessionBuilder.java:835)
at algo.trade.nosql.ConnectDatabase.main(ConnectDatabase.java:16)
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: https://db_id-europe-west1.db.astra.datastax.com:29080/metadata
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1913)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1509)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:245)
...
0 Likes 0 ·
Show more comments

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered

Unfortunately, I'm unable to replicate the issue you reported.

Please try these 2 things:

  1. Check that the database you're connecting to is active and operational. The quickest way to test this is by running the SELECT statement in your code on the CQL Console of your Astra DB.
  2. Add a call to the withKeyspace() method in the session builder of your code, specifying your keyspace.

Cheers!

Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.