首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有在本地应用程序中加载servlet的RemoteApi调用

没有在本地应用程序中加载servlet的RemoteApi调用
EN

Stack Overflow用户
提问于 2016-04-17 01:19:06
回答 1查看 82关注 0票数 0

如果我将脚本作为java应用程序运行,那么我正在尝试这个示例https://cloud.google.com/appengine/docs/java/tools/remoteapi --一切都运行得很好,但是当我作为servlet运行脚本时,它总是永远加载,不会抛出任何错误。在本地主机上也可以很好地工作。我还注意到,当查询完成时,当我注释掉它(datastore.put)时,servlet会立即加载。

代码语言:javascript
复制
import java.io.IOException;
import javax.servlet.http.*;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.tools.remoteapi.RemoteApiInstaller;
import com.google.appengine.tools.remoteapi.RemoteApiOptions;

@SuppressWarnings("serial")
public class Gae_java_Servlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    RemoteApiOptions options = new RemoteApiOptions()
        .server("java-dot-project.appspot.com", 443)
        .useApplicationDefaultCredential();
    RemoteApiInstaller installer = new RemoteApiInstaller();
    installer.install(options);
    try {
        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        System.out.println("Key of new entity is " +
                datastore.put(new Entity("Hello Remote API!")));
    } finally {
        installer.uninstall();
    }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-18 03:08:06

我想出来了,需要用RemoteApiOptions().useServiceAccountCredential("service电子邮件“,”p12key“来代替useApplicationDefaultCredential()

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36671668

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档