Reputation: 1
I have a Java EE app running on Tomcat that needs to connect to another Java EE app(host system) running on JBoss which accepts client connections using sockets.
What is the best way to connect to this system in order to send and receive messages?
I am currently using sockets to send and receive message to the Java EE app (host system). But I found in the Java EE specification that use of sockets in a Java EE app is a bad practice. As the host system is listening to clients over sockets on a specific port, how can I connect to this system from my java web application?
Upvotes: 0
Views: 939
Reputation: 6567
Without more details on how to communicate with the host system, I'm just going assume it uses a proprietary, sockets-based binary protocol and is purely client-server (i.e., not full-duplex where you need a listener on the client side).
Off the top of my head, I can think of a couple of options:
Use raw sockets. Just make sure not to keep them open for too long and close them properly. It sure sounds like the host system itself isn't following Java EE recommendations to the letter—so why should you?
Write a JCA resource adapter. The Java EE 'preferred' way of handling custom/legacy resources or messaging. Essentially, this turns the host system into a resource accessible via the Common Client Interface, and lets the container manage the lifecycle of your sockets/threads.
However, in the interest of the simplicity and not-over-engineering I say if raw sockets work for you then just use them until forced not too.
Unless you see value in making the custom service available via JCA, then it'd be hard to justify the effort.
You can even use an ESB platform to expose a Web service on one end and talk to the server via sockets on the other—but to me that's just even more 'accidental' complexity.
Upvotes: 1