You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jl...@apache.org on 2008/11/03 15:47:55 UTC
svn commit: r710073 - in /openejb/trunk/openejb3/container:
openejb-core/src/main/java/org/apache/openejb/config/
openejb-core/src/main/java/org/apache/openejb/config/rules/
openejb-core/src/main/resources/org/apache/openejb/config/rules/
openejb-core/...
Author: jlaskowski
Date: Mon Nov 3 06:47:54 2008
New Revision: 710073
URL: http://svn.apache.org/viewvc?rev=710073&view=rev
Log:
OPENEJB-847 Validation: @Resource UserTransaction injection mistakenly used on bean with Container-Managed Transactions
Added:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckUserTransactionRefs.java
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckUserTransactionRefsTest.java
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ValidateModules.java
openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/EnvEntry.java
openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/ResourceEnvRef.java
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java?rev=710073&r1=710072&r2=710073&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java Mon Nov 3 06:47:54 2008
@@ -30,13 +30,7 @@
import org.apache.commons.cli.PosixParser;
import org.apache.openejb.OpenEJBException;
import org.apache.openejb.cli.SystemExitException;
-import org.apache.openejb.config.rules.CheckClasses;
-import org.apache.openejb.config.rules.CheckMethods;
-import org.apache.openejb.config.rules.CheckAssemblyBindings;
-import org.apache.openejb.config.rules.CheckCallbacks;
-import org.apache.openejb.config.rules.CheckInjectionTargets;
-import org.apache.openejb.config.rules.CheckPersistenceRefs;
-import org.apache.openejb.config.rules.CheckDependsOn;
+import org.apache.openejb.config.rules.*;
import org.apache.openejb.util.Messages;
import org.apache.openejb.util.OpenEjbVersion;
@@ -100,7 +94,8 @@
new CheckAssemblyBindings(),
new CheckInjectionTargets(),
new CheckPersistenceRefs(),
- new CheckDependsOn()
+ new CheckDependsOn(),
+ new CheckUserTransactionRefs()
};
return rules;
}
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ValidateModules.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ValidateModules.java?rev=710073&r1=710072&r2=710073&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ValidateModules.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ValidateModules.java Mon Nov 3 06:47:54 2008
@@ -23,9 +23,6 @@
*/
public class ValidateModules implements DynamicDeployer {
- public ValidateModules() {
- }
-
public AppModule deploy(AppModule appModule) throws OpenEJBException {
AppValidator validator = new AppValidator();
return validator.validate(appModule);
Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckUserTransactionRefs.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckUserTransactionRefs.java?rev=710073&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckUserTransactionRefs.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckUserTransactionRefs.java Mon Nov 3 06:47:54 2008
@@ -0,0 +1,51 @@
+/**
+ * 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.openejb.config.rules;
+
+import org.apache.openejb.config.EjbModule;
+import org.apache.openejb.jee.EnterpriseBean;
+import org.apache.openejb.jee.ResourceEnvRef;
+import static org.apache.openejb.jee.TransactionType.CONTAINER;
+
+import java.util.Collection;
+
+/**
+ * Excerpt from EJB 3.0 Core spec, chapter <b>16.12. UserTransaction Interface</b>:
+ * <p>
+ * <i>The container must make the UserTransaction interface available to the enterprise beans that are
+ * allowed to use this interface (only session and message-driven beans with bean-managed transaction
+ * demarcation are allowed to use this interface)</i>
+ * </p>
+ *
+ * @version $Rev$ $Date$
+ */
+public class CheckUserTransactionRefs extends ValidationBase {
+ // FIXME: Shouldn't the parent method be protected?
+ public void validate(EjbModule ejbModule) {
+ for (EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
+ if (bean.getTransactionType() == CONTAINER) {
+ // FIXME: I think bean.getRes should be used instead, but OpenEJB doesn't allow it atm
+ Collection<ResourceEnvRef> resRefs = bean.getResourceEnvRef();
+ for (ResourceEnvRef resRef : resRefs) {
+ if ("javax.transaction.UserTransaction".equals(resRef.getResourceEnvRefType())) {
+ warn(bean, "userResourceRef.forbiddenForCmtdBeans", resRef.getResourceEnvRefName());
+ }
+ }
+ }
+ }
+ }
+}
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties?rev=710073&r1=710072&r2=710073&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties Mon Nov 3 06:47:54 2008
@@ -716,9 +716,6 @@
2.xml.businessRemote.notInterface = The value of <business-remote> is not an interface: {0}
3.xml.businessRemote.notInterface = The <business-remote> element of the ejb-jar.xml must be an interface. Classes, abstract classes or enums are not allowed. Either convert {0} to an interface or remove the related <business-remote> xml tag from your ejb-jar.xml
-
-
-
1.xml.businessLocal.ejbHome = javax.ejb.EJBHome interface declared as <business-local>. Use <home>{0}</home>
2.xml.businessLocal.ejbHome = javax.ejb.EJBHome interface declared as <business-local>. Use <home>{0}</home>
3.xml.businessLocal.ejbHome = Interfaces extending javax.ejb.EJBHome must use the <home> tag, not the <business-local> tag, when declared in the ejb-jar.xml. Declare this interface as <home>{0}</home> or alternatively add @RemoteHome({0}.class) to the top of your bean class.
@@ -752,3 +749,9 @@
1.dependsOn.circuit = Singleton circular dependency detected
2.dependsOn.circuit = Singleton circular dependency detected: {0}
3.dependsOn.circuit = A Singleton circular dependency has been detected in the application. Bean "{1}" refers to one or more other singleton beans via @DependsOn which directly or indirectly refer back to bean "{1}". This circle must be broken befor the application can be built: {0}
+
+# CheckUserTransactionRefs.java
+# warn(bean, "userResourceRef.forbiddenForCmtdBeans", resRef.getResourceEnvRefName());
+1.userResourceRef.forbiddenForCmtdBeans = Illegal resource reference to UserTransaction detected
+2.userResourceRef.forbiddenForCmtdBeans = Illegal resource reference to UserTransaction detected with JNDI name: {0}
+3.userResourceRef.forbiddenForCmtdBeans = Only session and message-driven beans with bean-managed transaction demarcation are allowed to use UserTransaction via @Resource or resource-env-ref
Added: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckUserTransactionRefsTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckUserTransactionRefsTest.java?rev=710073&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckUserTransactionRefsTest.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckUserTransactionRefsTest.java Mon Nov 3 06:47:54 2008
@@ -0,0 +1,74 @@
+/**
+ * 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.openejb.config.rules;
+
+import org.apache.openejb.config.AppModule;
+import org.apache.openejb.config.EjbModule;
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.ResourceRef;
+import org.apache.openejb.jee.StatelessBean;
+import static org.apache.openejb.jee.TransactionType.CONTAINER;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CheckUserTransactionRefsTest {
+
+ AppModule appModule;
+
+ @Before
+ public void setUp() {
+ // Stateless session bean with container-managed transaction demarcation
+ StatelessBean cmtdSlsb = new StatelessBean("CheckUserTransactionRefsTest", "nopackage.CheckUserTransactionRefsTestBean");
+ cmtdSlsb.setTransactionType(CONTAINER);
+
+ // "@Resource UserTransaction tx" declaration
+ ResourceRef resourceRef = new ResourceRef();
+ resourceRef.setName("nopackage.CheckUserTransactionRefsTestBean/tx");
+ resourceRef.setResType("javax.transaction.UserTransaction");
+
+ cmtdSlsb.getResourceRef().add(resourceRef);
+
+ EjbJar ejbJar = new EjbJar();
+ ejbJar.addEnterpriseBean(cmtdSlsb);
+ EjbModule ejbModule = new EjbModule(ejbJar);
+
+ appModule = new AppModule(getClass().getClassLoader(), "some/path");
+ appModule.getEjbModules().add(ejbModule);
+
+ }
+
+ @Test
+ public void testSLSBwithUserTransaction() {
+
+ CheckUserTransactionRefs checkUserTransactionRefs = new CheckUserTransactionRefs();
+ // FIXME: It's not possible to run validate(ejbModule) with warn without setting up module in the validate first
+ checkUserTransactionRefs.validate(appModule);
+
+ assert appModule.getValidation().getErrors().length == 0;
+ assert appModule.getValidation().getWarnings().length == 1;
+ assert appModule.getValidation().getFailures().length == 0;
+ }
+
+ @After
+ public void cleanUp() {
+ appModule = null;
+ }
+}
Modified: openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/EnvEntry.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/EnvEntry.java?rev=710073&r1=710072&r2=710073&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/EnvEntry.java (original)
+++ openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/EnvEntry.java Mon Nov 3 06:47:54 2008
@@ -92,7 +92,7 @@
this.envEntryValue = envEntryValue;
}
- public EnvEntry(String envEntryName, Class envEntryType, String envEntryValue) {
+ public EnvEntry(String envEntryName, Class<?> envEntryType, String envEntryValue) {
this(envEntryName, envEntryType.getName(), envEntryValue);
}
Modified: openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/ResourceEnvRef.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/ResourceEnvRef.java?rev=710073&r1=710072&r2=710073&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/ResourceEnvRef.java (original)
+++ openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/ResourceEnvRef.java Mon Nov 3 06:47:54 2008
@@ -84,6 +84,14 @@
@XmlID
protected String id;
+ public ResourceEnvRef() {
+ }
+
+ public ResourceEnvRef(String resourceEnvRefName, String resourceEnvRefType) {
+ this.resourceEnvRefName = resourceEnvRefName;
+ this.resourceEnvRefType = resourceEnvRefType;
+ }
+
@XmlTransient
public String getName() {
return getResourceEnvRefName();