0

I use Google Eclipse Plugin, develop a web page using GWT + GAE/Java. I would like to debug in localhost with the local GWT code but want to use the database in my actual deployed web page.

Is it possible?

lembas
  • 377
  • 1
  • 7
  • 21

2 Answers2

2

Yes, you can connect to your production database using Google App Engine Remote API. You can get inspired by Gealyk Remote Connector which is doing exactly the same. Check the Remote Connector Filter source code for example. Basically you need to create filter which

  1. Check if the Remote API is installed and if it's not install it using given credentials
  2. Proceed to your application code using chain.doFilter(request, response)
  3. Uninstall the Remote API Installer when the execution is finished

Just be careful that depending on your internet connection the application might be slow and sometimes timeouts.

musketyr
  • 808
  • 5
  • 16
  • musketyr, do you have any suggestion right now? "OAuth-based authorization not supported for clients running on App Engine" " http://stackoverflow.com/questions/33815315/how-to-debug-server-code-in-eclipse-on-appengine-database-oauth-based-remote-a – lembas Nov 20 '15 at 09:59
0

Filter doesn't work well with RemoteServiceServlets so add these to your RemoteServiceServlet:

RemoteApiOptions options;
RemoteApiInstaller installer;

@Override
protected void onBeforeRequestDeserialized(String serializedRequest) {
    if (getThreadLocalRequest().getRequestURL().indexOf("127.0.0.1") != -1) {
        if (options == null) {
            options = new RemoteApiOptions().server("example.appspot.com", 443).credentials("username",
                    "password");
            installer = new RemoteApiInstaller();
            try {
                installer.install(options);
                options.reuseCredentials("username", installer.serializeCredentials());
            }
            catch (IOException e) {
                e.printStackTrace();
            }
        }
        else {
            installer = new RemoteApiInstaller();
            try {
                installer.install(options);
            }
            catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

@Override
protected void onAfterResponseSerialized(String serializedResponse) {
    if (getThreadLocalRequest().getRequestURL().indexOf("127.0.0.1") != -1)
        installer.uninstall();
}
lembas
  • 377
  • 1
  • 7
  • 21