This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Transaction Handling when accessing external systems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Transaction Handling when accessing external systems" Watch "Transaction Handling when accessing external systems" New topic
Author

Transaction Handling when accessing external systems

Srinivas Pittala
Ranch Hand

Joined: May 22, 2011
Posts: 40
Hi,

SuD is interacting with external system and external web services.
Is it good to use javax.transaction.UserTransaction for handling distributed transactions?

Thanks,
Sree
Rishi Shehrawat
Ranch Hand

Joined: Aug 11, 2010
Posts: 218

Web services cannot participcate in JTA transactions.
The external system needs to be accessible via JCA to participate in JTA transactions.
Srinivas Pittala
Ranch Hand

Joined: May 22, 2011
Posts: 40
Hi Rishi,

Thanks for your response.
To consume external web services, generally we do not opt for JCA.Directly will invoke the link provided by web service providers
by writing a WS client(Session Bean--->WSPOJO--->External web services).

Is it the right way to handle a transactions in the following way by using container managed transaction attribute?
SuD invoke the session bean by using a controller

Appreciate your help.


@stateless
beanImplMethod(){
try{
invokeWebServiceMethod(){

//logic for invoking a web services...
}

}catch( Exception ex){
sessioncontext.setRollBackOnly()

}
}

Thanks,
Sree
Rishi Shehrawat
Ranch Hand

Joined: Aug 11, 2010
Posts: 218

To the best of my knowledge there is no out of the box support for transaction managment of web services using JTA. The snippet provided by you will not work.
However there are ways to make it work by using WS-AtomicTransaction, WS-Coordination, however it comes at a cost in terms of increased complexity, performance, etc.
Have a look at (http://metro.java.net/guide/Using_Web_Services_Atomic_Transactions.html)
Normally you try to avoid all this complexity by writing compensating logic which works in conjuction with reconcilling logic for reconcilling your app with the external system via day end job or some other mechanisim.
Srinivas Pittala
Ranch Hand

Joined: May 22, 2011
Posts: 40
Rishi,

Thank you very much for your repsponse..


Thanks,
Sree
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Transaction Handling when accessing external systems