Saturday, November 26, 2011

How to read HTTP headers through Synapse Config

You can use the following property mediator to read HTTP headers inside WSO2 ESB through Synapse Configuration.
<property name="Lang" expression="get-property('transport', 'Accept')"/>

Here, the value of the HTTP header called "Accept" get assigned in to property called "Lang"

Thursday, November 24, 2011

How to apply throttling policies through service.xml

You can always apply throttling to services deployed in WSO2 AS using the Management console. But what if you want to apply the throttling policy while the service get deployed. Then you can specify the throttling policy in the service.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<!-- This file was auto-generated from WSDL -->
<!-- by the Apache Axis2 version: 1.6.1-wso2v1  Built on : Jun 08, 2011 (07:37:38 IST) -->
<serviceGroup>
    <service name="echo">
        <messageReceivers>
            <messageReceiver mep="http://www.w3.org/ns/wsdl/in-out" class="org.wso2.carbon.sample.service.echo.EchoMessageReceiverInOut"/>
        </messageReceivers>
        <parameter name="ServiceClass">org.wso2.carbon.sample.service.echo.EchoSkeleton</parameter>
        <parameter name="useOriginalwsdl">true</parameter>
        <parameter name="modifyUserWSDLPortAddress">true</parameter>
        <operation name="echoString" mep="http://www.w3.org/ns/wsdl/in-out" namespace="http://echo.services.core.carbon.wso2.org">
            <actionMapping>urn:echoString</actionMapping>
            <outputActionMapping>urn:echoStringResponse</outputActionMapping>
            <faultActionMapping faultName="echoFault">urn:echoFaultMessage</faultActionMapping>
            <faultActionMapping faultName="EchoFault">urn:echoFaultMessage</faultActionMapping>
            <faultActionMapping faultName="EchoFault_Exception">urn:echoFaultMessage</faultActionMapping>
        </operation>
        <operation name="throwAxisFault" mep="http://www.w3.org/ns/wsdl/in-out" namespace="http://echo.services.core.carbon.wso2.org">
            <actionMapping>urn:throwAxisFault</actionMapping>
            <outputActionMapping>urn:throwAxisFaultResponse</outputActionMapping>
        </operation>
        <operation name="echoStringArrays" mep="http://www.w3.org/ns/wsdl/in-out" namespace="http://echo.services.core.carbon.wso2.org">
            <actionMapping>urn:echoStringArrays</actionMapping>
            <outputActionMapping>urn:echoStringArraysResponse</outputActionMapping>
        </operation>
        <operation name="echoOMElement" mep="http://www.w3.org/ns/wsdl/in-out" namespace="http://echo.services.core.carbon.wso2.org">
            <actionMapping>urn:echoOMElement</actionMapping>
            <outputActionMapping>urn:echoOMElementResponse</outputActionMapping>
        </operation>
        <operation name="echoInt" mep="http://www.w3.org/ns/wsdl/in-out" namespace="http://echo.services.core.carbon.wso2.org">
            <actionMapping>urn:echoInt</actionMapping>
            <outputActionMapping>urn:echoIntResponse</outputActionMapping>
        </operation>
 
       <module ref="wso2throttle"/>
       <wsp:Policy wsu:Id="WSO2ServiceThrottlingPolicy" 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">
  <wsp:ExactlyOne>
    <wsp:All>
      <throttle:ServiceThrottleAssertion xmlns:throttle="http://www.wso2.org/products/wso2commons/throttle">
        <wsp:Policy>
          <throttle:ID throttle:type="DOMAIN">172.16.49.1</throttle:ID>
          <wsp:Policy>
            <throttle:Control>
              <wsp:Policy>
                <throttle:MaximumCount>2</throttle:MaximumCount>
                <throttle:UnitTime>20000</throttle:UnitTime>
                <throttle:ProhibitTimePeriod wsp:Optional="true">30000</throttle:ProhibitTimePeriod>
              </wsp:Policy>
            </throttle:Control>
          </wsp:Policy>
        </wsp:Policy>
        <wsp:Policy>
          <throttle:ID throttle:type="DOMAIN">other</throttle:ID>
          <wsp:Policy>
            <throttle:Deny/>
          </wsp:Policy>
        </wsp:Policy>
      </throttle:ServiceThrottleAssertion>
    </wsp:All>
  </wsp:ExactlyOne>
</wsp:Policy>
    </service>
</serviceGroup>