• Subscription Options

  • What I write about

  • RSS Latest News From MuleSoft

  • Archives

  • Technical Features

  • Visitors Online

  • Stacking Interceptors

    Further to my earlier posts about Mule Interceptors and Envelope Interceptors, one quick point about having more than one interceptor in your Mule config is merited.

    Mule supports the concept of an interceptor stack which is nothing more than a list of interceptors. This is useful since you can avoid having to include all the interceptors in every service – just refer to the stack. Since interceptors are the sort of things you’d use in multiple locations, using an interceptor stack can greatly simplify things.

    Instead of doing this:

    <component>
            <custom-interceptor 
    		class="com.ricston.tests.HelloInterceptor"/>
            <custom-interceptor 
    		class="com.ricston.tests.SecondInterceptor"/>
            <prototype-object 
    		class="com.ricston.tests.SimpleBridge"/>
    </component>
     
    <component>
            <custom-interceptor 
    		class="com.ricston.tests.HelloInterceptor"/>
            <custom-interceptor 
    		class="com.ricston.tests.SecondInterceptor"/>
            <prototype-object 
    		class="com.ricston.tests.AnotherService"/>
    </component>

    you can do this:

     
    <interceptor-stack name="customIntercepting">
            <custom-interceptor 
    		class="com.ricston.tests.HelloInterceptor"/>
            <custom-interceptor 
    		class="com.ricston.tests.SecondInterceptor"/>
    </interceptor-stack>
     
    <model>
     
    <!-- Other services -->
    	<service name="Bridge">
    		<!-- Inbound router collection left out 
    			in this example -->
    		<component>
    			<interceptor-stack ref="customIntercepting"/>
    		        <prototype-object 
    			   class="com.ricston.tests.SimpleBridge"/>
    		</component>
    	</service>
     
    	<service name="Another">
    		<!-- Inbound router collection left out 
    			in this example -->
    		<component>
    			<interceptor-stack ref="customIntercepting"/>
    		        <prototype-object 
    			   class="com.ricston.tests.AnotherService"/>
    		</component>
    	</service>

    Additionally, you can also declare an interceptor stack as well as an interceptor on a service. This is useful in cases when you want to add one more interceptor to the standard list in a few cases:

    <!-- Other services -->
    <service name="Bridge">
    	<!-- Inbound router collection left out 
    		in this example -->
    	<component>
    		<interceptor-stack ref="customIntercepting"/>
    		<logging-interceptor/>
    	        <prototype-object 
    			class="com.ricston.tests.SimpleBridge"/>
    	</component>
    </service>

    If you enjoyed this post, make sure you subscribe to my RSS feed!

    Tags: , ,

    Leave a Reply

    Add video comment
    © Copyright 2005-2008 Ricston, All Rights Reserved
     Sitemap   Privacy Policy    Legal