简体   繁体   中英

RemoteApi calls from servlet not loading in local app engine app

I'am trying this example https://cloud.google.com/appengine/docs/java/tools/remoteapi Everything works fine if I run script as java application, but when I do it as servlet it always loads forever and doesn't throw any errors. Also works fine on localhost. Also I noticed it happens when query is made, when I comment it out (datastore.put), servlet loads instantly.

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();
    }
    }
}

我知道了,需要使用RemoteApiOptions()。useServiceAccountCredential(“ service email”,“ p12key”)而不是useApplicationDefaultCredential()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM