Skip to content

Commit

Permalink
Merge branch 'bugs/231-julroot' of github.com:jetty-project/appengine…
Browse files Browse the repository at this point in the history
…-java-vm-runtime into bugs/231-julroot
  • Loading branch information
joakime committed Aug 25, 2016
2 parents 846e4d2 + cf4ce6a commit 75f37b8
Show file tree
Hide file tree
Showing 22 changed files with 121 additions and 137 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ To use custom build docker image as the basis for a Java Web Application Archive
First, build custom docker image of jetty9-compat, push to google cloud repo.

mvn clean install
# For latest docker beta on Mac, use mvn install -DdockerHost=unix:///var/run/docker.sock
docker tag -f jetty9-compat gcr.io/<your_gcp_project_id>/jetty9-compat:<your_label>
gcloud docker push gcr.io/<your_gcp_project_id>/jetty9-compat:<your_label>

Then, use your custom docker image in the Dcokerfile, and run the App Engine flexible environment container via the Cloud SDK.
Then, use your custom docker image in the Dockerfile, and run the App Engine flexible environment container via the Cloud SDK.

FROM gcr.io/<your_gcp_project_id>/jetty9-compat:<your_label>
ADD . /app
Expand Down
2 changes: 1 addition & 1 deletion appengine-java-logging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-java-vm-runtime</artifactId>
<version>1.9.38-SNAPSHOT</version>
<version>1.9.40-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<name>Google App Engine Logging Support</name>
Expand Down
4 changes: 2 additions & 2 deletions appengine-managed-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-java-vm-runtime</artifactId>
<version>1.9.38-SNAPSHOT</version>
<version>1.9.40-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<name>Google App Engine Runtime Utilities</name>
Expand All @@ -36,7 +36,7 @@
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-java-logging</artifactId>
<version>1.9.38-SNAPSHOT</version>
<version>1.9.40-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ public static enum ScalingType {
public static final String URL_HANDLER_URLFETCH = "urlfetch";
public static final String URL_HANDLER_NATIVE = "native";

// Runtime ids.
private static final String JAVA_7_RUNTIME_ID = "java7";
// Should accept java8* for multiple variations of Java8.
private static final String JAVA_8_RUNTIME_ID = "java8";
// This was used for Java6, but now is used only for Managed VMs,
// not for standard editiom.
private static final String JAVA_RUNTIME_ID = "java";

private String appId;

private String majorVersionId;
Expand All @@ -85,7 +93,7 @@ public static enum ScalingType {
private final ManualScaling manualScaling;
private final BasicScaling basicScaling;

private String sourceLanguage;
private String runtime;
private boolean sslEnabled = true;
private boolean useSessions = false;
private boolean asyncSessionPersistence = false;
Expand Down Expand Up @@ -235,12 +243,21 @@ public void setMajorVersionId(String majorVersionId) {
this.majorVersionId = majorVersionId;
}

public String getSourceLanguage() {
return this.sourceLanguage;
public String getRuntime() {
if (runtime != null) {
return runtime;
}
// The new env:flex means java, not java7:
if (isFlexible()) {
runtime = JAVA_RUNTIME_ID;
} else {
runtime = JAVA_7_RUNTIME_ID;
}
return runtime;
}

public void setSourceLanguage(String sourceLanguage) {
this.sourceLanguage = sourceLanguage;
public void setRuntime(String runtime) {
this.runtime = runtime;
}

public String getModule() {
Expand Down Expand Up @@ -573,8 +590,8 @@ public String toString() {
+ ", majorVersionId='"
+ majorVersionId
+ '\''
+ ", sourceLanguage='"
+ sourceLanguage
+ ", runtime='"
+ runtime
+ '\''
+ ", service='"
+ service
Expand Down Expand Up @@ -749,9 +766,9 @@ public boolean equals(Object o) {
: that.majorVersionId != null) {
return false;
}
if (sourceLanguage != null
? !sourceLanguage.equals(that.sourceLanguage)
: that.sourceLanguage != null) {
if (runtime != null
? !runtime.equals(that.runtime)
: that.runtime != null) {
return false;
}
if (publicRoot != null ? !publicRoot.equals(that.publicRoot) : that.publicRoot != null) {
Expand Down Expand Up @@ -853,7 +870,7 @@ public int hashCode() {
result = 31 * result + (userPermissions != null ? userPermissions.hashCode() : 0);
result = 31 * result + (appId != null ? appId.hashCode() : 0);
result = 31 * result + (majorVersionId != null ? majorVersionId.hashCode() : 0);
result = 31 * result + (sourceLanguage != null ? sourceLanguage.hashCode() : 0);
result = 31 * result + (runtime != null ? runtime.hashCode() : 0);
result = 31 * result + (service != null ? service.hashCode() : 0);
result = 31 * result + (instanceClass != null ? instanceClass.hashCode() : 0);
result = 31 * result + automaticScaling.hashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,14 @@ private void processSecondLevelNode(Element elt, AppEngineWebXml appEngineWebXml
case "application":
processApplicationNode(elt, appEngineWebXml);
break;
case "runtime":
processRuntimeNode(elt, appEngineWebXml);
break;
case "version":
processVersionNode(elt, appEngineWebXml);
break;
case "source-language":
processSourceLanguageNode(elt, appEngineWebXml);
// Obsolete, ignore.
break;
case "module":
moduleNodeFound = true;
Expand Down Expand Up @@ -242,8 +245,8 @@ private void processVersionNode(Element node, AppEngineWebXml appEngineWebXml) {
appEngineWebXml.setMajorVersionId(XmlUtils.getText(node));
}

private void processSourceLanguageNode(Element node, AppEngineWebXml appEngineWebXml) {
appEngineWebXml.setSourceLanguage(XmlUtils.getText(node));
private void processRuntimeNode(Element node, AppEngineWebXml appEngineWebXml) {
appEngineWebXml.setRuntime(XmlUtils.getText(node));
}

private void processModuleNode(Element node, AppEngineWebXml appEngineWebXml) {
Expand Down
4 changes: 2 additions & 2 deletions jetty9-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-java-vm-runtime</artifactId>
<version>1.9.38-SNAPSHOT</version>
<version>1.9.40-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<name>Google App Engine Image Jetty (jetty9-base)</name>
Expand Down Expand Up @@ -125,7 +125,7 @@
<arguments>
<argument>-jar</argument>
<argument>../jetty-distribution-${jetty.version}/start.jar</argument>
<argument>--add-to-startd=gae,http,deploy,jsp,jstl</argument>
<argument>--add-to-startd=gae,http,jsp,jstl</argument>
</arguments>
</configuration>
</plugin>
Expand Down
16 changes: 16 additions & 0 deletions jetty9-base/src/main/jetty-base/etc/gae-web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">

<!-- Protect app.yaml -->
<Get id="protected" name="ProtectedTargets"/>
<Set name="ProtectedTargets">
<Call class="org.eclipse.jetty.util.ArrayUtil" name="addToArray">
<Arg><Ref refid="protected"/></Arg>
<Arg>/app.yaml</Arg>
<Arg></Arg>
</Call>
</Set>

</Configure>

14 changes: 14 additions & 0 deletions jetty9-base/src/main/jetty-base/etc/gae.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,18 @@
</Arg>
</Call>
</Ref>

<Ref refid="DeploymentManager">
<Call name="addLifeCycleBinding">
<Arg>
<New class="org.eclipse.jetty.deploy.bindings.GlobalWebappConfigBinding">
<Set name="jettyXml"><Property name="jetty.base"/>/etc/gae-web.xml</Set>
</New>
</Arg>
</Call>
</Ref>

<!-- TODO remove when this has been added to jetty.xml -->
<Set name="stopTimeout"><Property name="jetty.server.stopTimeout" default="30000"/></Set>

</Configure>
3 changes: 3 additions & 0 deletions jetty9-base/src/main/jetty-base/modules/gae.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[depend]
resources
server
deploy

[optional]

Expand All @@ -25,3 +26,5 @@ jetty.httpConfig.sendDateHeader=false
#gae.httpPort=80
#gae.httpsPort=443
#jetty.server.stopTimeout=30000
2 changes: 1 addition & 1 deletion jetty9-compat-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-java-vm-runtime</artifactId>
<version>1.9.38-SNAPSHOT</version>
<version>1.9.40-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<name>Google App Engine Container with GAE Compatibility (jetty9-compat-base)</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,133 +16,46 @@

package com.google.apphosting.vmruntime.jetty9;

import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.webapp.AbstractConfiguration;
import org.eclipse.jetty.webapp.WebAppClassLoader;
import org.eclipse.jetty.webapp.WebAppContext;

import java.util.logging.Level;

public class AppengineApiConfiguration extends AbstractConfiguration {

// A class to check if the GAE API is available.
public static final String GAE_CHECK_CLASS = "com.google.appengine.api.ThreadManager";

// Hide the all container classes from the webapplication
// TODO update to use '.' when supported by Jetty
private static final String[] SERVER_CLASSES = {
"com.",
"javax.",
"org.",
"mozilla."
// It's undesirable to have the user app override classes provided by us.
// So we mark them as Jetty system classes, which cannot be overridden.
private static final String[] SYSTEM_CLASSES = {
"com.google.appengine.api.",
"com.google.appengine.tools.",
"com.google.apphosting.",
"com.google.cloud.sql.jdbc.",
"com.google.protos.cloud.sql.",
"com.google.storage.onestore.",
};

// Classes & Packages to be shared from the containers classloader
// to the webapp. Classes included here will be marked both as
// exclusions from serverclasses (not hidden from webapp) and inclusion
// to the systemclasses (cannot be overriden by the webapp)
private static final String[] SHARED_CLASSES = {
// Expose the GAE API classes
"com.google.appengine.api.LifecycleManager",
"com.google.apphosting.api.ApiProxy",
"com.google.apphosting.api.ApiStats",
"com.google.apphosting.api.CloudTrace",
"com.google.apphosting.api.CloudTraceContext",
"com.google.apphosting.api.DeadlineExceededException",
"com.google.apphosting.runtime.SessionData",
"com.google.apphosting.runtime.UncatchableError",

// Expose the standard APIs that are provided by the container
"javax.servlet.",
"javax.el.",
"javax.mail.", // TODO Review

// Expose the standard APIs that are provided by the JVM
"com.oracle.",
"com.sun.",
"javax.accessibility.",
"javax.activation.",
"javax.activity.",
"javax.annotation.",
"javax.imageio.",
"javax.jws.",
"javax.lang.model.",
"javax.management.",
"javax.naming.",
"javax.net.",
"javax.print.",
"javax.rmi.",
"javax.script.",
"javax.security.",
"javax.smartcardio.",
"javax.sound.",
"javax.sql.",
"javax.swing.",
"javax.tools.",
"javax.transaction.",
"javax.xml.",
"jdk.",
"org.ietf.jgss.",
"org.jcp.xml.dsig.internal.",
"org.omg.",
"org.w3c.dom.",
"org.xml.",
"sun.",

// Expose classes needed for JSP and JSTL
"org.apache.jasper.runtime.",
"org.apache.jasper.JasperException",
"org.apache.el.ExpressionFactoryImpl",
"org.apache.tomcat.InstanceManager",
"org.apache.taglibs.",

// Hide the container classes from the webapplication
private static final String[] SERVER_CLASSES = {
"org.apache.commons.codec.",
"org.apache.commons.logging.",
"org.apache.http.",
"com.google.gson."
};

@Override
public void preConfigure(WebAppContext context) {
for (String systemClass : SYSTEM_CLASSES) {
context.addSystemClass(systemClass);
}
for (String systemClass : SERVER_CLASSES) {
context.addServerClass(systemClass);
}
for (String gaeClass : SHARED_CLASSES) {
// Don't hide shared classes
context.prependServerClass("-" + gaeClass);
// Don't allow shared classes to be replaced by webapp
context.addSystemClass(gaeClass);
}
}

public void configure(WebAppContext context) throws Exception {
ClassLoader loader = context.getClassLoader();
try {
// Test if the appengine api is available
loader.loadClass(GAE_CHECK_CLASS);
} catch (Exception ex) {
if (VmRuntimeWebAppContext.logger.isLoggable(Level.FINE)) {
VmRuntimeWebAppContext.logger.log(Level.WARNING,
"No appengine API jar included in WEB-INF/lib! Please update your SDK!", ex);
} else {
VmRuntimeWebAppContext.logger.log(Level.WARNING,
"No appengine API jar included in WEB-INF/lib! Please update your SDK!");
}

// The appengine API is not available so we will add it and it's dependencies
Resource providedApi =
Resource.newResource(
URIUtil.addPaths(System.getProperty("jetty.base"), "/lib/gae/provided-api/"));

if (providedApi != null) {
String[] list = providedApi.list();
if (list != null) {
WebAppClassLoader wloader = (WebAppClassLoader) loader;
for (String jar : list) {
wloader.addClassPath(providedApi.addPath(jar));
VmRuntimeWebAppContext.logger.log(Level.INFO, "Added " + jar + " to webapp classpath");
}
}
}

// Ensure the API can now be loaded
loader.loadClass(GAE_CHECK_CLASS);
}
// Ensure the API can be loaded
loader.loadClass(GAE_CHECK_CLASS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.eclipse.jetty.server.HttpOutput;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.ArrayUtil;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.log.JavaUtilLog;
import org.eclipse.jetty.util.resource.Resource;
Expand Down Expand Up @@ -343,6 +344,8 @@ public void init(String appengineWebXmlFile) throws AppEngineConfigException, IO
getSessionHandler().setSessionManager(sessionManager);

VmRuntimeInterceptor.init(appEngineWebXml);

setProtectedTargets(ArrayUtil.addToArray(getProtectedTargets(), "/app.yaml", String.class));
}

@Override
Expand Down
Loading

0 comments on commit 75f37b8

Please sign in to comment.