Tommy Siu
Tommy Siu

Reputation: 1295

Firebase init error in Google App Engine

I am now developing a java Google cloud endpoint in GAE. Inside the endpoint it will try to connect to the Firebase server to get some data.

However, when I create the Firebase object in my endpoint,

Firebase ref = new Firebase(<My Firebase URL>);

GAE throws the following error:

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)

I am using Firebase client 2.2.3. It seems like GAE does not allow an application to create new threads. Any idea?

Upvotes: 6

Views: 1560

Answers (3)

Manish Patiyal
Manish Patiyal

Reputation: 4467

I think this link will help you, it describes how we can use firebase realtime database from server application using service account.

You can use following code snippet to connect to firebase database .

// 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);
    }
});

Upvotes: -3

Shobhit
Shobhit

Reputation: 488

@ Mario is correct, App Engine app may not spawn new threads according to the 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 in which you don't have these types of restrictions.

Upvotes: 2

Mario
Mario

Reputation: 1230

In the Java runtime for Google App Engine there are some restrictions on creating new threads.

Please see the Threads section for details.

Upvotes: 4

Related Questions