我想写一个数据编织代码,其中如果数据是空的,那么它应该路由到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(异常处理)?
发布于 2018-10-02 02:39:50
您可能希望尝试使用验证模块。MuleSoft documentation here。
<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。您可以将其切换为任何您想要的异常。
<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"/>发布于 2018-10-01 14:28:21
您可以在transformer之后使用choice router来检查payload.event_ops_type == "400"。然后提出用于异常处理的自定义异常,或者基于event_ops_type 400设置响应状态和原因。
https://stackoverflow.com/questions/52578090
复制相似问题