Skip to content

Commit

Permalink
Merge branch 'master' into speech-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
gguuss committed Jul 12, 2017
2 parents cc37a89 + 0756f07 commit 6c93178
Show file tree
Hide file tree
Showing 8 changed files with 480 additions and 416 deletions.
8 changes: 4 additions & 4 deletions appengine-java8/cloudsql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@
<password>myPassword</password>
<database>sqldemo</database>

<!-- [START_EXCLUDE] -->
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<!-- [END_EXCLUDE] -->
</properties>
<!-- [END properties] -->

<dependencies>
<!-- Parent POM defines ${appengine.sdk.version} (updates frequently). -->
<dependency>
Expand All @@ -68,15 +67,16 @@
</dependency>

<!-- [START dependencies] -->
<dependency>
<!-- Driver injected at runtime by the use of <use-google-connector-j> in appengine-web.xml -->
<dependency> <!-- Only used locally -->
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.42</version> <!-- v5.x.x is for production, v6.x.x EAP X DevAPI -->
<!--<version>6.0.6</version>-->
</dependency>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>mysql-socket-factory</artifactId> <!-- mysql-socket-factory-connector-j-6 -->
<artifactId>mysql-socket-factory</artifactId>
<version>1.0.3</version>
</dependency>
<!-- [END dependencies] -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

package com.example.appengine.cloudsql;

import com.google.apphosting.api.ApiProxy;
import com.google.common.base.Stopwatch;


import java.io.IOException;
import java.io.PrintWriter;
import java.net.Inet4Address;
Expand All @@ -30,6 +32,7 @@
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.servlet.ServletException;
Expand Down Expand Up @@ -100,15 +103,17 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOExc
@Override
public void init() throws ServletException {
try {
String url = System.getProperty("cloudsql");
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 {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url);
} catch (ClassNotFoundException e) {
throw new ServletException("Error loading JDBC Driver", e);
} catch (SQLException e) {
throw new ServletException("Unable to connect to PostGre", e);
throw new ServletException("Unable to connect to Cloud SQL", e);
}

} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<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:mysql://google/${database}?useSSL=false&amp;cloudSqlInstance=${INSTANCE_CONNECTION_NAME}&amp;socketFactory=com.google.cloud.sql.mysql.SocketFactory&amp;user=${user}&amp;password=${password}" />
<property name="cloudsql" value="jdbc:google:mysql://${INSTANCE_CONNECTION_NAME}/${database}?user=${user}&amp;password=${password}" />
<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}" />
</system-properties>
</appengine-web-app>
<!-- [END config] -->
6 changes: 3 additions & 3 deletions appengine-java8/endpoints-v2-backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ endpointsServer {
hostname = "echo-api.endpoints.${projectId}.cloud.goog"
}

sourceCompatibility = 1.7 // App Engine Standard uses Java 7
targetCompatibility = 1.7 // App Engine Standard uses Java 7
sourceCompatibility = 1.8
targetCompatibility = 1.8

// this replaces the ${endpoints.project.id} in appengine-web.xml and web.xml
task replaceProjectId(type: Copy) {
from 'src/main/webapp/WEB-INF/'
include '*.xml'
into 'build/exploded-backend/WEB-INF'
into "build/exploded-${archivesBaseName}/WEB-INF"
expand(endpoints:[project:[id:projectId]])
filteringCharset = 'UTF-8'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private static String createJwtRsa(String projectId, String privateKeyFile) thro

byte[] keyBytes = Files.readAllBytes(Paths.get(privateKeyFile));
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory kf = KeyFactory.getInstance("RSA256");
KeyFactory kf = KeyFactory.getInstance("RSA");

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

if (options.algorithm == "RSA256") {
System.out.println(options.algorithm);
if (options.algorithm.equals("RS256")) {
connectOptions.setPassword(
createJwtRsa(options.projectId, options.privateKeyFile).toCharArray());
} else if (options.algorithm == "ES256") {
} else if (options.algorithm.equals("ES256")) {
connectOptions.setPassword(
createJwtEs(options.projectId, options.privateKeyFile).toCharArray());
} else {
Expand Down
Loading

0 comments on commit 6c93178

Please sign in to comment.