Java – Why Does Java Require a Servlet Container for Simple RPC Service?

javajsonrpctomcat

I have a big database controller which is written in Java. The controller reads information from the database, and interprets it into data structures which are then displayed in a CLI.

Java was chosen because writing code in it is fast and easy. Now I want to create an RPC server on top of the controller (XML-RPC or JSON-RPC for future AJAX calls), but it looks like I need a servlet container for my RPC service. I am confused because last year when I needed this kind of capability for another project in python, it took me less than 5 minutes to create the same functionality using the SimpleXMLRPCServer

The same ease of creation applies also to C# as far as I recall.

But in Java the story is different; now I need a servlet and therefore a servlet container (i.e Tomcat, Jetty) which means I need to install and maintain web servers. From what I can tell, JSON-RPC requires Spring framework in order to work.

I have already spent around two hours in learning the design and sort-of how Tomcat works without writing even one line of code.

I searched the web and found out that I have standalone options: I can use this library, but it doesn't seem maintained and it is also somewhat complex (I'm looking for something with decorators / annotations).
The other option I found is to use the so called "embedded" jetty and then trying to set it and configure it by code which also seems a tedious task.

Why isn't there a standalone mechanism for such a popular interface? Am I missing out something here?

Best Answer

Incorrect assumptions

Your assumption that you need servlets and a server is mis-guided and incorrect. there are plenty of embeddable HTTP servers in Java, some are single classes, they aren't full featured servers, but an HTTP server is just a TCP/IP Socket based protocol. The Servlet API is just a nice abstraction away from the details.

You don't want to do RPC, you want to do REST

You will need a minimal Servlet container to use something that will accelerate your development like RESTEasy.

Related Topic