简体   繁体   中英

Best practice to communicate with Java EE server

We have a Swing application. Now I need to set up a Java EE server that provides some services to these Swing clients on a LAN.

What is the best practice to implement this, considering that client and server communicate in both ways?

If the clients are in the LAN and you are programming both sides I would take RMI. Because it is much more performant than Webservices. I think it is the native way for communication with a Java EE Server.

Perhaps you should create Facade classes on the server-side which are providing the services.

Using JAX-RS with implementations like Jersey or Apache CXF with XML or JSON data format is a decent option.

If you need flexibility, go with Spring remoting , as it abstracts the remoting layer, so an eventual change of implementation keeps your hands clean.

I use HTTP Invoker , beacuse it's lightweight and uses java serialization, so it's a good choice for Java client -> Java server communication.

The downside of HTTP Invoker, in contrast to RMI, is that you always get new instances of objects from the server, so if an object sent from the client is changed on the server, the change won't be reflected in the client instance.

Good info is here: Considerations when choosing a technology

I would advice using Webservices .

  • RMI - This is pretty fine for Java applications, but it's general interoperatibility is imho low. If i imagine that you would like to switch from Swing to other technology or add another client not written in Java, RMI would be nightmare then.

  • Web services - It does not cover both directions communication. It's fine for Swing - Java EE, but you would have to do also some WS (or any other exposing mechanism) on Swing side which would take care of Java EE - Swing communication. Eg like REST on Java EE and XML-RPC on Swing.

You can also think of using ESB .

I would suggest Spring RPC or maybe EJB 3 if you have a Java EE server and prefer to stick to standards of Java EE specification Web Services are not binary and therefor will suffer from performance issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM