Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.IllegalStateException: This feature is only available to backend instances

In my api explorer I get following error while performing an insert to an endpoint, which inserts some data to firebase.

503

- Show headers -

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "backendError",
    "message": "java.lang.IllegalStateException: This feature is only available to backend instances."
   }
  ],
  "code": 503,
  "message": "java.lang.IllegalStateException: This feature is only available to backend instances."
 }
}

Also I am using following code inside an endpoint class where firebase is a static object reference.

FirebaseOptions options = new FirebaseOptions.Builder()
        .setServiceAccount(servletContext.getResourceAsStream("/WEB-INF/google-services.json"))
        .setDatabaseUrl("https://contactifyapp.firebaseio.com/")
        .build();

if (firebaseApp == null)
    firebaseApp = 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();
String data = runMeNow.getData();
JSONObject jsonObject = new JSONObject(data);
Random rand = new Random();
ref.child(Keys.CONTACT_INFO).child("child").child(Keys.USER_INFO).setValue(jsonObject.get(Keys.USER_INFO));

The logs are as following on server:

19:30:43.061
com.google.api.server.spi.SystemService invokeServiceMethod: exception occurred while calling backend method
java.lang.IllegalStateException: This feature is only available to backend instances.
    at com.google.appengine.api.system.SystemServiceImpl.translateException(SystemServiceImpl.java:40)
    at com.google.appengine.api.system.SystemServiceImpl.startBackgroundRequest(SystemServiceImpl.java:28)
    at com.google.firebase.database.utilities.DefaultRunLoop$FirebaseThreadFactory.newThread(DefaultRunLoop.java:13)
    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 com.google.firebase.database.connection.PersistentConnectionImpl.doIdleCheck(PersistentConnectionImpl.java:1098)
    at com.google.firebase.database.connection.PersistentConnectionImpl.<init>(PersistentConnectionImpl.java:266)
    at com.google.firebase.database.core.GaePlatform.newPersistentConnection(GaePlatform.java:128)
    at com.google.firebase.database.core.Context.newPersistentConnection(Context.java:195)
    at com.google.firebase.database.core.Repo.<init>(Repo.java:64)
    at com.google.firebase.database.core.RepoManager.createLocalRepo(RepoManager.java:87)
    at com.google.firebase.database.core.RepoManager.createRepo(RepoManager.java:28)
    at com.google.firebase.database.FirebaseDatabase.ensureRepo(FirebaseDatabase.java:249)
    at com.google.firebase.database.FirebaseDatabase.getReference(FirebaseDatabase.java:114)
    at com.safran.contactify.backend.RunMeNowEndpoint.insert(RunMeNowEndpoint.java:105)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:44)
    at com.google.api.server.spi.SystemService.invokeServiceMethod(SystemService.java:363)
    at com.google.api.server.spi.SystemServiceServlet.execute(SystemServiceServlet.java:113)
    at com.google.api.server.spi.SystemServiceServlet.doPost(SystemServiceServlet.java:71)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.googlecode.objectify.ObjectifyFilter.doFilter(ObjectifyFilter.java:48)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:439)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:446)
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:256)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:310)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:302)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:443)
    at java.lang.Thread.run(Thread.java:745)
like image 896
Manish Patiyal Avatar asked Jun 28 '16 14:06

Manish Patiyal


1 Answers

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. Add following configuration to your appengine-web.xml

<manual-scaling>
   <instances>1</instances>
</manual-scaling>
like image 136
Yevgen Avatar answered Sep 21 '22 01:09

Yevgen