com.google.gdata.util.AuthenticationException: Error connecting with login URI

3.9k views Asked by At

I have written a Java application which I am launching with the following command:

java -jar MyApp.jar

The application uses Google's GData Java libraries to edit a Google Spreadsheet. When I run this application from my Mac, it runs fine. However, I need to run it on my dedicated server. When I upload it there and try to run it, I receive the following error:

$ java -jar MyApp.jar
com.google.gdata.util.AuthenticationException: Error connecting with login URI
    at com.google.gdata.client.GoogleAuthTokenFactory.getAuthToken(GoogleAuthTokenFactory.java:489)
    at com.google.gdata.client.GoogleAuthTokenFactory.setUserCredentials(GoogleAuthTokenFactory.java:346)
    at com.google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:362)
    at com.google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:317)
    at org.graalcenter.stats.bot.GraalStatBot.main(GraalStatBot.java:42)
Caused by: javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
    at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1611)
    at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1574)
    at sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1557)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1150)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1127)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:423)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:850)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
    at com.google.gdata.client.GoogleAuthTokenFactory.makePostRequest(GoogleAuthTokenFactory.java:551)
    at com.google.gdata.client.GoogleAuthTokenFactory.getAuthToken(GoogleAuthTokenFactory.java:487)
    ... 4 more
Caused by: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
    at sun.security.validator.PKIXValidator.(PKIXValidator.java:75)
    at sun.security.validator.Validator.getInstance(Validator.java:178)
    at sun.security.ssl.X509TrustManagerImpl.getValidator(X509TrustManagerImpl.java:129)
    at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:225)
    at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:270)
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:973)
    at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:142)
    at sun.security.ssl.Handshaker.processLoop(Handshaker.java:533)
    at sun.security.ssl.Handshaker.process_record(Handshaker.java:471)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:904)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1116)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1143)
    ... 11 more
Caused by: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
    at java.security.cert.PKIXParameters.setTrustAnchors(PKIXParameters.java:200)
    at java.security.cert.PKIXParameters.(PKIXParameters.java:120)
    at java.security.cert.PKIXBuilderParameters.(PKIXBuilderParameters.java:104)
    at sun.security.validator.PKIXValidator.(PKIXValidator.java:73)
    ... 22 more

This is the code that is causing the error:

    public static void main(String[] args) {
        FeedURLFactory factory = FeedURLFactory.getDefault();
        SpreadsheetService service = new SpreadsheetService("my-app");

        try {
            service.setUserCredentials(USER_NAME, USER_PASSWORD, ACCOUNT_TYPE);
        } catch (AuthenticationException ex) {
            ex.printStackTrace();
            System.exit(0);
        }
    }

I have tried Googling the error and it suggests that it is often caused by a proxy; however, I am not behind a proxy on my dedicated server. Other Java applications I have written work fine with the network.

Any ideas how to fix this? All help is appreciated. Thanks!

1

There are 1 answers

0
erloewe On BEST ANSWER

You are getting the error most likely because your trust store file which holds SSL certificates is missing on your server, or contains something invalid.

Try this out:

  • On the server: find / -name jssecacerts
  • On the server: find / -name cacerts
  • Take a note at the path these files reside in. Move these files somewhere, ie. to /tmp/
  • Copy your truststore file from the imac (probably /Library/Java/JavaVirtualMachines/1.6.0_22-b04-307.jdk/Contents/Home/lib/security/cacerts ) to your server, to the path you saw earlier
  • Retry your application

Also you could inspect files on both computers with the keytool utility (see the JSSE Reference Guide for more information) and compare them for differences.