Reputation: 738
Hi I have the source view of my api from APIM and modified it to get the the htttp header "Authorization" and log it to the log file I added 2 entries in code one for insequence and one for outsequence. In the insequence I added the line
<property name="AuthHeader" expression="$trp:Authorization"/>
In order to get the header and assign it to a property. In the out sequence I added
<log level="custom">
<property name="AuthHeader value" expression="get-property('AuthHeader')"/>
</log>
To determine if the AuthHeader property will display and get the header, however inside the log file it was said that
TID: [0] [AM] [2014-11-19 04:23:01,997] INFO {org.apache.synapse.mediators.builtin.LogMediator} - AuthHeader value = null {org.apache.synapse.mediators.builtin.LogMediator}
TID: [0] [AM] [2014-11-19 04:23:07,335] INFO {org.apache.synapse.mediators.builtin.LogMediator} - AuthHeader value = null {org.apache.synapse.mediators.builtin.LogMediator}
TID: [0] [AM] [2014-11-19 04:56:17,177] INFO {org.apache.synapse.mediators.builtin.LogMediator} - AuthHeader value = null {org.apache.synapse.mediators.builtin.LogMediator}
Which means I'm not getting the correct http header value, is there something wrong with the code? Please help, the complete API code is below.
Thanks, Drew
<api name="admin--fte" context="/fte">
<resource methods="POST GET DELETE OPTIONS PUT" url-mapping="/*">
<inSequence>
<property name="AuthHeader" expression="$trp:Authorization"/>
<property name="isDefault" expression="get-property('transport', 'WSO2_AM_API_DEFAULT_VERSION')"/>
<filter source="get-property('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"/>
<property name="uri.var.portnum" expression="get-property('http.nio.port')"/>
<send>
<endpoint>
<http uri-template="http://localhost:{uri.var.portnum}/fte/1.0">
<timeout>
<duration>30000</duration>
<responseAction>fault</responseAction>
</timeout>
<suspendOnFailure>
<errorCodes>-1</errorCodes>
<initialDuration>0</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<errorCodes>-1</errorCodes>
</markForSuspension>
</http>
</endpoint>
</send>
</else>
</filter>
</inSequence>
<outSequence>
<property name="messageType" value="application/json" scope="axis2" type="STRING"/>
<log level="custom">
<property name="AuthHeader value" expression="get-property('AuthHeader')"/>
</log>
<send/>
</outSequence>
</resource>
<handlers>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.common.SynapsePropertiesHandler"/>
</handlers>
</api>
Upvotes: 1
Views: 965
Reputation: 201
By default, the Authorization header is removed by the Authentication handler. That's why you cant' seem to access it or log it. Handlers act before the mediation inSequence.
The Authentication header can be preserved by editing the api-manager.xml config file in /repository/conf. Simply uncomment the following node and change the value to false:
<RemoveOAuthHeadersFromOutMessage>false</RemoveOAuthHeadersFromOutMessage>
Upvotes: 2