views:

211

answers:

3

We would like to serve some client requests within our J2EE application server (JBoss 4.2.3). I read that the J2EE spec doesn't allow opening a socket from an enterprise bean. But the spec suggests no alternatives.

Specifically, enterprise beans should not:

  • listen on, accept connections on, or multicast from a network socket

So the question is: What can I do to serve some binary tcp based protocols (not http) from within an application server?

Here someone suggests to implement a resource adapter. Is this the way you have to go or are there other (easier) solutions?

+1  A: 

Neither should you access files :(

This is in the spec because EJBs have to be:

  • distributable (you don't know beforehand on what server/instance your EJB will be deployed
  • the container is to be able to manage "everything" so you must not spawn your own threads

That in mind nothing will halt you from starting a server socket in your app (the best place would probably be in a servlet) but you should take care about how the serversocket is closed when your app goes down...

pgras
+3  A: 

You're right, since you can declare transactions for every thing in J2EE they must be supported from all components you want to connect. Files if any should be stored in a database. Everything should be controlled by the container, because it the only way to have a scaling application using J2EE.

A few options:

stacker
+1: Thanks for the link to the JCA example.
tangens
+1  A: 

Right now I implement a workaround:

alt text

I use a standalone java application that accepts tcp calls from the client and forwards them as JNDI calls to the application server.

tangens
Java Naming and Directory Interface (JNDI) you usually make lookup calls, you could lookup an ejb and make remote calls to process the data received from your standalone server.
stacker