当前位置: 首页>>代码示例>>Java>>正文


Java ApiProxy.Environment方法代码示例

本文整理汇总了Java中com.google.apphosting.api.ApiProxy.Environment方法的典型用法代码示例。如果您正苦于以下问题:Java ApiProxy.Environment方法的具体用法?Java ApiProxy.Environment怎么用?Java ApiProxy.Environment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.apphosting.api.ApiProxy的用法示例。


在下文中一共展示了ApiProxy.Environment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
@Override
public void init() throws ServletException {
  try {
    ApiProxy.Environment env = ApiProxy.getCurrentEnvironment();
    Map<String,Object> attr = env.getAttributes();
    String hostname = (String) attr.get("com.google.appengine.runtime.default_version_hostname");

    String url = hostname.contains("localhost:")
        ? System.getProperty("cloudsql-local") : System.getProperty("cloudsql");
    log("connecting to: " + url);
    try {
      conn = DriverManager.getConnection(url);
    } catch (SQLException e) {
      throw new ServletException("Unable to connect to Cloud SQL", e);
    }

  } finally {
    // Nothing really to do here.
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:21,代码来源:CloudSqlServlet.java

示例2: testGetDefaultGcsBucketName

import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
@Test
public void testGetDefaultGcsBucketName() {
    ApiProxy.Environment env = ApiProxy.getCurrentEnvironment();
    String expectedBucketName;
    Property property = property("testGetDefaultGcsBucketName");
    if (property.exists()) {
        expectedBucketName = property.getPropertyValue();
    } else {
        expectedBucketName = (String) env.getAttributes().get("com.google.appengine.runtime.default_version_hostname");
    }

    try {
        String bucketName = appIdentity.getDefaultGcsBucketName();
        Assert.assertEquals(expectedBucketName, bucketName);
    } catch (AppIdentityServiceFailureException aisfe) {
        //TODO: This means that there is no default bucket setup for this project.  Have a better way to verify this.
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:19,代码来源:AppIdentityServiceTest.java

示例3: getConnections

import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
/**
 * Set up the connection objections
 */
public void getConnections()
{
	ApiProxy.Environment env = ApiProxy.getCurrentEnvironment();
    Map<String,Object> attr = env.getAttributes();
	String hostname = (String) attr.get("com.google.appengine.runtime.default_version_hostname");
	/**
	 * the cloudsql-local and cloudsql files are stated in the appengine-web.xml
	 */
	String aUrl = hostname.contains("localhost:")
	          ? System.getProperty("asteroid-cloudsql-local") : System.getProperty("asteroid-cloudsql");
	String requestUrl = hostname.contains("localhost:")
			  ? System.getProperty("request-cloudsql-local") : System.getProperty("request-cloudsql");
	String resultUrl = hostname.contains("localhost:")
			  ? System.getProperty("result-cloudsql-local") : System.getProperty("result-cloudsql");
    try
    {
        aConn = DriverManager.getConnection(aUrl);
        requestConn = DriverManager.getConnection(requestUrl);
        resultConn = DriverManager.getConnection(resultUrl);
    }
    catch(SQLException e)
    {
    	aConn = null;
    	requestConn = null;
    	resultConn = null;
    	System.out.println("HERE'S THE ERROR:");
    	System.out.println(e.getMessage());
    }
}
 
开发者ID:DanielHawes,项目名称:AsteroidEndpointTest,代码行数:33,代码来源:DatabaseControl.java

示例4: doGet

import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
  resp.setContentType("text/plain");
  ApiProxy.Environment env = ApiProxy.getCurrentEnvironment();
  resp.getWriter().print("default_version_hostname: ");
  resp.getWriter()
      .println(env.getAttributes().get("com.google.appengine.runtime.default_version_hostname"));
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:9,代码来源:IdentityServlet.java

示例5: makeSyncCall

import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
@Override
public byte[] makeSyncCall(
    ApiProxy.Environment environment, String packageName, String methodName, byte[] request) {
  if (!"remote_socket".equals(packageName)) {
    throw new UnsupportedOperationException();
  }
  return makeResponse(methodName, request);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:9,代码来源:TestDatagramSocketServlet.java

示例6: makeAsyncCall

import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
@Override
public Future<byte[]> makeAsyncCall(
    ApiProxy.Environment environment,
    String packageName,
    String methodName,
    byte[] request,
    ApiProxy.ApiConfig apiConfig) {
  if ("remote_socket".equals(packageName)) {
    final byte[] response = makeResponse(methodName, request);
    return new Future<byte[]>() {
      @Override
      public boolean cancel(boolean mayInterruptIfRunning) {
        return false;
      }

      @Override
      public boolean isCancelled() {
        return false;
      }

      @Override
      public boolean isDone() {
        return true;
      }

      @Override
      public byte[] get() throws InterruptedException, ExecutionException {
        return response;
      }

      @Override
      public byte[] get(long timeout, TimeUnit unit)
          throws InterruptedException, ExecutionException, TimeoutException {
        return response;
      }
    };
  }
  throw new UnsupportedOperationException();
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:40,代码来源:TestSocketServlet.java

示例7: makeSyncCall

import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
@Override
public byte[] makeSyncCall(
    ApiProxy.Environment environment, String packageName, String methodName, byte[] request) {
  if ("remote_socket".equals(packageName) && "Resolve".equals(methodName)) {
    return RESOLVER_RESPONSE;
  }
  throw new UnsupportedOperationException();
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:9,代码来源:TestInetAddressServlet.java

示例8: makeAsyncCall

import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
@Override
public Future<byte[]> makeAsyncCall(
    ApiProxy.Environment environment,
    String packageName,
    String methodName,
    byte[] request,
    ApiProxy.ApiConfig apiConfig) {
  if ("remote_socket".equals(packageName) && "Resolve".equals(methodName)) {
    return new Future<byte[]>() {
      @Override
      public boolean cancel(boolean mayInterruptIfRunning) {
        return false;
      }

      @Override
      public boolean isCancelled() {
        return false;
      }

      @Override
      public boolean isDone() {
        return true;
      }

      @Override
      public byte[] get() throws InterruptedException, ExecutionException {
        return RESOLVER_RESPONSE;
      }

      @Override
      public byte[] get(long timeout, TimeUnit unit)
          throws InterruptedException, ExecutionException, TimeoutException {
        return RESOLVER_RESPONSE;
      }
    };
  }
  throw new UnsupportedOperationException();
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:39,代码来源:TestInetAddressServlet.java

示例9: doGet

import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
  resp.setContentType("text/plain");
  ApiProxy.Environment requestEnv = ApiProxy.getCurrentEnvironment();

  for (String key : requestEnv.getAttributes().keySet()) {
    if (!INIT_ENV.getAttributes().containsKey(key) && !REQUEST_ONLY_ATTRIBUTES.contains(key)) {
      resp.getWriter().println("Init environment attributes do not contain " + key);
    }
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:13,代码来源:LoadOnStartupServlet.java

示例10: fullVersionId

import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
private String fullVersionId() {
  ApiProxy.Environment environment = ApiProxy.getCurrentEnvironment();
  String actualVersionId = environment.getVersionId();
  if (!(environment.getModuleId() == null
        || environment.getModuleId().isEmpty()
        || environment.getModuleId().equals("default"))) {
    actualVersionId = environment.getModuleId() + ":" + actualVersionId;
  }
  return actualVersionId;
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:11,代码来源:VmHealthServlet.java

示例11: makeAsyncCall

import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
public Future<byte[]> makeAsyncCall(
    ApiProxy.Environment environment,
    String packageName,
    String methodName,
    byte[] request,
    ApiProxy.ApiConfig apiConfig) {
  if (packageName.equals("datastore_v3") && timeoutCount > 0) {
    timeoutCount--;
    throw new DatastoreTimeoutException("Timeout");
  }
  return delegate.makeAsyncCall(environment, packageName, methodName, request, apiConfig);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:13,代码来源:SessionManagerTest.java

示例12: testParseFullAppId

import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
@Test
public void testParseFullAppId() {
    // [(partition)~][(domain):](display-app-id)
    ApiProxy.Environment env = ApiProxy.getCurrentEnvironment();
    String hostname = (String) env.getAttributes().get("com.google.appengine.runtime.default_version_hostname");
    AppIdentityService.ParsedAppId parsed = appIdentity.parseFullAppId(hostname);

    String message = createParsed(parsed);
    Assert.assertEquals(message, property("testParseFullAppId_partition").getPropertyValue(), parsed.getPartition());
    Assert.assertEquals(message, getExpectedAppHostname("testParseFullAppId_domain"), parsed.getDomain());
    Assert.assertEquals(message, getExpectedAppId("testParseFullAppId_id"), parsed.getId());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:13,代码来源:AppIdentityServiceTest.java

示例13: testGetVersionedHostname

import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
@Test
public void testGetVersionedHostname() {
    String expectedHostname = getExpectedAppHostname("testGetVersionedHostname");
    ApiProxy.Environment env = ApiProxy.getCurrentEnvironment();
    String hostname = (String) env.getAttributes().get("com.google.appengine.runtime.default_version_hostname");
    String errMsg = "The versioned hostname should end with " + expectedHostname + ", but was " + hostname;
    Assert.assertTrue(errMsg, hostname.endsWith(expectedHostname));
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:9,代码来源:AppIdentityBasicTest.java

示例14: testInstanceId

import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
@Test
public void testInstanceId() {
    ApiProxy.Environment env = ApiProxy.getCurrentEnvironment();
    String instanceId = (String) env.getAttributes().get("com.google.appengine.instance.id");
    String errMsg = "The instance id should not be null";
    Assert.assertNotNull(errMsg, instanceId);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:8,代码来源:AppIdentityBasicTest.java

示例15: testRequestId

import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
@Test
public void testRequestId() {
    ApiProxy.Environment env = ApiProxy.getCurrentEnvironment();
    String requestId = (String) env.getAttributes().get("com.google.appengine.runtime.request_log_id");
    String errMsg = "The request id should not be null";
    Assert.assertNotNull(errMsg, requestId);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:8,代码来源:AppIdentityBasicTest.java


注:本文中的com.google.apphosting.api.ApiProxy.Environment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。