com.google.apphosting.utils.config.AppEngineWebXml Java Examples

The following examples show how to use com.google.apphosting.utils.config.AppEngineWebXml. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractAppCfgMojo.java    From appengine-maven-plugin with Apache License 2.0 6 votes vote down vote up
String getProjectId() throws MojoExecutionException {
  if (project != null) {
    return project;
  }
  if (appId != null) {
    return appId;
  }
  File f = new File(getAppDir(), "WEB-INF/appengine-web.xml");
  if (f.exists()) {
    AppEngineWebXmlReader aewebReader = new AppEngineWebXmlReader(getAppDir());
    AppEngineWebXml appEngineWebXml = aewebReader.readAppEngineWebXml();
    return appEngineWebXml.getAppId();
  } else if (EarHelper.isEar(getAppDir(), false)) {
    EarInfo earInfo = EarHelper.readEarInfo(getAppDir(),
            new File(Application.getSdkDocsDir(), "appengine-application.xsd"));
    return earInfo.getAppengineApplicationXml().getApplicationId();
  }
  throw new MojoExecutionException(
          "No <application> defined in appengine-web.xml, nor <project>"
          + " <configuration> defined in the pom.xml.");
}
 
Example #2
Source File: AppEngineUtil.java    From endpoints-java with Apache License 2.0 5 votes vote down vote up
/**
 * Given the directory of an App Engine application, returns its application id by checking
 * WEB-INF/app.yaml first and then WEB-INF/appengine-web.xml.
 */
public static String getApplicationId(String appDir) {
  return getAppProperty(appDir, new AppPropertyReader() {
    @Override
    public String readYaml(AppYaml yaml) {
      return yaml.getApplication();
    }

    @Override
    public String readXml(AppEngineWebXml xml) {
      return xml.getAppId();
    }
  });
}
 
Example #3
Source File: AppEngineUtil.java    From endpoints-java with Apache License 2.0 5 votes vote down vote up
/**
 * Given the directory of an App Engine application, returns its version by checking
 * war/WEB-INF/app.yaml first and then war/WEB-INF/appengine-web.xml.
 */
public static String getApplicationVersion(String appDir) {
  return getAppProperty(appDir, new AppPropertyReader() {
    @Override
    public String readYaml(AppYaml yaml) {
      return yaml.getVersion();
    }

    @Override
    public String readXml(AppEngineWebXml xml) {
      return xml.getMajorVersionId();
    }
  });
}
 
Example #4
Source File: VmRuntimeUtils.java    From appengine-java-vm-runtime with Apache License 2.0 5 votes vote down vote up
/**
 * Install system properties based on the provided VmApiProxyEnvironment.
 */
public static void installSystemProperties(
    VmApiProxyEnvironment environment, AppEngineWebXml appEngineWebXml) {
  setEnvironmentSystemProperty(environment.getPartition());
  System.setProperty(SystemProperty.version.key(), getServerInfo());
  System.setProperty(
      SystemProperty.applicationId.key(), AppId.parse(environment.getAppId()).getLongAppId());
  System.setProperty(SystemProperty.applicationVersion.key(), environment.getVersionId());
  System.setProperty("appengine.jetty.also_log_to_apiproxy", "true");
  if (appEngineWebXml!=null) {
    for (Map.Entry<String, String> entry : appEngineWebXml.getSystemProperties().entrySet()) {
      System.setProperty(entry.getKey(), entry.getValue());
    }
  }
}
 
Example #5
Source File: VmRuntimeWebAppContext.java    From appengine-java-vm-runtime with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a List of SessionStores based on the configuration in the provided AppEngineWebXml.
 *
 * @param appEngineWebXml The AppEngineWebXml containing the session configuration.
 * @return A List of SessionStores in write order.
 */
private static List<SessionStore> createSessionStores(AppEngineWebXml appEngineWebXml) {
  DatastoreSessionStore datastoreSessionStore =
      appEngineWebXml.getAsyncSessionPersistence() ? new DeferredDatastoreSessionStore(
          appEngineWebXml.getAsyncSessionPersistenceQueueName())
          : new DatastoreSessionStore();
  // Write session data to the datastore before we write to memcache.
  return Arrays.asList(datastoreSessionStore, new MemcacheSessionStore());
}
 
Example #6
Source File: AppengineWebAppContext.java    From yawp with MIT License 5 votes vote down vote up
private void applySystemProperties(AppEngineWebXml appEngineWebXml) {
    Map<String, String> props = appEngineWebXml.getSystemProperties();

    for (String key : props.keySet()) {
        System.setProperty(key, interpolate(props.get(key)));
    }
}
 
Example #7
Source File: VmRuntimeWebAppContext.java    From appengine-java-vm-runtime with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize the WebAppContext for use by the VmRuntime.
 *
 * This method initializes the WebAppContext by setting the context path and application folder.
 * It will also parse the appengine-web.xml file provided to set System Properties and session
 * manager accordingly.
 *
 * @param appengineWebXmlFile The appengine-web.xml file path (relative to appDir).
 * @throws AppEngineConfigException If there was a problem finding or parsing the
 *         appengine-web.xml configuration.
 * @throws IOException If the runtime was unable to find/read appDir.
 */
public void init(String appengineWebXmlFile)
    throws AppEngineConfigException, IOException {

  String appDir=getBaseResource().getFile().getCanonicalPath();  
  defaultEnvironment = VmApiProxyEnvironment.createDefaultContext(
      System.getenv(), metadataCache, VmRuntimeUtils.getApiServerAddress(), wallclockTimer,
      VmRuntimeUtils.ONE_DAY_IN_MILLIS, appDir);
  ApiProxy.setEnvironmentForCurrentThread(defaultEnvironment);
  if (ApiProxy.getEnvironmentFactory() == null) {
    // Need the check above since certain unit tests initialize the context multiple times.
    ApiProxy.setEnvironmentFactory(new VmEnvironmentFactory(defaultEnvironment));
  }

  isDevMode = defaultEnvironment.getPartition().equals("dev");
  AppEngineWebXml appEngineWebXml = null;
  File appWebXml = new File(appDir, appengineWebXmlFile);
  if (appWebXml.exists()) {
    AppEngineWebXmlReader appEngineWebXmlReader
            = new AppEngineWebXmlReader(appDir, appengineWebXmlFile);
    appEngineWebXml = appEngineWebXmlReader.readAppEngineWebXml();
  }
  VmRuntimeUtils.installSystemProperties(defaultEnvironment, appEngineWebXml);
  VmRuntimeLogHandler.init();
  VmRuntimeFileLogHandler.init();

  for (String systemClass : SYSTEM_CLASSES) {
    addSystemClass(systemClass);
  }
  if (appEngineWebXml == null) {
    // No need to configure the session manager.
    return;
  }
  AbstractSessionManager sessionManager;
  if (appEngineWebXml.getSessionsEnabled()) {
    sessionManager = new SessionManager(createSessionStores(appEngineWebXml));
    getSessionHandler().setSessionManager(sessionManager);
  }

  setProtectedTargets(ArrayUtil.addToArray(getProtectedTargets(), "/app.yaml", String.class));
}
 
Example #8
Source File: AppengineWebAppContext.java    From yawp with MIT License 4 votes vote down vote up
private AppEngineWebXml readAppengineWebXml() {
    AppEngineWebXmlReader reader = new AppEngineWebXmlReader(mojo.getAppDir());
    AppEngineWebXml appEngineWebXml = reader.readAppEngineWebXml();
    applySystemProperties(appEngineWebXml);
    return appEngineWebXml;
}
 
Example #9
Source File: AbstractGcloudMojo.java    From gcloud-maven-plugin with Apache License 2.0 4 votes vote down vote up
protected AppEngineWebXml getAppEngineWebXml(String webAppDir) throws MojoExecutionException {
  AppEngineWebXmlReader reader = new AppEngineWebXmlReader(webAppDir);
  AppEngineWebXml appengineWebXml = reader.readAppEngineWebXml();
  return appengineWebXml;
}
 
Example #10
Source File: AppEngineUtil.java    From endpoints-java with Apache License 2.0 votes vote down vote up
String readXml(AppEngineWebXml xml);