Google App Engine + Firebase

518 views
Skip to first unread message

Doug Thompson

unread,
Dec 30, 2015, 11:47:02 AM12/30/15
to Firebase Google Group
Using Google App Engine to connect to Firebase is throwing a 'thread' error. I've been following the tutorial at this link as closely as I can:


It instructs you to run a threadsafe version. I've followed the remaining instructions best I can - although the libraries it references have since been updated, so I'm running newer versions of the dependencies:

appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.30'
compile 'javax.servlet:servlet-api:2.5'
compile 'com.firebase:firebase-client-jvm:2.5.0'
compile 'org.apache.httpcomponents:httpclient:4.5.1'

In spite following those directions - although I clearly may have done SOMETHING wrong. Following is part of the error log on GAE:

    W 11:28:01.224 /hello
      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 com.google.apphosting.runtime.security.CustomSecurityManager.checkPermission(CustomSecurityManager.java:55)
      	at com.google.apphosting.runtime.security.CustomSecurityManager.checkAccess(CustomSecurityManager.java:136)
      	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)
      	...

Based on this tutorial, and on what I've read elsewhere, I thought that by setting to a threadsafe version that the Servlet would run. This is the code the Servlet is trying to run:

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
Log.warning ("Running.");


Firebase firebaseRecord = new Firebase("https://sampletest.firebaseio.com/");
firebaseRecord.child("fullName").setValue("Alan Turing");

}

Questions:

- Has anyone else tried to implement the tutorial?
- Has anyone run into problems with thread prevention on GAE and how have they dealt with it?
- Any other hints on what we might be missing? The tutorial seemed so simple but we're stuck on how to resolve.

Benjamin Wulfe

unread,
Dec 30, 2015, 2:58:16 PM12/30/15
to Firebase Google Group
This error is *usually* an indication that this step in the tutorial wasn't done:

"To use Firebase with App Engine, you must use manual scaling. This is because Firebase uses background threads to listen for changes and App Engine only allows long-lived background threads on manually scaled backend instances."


Look for the section titled "Configure the App Engine Backend to use manual scaling"

  1. Can you past the contents of your appengine-web.xml if you've already done this and it still doesn't work?

Doug Thompson

unread,
Dec 30, 2015, 3:31:35 PM12/30/15
to Firebase Google Group
Thanks Benjamin.

This is the appengine.web.xml file:

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>myApplicationId</application>
<version>1</version>
<threadsafe>true</threadsafe>
<manual-scaling>
<instances>1</instances>
</manual-scaling>
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties" />
</system-properties>
</appengine-web-app>

Benjamin Wulfe

unread,
Dec 30, 2015, 3:47:39 PM12/30/15
to Firebase Google Group
Just to make sure -- you've named this file "appengine-web.xml" right?  Not "appengine.web.xml".
Try to make a typo in the file (say missing an end tag) and re-deploy to ensure the file is being picked up at all.

Doug Thompson

unread,
Dec 30, 2015, 4:05:03 PM12/30/15
to Firebase Google Group
Yes, the file is called appengine-web.xml

I removed an end tag and tried to deploy but had an error "Bad configuration: XML error validating <?xml version="1.0" encoding="utf-8"?>

Putting the tag back in it deployed OK.

In my log files, I also show the following log in my log file:

"Running"

From the following in the myServlet::
Log.warning ("Running.");

I feel like I must be overlooking some simple thing.

Benjamin Wulfe

unread,
Dec 30, 2015, 6:18:56 PM12/30/15
to Firebase Google Group
Can you see the method that is creating the thread?
      	at java.lang.Thread.<init>(Thread.java:675)

Is there any more to the callstack?

Also, if you add the following code to your servlet, do you get a valid  value for threadFactoryInstance?

Class c = Class.forName("com.google.appengine.api.ThreadManager");
if (c != null) {
threadFactoryInstance = (ThreadFactory)
c.getMethod("backgroundThreadFactory").invoke(null);
}
The only thing I can think of is that the sdk isnt properly detecting running within AppEngine for some reason. Or there is a codepath creating a thread that we havent caught

Benjamin Wulfe

unread,
Dec 30, 2015, 7:13:09 PM12/30/15
to Firebase Google Group
actually I wonder if the reason this isnt working is because you neglected to add:

appengine-api-1.0-sdk

as a dependency.  This may cause the ThreadManager not to be located via reflection and our sdk then to not turn on GAE support.
Try adding this dependency and see if it helps.

Benjamin Wulfe

unread,
Dec 30, 2015, 7:18:49 PM12/30/15
to Firebase Google Group
note that specifying this dependency is different than specifying the appengine sdk via:

appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.30'

the above line downloads the appengine sdk so you can execute commands such as appcfg.

Doug Thompson

unread,
Dec 31, 2015, 8:33:43 AM12/31/15
to Firebase Google Group
Genius! That did the trick.

I can't believe how patient you were with me and I really appreciate it. My oversight was that the screen shot for the tutorial and adding a dependency somehow confused me, and I made a mistake in adding the incorrect dependency.

The first one is what I added, the second is the one I SHOULD have added:



I feel stupid of course, and grateful for your help! 


Success:



Thanks again.

Reply all
Reply to author
Forward
0 new messages