• Post Reply Bookmark Topic Watch Topic
  • New Topic

J2EE server listening to socket  RSS feed

 
Ragav Baskaran
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I have a requirement to receive a set of character data through Socket.
Some how(dont know how) i have to receive the message from the socket and make a call to my business ejb.

Logically my ejb should act like a listener to a socket.
The client(Non J2EE) who transmit data via socket, doesn't have the ability to make a direct ejb call.

Please advice if we have such provision in a J2EE server.

Any discussion related to this topic. Please forward.

Thanks,
Ragavendran
 
Bupjae Lee
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want to make some ejb "listening" on a socket?

Unfortunely, However, listening on a socket is prohibited in the EJB container.

I quote from Specification of Enterprise JavaBeans 3.0 Final release (ejbcore), section 21.1.2 Programming Restrictions


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

The EJB architecture allows an enterprise bean instance to be a network socket client, but it does not allow it to be a network server. Allowing the instance to become a network server would conflict with the basic function of the enterprise bean� to serve the EJB clients.


You can download PDF from this link

By the way, why do you want to listening on the socket, instead of obtaining remote enterprise bean and calling business method?
[ September 02, 2008: Message edited by: Bupjae Lee ]
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

Many ways you could tackle this! A couple of questions first:

1.) What version of EJB are you using?

2.) Are you in control of the client as well? (It _might_ be easier if the client could post to a JMS topic/queue or to a Webservice).

Then again after re-reading your post, it indicates that your client can't make EJB calls directly, so I assume you can't alter the client?

A couple of Hints:

1.) Look at Message Driven Beans (more importantly the concepts around them, as an MDB isn't the direct solution here)
2.) Look at the ServerSocket class and associated networking APIs around it

Hope some of that helps!

PS: I've found OReilly Java Network Programming book to be very useful in this area.
[ September 02, 2008: Message edited by: Martijn Verburg ]
 
Ragav Baskaran
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response.
Is it possible by any other means ?

May be can we listen to a socket from a servlet and then the servlet making the ejb call ?

Thanks
Ragavendran
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bupjae Lee:
You want to make some ejb "listening" on a socket?

Unfortunately, listening on a socket is prohibited in the EJB container.

I quote from Specification of Enterprise JavaBeans 3.0 Final release


Indeed, an implementation would involve his EJB enabled app to talk to a separate non EJB module that is acting as a ServerSocket.

Originally posted by Bupjae Lee:
You want to make some ejb "listening" on a socket?
By the way, why do you want to listening on the socket, instead of obtaining remote enterprise bean and calling business method?


I think in his original post he states that the client can't make those sorts of remote calls, I'm assuming he has no control over the client software.
[ September 02, 2008: Message edited by: Martijn Verburg ]
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Raga Vendran:
Thanks for the response.
Is it possible by any other means ?

May be can we listen to a socket from a servlet and then the servlet making the ejb call ?

Thanks
Ragavendran


I believe it's possible yes (kick of a listening socket on the init() method is a technique I've seen before), another approach would be to use a Resource Adapter (JCA). I'd take what I say here about the Servlets with a grain of salt though, I normally receive messages via Web Services, JCA or JMS .
 
Bupjae Lee
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you can use servlet, then the client can send via normal HTTP request to servlet, then servlet will call EJB and return the result via HTTP response.

Since HTTP request protocol is just connecting to server and sending informations via socket, it'll be not that hard.


If you can't change client code at all, you should make some "delegate" server outside J2EE server. It'll act as server of the client code, and client of J2EE server.
 
Ragav Baskaran
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As i mentioned earlier, i don't have a control over the client and they will send some set of characters through socket.

May be i can think of the below options.

1. Have a stand-alone java application(acting as a socket server -listener, ouside container), as soon as i receive the complete message, i can try invoking my business ejb from there.
The downside of the approach is to maintain this stand alone application ***outside*** the container.

2. Servlet acting as a Socket listener. May be opening and closing the socket to be handled by init() and destroy() respectively.

3. Resource Adapter (JCA) ?? As Martijn pointed out in his post. Can you send some links which explains the usage.

4. Any other approach??

Comments/Suggestions are welcome..

Thanks
Ragavendran

[ September 02, 2008: Message edited by: Raga Vendran ]
[ September 02, 2008: Message edited by: Raga Vendran ]
 
Ragav Baskaran
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Martijn Verburg:
Hi there,

Many ways you could tackle this! A couple of questions first:

1.) What version of EJB are you using?
EJB 2.0

2.) Are you in control of the client as well? (It _might_ be easier if the client could post to a JMS topic/queue or to a Webservice).

Then again after re-reading your post, it indicates that your client can't make EJB calls directly, so I assume you can't alter the client?

Yes you are correct. I can't alter my client.

A couple of Hints:

1.) Look at Message Driven Beans (more importantly the concepts around them, as an MDB isn't the direct solution here)
2.) Look at the ServerSocket class and associated networking APIs around it

Hope some of that helps!

PS: I've found OReilly Java Network Programming book to be very useful in this area.

[ September 02, 2008: Message edited by: Martijn Verburg ]
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Raga Vendran:

3. Resource Adapter (JCA) ?? As Martijn pointed out in his post. Can you send some links which explains the usage.


Start at Here, but bear in mind that Resource Adapters are pretty heavyweight, you might be better off going with the stand alone or servlet option.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!