2
votes

Not able to connect to Googe Cloud Spanner with Java code Getting SSLException error.

Written a code in java which tries to connect to Google Spanner I have already created the Spanner instance and also the database along with a table.

However when I try to run the Java code it gives error of getting error com.google.cloud.spanner.SpannerException: UNKNOWN: javax.net.ssl.SSLException: unable to setup trustmanager

try (InputStream credentialsStream = new FileInputStream(credentialsFile)){
   credentials = GoogleCredentials.fromStream(new FileInputStream(credentialsFile));
} catch (FileNotFoundException e) {
   e.printStackTrace();
} catch (IOException e) {
   e.printStackTrace();
}       
SpannerOptions options = SpannerOptions.newBuilder().setProjectId("coral-velocity-252502").build();
Spanner spanner = options.getService();
2
gtting this error stack flow com.google.cloud.spanner.SpannerException: UNKNOWN: javax.net.ssl.SSLException: unable to setup trustmanager at com.google.cloud.spanner.SpannerExceptionFactory.newSpannerExceptionPreformatted(SpannerExceptionFactory.java:151) at com.google.cloud.spanner.SpannerExceptionFactory.newSpannerException(SpannerExceptionFactory.java:45) at ..Amit Nerkar
Can you add the full stack trace to the question please? Also do you need to use a proxy to access the internet?RedPandaCurios
Also, could it be that you are using a 32-bit version of Windows?Knut Olav Løite
Hi @RedPandaCurios no not using proxy. using my direct internet connection.Amit Nerkar
Hi @KnutOlavLoite - its 64 bit windows 10 Enterprise.Amit Nerkar

2 Answers

0
votes

Got Resolved!

The issue was i was using PowerMock to test the Google DB Spanner apis. Somehow the mock messes up with the SSL issues. The solution for that is to use an annotation on the test class:

@PowerMockIgnore("javax.net.ssl.*")

this is taken from When a TrustManagerFactory is not a TrustManagerFactory (Java)