geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1000669 - in /geronimo/server/trunk: plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/ testsuite/javaee6-testsuite/jta1.1-test/ testsuite/javaee6-testsuite/jta1.1-test/src/main/jav...
Date Fri, 24 Sep 2010 00:22:54 GMT
Author: gawor
Date: Fri Sep 24 00:22:53 2010
New Revision: 1000669

URL: http://svn.apache.org/viewvc?rev=1000669&view=rev
Log:
Support injection of TransactionSynchronizationRegistry and TransactionManager

Added:
    geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/InjectionServlet.java
  (with props)
Modified:
    geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/AdminObjectRefBuilder.java
    geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/pom.xml
    geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/BJAcc.java
    geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/BaseServlet.java
    geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/DoTransfer.java
    geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/SHAcc.java
    geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/webapp/WEB-INF/web.xml
    geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/test/java/org/apache/geronimo/testsuite/javaee6/tests/jtaTest.java

Modified: geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/AdminObjectRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/AdminObjectRefBuilder.java?rev=1000669&r1=1000668&r2=1000669&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/AdminObjectRefBuilder.java
(original)
+++ geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/AdminObjectRefBuilder.java
Fri Sep 24 00:22:53 2010
@@ -22,13 +22,17 @@ import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import javax.annotation.Resource;
 import javax.naming.RefAddr;
 import javax.naming.Reference;
 import javax.naming.StringRefAddr;
+import javax.transaction.TransactionManager;
+import javax.transaction.TransactionSynchronizationRegistry;
 import javax.xml.namespace.QName;
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.common.UnresolvedReferenceException;
@@ -44,6 +48,7 @@ import org.apache.geronimo.kernel.GBeanN
 import org.apache.geronimo.kernel.config.Configuration;
 import org.apache.geronimo.kernel.repository.Environment;
 import org.apache.geronimo.naming.deployment.AbstractNamingBuilder;
+import org.apache.geronimo.naming.reference.GBeanReference;
 import org.apache.geronimo.naming.reference.JndiReference;
 import org.apache.geronimo.naming.reference.UserTransactionReference;
 import org.apache.geronimo.xbeans.geronimo.naming.GerMessageDestinationDocument;
@@ -121,6 +126,17 @@ public class AdminObjectRefBuilder exten
 
 
     public void buildNaming(JndiConsumer specDD, XmlObject plan, Module module, Map sharedContext)
throws DeploymentException {
+        
+        AbstractNameQuery transactionManager = module.getEarContext().getTransactionManagerName();
+        if (transactionManager != null) {
+            Set<AbstractNameQuery> query = new HashSet<AbstractNameQuery>();
+            query.add(transactionManager);
+            GBeanReference transactionManagerRef = new GBeanReference(module.getConfigId(),
query, TransactionManager.class);
+            put("java:comp/TransactionManager", transactionManagerRef, module.getJndiContext(),
new ArrayList<InjectionTarget>(), sharedContext);
+            GBeanReference transactionSynchronizationRef = new GBeanReference(module.getConfigId(),
query, TransactionSynchronizationRegistry.class);
+            put("java:comp/TransactionSynchronizationRegistry", transactionSynchronizationRef,
module.getJndiContext(), new ArrayList<InjectionTarget>(), sharedContext);
+        }
+        
         XmlObject[] gerResourceEnvRefsUntyped = plan == null ? NO_REFS : plan.selectChildren(GER_ADMIN_OBJECT_REF_QNAME_SET);
         Map<String, GerResourceEnvRefType> refMap = mapResourceEnvRefs(gerResourceEnvRefsUntyped);
         Map<String, Map<String, GerMessageDestinationType>> messageDestinations
= module.getRootEarContext().getMessageDestinations();
@@ -264,6 +280,9 @@ public class AdminObjectRefBuilder exten
         if ("javax.transaction.TransactionSynchronizationRegistry".equals(type)) {
             return new JndiReference("java:comp/TransactionSynchronizationRegistry");
         }
+        if ("javax.transaction.TransactionManager".equals(type)) {
+            return new JndiReference("java:comp/TransactionManager");
+        }
         try {
             AbstractNameQuery containerId = getAdminObjectContainerId(name, gerResourceEnvRef);
             Reference ref = buildAdminObjectReference(module, containerId);
@@ -457,6 +476,7 @@ public class AdminObjectRefBuilder exten
                         resourceType.equals("javax.validation.Validator") ||
                         resourceType.equals("javax.validation.ValidatorFactory") ||
                         resourceType.equals("javax.transaction.UserTransaction") ||
+                        resourceType.equals("javax.transaction.TransactionManager") ||
                         resourceType.equals("javax.transaction.TransactionSynchronizationRegistry"))
{
                     //mapped resource-env-ref
                     addResourceEnvRef(annotatedApp, resourceName, resourceType, method, field,
annotation);

Modified: geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/pom.xml?rev=1000669&r1=1000668&r2=1000669&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/pom.xml (original)
+++ geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/pom.xml Fri Sep 24 00:22:53
2010
@@ -17,11 +17,8 @@
     specific language governing permissions and limitations
     under the License.
 -->
-
 <!-- $Rev$ $Date$ -->
-
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
     <modelVersion>4.0.0</modelVersion>
 
     <parent>
@@ -32,7 +29,7 @@
 
     <artifactId>jta1.1-test</artifactId>
     <name>Geronimo TestSuite :: Java EE 6 Testsuite :: jta1.1-test</name>
-   <description>
+    <description>
     </description>
     <packaging>war</packaging>
 
@@ -42,7 +39,7 @@
             <artifactId>geronimo-servlet_3.0_spec</artifactId>
             <scope>provided</scope>
         </dependency>
-          <dependency>
+        <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-annotation_1.1_spec</artifactId>
             <scope>provided</scope>
@@ -51,76 +48,62 @@
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-jta_1.1_spec</artifactId>
             <scope>provided</scope>
-        </dependency>		
-    </dependencies> 
-	
-	<build>
-		<plugins>
-			<plugin>
-                    <groupId>org.apache.maven.plugins</groupId>
-                    <artifactId>maven-war-plugin</artifactId>
-                    <configuration>
-                        <archiveClasses>false</archiveClasses>
-                    </configuration>
-                </plugin>
-			</plugins>
-	</build>
-	
-	<profiles>
-    <profile>
-        <id>it</id>
-        <activation>
-            <property>
-                <name>it</name>
-            </property>
-        </activation>
-    <build>        
-        <plugins>   
-            <plugin>
-				<groupId>org.codehaus.mojo</groupId>
-				<artifactId>selenium-maven-plugin</artifactId>
-		    </plugin>	
-		
-		    <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-failsafe-plugin</artifactId>
-                <configuration>
-                    <suiteXmlFiles>
-                        <suiteXmlFile>
-							${project.build.testOutputDirectory}/testng.xml
-						</suiteXmlFile>
-                    </suiteXmlFiles>
-                </configuration>
-            </plugin>
-            <plugin>
-                <groupId>org.apache.geronimo.buildsupport</groupId>
-                <artifactId>geronimo-maven-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <id>deploy-wars</id>
-                        <phase>pre-integration-test</phase>
-                        <goals>
-                            <goal>deploy-module</goal>
-                        </goals>
-                        <configuration>
-                            <moduleArchive>${project.build.directory}/${project.artifactId}-${project.version}.war</moduleArchive>
-                        </configuration>
-                    </execution>
+        </dependency>
+    </dependencies>
 
-                    <execution>
-                        <id>undeploy-war-as-moduleId</id>
-                        <phase>post-integration-test</phase>
-                        <goals>
-                            <goal>undeploy-module</goal>
-                        </goals>
+    <profiles>
+        <profile>
+            <id>it</id>
+            <activation>
+                <property>
+                    <name>it</name>
+                </property>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>selenium-maven-plugin</artifactId>
+                    </plugin>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-failsafe-plugin</artifactId>
                         <configuration>
-                            <moduleId>${project.groupId}/${project.artifactId}/${project.version}/war</moduleId>
+                            <suiteXmlFiles>
+                                <suiteXmlFile>
+                                    ${project.build.testOutputDirectory}/testng.xml
+                                </suiteXmlFile>
+                            </suiteXmlFiles>
                         </configuration>
-                    </execution>
-                </executions>
-            </plugin>
-        </plugins>
-    </build>
-    </profile>
-</profiles>
+                    </plugin>
+                    <plugin>
+                        <groupId>org.apache.geronimo.buildsupport</groupId>
+                        <artifactId>geronimo-maven-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>deploy-wars</id>
+                                <phase>pre-integration-test</phase>
+                                <goals>
+                                    <goal>deploy-module</goal>
+                                </goals>
+                                <configuration>
+                                    <moduleArchive>${project.build.directory}/${project.artifactId}-${project.version}.war</moduleArchive>
+                                </configuration>
+                            </execution>
+                            <execution>
+                                <id>undeploy-war-as-moduleId</id>
+                                <phase>post-integration-test</phase>
+                                <goals>
+                                    <goal>undeploy-module</goal>
+                                </goals>
+                                <configuration>
+                                    <moduleId>${project.groupId}/${project.artifactId}/${project.version}/war</moduleId>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
 </project>

Modified: geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/BJAcc.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/BJAcc.java?rev=1000669&r1=1000668&r2=1000669&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/BJAcc.java
(original)
+++ geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/BJAcc.java
Fri Sep 24 00:22:53 2010
@@ -32,37 +32,35 @@ import javax.sql.DataSource;
    maxPoolSize=10,
    properties = {"createDatabase = create"})
 */
-@DataSourceDefinitions({
-	  @DataSourceDefinition(name = "java:app/BJAccNonTx",
-	    className="org.apache.derby.jdbc.ClientDataSource",
-	    portNumber = 1527,
-	    serverName = "localhost",
-            url="jdbc:derby://localhost:1527/BJAcc",
-	    databaseName="BJAcc",
-	    user="system",
-            password="manager",
-            transactional=false,
-	    properties = {"createDatabase=create"}),
-
-
-	  @DataSourceDefinition(name = "java:app/BJAccTx",
-	    className="org.apache.derby.jdbc.ClientXADataSource",
-	    portNumber = 1527,
-	    serverName = "localhost",
-            url="jdbc:derby://localhost:1527/BJAcc",
-	    databaseName="BJAcc",
-	    user="system",
-            password="manager",
-            transactional= true,
-	    properties = {"createDatabase=create"})
-	})
-
+@DataSourceDefinitions( {
+        @DataSourceDefinition(name = "java:app/BJAccNonTx", 
+                              className = "org.apache.derby.jdbc.ClientDataSource", 
+                              portNumber = 1527, 
+                              serverName = "localhost", 
+                              url = "jdbc:derby://localhost:1527/BJAcc", 
+                              databaseName = "BJAcc", 
+                              user = "system", 
+                              password = "manager", 
+                              transactional = false, 
+                              properties = { "createDatabase=create" }),
+
+        @DataSourceDefinition(name = "java:app/BJAccTx", 
+                              className = "org.apache.derby.jdbc.ClientXADataSource", 
+                              portNumber = 1527, 
+                              serverName = "localhost", 
+                              url = "jdbc:derby://localhost:1527/BJAcc", 
+                              databaseName = "BJAcc", 
+                              user = "system", 
+                              password = "manager", 
+                              transactional = true, 
+                              properties = { "createDatabase=create" }) 
+} )
 public class BJAcc extends BaseServlet {
 
-    @Resource(lookup="java:app/BJAccNonTx")
+    @Resource(lookup = "java:app/BJAccNonTx")
     DataSource dataSourceNonTx;
 
-    @Resource(lookup="java:app/BJAccTx")
+    @Resource(lookup = "java:app/BJAccTx")
     DataSource dataSourcenTx;
 
     @Override

Modified: geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/BaseServlet.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/BaseServlet.java?rev=1000669&r1=1000668&r2=1000669&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/BaseServlet.java
(original)
+++ geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/BaseServlet.java
Fri Sep 24 00:22:53 2010
@@ -25,7 +25,6 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.ArrayList;
-import java.util.Calendar;
 import java.util.List;
 
 import javax.servlet.ServletConfig;
@@ -45,11 +44,13 @@ public abstract class BaseServlet extend
         return getClass().getName();
     }
 
-    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
-        doPost(request,response);
+    protected void doGet(HttpServletRequest request, HttpServletResponse response)
+            throws ServletException, IOException {
+        doPost(request, response);
     }
 
-    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
+    protected void doPost(HttpServletRequest request, HttpServletResponse response)
+            throws ServletException, IOException {
 
         PrintWriter out = response.getWriter();
         out.println("<html><head><title>");
@@ -80,7 +81,7 @@ public abstract class BaseServlet extend
     }
 
     public void init(ServletConfig config) {
-        //System.out.println("Initializing servlet");
+        // System.out.println("Initializing servlet");
     }
 
     public void initDB() throws SQLException {
@@ -94,15 +95,15 @@ public abstract class BaseServlet extend
         }
 
         try {
-        	stmt.executeUpdate("CREATE TABLE ACCOUNTS (ID INTEGER GENERATED ALWAYS AS IDENTITY
PRIMARY KEY, SAVINGS INTEGER)");
+            stmt
+                    .executeUpdate("CREATE TABLE ACCOUNTS (ID INTEGER GENERATED ALWAYS AS
IDENTITY PRIMARY KEY, SAVINGS INTEGER)");
         } finally {
             stmt.close();
             con.close();
         }
 
-
         addAccount(200);
-        //addAccount(100);
+        // addAccount(100);
     }
 
     public List<Account> getAccounts() throws SQLException {
@@ -110,8 +111,7 @@ public abstract class BaseServlet extend
         Connection con = getTxDataSourceB().getConnection();
         Statement stmt = con.createStatement();
         try {
-            ResultSet rs = stmt.executeQuery(
-                    "SELECT ID, SAVINGS FROM ACCOUNTS");
+            ResultSet rs = stmt.executeQuery("SELECT ID, SAVINGS FROM ACCOUNTS");
             while (rs.next()) {
                 Account c = new Account();
                 c.id = rs.getLong(1);
@@ -128,10 +128,9 @@ public abstract class BaseServlet extend
 
     public void addAccount(long sav) throws SQLException {
         Connection con = getTxDataSourceB().getConnection();
-        PreparedStatement pstmt = con.prepareStatement(
-            "INSERT INTO ACCOUNTS (SAVINGS) VALUES (?)");
+        PreparedStatement pstmt = con.prepareStatement("INSERT INTO ACCOUNTS (SAVINGS) VALUES
(?)");
         try {
-            pstmt.setLong(1,sav);
+            pstmt.setLong(1, sav);
             pstmt.executeUpdate();
         } finally {
             pstmt.close();
@@ -139,9 +138,9 @@ public abstract class BaseServlet extend
         }
     }
 
-
     private static class Account {
         long id;
+
         long savings;
     }
 }

Modified: geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/DoTransfer.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/DoTransfer.java?rev=1000669&r1=1000668&r2=1000669&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/DoTransfer.java
(original)
+++ geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/DoTransfer.java
Fri Sep 24 00:22:53 2010
@@ -28,134 +28,131 @@ import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.sql.DataSource;
-import javax.annotation.Resource;
 import javax.transaction.UserTransaction;
 
 /**
  * Servlet implementation class DoTransfer
  */
 public class DoTransfer extends HttpServlet {
-	private static final long serialVersionUID = 1L;
-	//@Resource(lookup="java:app/SHAcc")
-	//DataSource ds_SH;
-	
-	//@Resource(lookup="java:app/SHAcc")
-	//DataSource ds_BJ;
+    private static final long serialVersionUID = 1L;
+
+    // @Resource(lookup="java:app/SHAcc")
+    // DataSource ds_SH;
+
+    // @Resource(lookup="java:app/SHAcc")
+    // DataSource ds_BJ;
 
     public DoTransfer() {
         super();
 
     }
 
+    protected void doGet(HttpServletRequest request, HttpServletResponse response)
+            throws ServletException, IOException {
+    }
 
-	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
-
-
-	}
-
-	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
+    protected void doPost(HttpServletRequest request, HttpServletResponse response)
+            throws ServletException, IOException {
 
-		int amount = new Integer(request.getParameter("amount")).intValue();
-		int isFaildFlag = new Integer(request.getParameter("flag")).intValue();
-        boolean failFlag = ( isFaildFlag == 1 )? true :false;
+        int amount = new Integer(request.getParameter("amount")).intValue();
+        int isFaildFlag = new Integer(request.getParameter("flag")).intValue();
+        boolean failFlag = (isFaildFlag == 1) ? true : false;
         String output = new String();
 
-		UserTransaction tx = null;
-		DataSource ds = null;
-		Connection conn_SH = null;
-		Connection conn_BJ = null;
-		Statement stmt = null;
-		String sql =null;
-		ResultSet rs = null;
-
-		try{
-			Context initContext = new InitialContext();
-
-			tx = (UserTransaction)initContext.lookup("java:comp/UserTransaction");
+        UserTransaction tx = null;
+        DataSource ds = null;
+        Connection conn_SH = null;
+        Connection conn_BJ = null;
+        Statement stmt = null;
+        String sql = null;
+        ResultSet rs = null;
+
+        try {
+            Context initContext = new InitialContext();
+
+            tx = (UserTransaction) initContext.lookup("java:comp/UserTransaction");
 
-			// Start a transaction
-			tx.begin();
+            // Start a transaction
+            tx.begin();
 
-			//System.out.println("tx begin!");
+            // System.out.println("tx begin!");
 
-			// First, add to SH
-			ds = (javax.sql.DataSource) initContext.lookup("java:app/SHAccTx");
+            // First, add to SH
+            ds = (javax.sql.DataSource) initContext.lookup("java:app/SHAccTx");
             System.out.println("in DoTransfer, get java:app/SHAcc sucess!");
-			//conn_SH = ds_SH.getConnection();
-			conn_SH = ds.getConnection();
+            // conn_SH = ds_SH.getConnection();
+            conn_SH = ds.getConnection();
             conn_SH.setAutoCommit(false);
-			stmt = conn_SH.createStatement();
-			sql = "UPDATE ACCOUNTS set SAVINGS = SAVINGS+"+amount;
-			stmt.executeUpdate(sql);
-                        //System.out.println("execute SQL 1 sucess!");
-
-			if(failFlag)
-            {throw new Exception("fail shoud happen!");}
-
-			// Second, del in BJ
-			ds = (javax.sql.DataSource) initContext.lookup("java:app/BJAccTx");
-            //System.out.println("in DoTransfer, get java:app/BJAcc sucess!");
-			//conn_BJ = ds_BJ.getConnection();
-			conn_BJ = ds.getConnection();
+            stmt = conn_SH.createStatement();
+            sql = "UPDATE ACCOUNTS set SAVINGS = SAVINGS+" + amount;
+            stmt.executeUpdate(sql);
+            // System.out.println("execute SQL 1 sucess!");
+
+            if (failFlag) {
+                throw new Exception("fail shoud happen!");
+            }
+
+            // Second, del in BJ
+            ds = (javax.sql.DataSource) initContext.lookup("java:app/BJAccTx");
+            // System.out.println("in DoTransfer, get java:app/BJAcc sucess!");
+            // conn_BJ = ds_BJ.getConnection();
+            conn_BJ = ds.getConnection();
             conn_BJ.setAutoCommit(false);
-			stmt = conn_BJ.createStatement();
-			rs = stmt.executeQuery("SELECT * FROM ACCOUNTS");
-			int saving_BJ = 0;
-			while (rs.next()) {
-				saving_BJ = rs.getInt("SAVINGS");
-				if (saving_BJ < amount){
-					// throw a exception if no enough money left
-					throw new Exception("No enough money left in BJ Account!");
-				}
-			}
-
-			sql = "UPDATE ACCOUNTS set SAVINGS = SAVINGS-"+amount;
-			stmt.executeUpdate(sql);
-
-			// commit all the operations
-			tx.commit();
-
-
-		}
-        catch(Exception e){
-			if(tx!=null){
-				try{
-					// rollback the operations
-					tx.rollback();
-					//System.out.println("catch: roll back success.");
-                                        output += "catch: roll back success.";
-				}catch(Exception e1){
-					//System.out.println("catch: roll back fail.");
-                                        output += "catch: roll back fail.";
-				}
-			}
-			System.out.println("catch: " + e.getClass() + "; " + e.getMessage()+"");
-		}
-       finally{
-			if(conn_SH!=null){
-				try{
-					conn_SH.close();
-					//System.out.println("finally: close conn_SH success.");
-                                        output += "finally: close conn_SH success.";
-				}catch(Exception e1){
-					//System.out.println("finally: close conn_SH fail.");
-                                        output += "finally: close conn_SH fail.";
-				}
-			}
-			if(conn_BJ!=null){
-				try{
-					conn_BJ.close();
-					//System.out.println("finally: close conn_BJ success.");
-                                        output += "finally: close conn_BJ success.";
-				}catch(Exception e1){
-					//System.out.println("finally: close conn_BJ fail.");
-                                        output += "finally: close conn_BJ success.";
-				}
-			}
-		request.setAttribute("output",output);
-		//response.sendRedirect("AccountList.jsp");
-        getServletContext().getRequestDispatcher("/display.jsp").forward(request,response);
-		}
-	}
+            stmt = conn_BJ.createStatement();
+            rs = stmt.executeQuery("SELECT * FROM ACCOUNTS");
+            int saving_BJ = 0;
+            while (rs.next()) {
+                saving_BJ = rs.getInt("SAVINGS");
+                if (saving_BJ < amount) {
+                    // throw a exception if no enough money left
+                    throw new Exception("No enough money left in BJ Account!");
+                }
+            }
+
+            sql = "UPDATE ACCOUNTS set SAVINGS = SAVINGS-" + amount;
+            stmt.executeUpdate(sql);
+
+            // commit all the operations
+            tx.commit();
+
+        } catch (Exception e) {
+            if (tx != null) {
+                try {
+                    // rollback the operations
+                    tx.rollback();
+                    // System.out.println("catch: roll back success.");
+                    output += "catch: roll back success.";
+                } catch (Exception e1) {
+                    // System.out.println("catch: roll back fail.");
+                    output += "catch: roll back fail.";
+                }
+            }
+            System.out.println("catch: " + e.getClass() + "; " + e.getMessage() + "");
+        } finally {
+            if (conn_SH != null) {
+                try {
+                    conn_SH.close();
+                    // System.out.println("finally: close conn_SH success.");
+                    output += "finally: close conn_SH success.";
+                } catch (Exception e1) {
+                    // System.out.println("finally: close conn_SH fail.");
+                    output += "finally: close conn_SH fail.";
+                }
+            }
+            if (conn_BJ != null) {
+                try {
+                    conn_BJ.close();
+                    // System.out.println("finally: close conn_BJ success.");
+                    output += "finally: close conn_BJ success.";
+                } catch (Exception e1) {
+                    // System.out.println("finally: close conn_BJ fail.");
+                    output += "finally: close conn_BJ success.";
+                }
+            }
+            request.setAttribute("output", output);
+            // response.sendRedirect("AccountList.jsp");
+            getServletContext().getRequestDispatcher("/display.jsp").forward(request, response);
+        }
+    }
 
 }

Added: geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/InjectionServlet.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/InjectionServlet.java?rev=1000669&view=auto
==============================================================================
--- geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/InjectionServlet.java
(added)
+++ geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/InjectionServlet.java
Fri Sep 24 00:22:53 2010
@@ -0,0 +1,58 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.sample.servlet;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.annotation.Resource;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.transaction.TransactionManager;
+import javax.transaction.TransactionSynchronizationRegistry;
+
+public class InjectionServlet extends HttpServlet {
+
+    @Resource
+    private TransactionSynchronizationRegistry tsr;
+
+    @Resource
+    private TransactionManager tm;
+
+    protected void doGet(HttpServletRequest request, HttpServletResponse response)
+            throws ServletException, IOException {
+        doPost(request, response);
+    }
+
+    protected void doPost(HttpServletRequest request, HttpServletResponse response)
+            throws ServletException, IOException {
+        PrintWriter out = response.getWriter();
+        out.println("<html><head><title>InjectionTest</title></head></html><body>");
+
+        out.println("TransactionSynchronizationRegistry: " + ((tsr == null) ? "not ok" :
"ok"));
+        out.println("<br/>");
+        out.println("TransactionManager: " + ((tm == null) ? "not ok" : "ok"));
+        out.println("<br/>");
+
+        out.println("<a href=\"index.jsp\">Return</a>");
+        out.println("</body></html>");
+    }
+
+}

Propchange: geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/InjectionServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/InjectionServlet.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/InjectionServlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/SHAcc.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/SHAcc.java?rev=1000669&r1=1000668&r2=1000669&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/SHAcc.java
(original)
+++ geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/java/org/apache/geronimo/sample/servlet/SHAcc.java
Fri Sep 24 00:22:53 2010
@@ -22,37 +22,35 @@ import javax.annotation.sql.DataSourceDe
 import javax.annotation.sql.DataSourceDefinitions;
 import javax.sql.DataSource;
 
-@DataSourceDefinitions({
-	  @DataSourceDefinition(name = "java:app/SHAccNonTx",
-	    className="org.apache.derby.jdbc.ClientDataSource",
-	    portNumber = 1527,
-	    serverName = "localhost",
-            url="jdbc:derby://localhost:1527/SHAcc",
-	    databaseName="SHAcc",
-	    user="system",
-            password="manager",
-            transactional=false,
-	    properties = {"createDatabase=create"}),
-
-
-	  @DataSourceDefinition(name = "java:app/SHAccTx",
-	    className="org.apache.derby.jdbc.ClientXADataSource",
-	    portNumber = 1527,
-	    serverName = "localhost",
-            url="jdbc:derby://localhost:1527/SHAcc",
-	    databaseName="SHAcc",
-	    user="system",
-            password="manager",
-            transactional= true,
-	    properties = {"createDatabase=create"})
-	})
-
+@DataSourceDefinitions( {
+        @DataSourceDefinition(name = "java:app/SHAccNonTx", 
+                              className = "org.apache.derby.jdbc.ClientDataSource", 
+                              portNumber = 1527, 
+                              serverName = "localhost", 
+                              url = "jdbc:derby://localhost:1527/SHAcc", 
+                              databaseName = "SHAcc", 
+                              user = "system", 
+                              password = "manager", 
+                              transactional = false, 
+                              properties = { "createDatabase=create" }),
+
+        @DataSourceDefinition(name = "java:app/SHAccTx", 
+                              className = "org.apache.derby.jdbc.ClientXADataSource", 
+                              portNumber = 1527, 
+                              serverName = "localhost", 
+                              url = "jdbc:derby://localhost:1527/SHAcc", 
+                              databaseName = "SHAcc", 
+                              user = "system", 
+                              password = "manager", 
+                              transactional = true, 
+                              properties = { "createDatabase=create" })
+} )
 public class SHAcc extends BaseServlet {
 
-    @Resource(lookup="java:app/SHAccNonTx")
+    @Resource(lookup = "java:app/SHAccNonTx")
     DataSource dataSourceNonTx;
 
-    @Resource(lookup="java:app/SHAccTx")
+    @Resource(lookup = "java:app/SHAccTx")
     DataSource dataSourcenTx;
 
     @Override

Modified: geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/webapp/WEB-INF/web.xml?rev=1000669&r1=1000668&r2=1000669&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/webapp/WEB-INF/web.xml
(original)
+++ geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/main/webapp/WEB-INF/web.xml
Fri Sep 24 00:22:53 2010
@@ -15,44 +15,55 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 -->
-<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
-  <servlet>
-    <display-name>SHAcc</display-name>
-    <servlet-name>SHAcc</servlet-name>
-    <servlet-class>org.apache.geronimo.sample.servlet.SHAcc</servlet-class>
-  </servlet>
-  <servlet-mapping>
-    <servlet-name>SHAcc</servlet-name>
-    <url-pattern>/SHAcc</url-pattern>
-  </servlet-mapping>
-  
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+    version="2.5">
     <servlet>
-    <display-name>BJAcc</display-name>
-    <servlet-name>BJAcc</servlet-name>
-    <servlet-class>org.apache.geronimo.sample.servlet.BJAcc</servlet-class>
-  </servlet>
-  <servlet-mapping>
-    <servlet-name>BJAcc</servlet-name>
-    <url-pattern>/BJAcc</url-pattern>
-  </servlet-mapping>
-  
-  <servlet>
-    <display-name>DoTransfer</display-name>
-    <servlet-name>DoTransfer</servlet-name>
-    <servlet-class>org.apache.geronimo.sample.servlet.DoTransfer</servlet-class>
-  </servlet>
-  <servlet-mapping>
-    <servlet-name>DoTransfer</servlet-name>
-    <url-pattern>/DoTransfer</url-pattern>
-  </servlet-mapping>
-  
-  <welcome-file-list>
-    <welcome-file>index.jsp</welcome-file>
-  </welcome-file-list>
-      <session-config>
+        <display-name>SHAcc</display-name>
+        <servlet-name>SHAcc</servlet-name>
+        <servlet-class>org.apache.geronimo.sample.servlet.SHAcc</servlet-class>
+    </servlet>
+    <servlet-mapping>
+        <servlet-name>SHAcc</servlet-name>
+        <url-pattern>/SHAcc</url-pattern>
+    </servlet-mapping>
+
+    <servlet>
+        <display-name>BJAcc</display-name>
+        <servlet-name>BJAcc</servlet-name>
+        <servlet-class>org.apache.geronimo.sample.servlet.BJAcc</servlet-class>
+    </servlet>
+    <servlet-mapping>
+        <servlet-name>BJAcc</servlet-name>
+        <url-pattern>/BJAcc</url-pattern>
+    </servlet-mapping>
+
+    <servlet>
+        <display-name>DoTransfer</display-name>
+        <servlet-name>DoTransfer</servlet-name>
+        <servlet-class>org.apache.geronimo.sample.servlet.DoTransfer</servlet-class>
+    </servlet>
+    <servlet-mapping>
+        <servlet-name>DoTransfer</servlet-name>
+        <url-pattern>/DoTransfer</url-pattern>
+    </servlet-mapping>
+    
+        <servlet>
+        <display-name>Injection</display-name>
+        <servlet-name>Injection</servlet-name>
+        <servlet-class>org.apache.geronimo.sample.servlet.InjectionServlet</servlet-class>
+    </servlet>
+    <servlet-mapping>
+        <servlet-name>Injection</servlet-name>
+        <url-pattern>/injection</url-pattern>
+    </servlet-mapping>
+
+    <welcome-file-list>
+        <welcome-file>index.jsp</welcome-file>
+    </welcome-file-list>
+    <session-config>
         <session-timeout>
             30
         </session-timeout>
     </session-config>
 
-</web-app>
\ No newline at end of file
+</web-app>

Modified: geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/test/java/org/apache/geronimo/testsuite/javaee6/tests/jtaTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/test/java/org/apache/geronimo/testsuite/javaee6/tests/jtaTest.java?rev=1000669&r1=1000668&r2=1000669&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/test/java/org/apache/geronimo/testsuite/javaee6/tests/jtaTest.java
(original)
+++ geronimo/server/trunk/testsuite/javaee6-testsuite/jta1.1-test/src/test/java/org/apache/geronimo/testsuite/javaee6/tests/jtaTest.java
Fri Sep 24 00:22:53 2010
@@ -22,65 +22,75 @@ package org.apache.geronimo.testsuite.ja
 import org.apache.geronimo.testsupport.SeleniumTestSupport;
 import org.testng.Assert;
 import org.testng.annotations.Test;
-import static org.testng.Assert.*;
-import java.util.regex.Pattern;
 
 public class jtaTest extends SeleniumTestSupport {
-	@Test 
-	public void testDerbyTxSucessCommit() throws Exception {
-		selenium.open("/jta1.1-test/");
-		selenium.click("link=BJAcc");
-		selenium.waitForPageToLoad("30000");
-		selenium.click("link=Return");
-		selenium.waitForPageToLoad("30000");
-		selenium.click("link=SHAcc");
-		selenium.waitForPageToLoad("30000");
-		selenium.click("link=Return");
-		selenium.waitForPageToLoad("30000");
-		selenium.click("link=TestJTA");
-		selenium.waitForPageToLoad("30000");
-		//test if transfer from BJ to SH sucess
-		selenium.type("amount", "1");
-		selenium.type("flag", "0");
-		selenium.click("//input[@value='Submit']");
-		selenium.waitForPageToLoad("30000");
-		Assert.assertEquals("199", selenium.getText("//*[@id=\"bj\"]"));
-		Assert.assertEquals("201", selenium.getText("//*[@id=\"sh\"]"));
-		//test if the DoTransfer Servlet can invoked again
-		selenium.type("amount", "1");
-		selenium.type("flag", "0");
-		selenium.click("//input[@value='Submit']");
-		selenium.waitForPageToLoad("30000");
-		Assert.assertEquals("198", selenium.getText("//*[@id=\"bj\"]"));
-		Assert.assertEquals("202", selenium.getText("//*[@id=\"sh\"]"));
-	}
-	
-	@Test 
-	public void testDerbyTxRollback() throws Exception {
-		selenium.open("/jta1.1-test/");
-		selenium.click("link=BJAcc");
-		selenium.waitForPageToLoad("30000");
-		selenium.click("link=Return");
-		selenium.waitForPageToLoad("30000");
-		selenium.click("link=SHAcc");
-		selenium.waitForPageToLoad("30000");
-		selenium.click("link=Return");
-		selenium.waitForPageToLoad("30000");
-		selenium.click("link=TestJTA");
-		selenium.waitForPageToLoad("30000");
-		//test if transaction fail can occured
-		selenium.type("amount", "1");
-		selenium.type("flag", "1");//input 1 for transaction rollback
-		selenium.click("//input[@value='Submit']");
-		selenium.waitForPageToLoad("30000");
-		Assert.assertEquals("200", selenium.getText("//*[@id=\"bj\"]"));
-		Assert.assertEquals("200", selenium.getText("//*[@id=\"sh\"]"));
-		//test if the DoTransfer Servlet can invoked again and do transaction.commit()
-		selenium.type("amount", "10");
-		selenium.type("flag", "0");
-		selenium.click("//input[@value='Submit']");
-		selenium.waitForPageToLoad("30000");
-		Assert.assertEquals("190", selenium.getText("//*[@id=\"bj\"]"));
-		Assert.assertEquals("210", selenium.getText("//*[@id=\"sh\"]"));
-	}
+    
+    @Test
+    public void testDerbyTxSucessCommit() throws Exception {
+        selenium.open("/jta1.1-test/");
+        selenium.click("link=BJAcc");
+        selenium.waitForPageToLoad("30000");
+        selenium.click("link=Return");
+        selenium.waitForPageToLoad("30000");
+        selenium.click("link=SHAcc");
+        selenium.waitForPageToLoad("30000");
+        selenium.click("link=Return");
+        selenium.waitForPageToLoad("30000");
+        selenium.click("link=TestJTA");
+        selenium.waitForPageToLoad("30000");
+        // test if transfer from BJ to SH sucess
+        selenium.type("amount", "1");
+        selenium.type("flag", "0");
+        selenium.click("//input[@value='Submit']");
+        selenium.waitForPageToLoad("30000");
+        Assert.assertEquals("199", selenium.getText("//*[@id=\"bj\"]"));
+        Assert.assertEquals("201", selenium.getText("//*[@id=\"sh\"]"));
+        // test if the DoTransfer Servlet can invoked again
+        selenium.type("amount", "1");
+        selenium.type("flag", "0");
+        selenium.click("//input[@value='Submit']");
+        selenium.waitForPageToLoad("30000");
+        Assert.assertEquals("198", selenium.getText("//*[@id=\"bj\"]"));
+        Assert.assertEquals("202", selenium.getText("//*[@id=\"sh\"]"));
+    }
+
+    @Test
+    public void testDerbyTxRollback() throws Exception {
+        selenium.open("/jta1.1-test/");
+        selenium.click("link=BJAcc");
+        selenium.waitForPageToLoad("30000");
+        selenium.click("link=Return");
+        selenium.waitForPageToLoad("30000");
+        selenium.click("link=SHAcc");
+        selenium.waitForPageToLoad("30000");
+        selenium.click("link=Return");
+        selenium.waitForPageToLoad("30000");
+        selenium.click("link=TestJTA");
+        selenium.waitForPageToLoad("30000");
+        // test if transaction fail can occured
+        selenium.type("amount", "1");
+        selenium.type("flag", "1");// input 1 for transaction rollback
+        selenium.click("//input[@value='Submit']");
+        selenium.waitForPageToLoad("30000");
+        Assert.assertEquals("200", selenium.getText("//*[@id=\"bj\"]"));
+        Assert.assertEquals("200", selenium.getText("//*[@id=\"sh\"]"));
+        // test if the DoTransfer Servlet can invoked again and do
+        // transaction.commit()
+        selenium.type("amount", "10");
+        selenium.type("flag", "0");
+        selenium.click("//input[@value='Submit']");
+        selenium.waitForPageToLoad("30000");
+        Assert.assertEquals("190", selenium.getText("//*[@id=\"bj\"]"));
+        Assert.assertEquals("210", selenium.getText("//*[@id=\"sh\"]"));
+    }
+    
+    @Test
+    public void testInjection() throws Exception {
+        selenium.open("/jta1.1-test/injection");
+        selenium.waitForPageToLoad("30000");
+        String text = selenium.getBodyText();
+        System.out.println(text);
+        assertTrue(text.contains("TransactionSynchronizationRegistry: ok"));
+        assertTrue(text.contains("TransactionManager: ok"));
+    }
 }



Mime
View raw message