wso2 esb - 如果中介返回false,如何处理请求

时间:2014-10-16 10:59:03

标签: wso2 wso2esb synapse

我有自定义中介,我们正在验证内部身份验证系统。如果身份验证失败,则介体返回false。客户端接收响应作为HTTP状态代码202.我想覆盖一些JSON响应,如{" authError" :"认证失败 - TOKEN_INVALID" }。请让我知道如何处理这种情况。

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>

1 个答案:

答案 0 :(得分:2)

  • 在您的班级调解员中,您可以抛出SynapseException
  • 在这种情况下,将执行inSequence中介停止和faultSequence
  • 在faultSequence中,你可以使用mediator payloadFactory和media-type =&#34; json&#34;构建您的json消息并使用<send/>
  • 将其发送给客户端