AppEngine + GWT-RPC +搜索API错误

时间:2018-04-29 19:32:50

标签: google-app-engine gwt google-cloud-platform

Appengine - 1.9.63

GWT - 2.8.1

客户端到服务器端调用:使用标准GWT RPC实现

服务器端代码:

IndexSpec indexSpec = IndexSpec.newBuilder().setName("index").build(); 
Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
Document doc = Document.newBuilder()...
try{
    index.put(doc); //Line that results in an exception
}catch(Exception e){
    e.printStackTrace();
}

堆栈跟踪:

com.google.apphosting.api.ApiProxy $ CallNotFoundException:无法在既不是原始请求线程也不是ThreadManager创建的线程的线程中进行API调用search.IndexDocument     在com.google.apphosting.api.ApiProxy $ CallNotFoundException.foreignThread(ApiProxy.java:800)     在com.google.apphosting.api.ApiProxy $ 1.get(ApiProxy.java:175)     在com.google.apphosting.api.ApiProxy $ 1.get(ApiProxy.java:172)     在com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:89)     在com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:89)     在com.google.appengine.api.search.FutureHelper.getInternal(FutureHelper.java:73)     在com.google.appengine.api.search.FutureHelper.quietGet(FutureHelper.java:32)     在com.google.appengine.api.search.IndexImpl.put(IndexImpl.java:485)     在com.vehicle.track.server.User.save(User.java:82)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:498)     在com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:587)     在com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:333)     在com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:303)     在com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:373)     在com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:707)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:790)     在org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)     在org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)     在org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)     在org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)     在org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)     at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)     在org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)     在org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)     at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)     在org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)     在org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)     在org.eclipse.jetty.server.handler.RequestLogHandler.handle(RequestLogHandler.java:95)     在org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)     在org.eclipse.jetty.server.Server.handle(Server.java:499)     在org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)     在org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)     在org.eclipse.jetty.io.AbstractConnection $ 2.run(AbstractConnection.java:544)     在org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)     在org.eclipse.jetty.util.thread.QueuedThreadPool $ 3.run(QueuedThreadPool.java:555)     在java.lang.Thread.run(Thread.java:748)

1 个答案:

答案 0 :(得分:0)

使用App Engine Java8运行时环境,您可以使用App Engine的ThreadManager API和Java的内置API创建线程,例如new Thread()。但是,正如documentation

中所述
  

目前,如果要调用App Engine API   (com.google.appengine.api。*),您必须从请求中调用这些API   线程或使用ThreadManager API创建的线程。

我可以在你的Stacktrace中看到你确实通过线程池使用了后台线程。您需要使用ThreadManager API实现它。