在我的api资源管理器中,我在向端点执行插入时遇到以下错误,该端点将一些数据插入到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."
}
}
此外,我在端点类中使用以下代码,其中firebase是静态对象引用。
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));
服务器上的日志如下:
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)
答案 0 :(得分:16)
要将Firebase与App Engine一起使用,您必须使用手动缩放。这是因为Firebase使用后台线程来侦听更改,而App Engine仅允许手动扩展后端实例上的长期后台线程。
将以下配置添加到appengine-web.xml
<manual-scaling>
<instances>1</instances>
</manual-scaling>