You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fx-dev@ws.apache.org by Dasarath Weeratunge <dw...@purdue.edu> on 2006/02/03 07:52:22 UTC

Re: »Ø¸´£ºRe: Re: Steps of running Kandula_1 exampes

Quoting Jack Wang <pi...@yahoo.com>:

> 
> I try to follow it and here is my web application code in H3 running Kandula.
> 
> 
> /* -- wstm begin in H3 ------- */             			
> ActivationStub stub = new ActivationStub(new
> EndpointReference("http://H3:port/axis/services/activationCoordinator"));
> CoordinationContext ctx =
> stub.createCoordinationContext(ATCoordinator.COORDINATION_TYPE_ID);
> EndpointReference cps = ctx.register(ATCoordinator.PROTOCOL_ID_COMPLETION,
> 	new EndpointReference
("http://H3:port/axis/services/completionInitiator"));
> SetCoordCtxHandler.setCtx(ctx);
> /* --------------------------- */             			


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.

> Question 1:
> I wonder if I do not configure "UserTransaction" in H1 and H2's tomcats now
> when I operate the
> database in the web services of H1 and H2, which will be called by H3's
> transaction. And Also
> wonder if I do not configure "UserTransaction" in H3's tomcat , where there
> is a local db
> operation which will also be placed in the H3's same transaction.
> 

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.

In fact in the earlier code we even supported exporting J2EE transactions 
automatically when ws calls were made from a thread with an active J2EE tx 
context.

> 
> My application will be a ws container application, so not consider standalone
> application. 

so then you will have no trouble using o.a.k.coordinator.at.TM

> 
> I try to follow it and here is my code in H1 or H2 to do the db transaction.
> The database server
> is mySQL 5.0 and I will use Connector/J 5.0 jdbc driver, so I can use
> Distributed Transactions.
> 
> /* -----db transaction in H1 and H2 --------- */   
> MysqlXADataSource xaDs = new MysqlXADataSource();
> XAConnection xaConn = xaDs.getXAConnection();
> javax.transaction.xa.XAResource xaRes = xaConn.getXAResource();
> /* ------------------------------------------ */   
> 
> > Transaction tx = tm.getTransaction();
> > tx.enlistResource(xaRes);
> > 

this is correct. But this should be done some where else. See the JOTM/Tomcat 
integration example.

> application container. I can
> get a UserTransaction. Can I get a Transaction instance directly by
> "Transaction tx =
> javax.transaction.TransactionManager.getTransaction();" ? If not, how can I
> get the local j2ee tx?

you can do this. Looking at the code of the TM will help resolve this type of 
questions. Get the source of the Geronimo TM and have a look or ask on geronimo-
user and David Jenks him self will answer:-)

> /* ----- SQL statements in H1 and H2 --------- */   
> Connection conn = xaConn.getConnection();
> Xid xid = createXid();
> xaRes.start(xid, XAResource.TMNOFLAGS);
> conn.createStatement().executeUpdate("INSERT INTO testCoordination VALUES
> (1)");
> xaRes.end(xid, XAResource.TMSUCCESS);
> int ret = xaRes.prepare(xid);
> if (ret == XAResource.XA_OK) { 
> 	xaRes.commit(xid, false); 
> } else{
> 	xaRes.rollback(xid); 
> }

this is NOT correct. User applications should never deal with XAResource 
interface directly. Use the commit/rollback methods in TM or Tx interface.

> /* ------------------------------------------ */   
> 
> Question 3:
> If H3's transaction also contains a local database operation, I should let
> the H3's local j2ee tx
> enlist the xaRes in H3's bean, which will be called by a jsp's request. Is it
> right?

your Q is not clear. Isn't H3 where Kandula is running?

> 
> Question 4:
> The key problem is that I don't know how to get the local JTA(j2ee) tx, and
> how kandula ties the
> local tx with the corresponding (global) ws-at tx, please ask in which class
> kandula ties them ?

this is very simple. Look at the o.a.k.geronimo.* package. 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.

thanks,
--dasarath

> 
> Thanks again
> 
> 
> 
> Wang Jun
> 
> 
> 	
> 
> 	
> 		
> ___________________________________________________________ 
> ÑÅ»¢1GÃâ·ÑÓÊÏä°Ù·Ö°Ù·ÀÀ¬»øÐÅ 
> http://cn.mail.yahoo.com/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: kandula-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: kandula-dev-help@ws.apache.org
> 
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: kandula-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: kandula-dev-help@ws.apache.org


Re: Steps of running Kandula_1 exampes

Posted by Dasarath Weeratunge <dw...@purdue.edu>.
Quoting Jack Wang <pi...@yahoo.com>:

> 
> 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: kandula-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: kandula-dev-help@ws.apache.org


Re: Steps of running Kandula_1 exampes

Posted by Dasarath Weeratunge <dw...@purdue.edu>.
Quoting Jack Wang <pi...@yahoo.com>:

> 
> 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: kandula-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: kandula-dev-help@ws.apache.org


Re: Steps of running Kandula_1 exampes

Posted by Jack Wang <pi...@yahoo.com>.
--- Dasarath Weeratunge <dw...@purdue.edu>写道:
> 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: kandula-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: kandula-dev-help@ws.apache.org


Re: Steps of running Kandula_1 exampes

Posted by Jack Wang <pi...@yahoo.com>.
--- Dasarath Weeratunge <dw...@purdue.edu>写道:
> 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: kandula-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: kandula-dev-help@ws.apache.org