users@glassfish.java.net

Re: ejb-jar.xml assembly-descriptor question: interceptor recognized, but not loaded?

From: Steven Siebert <smsiebe_at_gmail.com>
Date: Sun, 27 May 2012 20:00:30 -0400

Laird,

Are you using CDI? Do you have a beans.xml file in either of the ejb-jar
or the library jar in your ear?

S

On Sun, May 27, 2012 at 7:39 PM, Laird Nelson <ljnelson_at_gmail.com> wrote:

> OK, this one has me baffled.
>
> I have an .ear file.
>
> It contains an ejb jar file at the root. This is listed as an EJB module
> in application.xml and functions properly.
>
> The .ear file also has a lib directory. Classes etc. are loaded from it
> just fine; the app works normally.
>
> Inside the lib directory is another jar with an interceptor in it.
> Straightforward.
>
> The ejb jar file has a deployment descriptor inside its META-INF
> directory, named ejb-jar.xml.
>
> I am attempting to get an interceptor class--present in the interceptor
> jar--to get bound to a particular method in a particular EJB in the ejb
> jar. This is Java EE 101 stuff. I cannot get it to work.
>
> Attempt #1:
>
> Interceptor class was annotated with @Interceptor, but there was no
> <interceptor> stanza in my deployment descriptor. (The interceptor-binding
> stanza was present.)
>
> Result: failure. The interceptor was never found or created.
>
> Attempt #2:
>
> Interceptor class was annotated with @Interceptor, and, in addition, I
> placed an <interceptor> stanza in my deployment descriptor.
>
> Result: failure. The interceptor was never found or created.
>
> Attempt #3:
>
> Interceptor class was annotated with @Interceptor, and, in addition, I
> placed an <interceptor> stanza in my deployment descriptor, but this time
> specified a bogus class name.
>
> Result: failure, but Glassfish barfed at deploy time telling me that there
> was no such interceptor class. This tells me that the deployment
> descriptor is found and read.
>
> Here is my deployment descriptor in its entirety, with comments.
>
> <?xml version="1.0" encoding="utf-8"?>
> <ejb-jar 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/ejb-jar_3_1.xsd"
> version="3.1">
>
> <!-- this stanza isn't relevant to the current problem, but note the
> ejb-name here. -->
> <enterprise-beans>
> <session>
> <ejb-name>PersonBean</ejb-name>
> <ejb-class>com.foobar.PersonBean</ejb-class>
> <env-entry>
> <env-entry-name>entityClassName</env-entry-name>
> <env-entry-type>java.lang.String</env-entry-type>
> <env-entry-value>com.foobar.jpa.PersonEntity</env-entry-value>
> </env-entry>
> </session>
> </enterprise-beans>
>
> <interceptors>
>
> <!-- without this stanza, the interceptor is not found. -->
> <!-- with this stanza, the interceptor is not found. -->
> <!-- The interceptor class referenced below is in a jar file in the
> .ear file's lib directory. -->
> <!-- If the class name is switched to BOGUS, deployment fails. This
> tells me the DD is being read. -->
> <interceptor>
>
> <interceptor-class>com.foobar.NewPersonInterceptor</interceptor-class>
> <!-- the presence or absence of the following stanza makes no
> difference. -->
> <around-invoke>
> <method-name>addNewAuditItem</method-name>
> </around-invoke>
> </interceptor>
> </interceptors>
>
> <assembly-descriptor>
> <interceptor-binding>
> <ejb-name>PersonBean</ejb-name>
>
> <interceptor-class>com.foobar.NewPersonInterceptor</interceptor-class>
> <!-- The presence or absence of this stanza makes no difference. -->
> <method>
> <method-name>persist</method-name>
> </method>
> </interceptor-binding>
> </assembly-descriptor>
>
> </ejb-jar>
>
> Surely I am missing something profoundly obvious. Any help greatly
> appreciated.
>
> Best,
> Laird
>
> --
> http://about.me/lairdnelson
>
>