Akshat
Akshat

Reputation: 575

Can we have multiple CXF interceptors in same phase

I have creating a interceptor which will perform its specific logic for MultiPart request for UNMARSHAL phase , For this phase there is altogether a different CXF interceptor in which i don't want to write my logic.

My question is can we create multiple CXF interceptors for same phase ? If Yes than what is the order in which they are called upon as shown in eg below

Eg.

public class Interceptor1 extends AbstractPhaseInterceptor<Message> {

        public Interceptor1 () {
        super(Phase.UNMARSHAL);
        }
       @Override
      public void handleMessage(Message message) throws Fault {
          System.out.println("Interceptor1");
      }

}

public class Interceptor2 extends AbstractPhaseInterceptor<Message> {

        public Interceptor2 () {
        super(Phase.UNMARSHAL);
        }
         @Override
      public void handleMessage(Message message) throws Fault {
          System.out.println("Interceptor2");
      }

}

Upvotes: 1

Views: 1130

Answers (1)

kuhajeyan
kuhajeyan

Reputation: 11027

Each phase can contain as many interceptors you want, when more than one interceptors found in a phase they will be executed in the order they are added

 <bean id="cxf" class="org.apache.cxf.bus.CXFBusImpl">
        <property name="inInterceptors">
            <ref bean="MyInterceptor"/>
            <ref bean="OtherInterceptor"/>
        </property>
        <property name="outInterceptors">
            <ref bean="MyInterceptor"/>
        </property>
    </bean> 

MyInterceptor(1) -> OtherInterceptor(2)

Upvotes: 1

Related Questions