本文整理汇总了Java中com.google.apphosting.api.ApiProxy.getCurrentEnvironment方法的典型用法代码示例。如果您正苦于以下问题:Java ApiProxy.getCurrentEnvironment方法的具体用法?Java ApiProxy.getCurrentEnvironment怎么用?Java ApiProxy.getCurrentEnvironment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.apphosting.api.ApiProxy
的用法示例。
在下文中一共展示了ApiProxy.getCurrentEnvironment方法的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.
}
}
示例2: continueObjectCreationAsync
import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
/**
* 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);
}
示例3: 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.
}
}
示例4: 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());
}
}
示例5: 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"));
}
示例6: printGaeProperties
import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
private void printGaeProperties(StringBuilder sb)
{
sb.append("<h2>GAE Properties</h2>");
Environment env = ApiProxy.getCurrentEnvironment();
Iterator<Entry<String, Object>> iter = env.getAttributes().entrySet().iterator();
sb.append("<table><tr><th>Name</th><th>Value</th></tr>");
sb.append("<tr><td>").append("getAppId()").append("</td><td>").append(env.getAppId()).append("</td></tr>");
sb.append("<tr><td>").append("getVersionId()").append("</td><td>").append(env.getVersionId()).append("</td></tr>");
sb.append("<tr><td>").append("getModuleId()").append("</td><td>").append(env.getModuleId()).append("</td></tr>");
sb.append("<tr><td>").append("getAuthDomain()").append("</td><td>").append(env.getAuthDomain()).append("</td></tr>");
sb.append("<tr><td>").append("getEmail()").append("</td><td>").append(env.getEmail()).append("</td></tr>");
UserService userService = UserServiceFactory.getUserService();
boolean userLoggedIn = userService.isUserLoggedIn();
sb.append("<tr><td>").append("isUserLoggedIn()").append("</td><td>").append(userLoggedIn).append("</td></tr>");
if (userLoggedIn)
{
String logoutUrl = "Click <a href=\"" + userService.createLogoutURL(request.getRequestURI()) + "\">here</a> to Logout";
sb.append("<tr><td>").append("createLogoutURL()").append("</td><td>").append(logoutUrl).append("</td></tr>");
}
else
{
String loginUrl = "Click <a href=\"" + userService.createLoginURL(request.getRequestURI()) + "\">here</a> to Login";
sb.append("<tr><td>").append("createLoginURL()").append("</td><td>").append(loginUrl).append("</td></tr>");
}
while (iter.hasNext())
{
Entry<String, Object> entry = iter.next();
String paramName = entry.getKey();
String paramValue = entry.getValue().toString();
sb.append("<tr><td>").append(paramName).append("</td><td>").append(paramValue).append("</td></tr>");
}
sb.append("</table>");
}
示例7: setUp
import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
@Override
public void setUp() throws Exception {
super.setUp();
traceBuffer = new StringBuffer();
helper.setUp();
apiProxyEnvironment = ApiProxy.getCurrentEnvironment();
System.setProperty(USE_SIMPLE_GUIDS_FOR_DEBUGGING, "true");
taskQueue = LocalTaskQueueTestConfig.getLocalTaskQueue();
}
示例8: getInfo
import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
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;
}
示例9: doGet
import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
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());
}
}
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:9,代码来源:GetEnvironmentAttributesServlet.java
示例10: 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);
}
}
}
示例11: 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;
}
示例12: getThreadLocalEnvironment
import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
/**
* 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;
}
示例13: getThreadLocalEnvironment
import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
/**
* 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;
}
示例14: loadSession
import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
SessionData loadSession(String sessionId) {
String key = SESSION_PREFIX + sessionId;
SessionData data = null;
for (SessionStore sessionStore : sessionStoresInReadOrder) {
// Keep iterating until we find a store that has the session data we
// want.
try {
data = sessionStore.getSession(key);
if (data != null) {
break;
}
} catch (RuntimeException e) {
String msg = "Exception while loading session data";
logger.log(Level.WARNING, msg, e);
if (ApiProxy.getCurrentEnvironment() != null) {
ApiProxy.log(createWarningLogRecord(msg, e));
}
break;
}
}
if (data != null) {
if (System.currentTimeMillis() > data.getExpirationTime()) {
logger.fine("Session " + sessionId + " expired " +
((System.currentTimeMillis() - data.getExpirationTime()) / 1000) +
" seconds ago, ignoring.");
return null;
}
}
return data;
}
示例15: doStart
import com.google.apphosting.api.ApiProxy; //导入方法依赖的package包/类
@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();
}