Skip to content

Commit 6c93178

Browse files
authored
Merge branch 'master' into speech-upgrade
2 parents cc37a89 + 0756f07 commit 6c93178

File tree

8 files changed

+480
-416
lines changed

8 files changed

+480
-416
lines changed

appengine-java8/cloudsql/pom.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@
3939
<password>myPassword</password>
4040
<database>sqldemo</database>
4141

42-
<!-- [START_EXCLUDE] -->
4342
<maven.compiler.target>1.8</maven.compiler.target>
4443
<maven.compiler.source>1.8</maven.compiler.source>
45-
<!-- [END_EXCLUDE] -->
4644
</properties>
4745
<!-- [END properties] -->
46+
4847
<dependencies>
4948
<!-- Parent POM defines ${appengine.sdk.version} (updates frequently). -->
5049
<dependency>
@@ -68,15 +67,16 @@
6867
</dependency>
6968

7069
<!-- [START dependencies] -->
71-
<dependency>
70+
<!-- Driver injected at runtime by the use of <use-google-connector-j> in appengine-web.xml -->
71+
<dependency> <!-- Only used locally -->
7272
<groupId>mysql</groupId>
7373
<artifactId>mysql-connector-java</artifactId>
7474
<version>5.1.42</version> <!-- v5.x.x is for production, v6.x.x EAP X DevAPI -->
7575
<!--<version>6.0.6</version>-->
7676
</dependency>
7777
<dependency>
7878
<groupId>com.google.cloud.sql</groupId>
79-
<artifactId>mysql-socket-factory</artifactId> <!-- mysql-socket-factory-connector-j-6 -->
79+
<artifactId>mysql-socket-factory</artifactId>
8080
<version>1.0.3</version>
8181
</dependency>
8282
<!-- [END dependencies] -->

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

+10-5
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
package com.example.appengine.cloudsql;
1818

19+
import com.google.apphosting.api.ApiProxy;
1920
import com.google.common.base.Stopwatch;
2021

22+
2123
import java.io.IOException;
2224
import java.io.PrintWriter;
2325
import java.net.Inet4Address;
@@ -30,6 +32,7 @@
3032
import java.sql.SQLException;
3133
import java.sql.Timestamp;
3234
import java.util.Date;
35+
import java.util.Map;
3336
import java.util.concurrent.TimeUnit;
3437

3538
import javax.servlet.ServletException;
@@ -100,15 +103,17 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOExc
100103
@Override
101104
public void init() throws ServletException {
102105
try {
103-
String url = System.getProperty("cloudsql");
106+
ApiProxy.Environment env = ApiProxy.getCurrentEnvironment();
107+
Map<String,Object> attr = env.getAttributes();
108+
String hostname = (String) attr.get("com.google.appengine.runtime.default_version_hostname");
109+
110+
String url = hostname.contains("localhost:")
111+
? System.getProperty("cloudsql-local") : System.getProperty("cloudsql");
104112
log("connecting to: " + url);
105113
try {
106-
Class.forName("com.mysql.jdbc.Driver");
107114
conn = DriverManager.getConnection(url);
108-
} catch (ClassNotFoundException e) {
109-
throw new ServletException("Error loading JDBC Driver", e);
110115
} catch (SQLException e) {
111-
throw new ServletException("Unable to connect to PostGre", e);
116+
throw new ServletException("Unable to connect to Cloud SQL", e);
112117
}
113118

114119
} finally {

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@
1515
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
1616
<threadsafe>true</threadsafe>
1717
<runtime>java8</runtime>
18+
<use-google-connector-j>true</use-google-connector-j>
19+
20+
<service>cloudsql</service>
1821

1922
<system-properties>
20-
<property name="cloudsql" value="jdbc:mysql://google/${database}?useSSL=false&amp;cloudSqlInstance=${INSTANCE_CONNECTION_NAME}&amp;socketFactory=com.google.cloud.sql.mysql.SocketFactory&amp;user=${user}&amp;password=${password}" />
23+
<property name="cloudsql" value="jdbc:google:mysql://${INSTANCE_CONNECTION_NAME}/${database}?user=${user}&amp;password=${password}" />
24+
<property name="cloudsql-local" value="jdbc:mysql://google/${database}?useSSL=false&amp;cloudSqlInstance=${INSTANCE_CONNECTION_NAME}&amp;socketFactory=com.google.cloud.sql.mysql.SocketFactory&amp;user=${user}&amp;password=${password}" />
2125
</system-properties>
2226
</appengine-web-app>
2327
<!-- [END config] -->

appengine-java8/endpoints-v2-backend/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ endpointsServer {
5454
hostname = "echo-api.endpoints.${projectId}.cloud.goog"
5555
}
5656

57-
sourceCompatibility = 1.7 // App Engine Standard uses Java 7
58-
targetCompatibility = 1.7 // App Engine Standard uses Java 7
57+
sourceCompatibility = 1.8
58+
targetCompatibility = 1.8
5959

6060
// this replaces the ${endpoints.project.id} in appengine-web.xml and web.xml
6161
task replaceProjectId(type: Copy) {
6262
from 'src/main/webapp/WEB-INF/'
6363
include '*.xml'
64-
into 'build/exploded-backend/WEB-INF'
64+
into "build/exploded-${archivesBaseName}/WEB-INF"
6565
expand(endpoints:[project:[id:projectId]])
6666
filteringCharset = 'UTF-8'
6767
}

iot/api-client/mqtt_example/src/main/java/com/google/cloud/iot/examples/MqttExample.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private static String createJwtRsa(String projectId, String privateKeyFile) thro
5353

5454
byte[] keyBytes = Files.readAllBytes(Paths.get(privateKeyFile));
5555
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
56-
KeyFactory kf = KeyFactory.getInstance("RSA256");
56+
KeyFactory kf = KeyFactory.getInstance("RSA");
5757

5858
return jwtBuilder.signWith(SignatureAlgorithm.RS256, kf.generatePrivate(spec)).compact();
5959
}
@@ -107,10 +107,11 @@ public static void main(String[] args) throws Exception {
107107
// to authorize the device.
108108
connectOptions.setUserName("unused");
109109

110-
if (options.algorithm == "RSA256") {
110+
System.out.println(options.algorithm);
111+
if (options.algorithm.equals("RS256")) {
111112
connectOptions.setPassword(
112113
createJwtRsa(options.projectId, options.privateKeyFile).toCharArray());
113-
} else if (options.algorithm == "ES256") {
114+
} else if (options.algorithm.equals("ES256")) {
114115
connectOptions.setPassword(
115116
createJwtEs(options.projectId, options.privateKeyFile).toCharArray());
116117
} else {

0 commit comments

Comments
 (0)