Google App Engine 中的 Firebase 初始化错误
Firebase init error in Google App Engine
我现在正在 GAE 中开发 java Google 云端点。在端点内,它将尝试连接到 Firebase 服务器以获取一些数据。
但是,当我在端点中创建 Firebase 对象时,
Firebase ref = new Firebase(<My Firebase URL>);
GAE 抛出以下错误:
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "modifyThreadGroup")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:382)
at java.security.AccessController.checkPermission(AccessController.java:572)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.ThreadGroup.checkAccess(ThreadGroup.java:315)
at java.lang.Thread.init(Thread.java:391)
at java.lang.Thread.init(Thread.java:349)
at java.lang.Thread.<init>(Thread.java:675)
at java.util.concurrent.Executors$DefaultThreadFactory.newThread(Executors.java:572)
at com.firebase.client.utilities.DefaultRunLoop$FirebaseThreadFactory.newThread(DefaultRunLoop.java:25)
at java.util.concurrent.ThreadPoolExecutor$Worker.<init>(ThreadPoolExecutor.java:600)
at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:943)
at java.util.concurrent.ThreadPoolExecutor.ensurePrestart(ThreadPoolExecutor.java:1635)
at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:307)
at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:526)
at java.util.concurrent.ScheduledThreadPoolExecutor.execute(ScheduledThreadPoolExecutor.java:615)
at com.firebase.client.utilities.DefaultRunLoop.scheduleNow(DefaultRunLoop.java:57)
at com.firebase.client.core.Repo.scheduleNow(Repo.java:176)
at com.firebase.client.core.Repo.<init>(Repo.java:58)
at com.firebase.client.core.RepoManager.getLocalRepo(RepoManager.java:46)
at com.firebase.client.core.RepoManager.getRepo(RepoManager.java:19)
at com.firebase.client.Firebase.<init>(Firebase.java:194)
at com.firebase.client.Firebase.<init>(Firebase.java:199)
at com.firebase.client.Firebase.<init>(Firebase.java:177)
我正在使用 Firebase 客户端 2.2.3。似乎 GAE 不允许应用程序创建新线程。有什么想法吗?
在 Google App Engine 的 Java 运行时中,对创建新线程有一些限制。
详情请见the Threads section。
@ Mario 是正确的,App Engine 应用程序可能不会根据您没有这些类型限制的 docs.This is because the AppEngine application run in the sandbox environment in which you have some restrictions.If still you want to develop your app without out any restriction then I would suggest try Managed VM 生成新线程。
我认为 this link 会对您有所帮助,它描述了我们如何使用服务帐户从服务器应用程序使用 firebase 实时数据库。
您可以使用以下代码片段连接到 firebase 数据库。
// Initialize the app with a service account, granting admin privileges
FirebaseOptions options = new FirebaseOptions.Builder()
.setDatabaseUrl("https://databaseName.firebaseio.com")
.setServiceAccount(new FileInputStream("path/to/serviceAccountCredentials.json"))
.build();
FirebaseApp.initializeApp(options);
// As an admin, the app has access to read and write all data, regardless of Security Rules
DatabaseReference ref = FirebaseDatabase
.getInstance()
.getReference("restricted_access/secret_document");
ref.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Object document = dataSnapshot.getValue();
System.out.println(document);
}
});
我现在正在 GAE 中开发 java Google 云端点。在端点内,它将尝试连接到 Firebase 服务器以获取一些数据。
但是,当我在端点中创建 Firebase 对象时,
Firebase ref = new Firebase(<My Firebase URL>);
GAE 抛出以下错误:
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "modifyThreadGroup")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:382)
at java.security.AccessController.checkPermission(AccessController.java:572)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.ThreadGroup.checkAccess(ThreadGroup.java:315)
at java.lang.Thread.init(Thread.java:391)
at java.lang.Thread.init(Thread.java:349)
at java.lang.Thread.<init>(Thread.java:675)
at java.util.concurrent.Executors$DefaultThreadFactory.newThread(Executors.java:572)
at com.firebase.client.utilities.DefaultRunLoop$FirebaseThreadFactory.newThread(DefaultRunLoop.java:25)
at java.util.concurrent.ThreadPoolExecutor$Worker.<init>(ThreadPoolExecutor.java:600)
at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:943)
at java.util.concurrent.ThreadPoolExecutor.ensurePrestart(ThreadPoolExecutor.java:1635)
at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:307)
at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:526)
at java.util.concurrent.ScheduledThreadPoolExecutor.execute(ScheduledThreadPoolExecutor.java:615)
at com.firebase.client.utilities.DefaultRunLoop.scheduleNow(DefaultRunLoop.java:57)
at com.firebase.client.core.Repo.scheduleNow(Repo.java:176)
at com.firebase.client.core.Repo.<init>(Repo.java:58)
at com.firebase.client.core.RepoManager.getLocalRepo(RepoManager.java:46)
at com.firebase.client.core.RepoManager.getRepo(RepoManager.java:19)
at com.firebase.client.Firebase.<init>(Firebase.java:194)
at com.firebase.client.Firebase.<init>(Firebase.java:199)
at com.firebase.client.Firebase.<init>(Firebase.java:177)
我正在使用 Firebase 客户端 2.2.3。似乎 GAE 不允许应用程序创建新线程。有什么想法吗?
在 Google App Engine 的 Java 运行时中,对创建新线程有一些限制。
详情请见the Threads section。
@ Mario 是正确的,App Engine 应用程序可能不会根据您没有这些类型限制的 docs.This is because the AppEngine application run in the sandbox environment in which you have some restrictions.If still you want to develop your app without out any restriction then I would suggest try Managed VM 生成新线程。
我认为 this link 会对您有所帮助,它描述了我们如何使用服务帐户从服务器应用程序使用 firebase 实时数据库。
您可以使用以下代码片段连接到 firebase 数据库。
// Initialize the app with a service account, granting admin privileges
FirebaseOptions options = new FirebaseOptions.Builder()
.setDatabaseUrl("https://databaseName.firebaseio.com")
.setServiceAccount(new FileInputStream("path/to/serviceAccountCredentials.json"))
.build();
FirebaseApp.initializeApp(options);
// As an admin, the app has access to read and write all data, regardless of Security Rules
DatabaseReference ref = FirebaseDatabase
.getInstance()
.getReference("restricted_access/secret_document");
ref.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Object document = dataSnapshot.getValue();
System.out.println(document);
}
});