Alternatives to RMI
Asked Answered
R

3

7

I have a small Java SE application, it´s practically a fat client sitting on top of a database. To further my Java skills, I decided to make a client-server application out of it. The server application communicates with the database and handles all kinds of lengthy operations, while the client application only receives the results, mostly ArrayLists of moderate length and primitives.

To this end, I started reading on RMI and did the Oracle tutorial, which I found surprisingly difficult to understand and even get to work.

Is there anything else I can use instead of RMI, without having to dive into JavaEE?

Rickie answered 25/3, 2014 at 7:44 Comment(12)
web services; give jersey tutorial a go; it is annotation based and requires very little plumbingMagnanimity
Wrong forum probably, vaadin is an entirely different approach though based on JavaEE. JavaFX might be interesting.Ramsden
When it comes to communication between two Java SE applications, RMI is a standard way. Which part of RMI you did not understand?Emptyhanded
@Santosh: RMI is not used that frequently nowadays. REST/JSON are used more and more because they work with other non-Java platforms.Sonya
While I understand not wanting to have to get into the low-level details of Java EE, would using an autoconfigured embedded Web server like Tomcat on Spring Boot be workable? This option lets you create HTTP APIs with little or no server configuration and simple controller code.Rives
@Sonya agreed its true only when you writing client server based application from scratch. The use case of OP is different. There is already a standalone application (fat client) which simply needs to be converted to client server mode (without using J2EE).Emptyhanded
@Emptyhanded Theoretically, there is not much to understand. The implementation problems are alienating me though, I seem to be having to deal with every Exception the API has to offer.Rickie
@Sonya That would involve redoing the application from scratch. While I might in the end, I prefer to explore my other options firstRickie
Lets think about the requirements here. What Java skill do you want to further(I mean what do you want to learn by going through this exercise)? Do you have time constraint? Will your new application be running on a single machine? Why re-architect the application to client-server model is desirable (only for educational purpose)?Israelite
@Israelite I have no deadline on this, but it´s on my free time, which isn´t much. This is, at this point, purely educational, I want to learn how to handle requests for data between two layers of an application which will run on multiple machines (atleast the clients will).Rickie
Ah I see. Although I would strongly recommend looking into J2EE and expose your server as REST/SOAP/XMLPRC service, here is an alternative to Java's RMI: code.google.com/p/gson-rmiIsraelite
I suggest you persevere a bit further with RMI before deciding on several orders of magnitude more complication with J2EE.Herzog
S
4

One way I would suggest would be to use JSON as the format for data exchange. You can use GSON to convert the data from Java objects to JSON and back. The transport could be done directly on the HTTP protocol using REST. You can use Jersey as a REST server/client or roll your own (since you don't want to use JEE, which Jersey is part of).

Sonya answered 25/3, 2014 at 7:49 Comment(5)
OP does not want to use J2EE. This would need a web container.Emptyhanded
@Santosh: Not really. One can use JSON as a data transfer protocol between clients and servers written from scratch if one wants to.Sonya
True, but that would require OP to write a server who which could serve REST (over HTTP). How else the clients would make request for data ?Emptyhanded
@Santosh: A very simple REST server can be written easily with Java. But obviously, it would be too simple and error prone. It is better to use something like Jersey or even a Servlet and send the response in JSON.Sonya
True I am with you but OP does not want to use J2EE. That means no servlet container.Emptyhanded
A
2

SIMON is as simple to use as RMI, but with fewer traps in the initial setup. It also has some advantages over RMI. Here is a simple hello-world example:

http://dev.root1.de/projects/simon/wiki/Sample_helloworld110

Alverta answered 18/8, 2014 at 7:59 Comment(0)
M
1

I take it RMI = Remote Method Invocation ...

You can have a look at XMLRPC, JSONRPC, JMS, or if you want to roll your own, use JSON to POST messages and convert the JSON back to a java object on the other side using GSON (from Google) or setup RabbitMQ and use AMQP to submit and receive messages if you don't want to handle the POSTing yourself, Spring AMQP makes it fairly easy to do this.

Montana answered 25/3, 2014 at 7:49 Comment(4)
You think this is less complicated than RMI ?Emptyhanded
They are all simple to implement, especially rolling your own JSON service.Montana
A link with an example would be appreciated.Emptyhanded
Each link already has examples, looking for specific examples?Montana

© 2022 - 2024 — McMap. All rights reserved.