2014-10-16 39 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

相关问题