• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HTTP Post from EJB?

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic