• Post Reply Bookmark Topic Watch Topic
  • New Topic

HTTP Post from EJB?

 
Ramesh Donnipadu
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have a situation where our enterprise application needs to communitate with another system, whose only communication mechanism is an Http Post. I'm not sure if the J2EE spec allows Http Get/Post from within a Session bean. Do I need to write a JCA adapter? or a simple MDB that does Http Post? What are my choices?

I was wondering what is the best solution to this. Your suggestions are appreciated.

Thanks,
Ramesh
[ October 19, 2004: Message edited by: Ramesh Donnipadu ]
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do socket stuff wherever the heck you want (assuming you haven't done something crazy with security permissions to disallow it, but that's not specific to EJB). Just check out the "java.net" package and go for it.
 
Ramesh Donnipadu
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply!

But doesn't J2EE specification prohibit opening network connections, File IO, threading etc?

[ October 20, 2004: Message edited by: Ramesh Donnipadu ]
[ October 20, 2004: Message edited by: Ramesh Donnipadu ]
 
Roshan Lal
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But doesn't J2EE specification prohibit opening network connections, File IO, threading etc?


I think the spec prohibits the EJB from listening on a port but does not
prohibit it from becoming client to a listener. In other words, EJB can open client socket (your case) but not server socket.

My 2 cents.
 
Bruno Collet
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used an EJB to read from an URL. I think that there is no problem to use HTTP protocol from EJB, but there will be problems if you use low level protocols (such as sockets) or file IO, because of the distributed nature of the EJB you cannot make any assumption on where it is located (this means trouble for machine IPs and local files...). I am not sure of this, you should check the EJB Spec.
But I had another unexpected problem when using EJB to access URLs: when the URL is not accessible, the EJB hangs, because URL connections do not allow to specify timeout. And guess what? EJB forbids programmatic thread management, so it was impossible to implement a thread timeout mechanism... In the end I moved the whole feature in a WAR file to the web container.
Hope it helps.
 
Pradeep Ram
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So long as you read data from a URL, the EJB spec does not have a problem with that. Try to use the following to help you achieve the solution
1. Try to have atomic URL calls (not a multi request-response back and forth communication). You can have a URL call to a server to read the stock quote, parse the response and send it back to your client.
2. Even better have a POJO to do this job, so that your bean code appears cleaner.
3. If you need timeout for your connection try using the HTTPUtils class in the apache soap implementation (I think the package is org.apache.soap.util.net , I am not too sure though)
4. Check to see if your appserver is not in a DMZ (De-militarized Zone). If it is you need to open ports in firewalls, also find out if you need a proxy for outgoing connections.
5. From the 'Best Practices' perspective the connector architecture would be a good bet, but I think it might be an overkill for something as small as a stock quote fetch (But will get you kudos from your application architect)

--pradeeP
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!