views:

50

answers:

2

Hi,

I have a question, that may sound strange.
I am interested to know if J2EE containers allow to the applications deployed, to open direct server sockets (by-passing essentially the container) for their own purposes.
I know that it is strange to want to do that, but the reason I am asking is because, I have read that a javax.xml.endoint can not be started in a container, and was wondering if this is the reason.

UPDATE:The answers for this POST, seem contradicting to me. The one answer (by andri) refers to EJB specification that it is forbidden, yet the other answer by Codemwnci (backed up by a comment from Hippo) says that it is something used in production. I am not sure what to conclude from this posts. Can anyone help on clearing this?

Thank you.

+2  A: 

I have a web application that runs on the WebSphere application server (WAS 7). In one of the applications, as part of a servlet that runs when the application starts, I create a ServerSocket.

This is running in a large scale production environment and has worked for many years.

Codemwnci
@Codemwnci:Thank you.Could there be any difference in other container implementations? I think that for example in allowing threads from applications, the approach various containers take, differs. Some disallow it. Or am I confused on this?
+1. I'm working on a similar product that runs on both Websphere and Tomcat.
Hippo
@user384706 I have never heard of that particular restriction, but that is not to say there is one. Each vendor may do their own thing, so it is hard to say for definite.
Codemwnci
+2  A: 

Strictly speaking, it is forbidden by the EJB specification, just as managing your own threads is forbidden:

An enterprise bean must not attempt to listen on a socket, accept connections on a socket, or use a socket for multicast.

The likely reason for disallowing this are distributed applications and moving EJBs between application server instances. The "official" solution for opening a raw socket is to write a JCA connector.

andri
@andri:This applies only to EJB's though right?Not any kind of servlet web app. Or I am confused on this?