users@glassfish.java.net

How to use InterceptorBinding?

From: <glassfish_at_javadesktop.org>
Date: Thu, 08 Apr 2010 02:26:40 PDT

Hello everyone,

I have a problem with the InterceptorBinding introduced in Java EE6. I followed the example from the API-doc (see http://java.sun.com/javaee/6/docs/api/javax/interceptor/InterceptorBinding.html) and created an interceptor that prints "Hello method" when a method is called. For this interceptor I created a InterceptorBinding @Friendly to annotate methods and types. Here is the code for both of them:

----------------------------------------
@Inherited
@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Friendly {}
----------------------------------------
@Friendly @Interceptor
public class HelloInterceptor {
    @AroundInvoke
    public Object sayHello(InvocationContext ic) throws Exception {
        System.out.println("Hello " + ic.getMethod());
        return ic.proceed();
    }
}
----------------------------------------

In the beans.xml descriptor I added this interceptor:

----------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
    <interceptors>
        <class>packagename.HelloInterceptor</class>
    </interceptors>
</beans>
----------------------------------------

No comes my problem: When I try to deploy the application (as a ear, with an EJB module and an application client) the application server throws the following exception, telling me that the interceptor is not annotated with @Interceptor (as it obviously is). Has anyone also encountered this problem? What have I done wrong?

SCHWERWIEGEND: Exception while loading the app
org.glassfish.deployment.common.DeploymentException: Enabled interceptor class class packagename.HelloInterceptor is neither annotated with @Interceptor, nor registered through a portable extension
        at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:183)
        at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:125)
        at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:239)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:339)
        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: Enabled interceptor class class packagename.HelloInterceptor is neither annotated with @Interceptor, nor registered through a portable extension
        at org.jboss.weld.Validator.validateEnabledInterceptorClasses(Validator.java:346)
        at org.jboss.weld.Validator.validateDeployment(Validator.java:270)
        at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:389)
        at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:180)
        ... 30 more
[Message sent by forum member 'muhkuh2k']

http://forums.java.net/jive/thread.jspa?messageID=395855