Followed the tutorial and my CloudSqlServlet.java init() function:
try {
ApiProxy.Environment env = ApiProxy.getCurrentEnvironment();
Map<String, Object> attr = env.getAttributes();
String hostname = (String) attr.get("com.google.appengine.runtime.default_version_hostname");
String url = hostname.contains("localhost:")
? System.getProperty("cloudsql-local") : System.getProperty("cloudsql");
log("connecting to: " + url);
try {
conn = DriverManager.getConnection(url);
} catch (SQLException e) {
throw new ServletException("Unable to connect to Cloud SQL", e);
}
This is my appegnine-web.xml:
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<version>1</version>
<threadsafe>true</threadsafe>
<runtime>java8</runtime>
<use-google-connector-j>true</use-google-connector-j>
<service>cloudsql</service>
<system-properties>
<property name="cloudsql" value="jdbc:google:mysql://${INSTANCE_CONNECTION_NAME}/${database}?user=${user}&password=${password}" />
<property name="cloudsql-local" value="jdbc:mysql://google/${database}?useSSL=false&cloudSqlInstance=${INSTANCE_CONNECTION_NAME}&socketFactory=com.google.cloud.sql.mysql.SocketFactory&user=${user}&password=${password}" />
</system-properties>
</appengine-web-app>
The app compiles with maven. I then run the appengine server in one terminal:
mvn appengine:run
And in another terminal I'll run the sql proxy:
./cloud_sql_proxy -instances=skeleton-182342:europe-west1:trial1131=tcp:3306
Then when I access the server locally: localhost:8080/cloudsql
The app throws an exception:
Caused by: java.lang.IllegalArgumentException: Invalid Cloud SQL instance [${INSTANCE_CONNECTION_NAME}], expected value in form [project:region:name].
And in the logs I can see that the properties are not inserted into the url:
log: CloudSQL: connecting to: jdbc:mysql://google/${database}?useSSL=false&cloudSqlInstance=${INSTANCE_CONNECTION_NAME}&socketFactory=com.google.cloud.sql.mysql.SocketFactory&user=${user}&password=${password}