Author: vishwanathk
Date: Sun Mar 4 05:30:11 2012
New Revision: 1296750
URL: http://svn.apache.org/viewvc?rev=1296750&view=rev
Log:
OPENEJB-1768 Validation: Check that @WebService beans are not @Stateful or
@MessageDriven or @ManagedBean
Added:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckAnnotations.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/CheckAnnotationTest.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/test/annotated/
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/test/annotated/Green.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/test/annotated/Red.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/test/annotated/Yellow.java
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java
openejb/trunk/openejb/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java?rev=1296750&r1=1296749&r2=1296750&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java
Sun Mar 4 05:30:11 2012
@@ -37,6 +37,7 @@ import org.apache.openejb.config.rules.C
import org.apache.openejb.config.rules.CheckMethods;
import org.apache.openejb.config.rules.CheckPersistenceRefs;
import org.apache.openejb.config.rules.CheckUserTransactionRefs;
+import org.apache.openejb.config.rules.CheckAnnotations;
import org.apache.openejb.config.rules.ValidationBase;
import org.apache.openejb.util.Messages;
import org.apache.openejb.util.OpenEjbVersion;
@@ -118,7 +119,8 @@ public class AppValidator {
new CheckDependsOn(),
new CheckUserTransactionRefs(),
new CheckAsynchronous(),
- new CheckDescriptorLocation()
+ new CheckDescriptorLocation(),
+ new CheckAnnotations()
};
if (additionalValidators == null || additionalValidators.length == 0) {
return defaultRules;
Added:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckAnnotations.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckAnnotations.java?rev=1296750&view=auto
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckAnnotations.java
(added)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckAnnotations.java
Sun Mar 4 05:30:11 2012
@@ -0,0 +1,93 @@
+/*
+ * 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.config.WebModule;
+import org.apache.openejb.util.LogCategory;
+import org.apache.openejb.util.Logger;
+import org.apache.xbean.finder.IAnnotationFinder;
+
+import javax.jws.WebService;
+import java.lang.annotation.Annotation;
+import java.util.Arrays;
+import java.util.List;
+
+public class CheckAnnotations extends ValidationBase {
+
+ Logger logger = Logger.getInstance(LogCategory.OPENEJB_STARTUP_VALIDATION,
CheckAnnotations.class);
+
+ @Override
+ public void validate(AppModule appModule) {
+ try {
+
+ for (EjbModule ejbModule : appModule.getEjbModules()) {
+ module = ejbModule;
+ findClassesAnnotatedWithWebService(ejbModule);
+ }
+
+ for (WebModule webModule : appModule.getWebModules()) {
+ module = webModule;
+ findClassesAnnotatedWithWebService(webModule);
+ }
+
+ } catch (Exception e) {
+ logger.error("Error while validating @WebService annotation", e);
+ }
+
+
+ }
+
+ private void findClassesAnnotatedWithWebService(EjbModule ejbModule) {
+
+ IAnnotationFinder finder = ejbModule.getFinder();
+ if (finder != null)
{findIncorrectAnnotationAndWarn(finder,ejbModule.toString());}
+ }
+
+
+ private void findClassesAnnotatedWithWebService(WebModule webModule) {
+ IAnnotationFinder finder = webModule.getFinder();
+ if (finder != null)
{findIncorrectAnnotationAndWarn(finder,webModule.toString());}
+
+ }
+
+ private void findIncorrectAnnotationAndWarn(IAnnotationFinder finder,
String component) {
+ List<Class<?>> webserviceAnnotatedClasses =
finder.findAnnotatedClasses(WebService.class);
+ for (Class clazz : webserviceAnnotatedClasses) {
+ Annotation[] annotations = clazz.getDeclaredAnnotations();
+
+ List<Annotation> declaredAnnotations = Arrays.asList(annotations);
+ for (Annotation declaredAnn : declaredAnnotations) {
+ if
(declaredAnn.annotationType().getName().equals("javax.ejb.Stateful")) {
+ warn(component, "annotation.invalid.stateful.webservice",
clazz.getName());
+ }
+ if
(declaredAnn.annotationType().getName().equals("javax.annotation.ManagedBean"))
{
+ warn(component,
"annotation.invalid.managedbean.webservice", clazz.getName());
+ }
+ if
(declaredAnn.annotationType().getName().equals("javax.ejb.MessageDriven")) {
+ warn(component,
"annotation.invalid.messagedriven.webservice", clazz.getName());
+ }
+
+ }
+ }
+ }
+
+
+
+
+}
\ No newline at end of file
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties?rev=1296750&r1=1296749&r2=1296750&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
Sun Mar 4 05:30:11 2012
@@ -876,3 +876,17 @@ public interface {0} extends {2}'{}'
1.cdi.injectionPointOnNonBean = Invalid @Inject InjectionPoint (see CDI 1.0
section 5.5.7)
2.cdi.injectionPointOnNonBean = Invalid @Inject InjectionPoint (see CDI 1.0
section 5.5.7): class {0} field {1}
3.cdi.injectionPointOnNonBean = Invalid @Inject InjectionPoint (see CDI 1.0
section 5.5.7): class {0} field {1}
+
+1.annotation.invalid.stateful.webservice = Class annotated with @WebService
cannot be annotated with @Stateful.
+2.annotation.invalid.stateful.webservice = Class annotated with @WebService
cannot be annotated with @Stateful: class {0}
+3.annotation.invalid.stateful.webservice = Class annotated with @WebService
cannot be annotated with @Stateful: class {0}
+
+
+1.annotation.invalid.messagedriven.webservice = Class annotated with
@WebService cannot be annotated with @MesssageDriven.
+2.annotation.invalid.messagedriven.webservice = Class annotated with
@WebService cannot be annotated with @MessageDriven: class {0}
+3.annotation.invalid.messagedriven.webservice = Class annotated with
@WebService cannot be annotated with @MessageDriven: class {0}
+
+
+1.annotation.invalid.managedbean.webservice = Class annotated with @WebService
cannot be annotated with @ManagedBean.
+2.annotation.invalid.managedbean.webservice = Class annotated with @WebService
cannot be annotated with @ManagedBean: class {0}
+3.annotation.invalid.managedbean.webservice = Class annotated with @WebService
cannot be annotated with @ManagedBean: class {0}
Added:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/CheckAnnotationTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/CheckAnnotationTest.java?rev=1296750&view=auto
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/CheckAnnotationTest.java
(added)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/CheckAnnotationTest.java
Sun Mar 4 05:30:11 2012
@@ -0,0 +1,72 @@
+/*
+ * 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;
+
+import org.apache.openejb.config.rules.Key;
+import org.apache.openejb.config.rules.KeyType;
+import org.apache.openejb.config.rules.Keys;
+import org.apache.openejb.config.rules.ValidationRunner;
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.ManagedBean;
+import org.apache.openejb.jee.MessageDrivenBean;
+import org.apache.openejb.jee.StatefulBean;
+import org.apache.openejb.test.annotated.Green;
+import org.apache.openejb.test.annotated.Red;
+import org.apache.openejb.test.annotated.Yellow;
+import org.apache.xbean.finder.AnnotationFinder;
+import org.apache.xbean.finder.archive.ClassesArchive;
+import org.junit.runner.RunWith;
+
+@RunWith(ValidationRunner.class)
+public class CheckAnnotationTest {
+
+ @Keys({@Key(value = "annotation.invalid.stateful.webservice", type =
KeyType.WARNING)})
+ public AppModule testWebServiceWithStateful() {
+ EjbJar ejbJar = new EjbJar();
+ ejbJar.addEnterpriseBean(new StatefulBean(Green.class));
+ EjbModule ejbModule = new EjbModule(ejbJar);
+ ejbModule.setFinder(new AnnotationFinder(new
ClassesArchive(Green.class)).link());
+
+ AppModule appModule = new AppModule(ejbModule);
+ return appModule;
+ }
+
+ @Keys({@Key(value = "annotation.invalid.messagedriven.webservice", type =
KeyType.WARNING)})
+ public AppModule testWebServiceWithMessageDriven() {
+ EjbJar ejbJar = new EjbJar();
+ ejbJar.addEnterpriseBean(new MessageDrivenBean(Yellow.class));
+ EjbModule ejbModule = new EjbModule(ejbJar);
+ ejbModule.setFinder(new AnnotationFinder(new
ClassesArchive(Yellow.class)).link());
+
+ AppModule appModule = new AppModule(ejbModule);
+ return appModule;
+ }
+
+
+ @Keys({@Key(value = "annotation.invalid.managedbean.webservice", type =
KeyType.WARNING)})
+ public AppModule testWebServiceWithManagedBean() {
+ EjbJar ejbJar = new EjbJar();
+ ejbJar.addEnterpriseBean(new ManagedBean(Red.class));
+ EjbModule ejbModule = new EjbModule(ejbJar);
+ ejbModule.setFinder(new AnnotationFinder(new
ClassesArchive(Red.class)).link());
+
+ AppModule appModule = new AppModule(ejbModule);
+ return appModule;
+ }
+
+
+}
Added:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/test/annotated/Green.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/test/annotated/Green.java?rev=1296750&view=auto
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/test/annotated/Green.java
(added)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/test/annotated/Green.java
Sun Mar 4 05:30:11 2012
@@ -0,0 +1,33 @@
+/*
+ * 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.test.annotated;
+
+import javax.ejb.Stateful;
+import javax.interceptor.AroundInvoke;
+import javax.jws.WebService;
+
+
+@Stateful(description = "test")
+@WebService
+public class Green {
+
+ // need to add this @AroundInvoke to cause validation to fail. Validation
does not
+ // fail on warnings, which causes this framework to not work properly
+ @AroundInvoke
+ public void sayCheese() {
+ }
+}
Added:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/test/annotated/Red.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/test/annotated/Red.java?rev=1296750&view=auto
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/test/annotated/Red.java
(added)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/test/annotated/Red.java
Sun Mar 4 05:30:11 2012
@@ -0,0 +1,32 @@
+/*
+ * 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.test.annotated;
+
+import javax.annotation.ManagedBean;
+import javax.interceptor.AroundInvoke;
+import javax.jws.WebService;
+
+@ManagedBean
+@WebService
+public class Red {
+
+ // need to add this @AroundInvoke to cause validation to fail. Validation
does not
+ // fail on warnings, which causes this framework to not work properly
+ @AroundInvoke
+ public void sayCheese() {
+ }
+}
Added:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/test/annotated/Yellow.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/test/annotated/Yellow.java?rev=1296750&view=auto
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/test/annotated/Yellow.java
(added)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/test/annotated/Yellow.java
Sun Mar 4 05:30:11 2012
@@ -0,0 +1,40 @@
+/*
+ * 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.test.annotated;
+
+import javax.ejb.MessageDriven;
+import javax.interceptor.AroundInvoke;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jws.WebService;
+
+
+@MessageDriven
+@WebService
+public class Yellow implements MessageListener {
+
+ // need to add this @AroundInvoke to cause validation to fail. Validation
does not
+ // fail on warnings, which causes this framework to not work properly
+ @AroundInvoke
+ public void sayCheese() {
+ }
+
+ @Override
+ public void onMessage(Message message) {
+ //To change body of implemented methods use File | Settings | File
Templates.
+ }
+}