views:

451

answers:

4

Currently, I only know a way of doing RPC for POJOs in Java, and is with the very complex EJB/JBoss solution.

Is there any better way of providing a similar functionality with a thiner layer (within or without a Java EE container), using RMI or something that can serialize and send full blown objects over the wire?

I'm not currently interested in HTTP/JSON serialization BTW.

EDIT: For clarification: I'm trying to replace an old EJB 2.1/JBoss 4 solution with something more easy to manage at the container level. I need to have entire control over the database(planning to use iBATIS which would allow me to use fairly complex SQL very easily), but the only things I want to keep over the wire are:

  • Invocation of lookup/data modification methods (automagic serialization goes here).
  • Transparent session control (authentication/authorization). I still have to see how to accomplish this.

Both items have to work as a whole, of course. No access should be granted to users without credentials.

Because I'm not very fond of writing webapps, I plan to build a GUI (Swing or SWT) that would only manage POJOs, do some reporting and invoke methods from the container. I want the serialization to be as easy as possible.

A: 

You could try XStream (http://xstream.codehaus.org) over REST. Easy to apply on e pre-existing set of pojos.

Can you give some further information as to what you're trying to achieve, since you're not interested in rest/json ?

krosenvold
I have added some clarifications to my original question. In short, I'm trying to find a container server/something that would allow me to use RMI as easy as possible, and also keep session information. I don't know how I'd manage to use JSON/REST information without using a servlet container.
Camilo Díaz
A: 

Simple RPC is exactly what RMI was built for. If you make a serializable interface, you can call methods on one app from another app.

Paul Tomblin
If the calls are restricted to an intranet, RMI is simple, robust, and hard to beat.
erickson
Seems interesting. I'm looking somehow for a contained-managed wrapper over RMI that would require me to write the least amount of code and also keep session information through each call. Something over what JBoss RPC provides, but far simpler.
Camilo Díaz
This is a bit longwinded and all that code seems unnecessary to answer the question.
cletus
Yeah, I was having second thoughts about the code.
Paul Tomblin
A: 

If you only need value objects then just ensure the POJOs implement Serializable and write the objects across sockets (using ObjectOutputStream). On the receiving end read the objects using ObjectInputStream. The receiving end has to have a compatible version of the POJO (see serialVersionUID). Hessian/Burlap 'protocol-ize this: http://hessian.caucho.com/ and http://www.caucho.com/resin-3.0/protocols/burlap.xtp

+2  A: 

As is nearly always the case, Spring comes to the rescue. From the reference documentation, you will want to read Chapter 17. Remoting and web services using Spring.

There are several methods to choose from. The beauty of Spring is that all your interfaces and implementations are vanilla POJOs. The wiring into RMI or whatever is handled by Spring. You can:

  1. Export services using RMI: probably the simplest approach;
  2. Use HTTP invoker: if remote access is an issue, this might be better for firewalls, etc than pure RMI; or
  3. Use Web Services, in which case I would favour JAX-WS over JAX-RPC.

Spring has the additional benefit in that it can do the wiring for both the server and the client, easily and transparently.

Personally I would choose either (2) or (3). HTTP is network friendly. It's easy to deploy in a Web container. Jetty's long-lived connections give you the option over server push (effectively) over HTTP.

All of these methods allow complex objects to be sent across the wire but they are subtly different in this regard. You need to consider if your server and client are going to be distributed separately and whether it's an issue if you change the interface that you need to redistribute the class files. Or you can use a customized serialization solution (even XML) to avoid this. But that has issues as well.

Using a Web container will allow you to easily plug-in Spring Security, which can be a bit daunting at first just because there are so many options. Also, HttpSession can be used to provide state information between requests.

cletus