2014-11-19 4 views
1

안녕하세요, APIM에서 내 API의 소스보기를 가지고 htttp 헤더 "인증"을 가져 와서 그것을 수정하여 로그 파일에 기록합니다. 결과. 결과적으로 나는 라인을 추가했다.http 헤더를 얻을 수 없습니다.

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

헤더를 가져 와서 속성에 할당하려면. 아웃 순서에서 나는 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} 

내가을받지 못했습니다 의미합니다 있다고 말했다, 표시 헤더를 얻을 것이다 경우

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

가 확인하려면 추가 올바른 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> 
+0

API를 호출 할 때 확실히 Authorization 헤더를 보내시겠습니까? AuthHeader 속성을 지정하고 확인한 직후 로그를 추가하십시오. –

+0

예 헤더를 보내는 데 사용 된 명령은 다음과 같습니다. curl -v \ -H "Authorization : Bearer a533cffb7d57895e377d4ab43bbe0c3"\ -X GET \'인증 헤더가 있습니까? 이 올바른지? (이 물건에 대한 미안 초보자) AuthHeader 속성에 할당 한 후에 기록 할 것입니다. 고맙습니다 –

답변

2

은 인증 헤더는 인증 핸들러에 의해 제거된다. 그래서 당신은 그것을 읽거나 기록하는 것처럼 보이지 않습니다. 처리기는 중재 inSequence 전에 작동합니다.

인증 헤더는/repository/conf에있는 api-manager.xml 구성 파일을 편집하여 보존 할 수 있습니다. 다음 노드의 주석 처리를 취소하고 값을 false로 변경하십시오.

<RemoveOAuthHeadersFromOutMessage>false</RemoveOAuthHeadersFromOutMessage>