2014-10-16 82 views
2

我有自定義介體,我們正在驗證內部身份驗證系統。如果認證失敗,mediator返回false。客戶端將響應作爲HTTP狀態碼202接收。我想用諸如{「authError」:「Authetication failed - TOKEN_INVALID」}的一些JSON響應來覆蓋。請讓我知道如何處理這種情況。wso2 esb - 如果調解員返回假的情況下如何處理請求

ESB版本 - 4.81。 這裏是我的代理配置 -

<?xml version="1.0" encoding="UTF-8"?> 
<proxy xmlns="http://ws.apache.org/ns/synapse" 
     name="UGCGetJSONFileList" 
     transports="https,http" 
     statistics="enable" 
     trace="disable" 
     startOnLoad="true"> 
    <target outSequence="WEB_OUT_Sequence"> 
     <inSequence> 
     <log level="full" separator=","/> 
     <class name="com.hc.synapse.mediator.HCAuthenticationMediator"/> 
     <property name="RESPONSE" value="true" scope="axis2"/> 
     <property name="uri.var.querystrings" 
        expression="substring-after(get-property('To'), '?')" 
        scope="axis2" 
        type="STRING"/> 
     <log level="full" separator=","/> 
     <switch source="$axis2:HTTP_METHOD"> 
      <case regex="GET"> 
       <property name="uri.var.querystrings" 
         expression="substring-after(get-property('To'), '?')" 
         scope="default" 
         type="STRING"/> 
       <log level="full" separator=","/> 
       <send> 
        <endpoint> 
        <http method="get" 
          uri-template="http://dalx-entsvc-d1:9660/ugc/getJSONFileList?{uri.var.querystrings}"/> 
        </endpoint> 
       </send> 
      </case> 
      <case regex="POST"> 
       <log level="full" separator=","/> 
       <send> 
        <endpoint> 
        <address uri="http://dalx-entsvc-d1:9660/ugc/getJSONFileList?{uri.var.querystrings};content" 
           trace="enable" 
           statistics="enable"> 
         <timeout> 
          <duration>30000</duration> 
          <responseAction>discard</responseAction> 
         </timeout> 
         <suspendOnFailure> 
          <initialDuration>0</initialDuration> 
          <progressionFactor>1.0</progressionFactor> 
          <maximumDuration>0</maximumDuration> 
         </suspendOnFailure> 
        </address> 
        </endpoint> 
       </send> 
      </case> 
      <default/> 
     </switch> 
     </inSequence> 
     <faultSequence> 
     <log level="full" separator=","> 
      <property name="trace" expression="get-property('ERROR_MESSAGE')"/> 
     </log> 
     <payloadFactory media-type="json"> 
      <format>{ "authError" : "Authetication failed - TOKEN_INVALID" }</format> 
      <args/> 
     </payloadFactory> 
     <property name="RESPONSE" value="true"/> 
     <header name="To" action="remove"/> 
     <send/> 
     </faultSequence> 
    </target> 
    <description/> 
</proxy> 

回答

2
  • 在你的類中介,你可以拋出一個SynapseException
  • 在這種情況下,inSequence中調解站,faultSequence將被執行
  • 在faultSequence,你就可以使用media-type =「json」的mediator payloadFactory來構建您的json消息並將其發送給客戶端。<send/>
+0

感謝您的回覆。我做了上面的改變,現在我得到了200個http響應。但在瀏覽器中沒有收到任何消息。通過日誌驗證。但沒有運氣。 – 2014-12-02 11:11:31