--- Dasarath Weeratunge <[EMAIL PROTECTED]>写道:
> This code though gets the job done is ABSOLUTELY unnecessary. Use the
> o.a.k.coordinator.at.TransactionManager.begin/commit for this. The reason why
> it is not used in the InteropIBM sample is because that sample is a
> standalone
> application. Look at how things are done in test-suite1 implementation.
>
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();
--------------------------------
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();
--------------------------------
Question 1:
Here, I get the local j2ee tx from o.a.k.geronimo.Bridge. This tx will be used
to control the
local db operation in H3 where Kandula runs. If ws_at has other ws (for
example, ws4 in host H4)
to call, can I commit this tx ? Will it affect the ws_at's tx ?
"However, the current code only supports importing ws tx s into j2ee. It is
also possible to
export j2ee tx s as ws tx s but it not implemented yet.", I want to know what
it means. Does It
mean j2ee can run the kandula to call web service transactions, but can not
call local (j2ee) tx s
directly ?
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]