Java Reference
In-Depth Information
LISTING 8-8 (continued)
String user = context.getContextData.get("user");
if (user==null){
user=(String)context.getParameters()[0];
context.getContextData.put("user", user)'
}
        return context.proceed();
}
@PostConstruct
public void onStart(){
Logger.getLogger("SecurityLog").info("Activating");
}
@PreDestroy
public void onShutdown(){
Logger.getLogger("SecurityLog").info("Deactivating");
}
}
Because the hooks rely on annotations, method names do not make a difference; you can use any name.
Default‐Level Interceptors
Marking the target advice with Interceptors annotation provides an easy implementation and setup, but
the nature of AOP usually asks for more. Most scenarios require the interceptor to perform its operation
targeting all advices. Imagine adding interceptors for logging or security—targeting only a subset of EJB
wouldn't work. Also, annotating each EJB can become cumbersome and can easily lead to human error.
Java EE offers default‐level interceptors to target all or subsets of EJB matching the naming scheme
provided. Unlike in the previous example, to implement default‐level interceptors, you need XML
coni guration:
<ejb-jar...>
<interceptors>
<interceptor>
<interceptor‐class>
com.devchronicles.SecurityInterceptor
</interceptor‐class>
</interceptor>
</interceptors>
<assembly-descriptor>
<interceptor-binding>
<ejb‐name>*</ejb‐name>
<interceptor‐class>
<interceptor‐class>
com.devchronicles.SecurityInterceptor
</interceptor‐class>
</interceptor‐class>
</interceptor-binding>
</assembly-descriptor>
</ejb-jar>
 
Search WWH ::




Custom Search