[weld-issues] [JBoss JIRA] (WELD-1082) Interceptor resolution works across bean archive boundaries

Manuel Hartl (JIRA) jira-events at lists.jboss.org
Thu Mar 8 09:48:36 EST 2012


    [ https://issues.jboss.org/browse/WELD-1082?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12675159#comment-12675159 ] 

Manuel Hartl commented on WELD-1082:
------------------------------------

i will try a pull request the next time, for now i will paste the three classes in here:

------------------------------------------------------------
package org.jboss.weld.tests.unit.bootstrap;

/**
 * 
 * @author Manuel Hartl / FlexSecure GmbH
 *
 */
public class SomeBean {

	@TestBinding
	public boolean businessMethod() {
		return true;
	}
}
------------------------------------------------------------
package org.jboss.weld.tests.unit.bootstrap;

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

/**
 * 
 * @author Manuel Hartl / FlexSecure GmbH
 *
 */
@Interceptor
@TestBinding
public class TestInterceptor {

	@AroundInvoke
	public Object process(InvocationContext invocationContext) throws Exception {
		throw new RuntimeException("should not be thrown");
	}

}
------------------------------------------------------------
package org.jboss.weld.tests.unit.bootstrap;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static org.junit.Assert.assertTrue;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import javax.inject.Inject;
import javax.interceptor.InterceptorBinding;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;

@Retention(RUNTIME)
@Target({ METHOD, TYPE })
@Documented
@InterceptorBinding
@interface TestBinding {
}

/**
 * 
 * @author Manuel Hartl / FlexSecure GmbH
 *
 */
@RunWith(Arquillian.class)
public class InterceptorTest {

	@Deployment
	public static WebArchive createWebappWithTwoJars() {
		// first bean archive: has interceptor and a beans.xml that enables it.
		JavaArchive bda1 = ShrinkWrap
				.create(JavaArchive.class, "bda1.jar")
				.addClasses(TestInterceptor.class)
				.addAsManifestResource(
						new ByteArrayAsset(
								("<beans><interceptors><class>" + TestInterceptor.class.getName() + "</class></interceptors></beans>")
										.getBytes()), ArchivePaths.create("beans.xml"));
		// second bean archive: has a bean with the interceptor binding on a method, but no enabled interceptor!
		JavaArchive bda2 = ShrinkWrap.create(JavaArchive.class, "bda2.jar")
				.addClasses(SomeBean.class)
				.addAsManifestResource(EmptyAsset.INSTANCE,
				ArchivePaths.create("beans.xml"));
		return ShrinkWrap.create(WebArchive.class, "test.war").addAsLibraries(bda1).addAsLibraries(bda2);
	}

	@Inject
	SomeBean someBean;

	@Test
	public void testGlobalInterceptors() {
		assertTrue(someBean.businessMethod());
	}

}

                
> Interceptor resolution works across bean archive boundaries
> -----------------------------------------------------------
>
>                 Key: WELD-1082
>                 URL: https://issues.jboss.org/browse/WELD-1082
>             Project: Weld
>          Issue Type: Bug
>          Components: Interceptors and Decorators
>    Affects Versions: 1.1.5.Final
>         Environment: tomcat 7.0.25, windows 7, weld 1.1.5,
>            Reporter: Manuel Hartl
>
> Enabling Interceptors in beans.xml in a bean archive will enable the interceptor for ALL bean archives in the class path.
> according to CDI spec 1.0 (9.5. Interceptor resolution) this is wrong:
> "An interceptor is bound to a method if: [....] The interceptor is enabled in the bean archive containing the bean."

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the weld-issues mailing list