Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

AS7-4520 Add better error messages for invalid EJB classes

  • Loading branch information...
commit 723393c4c0231518d3d92d04a136d39533eb9f3b 1 parent 586419e
Stuart Douglas stuartwdouglas authored bstansberry committed
12 ejb3/src/main/java/org/jboss/as/ejb3/EjbMessages.java
View
@@ -2086,4 +2086,16 @@
@Message(id = 14226, value = "Could not lookup service %s")
IllegalStateException serviceNotFound(ServiceName serviceName);
+
+ @Message(id = 14227, value = "EJB %s of type %s must have public default constructor")
+ DeploymentUnitProcessingException ejbMustHavePublicDefaultConstructor(String componentName, String componentClassName);
+
+ @Message(id = 14228, value = "EJB %s of type %s must not be inner class")
+ DeploymentUnitProcessingException ejbMustNotBeInnerClass(String componentName, String componentClassName);
+
+ @Message(id = 14229, value = "EJB %s of type %s must be declared public")
+ DeploymentUnitProcessingException ejbMustBePublicClass(String componentName, String componentClassName);
+
+ @Message(id = 14230, value = "EJB %s of type %s must not be declared final")
+ DeploymentUnitProcessingException ejbMustNotBeFinalClass(String componentName, String componentClassName);
}
1  ejb3/src/main/java/org/jboss/as/ejb3/component/EJBComponentDescription.java
View
@@ -233,6 +233,7 @@ public EJBComponentDescription(final String componentName, final String componen
//we need to make sure this is up before the EJB starts, so that remote invocations are available
addDependency(deploymentUnitServiceName.append(ModuleDeployment.SERVICE_NAME), ServiceBuilder.DependencyType.REQUIRED);
+ getConfigurators().addFirst(EJBValidationConfigurator.INSTANCE);
getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
74 ejb3/src/main/java/org/jboss/as/ejb3/component/EJBValidationConfigurator.java
View
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.as.ejb3.component;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+
+import org.jboss.as.ee.component.ComponentConfiguration;
+import org.jboss.as.ee.component.ComponentConfigurator;
+import org.jboss.as.ee.component.ComponentDescription;
+import org.jboss.as.ejb3.EjbMessages;
+import org.jboss.as.server.deployment.Attachments;
+import org.jboss.as.server.deployment.DeploymentPhaseContext;
+import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
+import org.jboss.as.server.deployment.reflect.ClassReflectionIndex;
+import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
+
+/**
+ *
+ * Configurator that validates than an EJB class does not validate the EJB specification
+ *
+ * @author Stuart Douglas
+ */
+public class EJBValidationConfigurator implements ComponentConfigurator {
+
+ public static final EJBValidationConfigurator INSTANCE = new EJBValidationConfigurator();
+
+ private EJBValidationConfigurator() {
+
+ }
+
+ @Override
+ public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
+ final DeploymentReflectionIndex deploymentReflectionIndex = context.getDeploymentUnit().getAttachment(Attachments.REFLECTION_INDEX);
+ final ClassReflectionIndex<?> classIndex = deploymentReflectionIndex.getClassIndex(configuration.getComponentClass());
+ final Constructor<?> ctor = classIndex.getConstructor(new String[0]);
+
+ if(ctor == null) {
+ throw EjbMessages.MESSAGES.ejbMustHavePublicDefaultConstructor(description.getComponentName(), description.getComponentClassName());
+ }
+ if(!Modifier.isPublic(ctor.getModifiers())) {
+ throw EjbMessages.MESSAGES.ejbMustHavePublicDefaultConstructor(description.getComponentName(), description.getComponentClassName());
+ }
+ if(configuration.getComponentClass().getEnclosingClass() != null) {
+ throw EjbMessages.MESSAGES.ejbMustNotBeInnerClass(description.getComponentName(), description.getComponentClassName());
+ }
+ if(!Modifier.isPublic(configuration.getComponentClass().getModifiers())) {
+ throw EjbMessages.MESSAGES.ejbMustBePublicClass(description.getComponentName(), description.getComponentClassName());
+ }
+ if(Modifier.isFinal(configuration.getComponentClass().getModifiers())) {
+ throw EjbMessages.MESSAGES.ejbMustNotBeFinalClass(description.getComponentName(), description.getComponentClassName());
+ }
+ }
+}
4 ...e/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/packaging/warlib/WarLibEjb.java
View
@@ -32,6 +32,10 @@
private final OtherEjb ejb;
+ public WarLibEjb() {
+ ejb = null;
+ }
+
@Inject
public WarLibEjb(final OtherEjb ejb) {
this.ejb = ejb;
Please sign in to comment.
Something went wrong with that request. Please try again.