1 2 Previous Next 20 Replies Latest reply on Sep 6, 2007 9:42 AM by gbiemolt

    JTA & Webservices

    gbiemolt

      Hi,

      I'm working on a Java application that has to invoke some web services, preferably deployed on Tomcat. This has to happen transactional.

      I was thinking about a JTA transaction, to be initialized in the Java App. But I'm a little but stuck on a few points.

      1) is this actually possible

      2) how to adapt the webservices to make them transactional

      3) how to invoke web services transactional

      thanks in advance

      Gerard



        • 1. Re: JTA & Webservices
          jhalliday

          1) yes, although it's currently unsupported and will require a fair bit of fiddling around on your part.

          2) look at the samples that ship with XTS, or if the services are already capable of using JTA (e.g. EJBs on an XA database) then look at the transaction bridging stuff from our JavaOne BOF. Come to think of it, look at that anyhow as it's relevant to doing the JTA->transactional WS call stuff too.

          3) see 2).

          • 2. Re: JTA & Webservices
            gbiemolt

            Hi,

            Thanks for your quick reply, it it good to know that it is actually possible to build such a construction. I've been toying with jboss transactions for a while now, and I've got the xts demo running, took a look at the JTA examples and created some usertransactions with JTA.

            But I'm not seeing how to connect these somehow. Using a database transactional straigtforward with a dedicated transactional Statement. But how does one call a WS transactional, there doesn't seem to be a transactional Call. And I assume that just calling the service between a UserTransactions Begin and Commit will not suffice.

            Regards,

            Gerard

            PS. could you also explain a bit about JavaOne BOF, and what you mean by it?

            • 3. Re: JTA & Webservices
              jhalliday

              Look at the BasicClient from the XTS demo app for an example of how to make a transactional call to a web service.

              The BOF at JavaOne covered transaction bridging i.e. mixing JTA and WS-AT. The presentation and related code are in our svn repository.

              • 4. Re: JTA & Webservices
                gbiemolt

                Hi,

                The problem is just as I feared. The usertransaction's context, created in the java-app is not known at the web service. I didn't find a solution with the javaone bof documentation. I realize that this is a delicate not to usual problem. But this shouldn't be too much of a problem,since it sounds quite useful.

                Hope anyone has a solution, thanks in advance,

                Gerard

                • 5. Re: JTA & Webservices
                  jhalliday

                  Either I have not understood what you are trying to achieve, or you have not understood the material from the BOF. Interop of WS-AT and JTA/XA is exactly what we are addressing in that work. Although actually there is no indication you need XA, It seems like you really just want to drive a WS-AT transactions using the JTA API, which is also feasible although likewise not currently supported out of the box.

                  • 6. Re: JTA & Webservices
                    gbiemolt

                    Hi, sorry for the confusion, I'll try to make clear what my plan is:

                    Basically what I want is the following:

                    - Run a JavaApp that initializes a UserTransaction.
                    e.g. com.arjuna.ats.jta.UserTransaction.userTransaction()
                    javax.transaction.Usertransaction
                    - That begins the usertransaction.

                    - It executes a webservice (transactional) that's deployed on Tomcat or Jboss.

                    - Finally the transaction should be committed.


                    I did find the JavaOne example with the Bistro, but this seems to be a transaction between a web service and a servlet, instead of a standalone java app and a web service.

                    Does this clear things up?
                    Regards,

                    Gerard

                    • 7. Re: JTA & Webservices
                      jhalliday

                      What you describe is transaction bridging. In fact the steps you have above match almost exactly the use case on slide 14 of our presentation. Your particular use case if the mirror image of the one we demoed at JavaOne, but the techniques you need to implement it are the same.

                      We have already discussed the use of xts standalone in a previous thread, perhaps you should go back and re-read that to understand why all web service transaction clients must also be web servers.

                      • 8. Re: JTA & Webservices
                        gbiemolt

                        oh i'm terribly sorry, i didn't recognize that the odp-file contains the sheets at first. apoligies and thanks for your replies!

                        • 9. Re: JTA & Webservices
                          gbiemolt

                          Hi,

                          You were right, the problem is exactly like you mentioned in the slides. But I can't find any source code that is similar to the slide. The only source code available seems to be the code in the Basicclient, but that is nothing different from the original xtsdemo.

                          Also I'm not able to figure out the role of the JaxWSClientHeaderContextProcessor and the JaxWSServerHeaderContextProcessor. Might that be the link i'm missing?

                          Regards

                          • 10. Re: JTA & Webservices
                            adinn

                             


                            Also I'm not able to figure out the role of the JaxWSClientHeaderContextProcessor and the JaxWSServerHeaderContextProcessor. Might that be the link i'm missing?


                            That is indeed the missing link. You need to study both of these.The handlers on the client and server side communicate using header data for both call and reply messages. Look for the suspend and resume calls on each side and see how they are associated with the direction of flow of the context.

                            • 11. Re: JTA & Webservices
                              jhalliday

                              > But I can't find any source code that is similar to the slide. The only source code available seems to be the code in the Basicclient, but that is nothing different from the original xtsdemo.

                              Exactly. The demo is, as I've stated previously in this thread and as is noted in the slides, showing bridging from WS-AT to JTA. Hence the web services client is unchanged. The whole point is the bridging is transparent to the client, it does not need to know about JTA, only WS-AT. Now mirror that to get what you want: a client that uses JTA and where the bridge translates transparently to WS-AT...

                              • 12. Re: JTA & Webservices
                                gbiemolt

                                Ah, I see what you mean; the example shows bridging from WS-AT to JTA. Whereas I probably need JTA to WS-AT bridging. After rereading the previous xts-standalone discussion, I'm getting the impression that using transactions is strictly possible between services, servlets or ejb's that are deployed on a web service container. Because web service listeners are needed.

                                However I'm limited to a stand-alone java app(is it possible to use listeners for a non-web service container application?), running on a different VM from the web services(which are deployed on tomcat5.5). I'm breaking my head on it and it's driving me nuts.

                                • 13. Re: JTA & Webservices
                                  jhalliday

                                  Define 'stand-alone'? It's obviously not completely isolated, since it's making web services calls. Why can't it also listen for inbound calls? Any java app that can open a server socket can do that...

                                  • 14. Re: JTA & Webservices
                                    gbiemolt

                                    the standalone app, is currently(while developing in eclipse) a simple java app, that creates a transaction and invokes a webservice. According to the following source(the code for the exact call is omitted.

                                    import javax.transaction.HeuristicMixedException;
                                    import javax.transaction.HeuristicRollbackException;
                                    import javax.transaction.NotSupportedException;
                                    import javax.transaction.RollbackException;
                                    
                                    import com.arjuna.wst.SystemException;
                                    import com.arjuna.wst.TransactionRolledBackException;
                                    import com.arjuna.wst.UnknownTransactionException;
                                    import com.arjuna.wst.WrongStateException;
                                    
                                    public class TestTimeService {
                                    
                                     public TestTimeService() {
                                     // TODO Auto-generated constructor stub
                                     }
                                    
                                     public static void main(String[] args) {
                                     try {
                                     invokeTimeservice();
                                     // testAtomicTransaction();
                                     } catch (Exception e) {
                                     // TODO Auto-generated catch block
                                     e.printStackTrace();
                                     }
                                     }
                                    
                                     public static void invokeTimeservice() throws NotSupportedException,
                                     SystemException, SecurityException, IllegalStateException,
                                     RollbackException, HeuristicMixedException,
                                     HeuristicRollbackException, WrongStateException, SystemException,
                                     TransactionRolledBackException, UnknownTransactionException,
                                     javax.transaction.SystemException {
                                    
                                     System.out.println("RULEENGINE: Starting Transaction.");
                                     javax.transaction.UserTransaction ut = com.arjuna.ats.jta.UserTransaction
                                     .userTransaction();
                                    
                                     if (ut == null)
                                     System.out.println("RULEENGINE: ut==null");
                                     ut.begin();
                                     System.out.println("RULEENGINE: Started Transaction.");
                                     if (ut == null)
                                     System.out.println("ut==null");
                                     else
                                     System.out.println("usertransaction ID " + ut.toString());
                                    
                                     TimeservicePortSoapBindingStub p = null;
                                    
                                     try {
                                     p = new TimeservicePortSoapBindingStub(new java.net.URL(
                                     "http://localhost:8084/axis/services/timeservicePort"), null);
                                     p.calculateTime("100");
                                     } catch (Exception e) {
                                     System.out.println("webservice not invoked " + e);
                                     }
                                    
                                     System.out.println("RULEENGINE: Commiting Transaction.");
                                     ut.commit();
                                     System.out.println("RULEENGINE: Commited Transaction.");
                                     }
                                    }
                                    


                                    The code should be integrated as a rule into a rule engine, to become part of a larger platform.

                                    Listening to a socket might be a solution, never thought of that, but I have limited knowledge of it.

                                    regards

                                    1 2 Previous Next