首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mule软数据编织

Mule软数据编织
EN

Stack Overflow用户
提问于 2018-09-30 20:58:36
回答 2查看 144关注 0票数 0

我想写一个数据编织代码,其中如果数据是空的,那么它应该路由到400。如何在Mule Soft中编写此代码?

我的流程如下: HTTP -->Transfomer->Logger

Tranformer代码{ event_ops_type: payload.EDM_generic_consumer_message.event_meta_data.event_operation_type }

现在我想实现的是,如果"event_ops_type“是null,那么路由到400(异常处理)?

EN

回答 2

Stack Overflow用户

发布于 2018-10-02 02:39:50

您可能希望尝试使用验证模块。MuleSoft documentation here

代码语言:javascript
复制
<validation:is-not-null message="event_ops_type is null!" value="#[flowVars.event_ops_type]" exceptionClass="com.example.MyException" doc:name="Validation"/>

您还可以在选择块中使用Groovy脚本抛出任何您喜欢的异常。在这里,它实际上将抛出一个带有API生成的异常处理的404。您可以将其切换为任何您想要的异常。

代码语言:javascript
复制
<choice doc:name="Choice">
    <when expression="#[flowVars.event_ops_type != null]">
        <logger message="#[flowVars.event_ops_type]" level="INFO" doc:name="Logger"/>
    </when>
    <otherwise>
        <scripting:component doc:name="Groovy">
            <scripting:script engine="Groovy"><![CDATA[throw new org.mule.module.apikit.exception.NotFoundException(flowVars['event_ops_type'] + " is null!"); ]]></scripting:script>
        </scripting:component>
    </otherwise>
</choice>
<exception-strategy ref="api-apiKitGlobalExceptionMapping" doc:name="Reference Exception Strategy"/>
票数 2
EN

Stack Overflow用户

发布于 2018-10-01 14:28:21

您可以在transformer之后使用choice router来检查payload.event_ops_type == "400"。然后提出用于异常处理的自定义异常,或者基于event_ops_type 400设置响应状态和原因。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52578090

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档