遗留Java GAE本地服务器连接Cloud DB遇错求助(SDK 1.9.84)
遗留GCP App Engine Java代码本地连接Cloud Datastore报错:ApiProxy$CallNotFoundException
环境背景
- 基于GCP的遗留Java代码库,使用
appengine-api-1.0-sdk-1.9.84.jar - 项目未使用Maven,WEB-INF/lib下的依赖jar包:
appengine-api-1.0-sdk-1.9.84.jar appengine-api-labs.jar appengine-api-labs-1.9.76.jar appengine-api-stubs-1.9.76.jar appengine-gcs-client.jar appengine-jsr107cache-1.9.76.jar appengine-mapper.jar appengine-testing-1.9.76.jar appengine-tools-sdk-1.9.76.jar charts4j-1.2.jar guava-11.0.2.jar javax.inject-1.jar json-20190722.jar
问题历程
最初在Filter的init方法中配置CloudDatastoreRemoteServiceConfig以连接Cloud Datastore时,遇到错误:
GlobalDatastoreConfig has already been set
排查发现是静态代码块提前初始化了DatastoreService,于是将所有DatastoreServiceFactory.getDatastoreService()调用替换为Const.java中的静态方法:
private static boolean hasInit = false; public static DatastoreService getDatastoreService() { if(!hasInit) { try { CloudDatastoreRemoteServiceConfig config = CloudDatastoreRemoteServiceConfig .builder() .appId(CloudDatastoreRemoteServiceConfig.AppId.create(CloudDatastoreRemoteServiceConfig.AppId.Location.US_CENTRAL, "gcp-project-id")) .build(); CloudDatastoreRemoteServiceConfig.setConfig(config); hasInit = true; } catch (Exception ignore) {} } return DatastoreServiceFactory.getDatastoreService(); }
该方法解决了初始化错误,但现在出现新的报错日志:
Dec 08, 2022 6:49:56 PM com.google.appengine.api.datastore.dev.LocalDatastoreService init INFO: Local Datastore initialized: Type: High Replication Storage: C:\Users\user\dev\repo\Celbux\core\Funksi179_NSFAS_modules\classes\artifacts\Funksi179_NSFAS_modules_war_exploded\WEB-INF\appengine-generated\local_db.bin Dec 08, 2022 6:49:56 PM com.google.appengine.api.datastore.dev.LocalDatastoreService load INFO: Time to load datastore: 20 ms 2022-12-08 18:49:56.757:WARN:oejs.HttpChannel:qtp1681595665-26: handleException / java.io.IOException: com.google.apphosting.api.ApiProxy$CallNotFoundException: Can't make API call urlfetch.Fetch in a thread that is neither the original request thread nor a thread created by ThreadManager 2022-12-08 18:49:56.762:WARN:oejsh.ErrorHandler:qtp1681595665-26: Error page too large: 500 org.apache.jasper.JasperException: com.google.apphosting.api.ApiProxy$RPCFailedException: I/O error
错误触发自以下代码行:
DatastoreService ds = Const.getDatastoreService(); Key ConstantKey = KeyFactory.createKey("Constants", 1); Entity Constants1 = ds.get(ConstantKey); // <-- 报错行
目标需求
希望本地运行的代码直接连接Cloud Datastore而非本地模拟器,以便调试多个共享同一云数据库的应用,求有相关遗留SDK经验的解决方案。
内容的提问来源于stack exchange,提问作者James
相关产品推荐
相关产品推荐

