November 30, 2015

Sample for Restricting Proxy with Throttle Mediator

Following is a sample of using Throttle mediator to restrict local proxy invocations. Notice that the IP has to be given as 127.0.0.1 and not "localhost".

A custom fault message can be added within onreject/makefault/reason tag (line 19-23) . Custom fault messages cannot be added for service level throttling.

<proxy name="ThrottleMediatorSample" startonload="true" trace="disable" transports="https http" xmlns="http://ws.apache.org/ns/synapse">
   <description>
   <target>
      <insequence>
         <throttle id="A">
            <policy>
               <wsp:policy wsu:id="WSO2MediatorThrottlingPolicy" xmlns:throttle="http://www.wso2.org/products/wso2commons/throttle" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
                  <throttle:mediatorthrottleassertion>
                     <wsp:policy>
                        <throttle:id throttle:type="IP">127.0.0.1</throttle:id>
                        <wsp:policy>
                           <throttle:deny>
                        </throttle:deny></wsp:policy>
                     </wsp:policy>
                  </throttle:mediatorthrottleassertion>
               </wsp:policy>
            </policy>
            <onreject>
               <makefault response="true" version="soap11">
                  <code value="tns:Receiver" xmlns:tns="http://www.w3.org/2003/05/soap-envelope">
                     <reason value="ERROR : Restricted IP Address"/>
                  </code>
               </makefault>
               <send/>           
            </onreject>
            <onaccept>
               <send>
                  <endpoint>
                     <address uri="http://localhost:9000/services/SimpleStockQuoteService">
                     </address>
                  </endpoint>
               </send>
            </onaccept>
         </throttle>
      </insequence>
      <outsequence>
         <send>
      </send></outsequence>
   </target>
</description></proxy>

Reference :

No comments:

Post a Comment