cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Diephouse <...@envoisolutions.com>
Subject Re: Interceptor Ordering
Date Wed, 01 Nov 2006 17:29:29 GMT
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".

If you don't have any kind of ordering information, then it is up to the 
user to order things themselves, which is exactly what we're trying to 
get away from. We don't want to have to have the user say "alright this 
one goes here and I think this stax one goes here...". It allows people 
to develop interceptors and have them automatically configured into the 
change.
> To get around this, we can have an integer IN_PHASE_ID ranged from 1 to 999 for each
interceptor, then it is the responsibility of who designs the whole chain (us, as we have
the knowledge of chain flow) to turn the IN_PHASE_ID around to make sure interceptors in the
same phase are at the expected positions. Does this sound a better solution than getBefore()/getAfter?
or any better ideas?
>
>   
-1. We don't know all the interceptors which will go in the chain and 
therefore can't order them all.
> I am not sure if making PhaseInterceptorChain aware of direction is a good idea. Looking
into PhaseManagerImpl, the ordering of inphase and outphase are already very different. I
noticed that you have separated RM interceptors into RMInInterceptor and RMOutInterceptor
so that you can put RM interceptors in different orders for inbout and outbound. This should
be the easiest solution.
>
> Cheers,
> Jervis
>
>
>   
>> -----Original Message-----
>> From: Andrea Smyth [mailto:andrea.smyth@iona.com]
>> Sent: Wednesday, November 01, 2006 2:37 AM
>> To: cxf-dev@incubator.apache.org
>> Subject: Interceptor Ordering
>>
>>
>> Hi all,
>>
>> I have come across a problem with ordering interceptors that 
>> belong to 
>> the same phase - specifically the logical RM and Addressing 
>> interceptors. Both are in the PRE_PROTOCOL phase but outbound the 
>> Addressing interceptor must be executed before the RM 
>> interceptor while 
>> inbound it's the other way round.
>> With the way the PhaseInterceptorChain uses the getBefore(), 
>> getAfter() 
>> it is not possible to use the same interceptor in and outbound.
>> As a workaround, I can manage the state in a third entity 
>> that is shared 
>> by the an RMInInterceptor and RMOutInterceptor, but that way 
>> configuration of the chains gets a bit more complicated: 
>> instead of just
>> <bean id="rmLogical" class="org.apache.cxf.ws.rm.impl.RMInterceptor">
>>     <property name="bus" ref="cxf"/>
>> </bean>
>>  and
>> <bean id="cxf" class="org.apache.cxf.bus.spring.SpringBusImpl">
>>     <property name="inInterceptors">
>>         <ref bean="rmLogical"/>
>>     </property>
>>    <property name="outInterceptors">
>>         <ref bean="rmLogical"/>
>>     </property>
>> </bean>
>>
>> I would now need something like:
>> <bean id="rmEndpointManager" 
>> class="org.apache.cxf.ws.rm.impl.RMEndpointManager"/>
>> <bean id="rmLogicalIn" 
>> class="org.apache.cxf.ws.rm.impl.RMInInterceptor">
>>     <property name="bus" ref="cxf"/>
>>     <property name="rmEndpointManager" ref="rmEndpointManager"/>
>> </bean>
>> <bean id="rmLogicalOut" 
>> class="org.apache.cxf.ws.rm.impl.RMOutInterceptor">
>>     <property name="bus" ref="cxf"/>
>>     <property name="rmEndpointManager" ref="rmEndpointManager"/>
>> </bean>
>>
>> <bean id="cxf" class="org.apache.cxf.bus.spring.SpringBusImpl">
>>     <property name="inInterceptors">
>>         <ref bean="rmLogicalIn"/>
>>     </property>
>>    <property name="outInterceptors">
>>         <ref bean="rmLogicalOut"/>
>>     </property>
>> </bean>
>>
>> The other solution I can think of is to make 
>> PhaseInterceptorChain aware 
>> of a direction, i.e. whether it's used in inbound or outbound 
>> direction. 
>> It could then treat the getBefore(), getAfter() according to 
>> the direction.
>> Is that something that would be of general interest?
>>
>> Any comments appreciated,
>> Andrea.
>>
>>
>>
>>
>>     


-- 
Dan Diephouse
Envoi Solutions
http://envoisolutions.com
http://netzooid.com/blog


Mime
View raw message