import com.google.apphosting.api.ApiProxy; ... final ApiProxy.Environment env = ApiProxy.getCurrentEnvironment(); final Map<String, Object> attributes = env.getAttributes(); final String hostAndPort = (String) attributes.get("com.google.appengine.runtime.default_version_hostname"); final String url = "http://" + hostAndPort + "/";
ApiProxy.Environment proxyEnvironment = ApiProxy.getCurrentEnvironment(); Map<String, Object> attributes = proxyEnvironment.getAttributes(); String hostname = (String) attributes.get(LocalEnvironment.DEFAULT_VERSION_HOSTNAME);
private static Task reconstructTask(HttpServletRequest request) { Properties properties = new Properties(); Enumeration<?> paramNames = request.getParameterNames(); while (paramNames.hasMoreElements()) { String paramName = (String) paramNames.nextElement(); String paramValue = request.getParameter(paramName); properties.setProperty(paramName, paramValue); } String taskName = request.getHeader(TASK_NAME_REQUEST_HEADER); Task task = Task.fromProperties(taskName, properties); task.getQueueSettings().setDelayInSeconds(null); String queueName = request.getHeader(TASK_QUEUE_NAME_HEADER); if (queueName != null && !queueName.isEmpty()) { String onQueue = task.getQueueSettings().getOnQueue(); if (onQueue == null || onQueue.isEmpty()) { task.getQueueSettings().setOnQueue(queueName); } Map<String, Object> attributes = ApiProxy.getCurrentEnvironment().getAttributes(); attributes.put(TASK_QUEUE_NAME_HEADER, queueName); } return task; } }
@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. } }
public static String getCurrentRequestId() { return (String) ApiProxy.getCurrentEnvironment().getAttributes().get("com.google.appengine.runtime.request_log_id"); } }
@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()); }
@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); }
private static Queue getQueue(String queueName) { if (queueName == null) { Map<String, Object> attributes = ApiProxy.getCurrentEnvironment().getAttributes(); queueName = (String) attributes.get(TaskHandler.TASK_QUEUE_NAME_HEADER); } return queueName == null ? QueueFactory.getDefaultQueue() : QueueFactory.getQueue(queueName); }
protected static URL getUrl(String path) throws MalformedURLException { ApiProxy.Environment env = ApiProxy.getCurrentEnvironment(); Object localhost = env.getAttributes().get("com.google.appengine.runtime.default_version_hostname"); return new URL("http://" + localhost + "/" + path); }
@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); } }
@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)); }