<api xmlns="http://ws.apache.org/ns/synapse"  name="$!apiName" context="$!apiContext" transports="$!transport">
   <resource methods="POST PATCH GET DELETE HEAD PUT OPTIONS"
             url-mapping="/*"
             faultSequence="fault">
	<inSequence>
		<property name="isDefault" expression="$trp:WSO2_AM_API_DEFAULT_VERSION"/>
		<filter source="$ctx:isDefault" regex="true">
		    <then>
		        <log level="custom">
		            <property name="STATUS" value="Faulty invoking through default API.Dropping message to avoid recursion.."/>
		        </log>
		        <payloadFactory media-type="xml">
		            <format>
		                <am:fault xmlns:am="http://wso2.org/apimanager">
		                    <am:code>500</am:code>
		                    <am:type>Status report</am:type>
		                    <am:message>Internal Server Error</am:message>
		                    <am:description>Faulty invoking through default API</am:description>
		                </am:fault>
		            </format>
		            <args/>
		        </payloadFactory>
		        <property name="HTTP_SC" value="500" scope="axis2"/>
		        <property name="RESPONSE" value="true"/>
		        <header name="To" action="remove"/>
		        <property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
		        <property name="ContentType" scope="axis2" action="remove"/>
		        <property name="Authorization" scope="transport" action="remove"/>
		        <property name="Host" scope="transport" action="remove"/>
		        <property name="Accept" scope="transport" action="remove"/>
		        <send/>
		    </then>
		    <else>
		        <header name="WSO2_AM_API_DEFAULT_VERSION" scope="transport" value="true"/>
                #if( $transport == "https" )
            	<property name="uri.var.portnum" expression="get-property('https.nio.port')"/>
                #else
            	<property name="uri.var.portnum" expression="get-property('http.nio.port')"/>
                #end

			<send>
			    <endpoint>
                #if( $transport == "https" )
				<http uri-template="https://localhost:{uri.var.portnum}/$!{fwdApiContext}">
                #else
				<http uri-template="http://localhost:{uri.var.portnum}/$!{fwdApiContext}">
                #end
			            <timeout>
			                <duration>60000</duration>
			                <responseAction>fault</responseAction>
			            </timeout>
			            <suspendOnFailure>
			                 <progressionFactor>1.0</progressionFactor>
			            </suspendOnFailure>
			            <markForSuspension>
			                <retriesBeforeSuspension>0</retriesBeforeSuspension>
                            <retryDelay>0</retryDelay>
			            </markForSuspension>
			        </http>
			    </endpoint>
			</send>
		    </else>
		</filter>
	    </inSequence>
	    <outSequence>
		<send/>
	    </outSequence>
	</resource>
        <handlers>
            <handler class="org.wso2.carbon.apimgt.gateway.handlers.common.SynapsePropertiesHandler"/>
            <handler class="org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler">
                  <property name="apiImplementationType" value="ENDPOINT"/>
            </handler>
        </handlers>
</api>
