views:

297

answers:

1

I'm writing a JAX-RS web service. It responds to client invocations by:

  1. Retrieving some info from a database
  2. Making a call to an external server

For 2) the server does not expose a web service interface (i.e. no WSDL interface or REST API). Instead, it uses a custom protocol over TCPIP. I'd like to make client calls from my JAX-RS resource directly to this server but I don't want to have to open a connection, authenticate, and close the connection for each call to my JAX-RS resource. Is there a way around this? In other words, is there something like a "socket connection pool" available to Java EE apps? Would I have to use something like an ESB? Or is there an alternative that I'm overlooking?

+1  A: 

The "right" way to do this would be to write a JCA connector for your external server. JCA is part of the Java EE stack, and is meant exactly for that: to provide inbound and outbound connectivity from the application server to external system. It supports pooling, authentication, transaction, etc. (Database and JMS broker are accesss through JCA connectors, btw).

Writing such an adapter can however be quite hard. Maybe investigate a lightweight approach which a generic pooling library (maybe you find something interesting in commons-pool, or c3p0) may be easier.

Have a look also at this answer about TCP connection pooling.

ewernli