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:

@Path("/hello/info")
interface RemoteCall{
  @Path ("/services/greet")
  @POST
  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")
  @POST
  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.


13 comments:

  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"?

    Thanks!

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

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

    ReplyDelete
  4. 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

    ReplyDelete
  5. 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... {facebook.com | 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}.

    ReplyDelete
  6. 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.

    ReplyDelete