Skip to content

Commit

Permalink
WELD-538
Browse files Browse the repository at this point in the history
* Introduce full validation of interceptors and
  decorators
* Add a (disabled) test that shows a 
  DefinitionException being thrown (can enable
  when Arquillian supports detecting deployment
  errors)
  • Loading branch information
pmuir committed Dec 7, 2010
1 parent 13467d8 commit f8b0445
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 7 deletions.
26 changes: 19 additions & 7 deletions impl/src/main/java/org/jboss/weld/bootstrap/Validator.java
Expand Up @@ -171,7 +171,7 @@ private void validateRIBean(RIBean<?> bean, BeanManagerImpl beanManager, Collect
}
specializedBeans.add(abstractBean.getSpecializedBean());
}
if ((bean instanceof AbstractClassBean<?>) && bean.isPassivationCapableBean())
if ((bean instanceof AbstractClassBean<?>))
{
AbstractClassBean<?> classBean = (AbstractClassBean<?>) bean;
if (classBean.hasDecorators())
Expand Down Expand Up @@ -201,28 +201,36 @@ private void validateInterceptors(BeanManagerImpl beanManager, AbstractClassBean
{
SerializableContextual<Interceptor<?>, ?> serializableContextual = cast(interceptorMetadata.getInterceptorReference().getInterceptor());

if (!((InterceptorImpl<?>) serializableContextual.get()).isSerializable())
if (classBean.isPassivationCapableBean() && !((InterceptorImpl<?>) serializableContextual.get()).isSerializable())
{
throw new DeploymentException(PASSIVATING_BEAN_WITH_NONSERIALIZABLE_INTERCEPTOR, classBean, serializableContextual.get());
}
for (InjectionPoint injectionPoint : serializableContextual.get().getInjectionPoints())
{
Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(injectionPoint));
validateInjectionPointPassivationCapable(injectionPoint, resolvedBean, beanManager);
validateInjectionPoint(injectionPoint, beanManager);
if (classBean.isPassivationCapableBean())
{
validateInjectionPointPassivationCapable(injectionPoint, resolvedBean, beanManager);
}
}
}
if (interceptorMetadata.getInterceptorReference().getInterceptor() instanceof ClassMetadata<?>)
{
ClassMetadata<?> classMetadata = (ClassMetadata<?>) interceptorMetadata.getInterceptorReference().getInterceptor();
if (!Reflections.isSerializable(classMetadata.getJavaClass()))
if (classBean.isPassivationCapableBean() && !Reflections.isSerializable(classMetadata.getJavaClass()))
{
throw new DeploymentException(PASSIVATING_BEAN_WITH_NONSERIALIZABLE_INTERCEPTOR, this, classMetadata.getJavaClass().getName());
}
InjectionTarget<Object> injectionTarget = cast(beanManager.createInjectionTarget(beanManager.createAnnotatedType(classMetadata.getJavaClass())));
for (InjectionPoint injectionPoint : injectionTarget.getInjectionPoints())
{
Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(injectionPoint));
validateInjectionPointPassivationCapable(injectionPoint, resolvedBean, beanManager);
validateInjectionPoint(injectionPoint, beanManager);
if (classBean.isPassivationCapableBean())
{
validateInjectionPointPassivationCapable(injectionPoint, resolvedBean, beanManager);
}
}
}
}
Expand All @@ -234,7 +242,7 @@ private void validateDecorators(BeanManagerImpl beanManager, AbstractClassBean<?
{
for (Decorator<?> decorator : classBean.getDecorators())
{
if (!((WeldDecorator<?>) decorator).getWeldAnnotated().isSerializable())
if (classBean.isPassivationCapableBean() && !((WeldDecorator<?>) decorator).getWeldAnnotated().isSerializable())
{
throw new UnserializableDependencyException(PASSIVATING_BEAN_WITH_NONSERIALIZABLE_DECORATOR, classBean, decorator);
}
Expand All @@ -243,7 +251,11 @@ private void validateDecorators(BeanManagerImpl beanManager, AbstractClassBean<?
if (!ij.isDelegate())
{
Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(ij));
validateInjectionPointPassivationCapable(ij, resolvedBean, beanManager);
validateInjectionPoint(ij, beanManager);
if (classBean.isPassivationCapableBean())
{
validateInjectionPointPassivationCapable(ij, resolvedBean, beanManager);
}
}
}
}
Expand Down
@@ -0,0 +1,29 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed 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.jboss.weld.tests.interceptors;


/**
* @author Marius Bogoevici
*/
public interface Ball
{

void shoot();

}
@@ -0,0 +1,30 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed 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.jboss.weld.tests.interceptors;


/**
* @author <a href="mailto:mariusb@redhat.com">Marius Bogoevici</a>
*/
public class BallImpl implements Ball
{
@Shot
public void shoot()
{
}
}
@@ -0,0 +1,45 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed 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.jboss.weld.tests.interceptors;

import java.io.Serializable;
import java.util.logging.Logger;

import javax.inject.Inject;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;

/**
* @author <a href="mailto:mariusb@redhat.com">Marius Bogoevici</a>
*/
@Shot @Interceptor
public class Goalkeeper implements Serializable
{

@Inject Logger log;

public static boolean called;

@AroundInvoke
public Object catchBall(InvocationContext invocationContext) throws Exception
{
called = true;
return invocationContext.proceed();
}
}
@@ -0,0 +1,48 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed 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.jboss.weld.tests.interceptors;

import static org.junit.Assert.assertTrue;

import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.BeanArchive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(Arquillian.class) @Ignore
public class InterceptionTest
{
@Deployment
public static Archive<?> deploy()
{
return ShrinkWrap.create(BeanArchive.class)
.intercept(Goalkeeper.class)
.addPackage(InterceptionTest.class.getPackage());
}

@Test
// WELD-538
public void testInterceptors(Ball ball) throws Exception
{
ball.shoot();
assertTrue(Goalkeeper.called);
}
}
@@ -0,0 +1,37 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed 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.jboss.weld.tests.interceptors;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
import java.lang.annotation.Documented;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import javax.interceptor.InterceptorBinding;

/**
* @author <a href="mailto:mariusb@redhat.com">Marius Bogoevici</a>
*/
@InterceptorBinding
@Retention(RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
@Documented
public @interface Shot
{
}

0 comments on commit f8b0445

Please sign in to comment.