• Post Reply Bookmark Topic Watch Topic
  • New Topic

Call URL from Stateful Session Bean

 
Stephen Hanley
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's what I am doing.

MessageManagerBean is a Stateful Session Bean.

It has a method called addMessage(String,String,String) which adds a new item in the 'message' table of the database.

When I call this addMessage method I also need to physically send the message. This can be done by calling a URL with the appropriate POST data or via an email.

Should the sendMessage method be in the MessageManagerBean or what? Which would be easier to implement, URL or SMTP? Is using jakarta commons overkill?

BTW the URL call responds with either "success" and a msg number or "error".

Any help greatly appreciated. Has taken me two days so far.
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stephen,

In my opinion from a high level design standpoint it doesn�t make much sense to have a method like sendEmail or postURL in your SFSB, because your SLSB supposed to implement application business logic and not pure technical tasks. On the other hand I believe that org.apache.commons.mail.send() method runs synchronously (please check this one first to be sure) and your method will take a long time to execute. If your SLSB is part of a transaction, then your design will be pretty poor; the same I believe is the story with sending http post requests. You also need to be careful about rolling back failing transaction.
One way to overcome these problems is to send the message asynchronously to an email queue and have an MDB sending the real email. You might implement another component, let�s say a SLSB something like EmailSenderBean that does the job and have your SFSB calling the sendEmail method of this new component. The only problem with this design is that you have to implement couple of more components, set up JMS destinations, etc. But it will definately take care of all your problems.
Regards.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!