无法获取http标头

时间:2014-11-19 05:33:45

标签: http wso2 wso2carbon wso2-am

您好我从APIM获取了我的api的源视图并修改了它以获取htttp标题“Authorization”并将其记录到日志文件中我在第一个代码中添加了两个条目,用于insequence,一个用于outsequence。在顺序中我添加了行

<property name="AuthHeader" expression="$trp:Authorization"/>

获取标题并将其分配给属性。在外面的序列中,我添加了

<log level="custom">
                    <property name="AuthHeader value" expression="get-property('AuthHeader')"/>
                </log>

确定AuthHeader属性是否会显示并获取标题,但是在日志文件中,它被认为是

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}

这意味着我没有得到正确的http标头值,代码有问题吗?请帮忙,完整的API代码如下。

谢谢, 德鲁

<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>

1 个答案:

答案 0 :(得分:2)

默认情况下,Authentication处理程序将删除Authorization标头。这就是为什么你不能这样做的原因。似乎访问它或记录它。处理程序在序列中的调解之前起作用。

可以通过编辑/ repository / conf中的api-manager.xml配置文件来保留Authentication头。只需取消注释以下节点并将值更改为false:

<RemoveOAuthHeadersFromOutMessage>false</RemoveOAuthHeadersFromOutMessage>