-
1. Re: Need to replace LoggingInterceptor
nickarls Nov 24, 2012 3:06 PM (in response to fernando.rubbo)If you use ejb-jar.xml to bind an interceptor to all ejbs, where in the interceptor stack does it end up?
-
2. Re: Need to replace LoggingInterceptor
fernando.rubbo Nov 24, 2012 3:28 PM (in response to nickarls)Hi Nicklas,
As far as I know, any EJB interceptor (specified in ejb-jar.xml or using @Interceptor) has the same lifecicle that the EJB it is intercepting has. So, it lives along together with the EJB. In my understanding, the stack would be something like this:
- ...
- LoggingInterceptor
- ...
- SecurityInterceptor
- ...
- CMTTxInterceptor
- ...
- <MyInterceptor>
- <MyEJB>
What I would like is
- ...
- <MyInterceptor>
- LoggingInterceptor
- ...
- SecurityInterceptor
- ...
- CMTTxInterceptor
- ...
- <MyEJB>
OR
- ...
- <MyInterceptor> replacing LoggingInterceptor
- ...
- SecurityInterceptor
- ...
- CMTTxInterceptor
- ...
- <MyEJB>
Please, let me know if my understanding is incorrect.
Thanks in advance
-
3. Re: Need to replace LoggingInterceptor
nickarls Nov 24, 2012 4:18 PM (in response to fernando.rubbo)Hmm. Looking at the stacktrace should reveal what interceptors an exception passed along. I haven't looked at the code that sets up the interceptor stack (SessionBeanComponentDescription?) so I don't know what the chances are of sneaking in a custom interceptor in the right place there. And even if it would be possible it sounds a bit brutal.
Having a CDI bean with a decorator wrapping the EJB sounds a bit intrusive, too. And not even sure that would work...
-
4. Re: Need to replace LoggingInterceptor
fernando.rubbo Nov 24, 2012 6:25 PM (in response to nickarls)I understand your point when you say "it sounds a bit brutal", but I think jboss (or, maybe, JavaEE spec) should provide a way to customize such interceptor stack. Without this, we have no alternative (as far as I know) without hacking out the code whenever we face such a common requirement.
It is important to say that it was a pretty ease task in older versions of jboss. Once the SLSB interceptor stack were implemented using jboss-aop. I haven't looked into the code yet, but I it does seem to be hardcoded into some jboss code. Do you have any idea were they define the interceptor chain. So we could download the source code and take a look on it?
-
5. Re: Need to replace LoggingInterceptor
nickarls Nov 25, 2012 12:33 PM (in response to fernando.rubbo)Not the first or the last chain in the link but the https://github.com/jbossas/jboss-as/blob/master/ee/src/main/java/org/jboss/as/ee/component/ComponentConfiguration.java looks to be involved (perhaps https://github.com/jbossas/jboss-as/blob/master/ejb3/src/main/java/org/jboss/as/ejb3/component/session/SessionBeanComponentDescription.java is used for building the stack at some point). It might be possible to extend the AS at some point (deployment processor?) to add an interceptor with an appropriate priority.
I just glanced at the code so I might be off on the wrong track, perhaps some dev might shed some light. It's only source code so if you don't care how much stabbing of the code you do, I'm sure it's doable ;-)
The sources can be pull from github.
-
6. Re: Need to replace LoggingInterceptor
fernando.rubbo Nov 25, 2012 1:26 PM (in response to nickarls)I think I found it in class EJBComponentDescription and it is hardcoded. :-(
[code]
protected void setupViewInterceptors(final EJBViewDescription view) {
// add a logging interceptor (to take care of EJB3 spec, section 14.3 logging requirements)
view.getConfigurators().add(new ViewConfigurator() {
@Override
public void configure(DeploymentPhaseContext context, ComponentConfiguration componentConfiguration, ViewDescription description, ViewConfiguration viewConfiguration) throws DeploymentUnitProcessingException {
viewConfiguration.addViewInterceptor(LoggingInterceptor.FACTORY, InterceptorOrder.View.EJB_EXCEPTION_LOGGING_INTERCEPTOR);
viewConfiguration.addViewInterceptor(new ImmediateInterceptorFactory(new TCCLInterceptor(componentConfiguration.getModuleClassLoader())), InterceptorOrder.View.TCCL_INTERCEPTOR);
//If this is the EJB 2.x local or home view add the exception transformer interceptor
if (view.getMethodIntf() == MethodIntf.LOCAL && EJBLocalObject.class.isAssignableFrom(viewConfiguration.getViewClass())) {
viewConfiguration.addViewInterceptor(EjbExceptionTransformingInterceptorFactories.LOCAL_INSTANCE, InterceptorOrder.View.REMOTE_EXCEPTION_TRANSFORMER);
} else if (view.getMethodIntf() == MethodIntf.LOCAL_HOME) {
viewConfiguration.addViewInterceptor(EjbExceptionTransformingInterceptorFactories.LOCAL_INSTANCE, InterceptorOrder.View.REMOTE_EXCEPTION_TRANSFORMER);
}
final List<SetupAction> ejbSetupActions = context.getDeploymentUnit().getAttachmentList(Attachments.OTHER_EE_SETUP_ACTIONS);
if (!ejbSetupActions.isEmpty()) {
viewConfiguration.addViewInterceptor(AdditionalSetupInterceptor.factory(ejbSetupActions), InterceptorOrder.View.EE_SETUP);
}
viewConfiguration.addViewInterceptor(shutDownInterceptorFactory, InterceptorOrder.View.SHUTDOWN_INTERCEPTOR);
}
});
this.addCurrentInvocationContextFactory(view);
this.setupSecurityInterceptors(view);
this.setupRemoteViewInterceptors(view);
view.getConfigurators().addFirst(new NamespaceViewConfigurator());
}
[/code]
It looks simple to implement my own interceptor and rebuild the as code. However, I think this strategy is to much intrusive and every update/migration will be a pain in the ass (we have had to many issues like this in the past). Do you think it is possible to jboss team to make a dynamic configuration for that? or through a subsystem or through a system property (for example: -Dejb3.LoggingInterceptorFactoryClass=com.xxx.MyLoggingInterceptorFactory). I've already opened an issue https://issues.jboss.org/browse/AS7-6022 for that.
Please, let me know your thoughts
Thanks,
Fernando Rubbo
-
7. Re: Need to replace LoggingInterceptor
fernando.rubbo Nov 30, 2012 8:00 AM (in response to fernando.rubbo)Anyone from Jboss developers have any idea if this kind of change request could be implemented into jboss?
I'm asking this because we need to know how should we proceed. Or we wait for an inproved interceptor stack configuration or we go for a "hacking alternative". Particularly I dislike the second option.
-
8. Re: Need to replace LoggingInterceptor
jaikiran Nov 30, 2012 8:57 AM (in response to fernando.rubbo)Isn't this what you are looking for https://issues.jboss.org/browse/AS7-5897
-
9. Re: Need to replace LoggingInterceptor
fernando.rubbo Nov 30, 2012 10:58 AM (in response to jaikiran) -
10. Re: Need to replace LoggingInterceptor
jaikiran Jan 16, 2013 8:19 AM (in response to fernando.rubbo)Fernando, the current AS7 upstream nightly build now has this feature implemented. Would you want to test it against your application and let us know how it goes. Here's an example of how to configure the container-interceptors https://github.com/jbossas/jboss-as/tree/master/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/container/interceptor (take a look at that testcase and the jboss-ejb3.xml included there).
-
11. Re: Need to replace LoggingInterceptor
jaikiran Jan 16, 2013 10:07 AM (in response to jaikiran)Here's the documentation for this feature https://docs.jboss.org/author/display/AS72/Container+interceptors
-
12. Re: Need to replace LoggingInterceptor
fernando.rubbo Jan 21, 2013 1:22 PM (in response to jaikiran)Hi Jaikiran,
First of all, thanks for your implementation.
Second, sorry by the delay. We are very busy here.
Third..
I haven't downloaded the nightly build yet, but I would like to ask you a question about compatibility. Thake the following code as an example (please, read the comments):
<code>
public class ContainerInterceptor
{
@AroundInvoke
public Object aroundInvoke(final InvocationContext invocationContext) throws Exception {
/*
In older version of jboss we were used to use org.jboss.aop.joinpoint.MethodInvocation class. For example:
public Object invoke(Invocation invocation) throws Throwable
{
final MethodInvocation mi = (MethodInvocation) invocation;
So, I can see the following correspondence in the new container interceptor strategy.
*/
// to get the arguments
Object[] parameters = invocationContext.getParameters(); // ~ mi.getArguments()
// to know which method has been called
Method method = invocationContext.getMethod(); // ~ mi.getMethod();
// to know which class has been called
Object target = invocationContext.getTarget(); // ~ mi.getTargetObject();
/*
However, according to documentation (https://docs.jboss.org/author/display/AS72/Container+interceptors) this
"method is illegal for container interceptors since these interceptors are invoked way before the EJB components
are setup or instantiated".
SO, THE QUESTION IS: how do I get the target class? Note, I'm not interested in the target object, but in the class. Is it possible to get using method.getDeclaringClass()???
*/
// to go on
return invocationContext.proceed(); // ~ mi.invokeNext()
}
</code>
Thanks again
-
13. Re: Need to replace LoggingInterceptor
fernando.rubbo Jan 25, 2013 2:56 PM (in response to fernando.rubbo)Hi Jaikiran
I've some time today for testing it in with the nightly build and it seems to work as expected
interceptor stack
TCCLInterceptor AditionalSetupInterceptor NamespaceContextInterceptor *LoggingInteceptor ShutdownInterceptor <MY CONTAINER INTERCEPTOR> *SecurityContextInterceptor CuncurrentInvocationInterceptor *CMTTxInterceptor PooledInstanceInterceptor ComponentDispatcherInterceptor SBInvocationInterceptor *ExecutionTimeInterceptor UserInterceptorFactory ManagedReferneceMethodInterceptor <MY EJB Interceptor> <MY EJB> Thanks,
Fernando Rubbo