views:

251

answers:

4

I'd like to write an applet (or a java Web start application) calling its server (servlet?) to invoke some methods and to send/retrieve data. What would be the best way/technology to send and to retrieve those message ?

+1  A: 

HTTP requests? Parameters in, xml out.

alamar
Yes, but I was hoped there was an interface-based solution (just like RMI ?). Where I would call an asynchronous method and my objects would be returned without parsing/validating the XML.
Pierre
I think you'll make your own api on top of xstream+commons_httpclient a waaaay faster than you'll figure out which lib to use.
alamar
+1  A: 

XML is still my preferred choice for data interchange.

Using XML with something like xstream that removes much of the hassle of XML Java libraries. You can serialize and deserialize objects in a very simple way.

dfa
+1  A: 

Protocol:

If you don't care about interoperability with other languages, I'd go with RMI over HTTP. It has support right from the JRE, quite easy to setup and very easy to use once you have the framework.

For applicative logic, I'd use either:

  1. The command pattern, passing objects that, when invoked, invoke methods on the server. This is good for small projects, but tends to over complicate as time goes by and more commands are added. Also, it require the client to be coupled to server logic.
  2. Request by name + DTO approach. This has the benefit of disassociating server logic from the client all together, leaving the server side free to change as needed. The overhead of building a supporting framework is a bit greater than the first option, but the separation of client from server is, in my opinion, worth the effort.

Implementation:

If you have not yet started, or you have and using Spring, then Spring remoting is a great tool. It works from everywhere (including applets) even if you don't use the IOC container.
If you do not want to use Spring, the basic RMI is quite easy to use as well and has an abundance of examples over the web.

Ran Biron
A: 

A lightweight solution could be Hessian too.

A simple example is here.

If you need an ORM for that case: try Cayenne.

Karussell