GWT Phonegap and App Engine RPC

1497 views
Skip to first unread message

John Gentilin

unread,
Apr 2, 2012, 2:49:06 AM4/2/12
to mgwt
With GWT PhoneGap, can you make RPC calls to an AppEngine server
hosted by Google/AppSpot ?

-John Gentilin

Daniel Kurka

unread,
Apr 2, 2012, 11:57:34 AM4/2/12
to mg...@googlegroups.com
Of corse you can use GWT RPC from your phonegap app, you need to take some things into consideration though: http://blog.daniel-kurka.de/2011/01/gwt-rpc-with-phonegap.html

John Gentilin

unread,
Apr 2, 2012, 7:23:02 PM4/2/12
to mgwt
Hi Daniel,

Thank you for pointing out that post. I actually saw it a month or so
back when
I was first visiting this issue but I could not find it again last
night for the life of me.

There are two comments to that post that seem to cast a doubt if that
mechanism
will work with App Engine apps hosted @ Google. Are these real issues
or just
end user config issues ?

-John Gentilin

Daniel Kurka

unread,
Apr 3, 2012, 1:14:08 AM4/3/12
to mg...@googlegroups.com
GWT RPC and phonegap work on google app engine. Those comments should be config issues.

-Daniel

John Gentilin

unread,
Apr 6, 2012, 6:59:05 AM4/6/12
to mg...@googlegroups.com
Hi Daniel,

I have my app so I can set the service point and I proved that when it's running in hosted
mode that I can the change occurs and I can redirect the service point. So I compiled
and ran my GWT PhoneGap app. The app launches and tries to connect to the server
but I get an error about a missing Serialization Policy, the error below. I don't think its a
missing file on the client although I did verify that the serialization policy file is in my
PicRollrMobilePG app directory..

It looks like in RemoteServiceServlet::loadSerializationPolicy the moduleBaseURL is the
offending variable. I chased it back through the stack and it appears that the value is originated
from a Header in the request called X-GWT-Module-Base. See the Request info below.

Have you seen this before ?

-John Gentilin

Request Header

POST /PicRollrMobile/yavcf HTTP/1.1
Host: 192.168.1.250:8888
User-Agent: Mozilla/5.0 (iPhone Simulator; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9A334
Content-Length: 441
Accept: */*
Origin: file://
X-GWT-Module-Base: file:///Users/gentijo/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/C79E5FC5-C3B9-4819-90AE-BF9EE9A8773D/PicRollrIOS.app/www/PicRollrMobilePG/
Content-Type: text/x-gwt-rpc; charset=UTF-8
X-GWT-Permutation: E8F159F312B9E0D13DC54B4C142451D1
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: keep-alive


Error on the Console of Eclipse running the Server instance.

INFO: javax.servlet.ServletContext log: YAVCFServlet: ERROR: The serialization policy file '/Users/gentijo/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/C79E5FC5-C3B9-4819-90AE-BF9EE9A8773D/PicRollrIOS.app/www/PicRollrMobilePG/913D86783F4956456B02EABF1CB48BA1.gwt.rpc' was not found; did you forget to include it in this deployment?
Apr 6, 2012 10:16:14 AM com.google.appengine.tools.development.ApiProxyLocalImpl log
INFO: javax.servlet.ServletContext log: YAVCFServlet: WARNING: Failed to get the SerializationPolicy '913D86783F4956456B02EABF1CB48BA1' for module 'file:///Users/gentijo/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/C79E5FC5-C3B9-4819-90AE-BF9EE9A8773D/PicRollrIOS.app/www/PicRollrMobilePG/'; a legacy, 1.3.3 compatible, serialization policy will be used.  You may experience SerializationExceptions as a result.
Apr 6, 2012 10:16:14 AM com.google.appengine.tools.development.ApiProxyLocalImpl log
SEVERE: javax.servlet.ServletContext log: YAVCFServlet: An IncompatibleRemoteServiceException was thrown while processing this call.

Daniel Kurka

unread,
Apr 6, 2012, 7:46:31 AM4/6/12
to mg...@googlegroups.com
Did you overwrite doGetSerializationPolicy" as suggested in my blogpost?

Because this sounds exactly like the behavior if you don`t.

-Daniel

John Gentilin

unread,
Apr 7, 2012, 12:35:36 AM4/7/12
to mg...@googlegroups.com
So for some reason I skipped over that section, my bad.. Although I am glad I did, it forced me to
comb through the code and understand the process flow. Now the comment left by "PRY" makes
sense, he is referring to the class com.sun.net.httpserver.Authenticator.Result in your RemoteServiceServlet
subclass. I don't think that any of the com.sun.* classes are on the whitelist for appspot/GAE apps.

The whole problem stems around a Http Header, X-GWT-Module-Base, that is populated
in com.google.gwt.user.client.rpc.RpcRequestBuilder in this method.

  protected void doFinish(RequestBuilder rb) {
    rb.setHeader(STRONG_NAME_HEADER, GWT.getPermutationStrongName());
    rb.setHeader(MODULE_BASE_HEADER, GWT.getModuleBaseURL());
  }


I initially found a workaround by overloading the RemoteServiceServlet::doGetSerializationPolicy
with the code below. Later I was reading the JS output from the GWT Compiler and noticed that
the $moduleName and $moduleBaseURL are used throughout the code. $moduleName is used as
the ID for some elements and such.. So instead of using the server based code I decided to see if
I could fix this from the client side to make everything more legitimate.  So I added two native methods
in my entry point that  allows me to set those variables. Note: GWT.getModuleName() and GWT.getModuleBaseURL()
are driven from native methods in the com.google.gwt.core.client.impl.Impl class with the same name.

Methods added to my entry point class.

 public static native void setModuleName(String name) /*-{
    $moduleName = name;
  }-*/;

  public static native void setModuleBaseURL(String url) /*-{
     $moduleBase = url;
  }-*/;


then I created a constructor in my EntryPoint class, which for me is the following

  public PGMobileEntryPoint()
  {
    setModuleName("PicRollrMobile");
    setModuleBaseURL("http://192.168.1.250:8888/PicRollrMobile/");
    m_rcp = new RemoteCommandProxy();
    m_rcp.setServiceEntryPoint("http://192.168.1.250:8888/PicRollrMobile/yavcf");
  }

RemoteCommandProxy is a class I created that manages my RemoteService class.

Now it works without the Server based modification..

Also it appears that if the Module's constructor is called in the JS file, all these items
will be set up correctly which may be something that can be generically handled in
GWT Phonegap.. i.e. for me in my PicRollrMobile.nocache.js, the top of the code
sets the moduleName.. Note: I compiled in "Pretty" mode.


function PicRollrMobile(){
  var $wnd_0 = window, $doc_0 = document, $stats = $wnd_0.__gwtStatsEvent?function(a){
    return $wnd_0.__gwtStatsEvent(a);
  }
  :null, $sessionId_0 = $wnd_0.__gwtStatsSessionId?$wnd_0.__gwtStatsSessionId:null, scriptsDone, loadDone, bodyDone, base = '', metaProps = {}, values = [], providers = [], answers = [], softPermutationId = 0, onLoadErrorFunc, propertyErrorFunc;
  $stats && $stats({moduleName:'PicRollrMobile', sessionId:$sessionId_0, subSystem:'startup', evtGroup:'bootstrap', millis:(new Date).getTime(), type:'begin'});



Server side method override, first attempt..

protected SerializationPolicy doGetSerializationPolicy(
      HttpServletRequest request, String moduleBaseURL, String strongName) {
    if (moduleBaseURL.startsWith("file:"))
    {
      String url = request.getRequestURL().toString();
      int lastSlash = url.lastIndexOf("/");
      if (lastSlash != -1)  url = url.substring(0, lastSlash+1);
      return super.doGetSerializationPolicy(request,url, strongName);
    }
    else
    {
      return super.doGetSerializationPolicy(request,moduleBaseURL, strongName);
    }
  }


-John Gentilin

Daniel Kurka

unread,
Apr 7, 2012, 2:49:51 PM4/7/12
to mg...@googlegroups.com
Hi John,

thank you for digging this deep. Actually I think that we should be able to write a linker that modifies the boot script so that we could include the server url directly (inside the gwt xml file), or make it at least globally configurable through a custom class.

I created an issue for tracking this: http://code.google.com/p/gwt-phonegap/issues/detail?id=38

Thanks for digging,

-Daniel

John Gentilin

unread,
Apr 7, 2012, 8:47:10 PM4/7/12
to mg...@googlegroups.com
Daniel,

Small changes to my previous post..

moduleName is only the module name in my case that would be "PicRollrMobile" and not
the shortened URL, late night hacking had me mix up the variables moduleName and moduleBaseURL..

Changing moduleBaseURL fixes the server but poses a small problem. I noticed in the GWTPhoneGap
code you reference GWT.getModuleBaseURL() to use as a base directory for file fetches. I noticed
because I am about to attack the camera module and that is how the file is read for storage mode.
Maybe GWTPhoneGap should store this as a different variable and clone the value before the entry
point has a chance to modify it..

Have you looked into this project, https://github.com/urish/gwt-titanium. Uri has a custom linker that
outputs all the segments as a single file. I am thinking of using it just so I can have an ANT script
that will compile my GWT PhoneGap and emit the code directly to the XCode project as well as
sync'ing my assets.
https://github.com/urish/gwt-titanium/blob/master/src/main/java/org/urish/gwtit/dev/linker/GwtTitaniumLinker.java

Although there may be a problem with that strongName used for the serializer.  My best guess here is the
name of the file is derived using a hash of the serialization.rpc contents, so it's assured that you are specifying
the same serialization policy on the client side is the one used on the server. So even though the compiled
output is encapsulated in the PhoneGap app, the RPC files need on the server side.. It may be easier to
just use the Eclipse Plugin to compile and the Ant Task to copy but its still a good example of how to
manipulate the linker.


-John Gentilin

Daniel Kurka

unread,
Apr 30, 2012, 12:25:33 PM4/30/12
to mgwt
I just revisited the issue and introduced a utility method to gwt
phonegap which will set the headers on the client as needed, see:
http://blog.daniel-kurka.de/2012/04/gwt-rpc-with-phonegap-revisited.html

On 8 Apr., 02:47, John Gentilin <gent...@gmail.com> wrote:
> Daniel,
>
> Small changes to my previous post..
>
> moduleName is only the module name in my case that would be
> "PicRollrMobile" and not
> the shortened URL, late night hacking had me mix up the variables
> moduleName and moduleBaseURL..
>
> Changing moduleBaseURL fixes the server but poses a small problem. I
> noticed in the GWTPhoneGap
> code you reference GWT.getModuleBaseURL() to use as a base directory for
> file fetches. I noticed
> because I am about to attack the camera module and that is how the file is
> read for storage mode.
> Maybe GWTPhoneGap should store this as a different variable and clone the
> value before the entry
> point has a chance to modify it..
>
> Have you looked into this project,https://github.com/urish/gwt-titanium.
> Uri has a custom linker that
> outputs all the segments as a single file. I am thinking of using it just
> so I can have an ANT script
> that will compile my GWT PhoneGap and emit the code directly to the XCode
> project as well as
> sync'ing my assets.https://github.com/urish/gwt-titanium/blob/master/src/main/java/org/u...
> > *Methods added to my entry point class.*
> > *Server side method override, first attempt..*
> >> *Request Header*
>
> >> POST /PicRollrMobile/yavcf HTTP/1.1
> >> Host: 192.168.1.250:8888
> >> User-Agent: Mozilla/5.0 (iPhone Simulator; CPU iPhone OS 5_0 like Mac OS
> >> X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9A334
> >> Content-Length: 441
> >> Accept: */*
> >> Origin: file://
> >> X-GWT-Module-Base:
> >> file:///Users/gentijo/Library/Application%20Support/iPhone%20Simulator/5.0/ Applications/C79E5FC5-C3B9-4819-90AE-BF9EE9A8773D/PicRollrIOS.app/www/PicRo llrMobilePG/
> >> Content-Type: text/x-gwt-rpc; charset=UTF-8
> >> X-GWT-Permutation: E8F159F312B9E0D13DC54B4C142451D1
> >> Accept-Language: en-us
> >> Accept-Encoding: gzip, deflate
> >> Connection: keep-alive
>
> >> *Error on the Console of Eclipse running the Server instance.*
> ...
>
> Erfahren Sie mehr »

John Gentilin

unread,
May 1, 2012, 3:35:02 PM5/1/12
to mg...@googlegroups.com
Suggestion to make this easier, can the GWTPhoneGap code pick up the
module URL and name from the .plist file. or anywhere that would not require
a GWT recompile ?

Any time frame when GWTPhoneGap 1.7 will be ready.. Currently GWTPhonegap
does not work with 1.6.1, correct ?

Thank you for the props..

-John Gentilin

Katharina

unread,
May 2, 2012, 3:28:51 AM5/2/12
to mgwt


On 1 Mai, 21:35, John Gentilin <gent...@gmail.com> wrote:
> Suggestion to make this easier, can the GWTPhoneGap code pick up the
> module URL and name from the .plist file. or anywhere that would not
> require
> a GWT recompile ?

actually you don`t need to specify the modulename (we already got
that)

This is the utility method:
>>public static void prepareService(ServiceDefTarget service, final String moduleUrl, String relativeServiceUrl)

you will need the full url to your server and the relative for the
concrete servlet.



>
> Any time frame when GWTPhoneGap 1.7 will be ready.. Currently GWTPhonegap
> does not work with 1.6.1, correct ?

We need to wait for the next release candidate of phonegap 1.7.rc2
(there is a major bug in rc1 that daniel helped fixing).
As soon as we have a new phonegap release (or candidate we can update
gwt phonegap)

If you like to use it right now I could send you the fixed phonegap js
for android and ios, that you can use with gwt phonegap trunk and
phonegap 1.7.rc1
> ...
>
> Erfahren Sie mehr »

John Gentilin

unread,
May 2, 2012, 4:06:59 AM5/2/12
to mg...@googlegroups.com
Katharina,

The point I was trying to make is that it would be great if GWTPhoneGap could retrieve those settings
from the PhoneGap.plist or Cordova.plist files so they can be set from the XCode env. Right now I would
need to change the GWT / Java code, redo a GWT compile, then recompile the Xcode app.. Today I was
jumping back and forth between Dev and production and redoing the GWT compile was a real drag..

I could give PhoneGap 1.7 a try.. send me the files.. I am very interested to see if the camera module
works with IOS 4.1 now.

-John Gentilin

Daniel Kurka

unread,
May 2, 2012, 5:31:35 AM5/2/12
to mgwt
the 1.7.0 phonegap tags are already in the git repos we should see a
realease very soon!
> ...
>
> Erfahren Sie mehr »

Daniel Kurka

unread,
May 2, 2012, 6:01:29 PM5/2/12
to mg...@googlegroups.com
phonegap is now released, download the gwt phonegap snapshot and test it.

We are going to do the same in the next days and if everything is going fine we have a new release.

-Daniel
Reply all
Reply to author
Forward
0 new messages