Enabling an interceptor in a library
matt.corey Dec 2, 2009 5:26 AMI am trying to create a simple .jar file which could be included in a web application, containing a number of CDI utilities, such as logging interceptors, a set of handy stereotypes, etc., but I am hitting an unexpected problem when attempting to enable the interceptors... namely, it appears that I need to define all of my interceptors in one location -- either in the beans.xml from the .jar library file, or in the beans.xml from the web app, but I am not permitted to define a list of interceptors in both locations, even if I have no duplication of actual interceptors... for example, if I have the following beans.xml in my library:
<beans> <interceptors> <class>com.users.log.LoggingInterceptor</class> </interceptors> </beans>
and the following beans.xml in my web application:
<beans> <interceptors> <class>com.users.security.SecurityInterceptor</class> </interceptors> </beans>
I get the following exception upon loading Glassfish (build 74, which is the latest at the time of writing):
SEVERE: Exception while loading the app org.glassfish.deployment.common.DeploymentException: <interceptor> can only be specified once, but it is specified muliple times [File: file:/C:/Documents and Settings/Matt/My Documents/NetBeansProjects/UserManagement/target/UserManagement/WEB-INF/beans.xml; Node: [interceptors: null], File: file:/C:/Program Files/glassfish-v3-b74/glassfishv3/glassfish/domains/domain1/generated/jsp/com.user_UserManagement_war_1.0-SNAPSHOT/loader_5889032/META-INF/beans.xml; Node: [interceptors: null], File: file:/C:/Program Files/glassfish-v3-b74/glassfishv3/glassfish/domains/domain1/generated/jsp/com.user_UserManagement_war_1.0-SNAPSHOT/loader_5889032/META-INF/beans.xml; Node: [interceptors: null]] at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:155) at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:125) at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:224) at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:338) at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:183) at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:272) at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:305) at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:320) at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1176) at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$900(CommandRunnerImpl.java:83) at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235) at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1224) at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:365) at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:204) at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:166) at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:100) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:245) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57) at com.sun.grizzly.ContextTask.run(ContextTask.java:69) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309) at java.lang.Thread.run(Thread.java:619) Caused by: org.jboss.weld.DeploymentException: <interceptor> can only be specified once, but it is specified muliple times [File: file:/C:/Documents and Settings/Matt/My Documents/NetBeansProjects/UserManagement/target/UserManagement/WEB-INF/beans.xml; Node: [interceptors: null], File: file:/C:/Program Files/glassfish-v3-b74/glassfishv3/glassfish/domains/domain1/generated/jsp/com.user_UserManagement_war_1.0-SNAPSHOT/loader_5889032/META-INF/beans.xml; Node: [interceptors: null], File: file:/C:/Program Files/glassfish-v3-b74/glassfishv3/glassfish/domains/domain1/generated/jsp/com.user_UserManagement_war_1.0-SNAPSHOT/loader_5889032/META-INF/beans.xml; Node: [interceptors: null]] at org.jboss.weld.xml.BeansXmlParser.parse(BeansXmlParser.java:202) at org.jboss.weld.bootstrap.BeanDeployment.parseBeansXml(BeanDeployment.java:107) at org.jboss.weld.bootstrap.BeanDeployment.<init>(BeanDeployment.java:85) at org.jboss.weld.bootstrap.WeldBootstrap$DeploymentVisitor.visit(WeldBootstrap.java:197) at org.jboss.weld.bootstrap.WeldBootstrap$DeploymentVisitor.visit(WeldBootstrap.java:174) at org.jboss.weld.bootstrap.WeldBootstrap.startContainer(WeldBootstrap.java:295) at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:151) ... 30 more
It seems odd that a framework writer would not be able to automatically turn on a set of interceptors from their library, and instead needs to require that the end-user include a (possibly long) list of enabled interceptors, and I don't see any reference in the spec of this restriction -- in fact, section 9.4 of the spec has a paragraph that reads An interceptor is said to be enabled if it is enabled in at least one bean archive.
, implying that it would be possible to enable it from multiple archives.. am I missing something here? Is there way to write a framework or CDI extension, and not require the end user to include a list of 7 or 8 interceptors by hand?
M