Skip to content

Commit

Permalink
Async support 245 (GoogleCloudPlatform#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
janbartel authored and aozarov committed Jun 10, 2016
1 parent 3015c69 commit 6fde3d1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@ public static VmApiProxyEnvironment createFromHeaders(
private final String server;
private volatile String ticket; // request ticket is only valid until response is committed.
private volatile String globalTicket; // global ticket is always valid
private final int serverPort;
private final String partition;
private final String appId;
private final String module;
Expand Down Expand Up @@ -541,11 +540,6 @@ private VmApiProxyEnvironment(

this.server = server;
this.partition = partition;
String port =
System.getenv(GAE_SERVER_PORT) == null
? System.getProperty("GAE_SERVER_PORT", "80")
: System.getenv(GAE_SERVER_PORT);
this.serverPort = Integer.decode(port);
this.appId = partition + "~" + appId;
this.module = module == null ? "default" : module;
this.majorVersion = majorVersion == null ? "" : majorVersion;
Expand Down Expand Up @@ -618,10 +612,6 @@ public String getPartition() {
return partition;
}

public int getServerPort() {
return serverPort;
}

@Override
public String getAppId() {
return appId;
Expand Down
6 changes: 6 additions & 0 deletions jetty9-compat-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
<version>${project.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>jetty9-base</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-security</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,27 +248,6 @@ private static List<SessionStore> createSessionStores(AppEngineWebXml appEngineW
return Arrays.asList(datastoreSessionStore, new MemcacheSessionStore());
}

/**
* Checks if the request was made over HTTPS. If so it modifies the request so that {@code
* HttpServletRequest#isSecure()} returns true, {@code HttpServletRequest#getScheme()} returns
* "https", and {@code HttpServletRequest#getServerPort()} returns 443. Otherwise it sets the
* scheme to "http" and port to 80.
*
* @param request The request to modify.
*/
private void setSchemeAndPort(Request request) {
String https = request.getHeader(VmApiProxyEnvironment.HTTPS_HEADER);
if ("on".equals(https)) {
request.setSecure(true);
request.setScheme(HttpScheme.HTTPS.toString());
request.setAuthority(request.getServerName(), 443);
} else {
request.setSecure(false);
request.setScheme(HttpScheme.HTTP.toString());
request.setAuthority(request.getServerName(), defaultEnvironment.getServerPort());
}
}

/**
* Creates a new VmRuntimeWebAppContext.
*/
Expand Down Expand Up @@ -450,9 +429,6 @@ public void requestInitialized(ServletRequestEvent sre) {

// Check for SkipAdminCheck and set attributes accordingly.
VmRuntimeUtils.handleSkipAdminCheck(requestContext);

// Change scheme to HTTPS based on headers set by the appserver.
setSchemeAndPort(baseRequest);
}

@Override
Expand Down
22 changes: 21 additions & 1 deletion jetty9-compat-base/src/main/jetty-base/etc/gae.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,30 @@
</Call>

<!-- =========================================================== -->
<!-- Ammend HttpConfig -->
<!-- Amend HttpConfig -->
<!-- =========================================================== -->
<Ref refid="httpConfig">
<Set name="headerCacheSize"><Property name="jetty.httpConfig.headerCacheSize" default="512"/></Set>
<Call name="addCustomizer">
<Arg>
<New class="com.google.apphosting.jetty9.GoogleRequestCustomizer">
<Arg name="httpPort" type="int">
<Property name="gae.httpPort">
<Default>
<Env name="GAE_SERVER_PORT">
<Default>
<SystemProperty name="GAE_SERVER_PORT">
<Default>80</Default>
</SystemProperty>
</Default>
</Env>
</Default>
</Property>
</Arg>
<Arg name="httpsPort" type="int"><Property name="gae.httpsPort" default="443"/></Arg>
</New>
</Arg>
</Call>
</Ref>

<!-- =========================================================== -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.google.apphosting.vmruntime.VmRuntimeFileLogHandler.JAVA_UTIL_LOGGING_CONFIG_PROPERTY;
import static com.google.apphosting.vmruntime.jetty9.VmRuntimeTestBase.JETTY_HOME_PATTERN;

import com.google.apphosting.jetty9.GoogleRequestCustomizer;
import com.google.apphosting.vmruntime.VmRuntimeFileLogHandler;

import org.eclipse.jetty.apache.jsp.JettyJasperInitializer;
Expand Down Expand Up @@ -166,6 +167,9 @@ public void doStart() throws Exception {
httpConfig.setSendServerVersion(true);
httpConfig.setSendDateHeader(false);
httpConfig.setDelayDispatchUntilContent(false);
GoogleRequestCustomizer requestCustomizer =
new GoogleRequestCustomizer(port, 443);
httpConfig.addCustomizer(requestCustomizer);

// Setup Server as done by gae.xml
server.addBean(bufferpool);
Expand Down Expand Up @@ -260,7 +264,6 @@ protected void setSystemProperties(File logs) throws IOException {
System.setProperty("jetty.appenginehost", "localhost");
System.setProperty("jetty.appengine.forwarded", "true");
System.setProperty("jetty.home", JETTY_HOME_PATTERN);
System.setProperty("GAE_SERVER_PORT", "" + port);
}

public static int findAvailablePort() {
Expand Down

0 comments on commit 6fde3d1

Please sign in to comment.