Skip to content

Commit bd6ee3c

Browse files
lesvdpebot
authored andcommitted
Run local w/o proxy (#453)
1 parent b8d6110 commit bd6ee3c

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

appengine/cloudsql/README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This sample demonstrates how to use [Cloud SQL](https://cloud.google.com/sql/) o
55
Before you can run or deploy the sample, you will need to create a [Cloud SQL instance)](https://cloud.google.com/sql/docs/create-instance)
66

77
1. Create a new user and database for the application. The easiest way to do this is via the [Google
8-
Developers Console](https://console.developers.google.com/sql/instances). Alternatively, you can use MySQL tools such as the command line client or workbench.
8+
Developers Console](https://console.cloud.google.com/sql/instances). Alternatively, you can use MySQL tools such as the command line client or workbench.
99
2. Change the root password (under Access Control) and / or create a new user / password.
1010
3. Create a Database (under Databases) (or use MySQL with `gcloud sql connect <instance> --user=root`)
1111
4. Note the **Instance connection name** under Overview > properties
@@ -18,10 +18,9 @@ $ mvn clean appengine:deploy -DINSTANCE_CONNECTION_NAME="instanceConnectionName"
1818
-Dpassword=myPassword -Ddatabase=myDatabase
1919
```
2020

21-
Or you can update the properties in `pom.xml` and
21+
Or you can update the properties in `pom.xml`
2222

2323
## Running locally
24-
1. You will need to be running a local instance of MySQL.
2524

2625
```bash
2726
$ mvn clean appengine:run -Duser=root -Dpassword=myPassowrd -Ddatabase=myDatabase

appengine/cloudsql/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@
6666
<artifactId>mysql-connector-java</artifactId>
6767
<version>5.1.40</version> <!-- v5.x.x is Java 7, v6.x.x is Java 8 -->
6868
</dependency>
69+
<dependency>
70+
<groupId>com.google.cloud.sql</groupId>
71+
<artifactId>mysql-socket-factory</artifactId>
72+
<version>1.0.2</version>
73+
</dependency>
6974
<!-- [END dependencies] -->
7075
</dependencies>
7176
<build>

appengine/cloudsql/src/main/java/com/example/appengine/cloudsql/CloudSqlServlet.java

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOExc
6262
final String createVisitSql = "INSERT INTO visits (user_ip, timestamp) VALUES (?, ?)";
6363
final String selectSql = "SELECT user_ip, timestamp FROM visits ORDER BY timestamp DESC "
6464
+ "LIMIT 10";
65+
6566
PrintWriter out = resp.getWriter();
6667
resp.setContentType("text/plain");
6768
String url;

appengine/cloudsql/src/main/webapp/WEB-INF/appengine-web.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<use-google-connector-j>true</use-google-connector-j>
1818
<system-properties>
1919
<property name="ae-cloudsql.cloudsql-database-url" value="jdbc:google:mysql://${INSTANCE_CONNECTION_NAME}/${database}?user=${user}&amp;password=${password}" />
20-
<property name="ae-cloudsql.local-database-url" value="jdbc:mysql://localhost/${database}?user=${user}&amp;PASSWORD=${password}&amp;useSSL=false" />
20+
<property name="ae-cloudsql.local-database-url" value="jdbc:mysql://google/${database}?cloudSqlInstance=${INSTANCE_CONNECTION_NAME}&amp;socketFactory=com.google.cloud.sql.mysql.SocketFactory&amp;user=${user}&amp;password=${password}&amp;useSSL=false" />
2121
</system-properties>
2222
</appengine-web-app>
2323
<!-- [END config] -->

0 commit comments

Comments
 (0)