lembas
lembas

Reputation: 487

debug in localhost using deployed database

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?

Upvotes: 0

Views: 130

Answers (2)

lembas
lembas

Reputation: 487

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

Upvotes: 0

musketyr
musketyr

Reputation: 828

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.

Upvotes: 2

Related Questions