Hi,

As it happens, I have also just this evening spent some time working
with GWT and Thrift. What I wanted to do was to consume Thrift
services from GWT using JSON. Here's what I've done.

1) Created a stripped down jar of Thrift, axed most protocol,
transport and server implementations, in order to get a
JavaScript-translatable version of Thrift. I did not need to change
any of the base Thrift classes, nor modify the compiler for GWT to
translate the structs, but I might have missed something here
(Mathias?).

2) Added an option for the Thrift Java compiler to generate
asynchronous service interfaces and client proxies. This is manifested
as:

public class Repository {
  public interface Iface {
    public Document get_document(String uri) throws TException;
    public int get_count() throws TException;
  }

  public interface AsyncIface {
    public void get_document(String uri, TAsyncCallback<Document>
callback) throws TException;
    public void get_count(TAsyncCallback<Integer> callback) throws TException;
  }
...

This is done inline with GWT's RPC framework and gives the developer
the standard synchronous interface to implement on the server side (I
use it with embedded Jetty in a daemon) and an asynchonous interface
to use in the GWT client. TAsyncCallback<T> just has a plain
onSuccess(T result) method.

3) Implemented a client transport using GWT's RequestBuilder (the
XmlHttpRequest abstraction) that executes the TAsyncCallback
asynchronously when the response has been received.

4) Modified the JSONProtocol slightly to be fully
JavaScript-translatable. This could probably be more efficiently done
by using GWT's JSNI framework, but I really haven't had the time to
optimize anything yet.

This actually works pretty well, considering the time I've spent on it
so far. I don't known if the asynchronous stuff is usable for anything
else (NIO-socket-based-server or whatever), the whole this is mostly a
hack, but I'll clean up the code and post it to JIRA if anybody's
interested.


Fredrik



On Sat, Sep 6, 2008 at 10:45 PM, Mathias Herberts
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> I've been playing with both GWT and Thrift lately and have come up
> with a solution that might prove of interest for others.
>
> Not knowing if any other solution has been devised yet here is what I
> came up with.
>
> I patched the Java code generation to generate 'issetX' methods that
> return the value of __isset.x.
>
> I also added an option to the Java code generator (gwt) which
> generates GWT translatable mirror classes (but does not take care of
> services). Basically those mirror classes are similar to the ones
> normally generated except they do not extend TBase. They are
> translated correctly by GWT 1.5.
>
> A utility class (called GWT) provides a static method 'convert' which
> can convert between both versions of the generated classes (this
> method needs the issetX methods to be ensure the classes being
> converted are indeed ones generated by the thrift compiler).
>
> If anyone is interested I'll gladly contribute this code.
>
> Mathias.
>

Reply via email to