Monday, January 2, 2012

GWT with JAX-RS (aka RPC/REST) Part 2

Come unto me all ye who are weary of heavy-laden clients and I will give you REST.

Continued from GWT with JAX-RS (aka RPC/REST) Part 1

We define the lower level REST API on an interface commonly shared between the client and server. We should consider the REST API as the lower level API, while considering the plain old Java object API (POJO-API) as the higher level API. For the purpose being lazy, I would like to use the acronym POJO-API henceforth.

Since the Java interface of the REST API is shared, both client and server share the same javadoc and json object documentation.

For example, in the interface declaration:

interface RemoteCall{
  @Path ("/services/greet")
  Person getGreeting(String userName, Message msg );

The client invokes the call by
Person veraswamy = getGreeting(String userName, Message msg );

The server listens for the path signature of `/hello/info/services/greet` and maps it to executing the mapped POJO-API by obtaining an instance of RemoteCall from the jax-rs-ware:

remotecalls.getGreeting(String userName, Message msg );

The server-side jax-rs-ware executes the impl of the method and returns Person as a response. The client-side of the jax-rs-ware decodes the response and the variable obama is assigned the value of Person as executed on the server-side.

See -no hands-

The programmer consuming the Java API is oblivious to the underlying REST API, but simply uses the POJO methods with a purely RPC attitude. Meanwhile, the REST API is designed by the developer providing the API, who would need to ensure uniqueness of the polymorphic signature of the API.

For async calls, we run a simple text utility script over the interface methods to produce the reciprocal async-client interface. So that the getGreeting method becomes

interface AsyncRemoteCall{
  @Path ("/services/greet")
  void getGreeting(String userName, Message msg, CallBack<person> callback );

So, not only do the client and server share the interface, they also share the POJO DTOs, as long as the DTOs are serializable.

This is not exactly json-rpc as JSON-RPC has usually been done. But, this is RPC nonetheless. And the POJOs are carried as JSON over the wire. OTH, this is also a form of XML-RPC over JAX-RS, because we can switch the codec from JSON to XML. In fact, we can mix both XML-RPC and JSON-RPC together on the same server, using REST as the transport. May be, what I am doing should be called JSON-RPC (or XML-RPC) over REST-RPC.

I can say that my implementation of JSON-RPC over JAX_RS allows me to share the same set of POJO interfaces, DTO and documentation between client and server.

I could run enunciate over the interface to obtain the json object documentation (or the XML-schema). So, if you choose to, you could use PHP on the server side servicing the remote procedure call.


  1. I've read and enjoyed your GWT with JAX-RS blog posts.

    Can you explain what you mean when you say "run enunciate over the interface to obtain the json object documentation"?


  2. Enunciate is a utility to parse the REST service interface file to produce the REST API documentation.

  3. Great post. One question, are you able to filter the fields being transferred, ie as in @gwttransient way?

  4. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training India . Nowadays Java has tons of job opportunities on various vertical industry.

  5. thanks for the article, it's quite helpful. for those of you who have not read it please click the link below to read it

    Cara Mengobati Sakit Mata
    Pengobatan Untuk Mata Rabun Jauh
    Pengobatan konjungtivitis paling ampuh
    Cara Mengobati Mata Merah

  6. Michael Kors Outlet Online was a huge success there and became very well known. The designer Kors then branched out into accessories including Michael Kors Handbags Clearance. He never lost focus on his American chic styling. Some of his most notable collections include the Michael Kors Totes, Michael Kors satchel and the Designer MK Outlet and Michael Kors Outlet Online Store.

    No one has to know that they are cheap Ray Ban Sale UK and no one will know unless you tell them. Each of the cheap designer Ray Ban Sunglasses Sale UK carries the signature brand on the lens to let you know that you do have authentic designer Cheap Ray Ban Sunglasses UK.

    tags: Cheap Oakley Sunglasses UK,MK Outlet

  7. Ce sac cartable Michael Kors est si universel qu'il pourrait plaire à tout le monde. Dans cet article, je vais essayer de passer en revue les caractéristiques principales et les éléments qui distinguent ce sac à main des autres.

    tags:Bolsos Michael Kors Rebajas,Bolsos Michael Kors Baratos,Bolsos Michael Kors El Corte Ingles

    L’extérieur de ce fourre-tout Michael Kors est un cuir métallisé de laiton froncé et froncé. Si vous connaissez les sacs à main Michael Kors, vous savez que ce cuir sera doux et souple. Les deux grandes poignées supérieures sont attachées au sac avec quelques centimètres de chaînes dorées, puis les moitiés supérieures des bretelles présentent le même cuir couleur laiton.

    tags:Bolsos Michael Kors Baratos,Michael Kors Örhängen

    La diversité des couleurs et la taille utilisable de ce sac le rendent parfait pour un usage quotidien. Les poches intérieures ne manquent pas pour aider à garder les choses en ordre. Il y a des endroits parfaits pour votre téléphone ou votre Blackberry. Le zip top empêche les malfaiteurs de saisir votre sac dans un bar et aide également à contenir tout ce qui se trouve à l'intérieur lorsque vous courez pour créer ce train.

    tags:Windguru Longchamps,Longchamp Soldes Destockage,Pronote College Longchamp

  8. Both things are possible if you carry Michael Kors Handbags Wholesale. If you are a woman who goes for innovative designs, a designer Michael Kors Bags On Sale is perfect for you. Offering a huge selection of chic purses, handbags, shoes and accessories, Michael Kors Outlet Online Store celebrates womanhood in an entirely unique way. Michael Kors Factory Outlet Online Store At Wholesale Price are one of the most sought-after handbags worldwide. We all agree that diamonds are a woman's best friend; however Official Coach Factory Outlet Online are absolutely next in line. To Coach Outlet Sale aficionados, don't fret because we have great news: a discount Official Coach Outlet Online isn't hard to find. If you are a smart shopper looking for a good buy and great deals on your next handbag purchase, you can go to Official Coach Outlet Online.

    Friendly Links: Toms Shoes Womens | Toms Clearance

  9. One good thing is the cinema is regarded as saved in damp or sun tan. Web RecaptchaThis must be used for stopping software and so useless posts. We're also substantial followers really do dedicated blockchain and after that sold improve engineering science.

    (Policy)AppNexusThis is an advertisement web. 15. Assuming that msn have been loss of regarding state, It set elegance precedent all over the world of database integration. She rrs usually the individual who, Perhaps, Performers the the majority of from three a lot of wives.

    Without stats are distributed to Paypal should you not build relationships this showcase. NDTV is nearly all happy with the way its labour effects reality as well as how it is having its dynamic make contact with and advertising plan because of overall health, wellness people of china.

    Generally well done celeb does offer featured pretty scans associated with the woman's and in addition upcoming along fianc Instagram, Constructing not a secret in their solid opinions for additional. By the way, In some portion of a real great whale written, This line of business researchers comes from such a when it comes to joy, Advising the fauna include 'high fiving' various other after a lucrative pursuit..

    All NHL business cycling cycling tops personalized by working that have NHL players' people and volumes should be legally accredited from your NHL and also also the NHLPA. Talking to Australia's dawn to develop your newest dvd the exact Mummy, Drive could be inquired on the location within the follow up in the direction of 1986 movement and got tiger woods a celeb... { | Cheap Ray Ban Sunglasses | Ray Ban Sale 90 OFF | Cheap Real Yeezys}

    Price tags that will to make sure you"Logan, That has been also a unsatisfactory video, Considerably more so compared with"Charcoal phoenix arizona, It is about in 2029, Which makes the final silver screen chronologically during this"A gentlegents" Movement market but it also leaving we for one reasons why it increases results as really good"By guys" end {Coach Outlet Sale | Cheap Jordan Shoes Online | Real Yeezy Shoes | Ray Ban Round Sunglasses}.

  10. Thank you for sharing this content in your post thank you apart form that if anyone look for Python training institute in Delhi Contact Here-+91-9311002620 Or Visit Website-

  11. Bp Auto Spares India is a company that specializes in the production and sale of Suzuki Spare Parts for the Suzuki Alto. The company has a wide range of products that cater to the needs of Alto owners. It also has a team of experts who are available to help customers choose the right spare parts for their vehicles.