Skip to main content

Telnet client inside EJB

1 reply [Last post]
Joined: 2009-08-27


I'm trying to use a Telnet client (using the libraries from Apache Commons-Net) in a Stateless Bean but I have trouble doing and I think it is because these beans can not have this type of elements. My application must read requests from a database and as execute various commands such through an existing Telnet connection which I think is a good idea to open the connection in a Singleton Bean for another Stateless Bean (programmed with a schedule @Schedule) use this connection, so my question is. How do I make a Stateless Bean use the POJOs (in this case the Telnet connection) of a Singleton Bean?.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2007-10-21

Inbound/outbound communications from the EJB world to the the "outside" world should theoretically be done through JCA connector. You can google "jca telnet connector", there seem to be a few people who developped such connector.
Using JCA is only a recommendation, and you can maybe use the telnet package right from you session bean.
Note also that if what you want is to have one connection that is initialized at startup, another way would be to use a ServletContextListener to open the connection and store it in a static field. It's not really great, because static field are also theoretically prohibited in the EJB spec, but it should work nevertheless.
Beware also to check if the telnet connection is thread-safe or not.