代理失败时如何响应状态500(服务器错误)?

时间:2015-11-19 07:05:50

标签: wso2 wso2esb esb

在我们的测试环境中,我们构建了一个单向代理服务,它使用callout从其他几个服务中获取数据。现在当其中一个服务失败时,无论如何都要接受代理发送202。是否有可能捕获异常"并返回不同的状态?

我知道在这种情况下最好使用请求 - 响应代理,但即使我们创建的代理只将有效负载存储在消息存储库中,也可能存在有关数据库存储有效负载的问题(数据库已关闭等)如果消息未存储在db中,我们不希望返回状态202。

编辑:

在我的问题的第一个回答中建议更改之后,这是我的代理:

<?xml version="1.0" encoding="UTF-8"?>
<proxy name="notifyOfClaimChangeOut" serviceGroup="" startOnLoad="true"
  trace="disable" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
  <target>
    <inSequence>
      <property description="OUT_ONLY" name="OUT_ONLY" scope="default"
        type="BOOLEAN" value="true"/>
      <property name="FORCE_ERROR_ON_SOAP_FAULT" scope="default"
        type="STRING" value="true"/>
      <property description="OriginalPayload" expression="$body"
        name="OriginalPayload" scope="default" type="STRING"/>
      <iterate description=""
        expression="$body//InsClaimData/PartnerList/PartnerEntry" id="" sequential="true">
        <target>
          <sequence>
            <payloadFactory description="" media-type="xml">
              <format>
                <plat:FindCustomerSync xmlns:plat="http://platform.###.pl/">
                  <plat:request>
                    <plat:FirstName>$1</plat:FirstName>
                    <plat:LastName>$2</plat:LastName>
                    <plat:Pesel>$3</plat:Pesel>
                  </plat:request>
                </plat:FindCustomerSync>
              </format>
              <args>
                <arg evaluator="xml" expression="$body/PartnerEntry/BusinessPartner/personData/firstName"/>
                <arg evaluator="xml" expression="$body/PartnerEntry/BusinessPartner/personData/lastName"/>
                <arg evaluator="xml" expression="$body/PartnerEntry/BusinessPartner/personData/PESEL"/>
              </args>
            </payloadFactory>
            <log level="custom">
              <property expression="$body" name="property_name"/>
            </log>
            <callout action="http://platform.###.pl/FindCustomerSync"
              description="QueryCustomersOut"
              endpointKey="gov:###/endpoints/###/QueryCustomersOut.xml" initAxis2ClientOptions="false">
              <source type="envelope"/>
              <target key="QueryCustomersOutResponse"/>
            </callout>
            <log description="" level="custom" separator=",">
              <property expression="$ctx:QueryCustomersOutResponse"
                name="QueryCustomersOut"
                xmlns:cla="http://###.###.io/service/internal/ClaimService" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"/>
            </log>
          </sequence>
        </target>
      </iterate>
      <!-- 
      <callout description="ClaimService"
        endpointKey="gov:###/endpoints/###/ClaimService.xml" initAxis2ClientOptions="false">
        <source type="envelope"/>
        <target key="ClaimServiceResponse"/>
      </callout>
      <log description="ClaimService Response" level="custom">
        <property expression="$ctx:ClaimServiceResponse" name="ClaimServiceResponse"/>
      </log>
       -->
      <drop/>
    </inSequence>
    <outSequence/>
    <faultSequence>
      <property name="HTTP_SC" scope="axis2" type="STRING" value="500"/>
      <log>
        <property name="Error" value="Fault :("/>
      </log>
    </faultSequence>
  </target>
  <publishWSDL key="gov:###/schemas/###/ClaimService.wsdl"/>
</proxy>

1 个答案:

答案 0 :(得分:3)

您可以使用HTTP_SC属性发送状态500.您还需要makefault mediator来构造故障消息。

<property name="HTTP_SC" value="500" scope="axis2"/>
<makefault version="soap11">

您可以参考this jira来了解相关信息。

此外,在inSequence中,您可能需要设置FORCE_ERROR_ON_SOAP_FAULT属性以在发生soap故障时移至故障序列。一些explanation available here

<inSequence>
        <property name="FORCE_ERROR_ON_SOAP_FAULT" value="true" scope="default" type="STRING"/>
</inSequence>