1 Reply Latest reply on Feb 6, 2004 10:41 PM by Juha Lindfors

    Big problem with EJBs running over Web tier!

    ccsaxton Newbie

      This is a copy of a post that I have sent to the J2EE design pattern forum so you might want to read the responses that I had there.

      I am reposting on this forum to see if I can get more feed back!!

      I have found a problem that could cause you a serious headache...please flame me if I am wrong...

      Some browsers will (mostly on a windows platform) cut short a connection request with an application server...Sometimes it is the server that can do this but whether the server or client closes the connection you don't really have any control over it! And here is the catch!!! Some browsers will then resend the POST/GET data without your intervention...what a headache...

      The problem with this is the following!

      1. Client posts data to servlet container over http.

      2. Servlet reads client data from form details passed as arguments and calls an EJB with the details...the EJB stores the data to a table the EJB also returns a confirmation string which is to be sent back to the calling client wrapped up in some pretty html layout...

      3. At point 2, at the end of the call to the EJB..."""THE TRANSACTION ENDS AND THE DATA IS COMMITTED TO THE DATABASE SINCE THE EJB TRANSACTION HANDLING IS HANDLED BY THE CONTAINER!!!!"""

      4. You now wrap up your request and return the data via the socket to the calling client...

      5. Midway through this IE or the server throw a wobbly(or through lack of resources) and close the connection...

      what happens next can be one of 2 things...

      6. in some cases you will get an error returned to the browser but in other cases the browser will resend the request, especially if it was the browser that closed the connection in the first place! You can see where I am going with this can you not...repeat steps 2 onwards and you get 2 sets of data posted to the database...

      7. The client will only receive one result page and will not be aware that the post as gone twice. I must admit that I have only observed this behaviour with IE but since it is on 95% of boxes out there then It is cause for concern!!

      How do you get round this...All I can think of is that you would have to abandon using an EJB and start a user transaction from within the servlet. The transaction can then complete on a finally clause after the socket connect closes finishing the request response...if the connection goes down you get an exception which you can the use to roll back the transaction...

      ANY IDEAS!!!

      The problem will also occur if you call EJBs over SOAP/XMLRPC...as anyone else seen this issue...I have noticed similar posts on the web where people are getting double posts using JSP....and they are unable to explain it since they have disabled client side submit buttons...etc.

      This is a fundimental flaw with using EJBs over a web container...can you setup the web container to initiate the transaction??? If not, then what?