Liu, Jervis wrote:

-----Original Message-----
From: Dan Diephouse [mailto:[EMAIL PROTECTED]
Sent: 2006?11?2? 1:29
To: [email protected]
Subject: Re: Interceptor Ordering


Hiya Jervis,

Liu, Jervis wrote:
The getBefore()/getAfter does not work very well for the
same phase in my experience. Besides the problem you encountered, I also ran into a similar problem when I was doing the saaj handlers stuff. See code snippet below:
  public SOAPHandlerInterceptor(Binding binding) {
       super(binding);
       setPhase(Phase.PRE_PROTOCOL);
       addBefore((new StaxOutInterceptor()).getId());
   }

Sometimes using (new StaxOutInterceptor()).getId() is not
possible as the interceptor referred to might be in a module invisible to SOAPHandlerInterceptor. This can happen when for example, both interceptors from soap module and jax-ws module need to be placed in PRE_PROTOCOL phase. In this case we have to explicitly use a string "org.apache.cxf.interceptor.StaxOutInterceptor". IMO, the interceptor should not be aware of any other interceptors in the chain at all.
The ID is just the class name by default. So you could do StaxOutInterceptor.class.getName() or you could do "org.apachecxf.interceptors.StaxOutInterceptor".


Our interceptor chain works very well for ordering interceptors from different phases, the complexity we try to resolve here is how to writer interceptors belong to same phase and somehow they can still be dropped into the chain in the expected order. Actually I am also not convinced that using sth like IN_PHASE_ID is an idea good enough, but IMO using a string representation of "org.apachecxf.interceptors.StaxOutInterceptor" is even worse. This is subjected to spelling errors and more importantly, why should the interceptor itself be aware of other interceptors?
Well first, the ID can be anything. It just defaults to the class name - so you could set the id to just "stax-out". Second, 99.9% of the time you can just do addBefore(StaxOutInterceptor.class.getName()), and then you don't have to worry about spelling issues.

In this case, using an IN_PHASE_ID can work like below:

   public SOAPHandlerInterceptor(Binding binding) {
       super(binding);
       setPhase(Phase.PRE_PROTOCOL);
       setInPhaseID(500);
   }

   public StaxOutInterceptor() {
       super();
       setPhase(Phase.PRE_PROTOCOL);
       setInPhaseID(700);
   }

Then its InterceptorChain's responsibility to sort SOAPHandlerInterceptor and 
StaxOutInterceptor in order for the same phase.


I don't like how this loses the ability to say "interceptor X depends on interceptor Y" and moves things to some arbitrary number. Think of it like the maven dependency mechanism. Even if its an optional dependency, I still need to declare it and it doesn't hurt to have the optional dependency in there. Also, what happens when you need to reorganize the interceptors or add some in between? It is a bit more fragile when using #s.

- Dan

--
Dan Diephouse
(616) 971-2053
Envoi Solutions LLC
http://netzooid.com

Reply via email to