Quoting Jack Wang <[EMAIL PROTECTED]>:
>
> So The code should be following. In machine H3 where kandula runs, I will
> start the transaction by
> code:
>
> --------------------------------
> org.apache.kandula.coordinator.at.TransactionManagerImpl wstm =
> org.apache.kandula.coordinator.at.TransactionManagerImpl.getInstance();
> wstm.begin();
> --------------------------------
>
> Then it starts to call the web services deployed in H1 and H2:
>
> --------------------------------
> // call ws 1 in H1
> po.MyService binding = new MyServiceServiceLocator().getMyService();
> ((MyServiceSoapBindingStub)binding).setMaintainSession(true);
> String result = binding.getString();
>
> // call ws 2 in H2
> TestSuite1PortType p = new
> TestSuite1PortTypeServiceLocator().getTestSuite1();
> p.justReturnOperation();
> --------------------------------
this is correct.
>
> If the web transaction started at H3 where Kandula runs, also has a local db
> operation, which
> should also be placed in the wstm, then add the following code in wsat.
>
> --------------------------------
> // Prepare to call local db operation in H3.
> // First get the xaRes
> MysqlXADataSource xaDs = new MysqlXADataSource();
> XAConnection xaConn = xaDs.getXAConnection();
> javax.transaction.xa.XAResource xaRes = xaConn.getXAResource();
>
> // Get the local j2ee tm from o.a.k.geronimo.Bridge
> javax.transaction.TransactionManager tm = o.a.k.geronimo.Bridge.getTM();
>
> // Enlist xaRes
> tm.getTransaction().enlistResource(xaRes);
>
> // Begin the local tx
> tm.begin();
>
> // Do the db operation
> Connection conn = xaConn.getConnection();
> Statement stmt = conn.createStatement();
> stmt.executeUpdate(...);
>
> // Commit or rollback the local tx, which is a part of wstm's transaction
> tm.commit();
> --------------------------------
in the impl of the service. you should neither begin nor terminate the local
(j2ee) tx. what happens is if you call the service with a ws-at ctx in the
header, kandula will attach a local tx to the thread that executes your service.
so you could enlist resource in *that* provided tx. You could even mark that tx
as rollback only. However, you should not attempt to terminate it. If you do
Kandula will abort the global ws-at tx along with it to preserve tx semantics.
the local tx will be terminated when the global tx is terminated by kandula.
you can get a reference to the local tx by first obtaining a ref to the TM from
the Bridge. However, this is not the proper way of doing it. You should
consider using JNDI-- of course you will have to initialize it.
> it means. Does It
> mean j2ee can run the kandula to call web service transactions, but can not
> call local (j2ee) tx s
> directly ?
what this means is think of an ejb calling another ejb. If the first ejb had a
tx context at the time of the call this ctx will be propagated to the second.
Support the second component called was not an ejb but a ws. Then Kandula will
create a ws-at tx and tie it with you local tx so that the work done by the ws
can also be controlled by your local tx.
--dasarath
>
> After I put the three calls (two ws calls, and one local db call) in one
> transaction, at last I
> will commit the wstm in H3 by:
>
> --------------------------------
> wstm.begin();
> --------------------------------
>
> or rollback the wstm by
>
> --------------------------------
> wstm.rollback();
> --------------------------------
>
>
> Question 2:
> Then the client side code is finished. In the web service side, it is similar
> as the client side
> to call the local db operation. So first get the local j2ee tx, and then
> enlist the xaRes, at last
> do the db operation. Is it right ?
>
>
> > The *correct* way to do this is to create objects "UserTransaction"
> > and "TransactionManager" and register them with JNDI at Tomcat startup.
> JOTM
> > provides a good document on how to do this with JOTM. Look at that and try
> to
> > do the same with Geronimo TM. Once thing to be careful here is not to
> create
> > two instances of the TM. Kandula Bridge (o.a.k.geronimo.Bridge) presently
> > instantiates the TM when the class is loaded. This instance can be obtained
> by
> > calling Bridge.getTM(). If this interface is not enough let us know and I
> will
> > change the code promptly.
> >
> > In future Kandula will be integrated with Geronimo and all this work will
> be
> > unnecessary.
> >
> > > In the normal application, I use UserTransaction configured in tomcat's
> > > sever.xml to operate
> > > database. The code is as follow:
> > >
> > > /* -- normal db application ----------------- */
> > > Context ctx = new InitialContext();
> > > UserTransaction ut =
> > > (UserTransaction)ctx.lookup("java:comp/env/UserTransaction");
> > > DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/myDB");
> > > java.sql.Connection conn = ds.getConnection();
> > > ut.begin();
> > > Statement stmt = conn.createStatement();
> > > PreparedStatement pstmt = conn.prepareStatement("update ...");
> > > ...
> >
> > This is correct. But to run this code you MUST do what I said before. Also
> note
> > that you are not directly using the ws-at protocol here. This is the most
> > likely way in which Kandula will be used by participants.
>
>
> Sorry£¬"using the ws-at protocol" means what ? Or you recommend me a url for
> me to read. I have
> read "http://www-128.ibm.com/developerworks/library/ws-comproto/index.html",
> but not comprehend
> yet.
>
> I will just do a test in host H1,H2 and H3. H1 has web service ws1. H2 has
> service ws2 and H3 is a
> jsp web application. User will send a request to H3, and H3 will call a
> bean. Then the bean will
> start a transaction, in which there are three calls (calling ws1, ws2 and
> local db opeation).
> That's it. I think current kandula will meet my needs, so I will try it out.
>
>
>
> Thanks.
>
>
>
> Wang Jun
>
>
>
>
>
>
> ___________________________________________________________
> ÑÅ»¢1GÃâ·ÑÓÊÏä°Ù·Ö°Ù·ÀÀ¬»øÐÅ
> http://cn.mail.yahoo.com/
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]