首页 > 解决方案 > 如何在 Mule 3 中返回 null 而不是异常消息

问题描述

有人可以帮助如何返回null而不是返回异常作为输出json。

在此处输入图像描述

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:validation="http://www.mulesoft.org/schema/mule/validation" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/validation http://www.mulesoft.org/schema/mule/validation/current/mule-validation.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="9097" doc:name="HTTP Listener Configuration"/>
    <validation:config name="Validation_Configuration" doc:name="Validation Configuration"/>
    <flow name="testFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/test" allowedMethods="GET" doc:name="HTTP"/>
        <db:select config-ref="Generic_Database_Configuration" doc:name="Database">
            <db:dynamic-query><![CDATA[SELECT * FROM SALESIT_DB.SALESIT_SC3VIS_BR.abcd  trx where trx.employee_id= '1232' and trx.so_number='abc']]></db:dynamic-query>
        </db:select>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
        <dw:transform-message doc:name="Transform Message" metadata:id="3581fe3a-a6f9-4071-b861-fcf16396358a">
            <dw:input-payload  mimeType="application/java"/>
            <dw:set-payload><![CDATA[

%dw 1.0
%output application/json
---
payload filter (($.payload != 0)) 

]]></dw:set-payload>
        </dw:transform-message>

    </flow>
</mule>

异常是无法识别数值“abc”(net.snowflake.client.jdbc.SnowflakeSQLException)。

有没有办法我们可以打印 null 作为输出有效负载而不是打印异常。

有人可以帮忙。

谢谢,尼基尔

标签: mule

解决方案


  1. 将 db:select 提取到单独的流中,然后使用流引用调用它。

  2. 在提取的流中定义 acatch-exception-strategy并在其中将 setPayload 设置为 null。


推荐阅读