Thursday, October 17, 2013

How do I refresh the OAuth Token when using Google Cloud SQL JDBC Driver?

I am using the Google Cloud SQL driver on a Google Compute Instance to persist results to a Google Cloud SQL database during a long running batch process.

At some point, perhaps after the first hour of running, the oAuth token seems to expire, and all subsequent requests fail with:

Caused by: java.sql.SQLException: 400 Bad Request  {     "error" : "unauthorized_client"  }  at com.google.cloud.sql.jdbc.internal.googleapi.RpcGoogleApi.newOpenConnectionIOException(RpcGoogleApi.java:168)  at com.google.cloud.sql.jdbc.internal.googleapi.RpcGoogleApi.openConnection(RpcGoogleApi.java:104)  at com.google.cloud.sql.jdbc.internal.SqlProtoClient.openConnection(SqlProtoClient.java:58)  at com.google.cloud.sql.jdbc.Driver.connect(Driver.java:66)  at com.google.cloud.sql.Driver.connectImpl(Driver.java:109)  at com.google.cloud.sql.Driver.connect(Driver.java:98)  at com.google.cloud.sql.Driver.connect(Driver.java:31)  

I can abort the process, run google_sql.sh from the client line and the restart the batch process, and the connection will be fine until the token expires again.

Apparently, the command line tool is doing something to refresh the token before connecting; how do I do the same for my batch process?

Looking at the google_sql jar, it seems that it using the Google API Client library under the hood; is there a way to control this process more explicitly?

Thanks,

Alex

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/bbf71d3a-ff2b-4304-9f02-0584383c1408%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment