com.google.apphosting.api.ApiProxy.Environment Java Examples

The following examples show how to use com.google.apphosting.api.ApiProxy.Environment. 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: AppEngineEnvironment.java    From nomulus with Apache License 2.0 6 votes vote down vote up
/** Returns a placeholder {@link Environment} that can return hardcoded AppId and Attributes. */
private static Environment createAppEngineEnvironment() {
  return (Environment)
      Proxy.newProxyInstance(
          Environment.class.getClassLoader(),
          new Class[] {Environment.class},
          (Object proxy, Method method, Object[] args) -> {
            switch (method.getName()) {
              case "getAppId":
                return "PlaceholderAppId";
              case "getAttributes":
                return ImmutableMap.<String, Object>of();
              default:
                throw new UnsupportedOperationException(method.getName());
            }
          });
}
 
Example #2
Source File: LocalRawGcsService.java    From appengine-gcs-client with Apache License 2.0 6 votes vote down vote up
/**
 * Runs calls in a background thread so that the results will actually be asynchronous.
 *
 * @see com.google.appengine.tools.cloudstorage.RawGcsService#continueObjectCreationAsync(
 *        com.google.appengine.tools.cloudstorage.RawGcsService.RawGcsCreationToken,
 *        java.nio.ByteBuffer, long)
 */
@Override
public Future<RawGcsCreationToken> continueObjectCreationAsync(final RawGcsCreationToken token,
    final ByteBuffer chunk, long timeoutMillis) {
  try {
    ensureInitialized();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
  final Environment environment = ApiProxy.getCurrentEnvironment();
  return writePool.schedule(new Callable<RawGcsCreationToken>() {
    @Override
    public RawGcsCreationToken call() throws Exception {
      ApiProxy.setEnvironmentForCurrentThread(environment);
      return append(token, chunk);
    }
  }, 50, TimeUnit.MILLISECONDS);
}
 
Example #3
Source File: HelloInfo.java    From appengine-java-vm-hello with Apache License 2.0 5 votes vote down vote up
public static String getInfo() {
  String version = SystemProperty.applicationVersion.get();
  String majorVersion = version.substring(0, version.indexOf('.'));
  Environment env = ApiProxy.getCurrentEnvironment();
  String hostname =
      "" + env.getAttributes().get("com.google.appengine.runtime.default_version_hostname");
  String infostring = "version: " + majorVersion + " and hostname: " + hostname;
  return infostring;
}
 
Example #4
Source File: LogTest.java    From appengine-java-vm-runtime with Apache License 2.0 5 votes vote down vote up
public Future<byte[]> makeAsyncCall(
    Environment environment,
    String packageName,
    String methodName,
    byte[] request,
    ApiProxy.ApiConfig apiConfig) {
  return oldDelegate.makeAsyncCall(environment, packageName, methodName, request, apiConfig);
}
 
Example #5
Source File: GetEnvironmentAttributesServlet.java    From appengine-java-vm-runtime with Apache License 2.0 5 votes vote down vote up
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
  resp.setContentType("text/plain");
  Environment env = ApiProxy.getCurrentEnvironment();

  for (Entry entry : env.getAttributes().entrySet()) {
    resp.getWriter().println(entry.getKey() + " => " + entry.getValue());
  }
}
 
Example #6
Source File: VmRuntimeLogHandler.java    From appengine-java-vm-runtime with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the thread local environment if it is a VmApiProxyEnvironment.
 *
 * @return The ThreadLocal environment or null if no VmApiProxyEnvironment is set on this thread.
 */
private VmApiProxyEnvironment getThreadLocalEnvironment() {
  Environment env = ApiProxy.getCurrentEnvironment();
  if (env instanceof VmApiProxyEnvironment) {
    return (VmApiProxyEnvironment) env;
  }
  return null;
}
 
Example #7
Source File: VmRequestThreadFactory.java    From appengine-java-vm-runtime with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new VmRequestThreadFactory.
 *
 * @param requestEnvironment The request environment to install on each thread.
 */
public VmRequestThreadFactory(Environment requestEnvironment) {
  this.mutex = new Object();
  this.requestEnvironment = requestEnvironment;
  this.createdThreads = Lists.newLinkedList();
  this.allowNewRequestThreadCreation = true;
}
 
Example #8
Source File: AppEngineAuthentication.java    From appengine-java-vm-runtime with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the thread local environment if it is a VmApiProxyEnvironment.
 *
 * @return The ThreadLocal environment or null if no VmApiProxyEnvironment is set.
 */
private VmApiProxyEnvironment getThreadLocalEnvironment() {
  Environment env = ApiProxy.getCurrentEnvironment();
  if (env instanceof VmApiProxyEnvironment) {
    return (VmApiProxyEnvironment) env;
  }
  return null;
}
 
Example #9
Source File: AppengineWebAppContext.java    From yawp with MIT License 5 votes vote down vote up
@Override
protected void doStart() throws Exception {
    this.helper = createHelper();
    this.environment = ApiProxy.getCurrentEnvironment();
    getServletContext().setAttribute(API_PROXY_LOCAL, ApiProxy.getDelegate());
    getServletContext().setAttribute(APPENGINE_WEB_XML, readAppengineWebXml());
    getServletContext().setAttribute(WEB_XML, readWebXml());
    SystemProperty.environment.set(SystemProperty.Environment.Value.Development);
    configureUserRealmAppengineHelper();
    super.doStart();
}
 
Example #10
Source File: LogTest.java    From appengine-java-vm-runtime with Apache License 2.0 4 votes vote down vote up
public List<Thread> getRequestThreads(Environment environmnent) {
  return oldDelegate.getRequestThreads(environmnent);
}
 
Example #11
Source File: LogTest.java    From appengine-java-vm-runtime with Apache License 2.0 4 votes vote down vote up
public byte[] makeSyncCall(
    Environment environment, String packageName, String methodName, byte[] request)
    throws ApiProxyException {
  return oldDelegate.makeSyncCall(environment, packageName, methodName, request);
}
 
Example #12
Source File: LogTest.java    From appengine-java-vm-runtime with Apache License 2.0 4 votes vote down vote up
public void log(Environment environment, LogRecord record) {
  records.add(record);
  oldDelegate.log(environment, record);
}
 
Example #13
Source File: LogTest.java    From appengine-java-vm-runtime with Apache License 2.0 4 votes vote down vote up
public void flushLogs(Environment environment) {
  oldDelegate.flushLogs(environment);
}