Skip to content

Commit

Permalink
WFLY-2165 NPE starting WildFly with Spring 3
Browse files Browse the repository at this point in the history
  • Loading branch information
jharting committed Sep 27, 2013
1 parent fd9988d commit c8daf60
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
Expand Up @@ -23,7 +23,6 @@
import org.jboss.weld.injection.producer.LifecycleCallbackInvoker;
import org.jboss.weld.injection.producer.NoopLifecycleCallbackInvoker;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.resources.ClassTransformer;

/**
* {@link javax.enterprise.inject.spi.InjectionTarget} implementation used for non-contextual EE components such as
Expand All @@ -39,11 +38,6 @@
*/
public class NonContextualComponentInjectionTarget<T> extends BasicInjectionTarget<T> {

@SuppressWarnings("unchecked")
public NonContextualComponentInjectionTarget(Class<?> componentClass, Bean<T> bean, BeanManagerImpl beanManager) {
this(beanManager.getServices().get(ClassTransformer.class).getEnhancedAnnotatedType((Class<T>) componentClass, beanManager.getId()), bean, beanManager);
}

public NonContextualComponentInjectionTarget(EnhancedAnnotatedType<T> type, Bean<T> bean, BeanManagerImpl beanManager) {
super(type, bean, beanManager);
}
Expand Down
Expand Up @@ -30,6 +30,7 @@

import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.InjectionTarget;
import javax.servlet.AsyncListener;

import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription;
Expand All @@ -42,12 +43,18 @@
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.jboss.msc.value.InjectedValue;
import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType;
import org.jboss.weld.bean.ManagedBean;
import org.jboss.weld.bean.SessionBean;
import org.jboss.weld.ejb.spi.EjbDescriptor;
import org.jboss.weld.injection.producer.BasicInjectionTarget;
import org.jboss.weld.injection.producer.InjectionTargetService;
import org.jboss.weld.injection.producer.NonProducibleInjectionTarget;
import org.jboss.weld.literal.AnyLiteral;
import org.jboss.weld.logging.UtilLogger;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.util.Beans;
import org.wildfly.security.manager.WildFlySecurityManager;

/**
Expand Down Expand Up @@ -101,7 +108,7 @@ public synchronized void start(final StartContext context) throws StartException
beanManager = weldContainer.getValue().getBeanManager(beanDeploymentArchiveId);

for (final Class<?> interceptor : interceptorClasses) {
interceptorInjections.put(interceptor, new NonContextualComponentInjectionTarget(interceptor, null, beanManager));
interceptorInjections.put(interceptor, createInjectionTarget(interceptor, null, beanManager));
}

if (ejbName != null) {
Expand All @@ -126,7 +133,7 @@ public synchronized void start(final StartContext context) throws StartException
}
}

NonContextualComponentInjectionTarget injectionTarget = new NonContextualComponentInjectionTarget(componentClass, bean, beanManager);
BasicInjectionTarget injectionTarget = createInjectionTarget(componentClass, bean, beanManager);
if (componentDescription instanceof MessageDrivenComponentDescription || componentDescription instanceof WebComponentDescription) {
// fire ProcessInjectionTarget for non-contextual components
this.injectionTarget = beanManager.fireProcessInjectionTarget(injectionTarget.getAnnotated(), injectionTarget);
Expand All @@ -140,6 +147,23 @@ public synchronized void start(final StartContext context) throws StartException
}
}

private <T> BasicInjectionTarget<T> createInjectionTarget(Class<?> componentClass, Bean<T> bean, BeanManagerImpl beanManager) {
EnhancedAnnotatedType<T> type = beanManager.getServices().get(ClassTransformer.class).getEnhancedAnnotatedType((Class<T>) componentClass, beanManager.getId());
if (Beans.getBeanConstructor(type) == null) {
if (AsyncListener.class.isAssignableFrom(componentClass)) {
/*
* AsyncListeners may be CDI-incompatible as long as the application never calls
* javax.servletAsyncContext#createListener(Class) and only instantiates the listener
* itself.
*/
return new NonProducibleInjectionTarget<>(type, bean, beanManager);
} else {
throw UtilLogger.LOG.unableToFindConstructor(type);
}
}
return new NonContextualComponentInjectionTarget<>(type, bean, beanManager);
}

private <T> ManagedBean<T> findManagedBeanForWSComponent(Class<T> definingClass) {
Set<Bean<?>> beans = beanManager.getBeans(definingClass, AnyLiteral.INSTANCE);
for (Iterator<Bean<?>> i = beans.iterator(); i.hasNext();) {
Expand Down

0 comments on commit c8daf60

Please sign in to comment.