Skip to content

Commit 1fcf3ec

Browse files
committed
*add platform infomration for transport options
*add logic to distinguish GAE standard java 7 and 8 on both DevServer and Prod
1 parent 7c20c6f commit 1fcf3ec

2 files changed

Lines changed: 51 additions & 3 deletions

File tree

google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
import com.google.api.client.http.HttpRequestInitializer;
2525
import com.google.api.client.http.HttpTransport;
2626
import com.google.api.client.http.javanet.NetHttpTransport;
27-
import com.google.api.core.InternalApi;
2827
import com.google.auth.Credentials;
2928
import com.google.auth.http.HttpCredentialsAdapter;
3029
import com.google.auth.http.HttpTransportFactory;
3130
import com.google.cloud.NoCredentials;
31+
import com.google.cloud.PlatformInformation;
3232
import com.google.cloud.ServiceOptions;
3333
import com.google.cloud.TransportOptions;
3434
import java.io.IOException;
@@ -55,8 +55,7 @@ public static class DefaultHttpTransportFactory implements HttpTransportFactory
5555
@Override
5656
public HttpTransport create() {
5757
// Consider App Engine Standard
58-
if (System.getProperty("com.google.appengine.runtime.version") != null
59-
&& System.getenv("GAE_SERVICE") == null) {
58+
if (PlatformInformation.isOnGAEStandard7()) {
6059
try {
6160
return new UrlFetchTransport();
6261
} catch (Exception ignore) {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2017 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud;
18+
19+
public final class PlatformInformation {
20+
public static final String SPECIFICATION_VERSION =
21+
System.getProperty("java.specification.version");
22+
public static final String GAE_RUNTIME_VERSION =
23+
System.getProperty("com.google.appengine.runtime.version");
24+
public static final String RUNTIME_JETTY_LOGGER =
25+
System.getProperty("org.eclipse.jetty.util.log.class");
26+
public static final String JETTY_LOGGER_ON_GAE8_PROD =
27+
"com.google.apphosting.runtime.jetty9.JettyLogger";
28+
public static final String JETTY_LOGGER_ON_GAE8_DEVSERVER =
29+
" com.google.appengine.development.jetty9.JettyLogger";
30+
31+
public static boolean isOnGAE() {
32+
return GAE_RUNTIME_VERSION != null;
33+
}
34+
35+
public static boolean isOnGAEStandard7() {
36+
//edge case: when a Java 7 GAE app is deployed to DevServer running on J8, SPECIFICATION_VERSION will be "1.8",
37+
//but RUNTIME_JETTY_LOGGER is unset
38+
return isOnGAE() && SPECIFICATION_VERSION.equals("1.7")
39+
|| isOnGAE() && RUNTIME_JETTY_LOGGER == null;
40+
}
41+
42+
public static boolean isOnGAEStandard8() {
43+
return isOnGAE()
44+
&& !SPECIFICATION_VERSION.equals("1.7")
45+
&& RUNTIME_JETTY_LOGGER != null
46+
&& (RUNTIME_JETTY_LOGGER.equals(JETTY_LOGGER_ON_GAE8_DEVSERVER)
47+
|| RUNTIME_JETTY_LOGGER.equals(JETTY_LOGGER_ON_GAE8_PROD));
48+
}
49+
}

0 commit comments

Comments
 (0)