Reputation: 219
Hi i've reading a mule 4 documentation a lot but did not find answer for this. How can i set the HTTP status in the dataweave transformer? In mule 3 it was set within the set property component. Thanks
Upvotes: 2
Views: 8673
Reputation: 287
Define a variable like below and it should work.
<set-variable value="404" doc:name="httpStatus" variableName="httpStatus" />
Upvotes: 1
Reputation: 11606
You can use the statusCode
attribute in the http:response of the listener to tell it where to pickup the status from. The following example will pick it up from a var called httpStatus
or default to 200 if the var is not available after flow execution:
<http:listener config-ref="api-httpListenerConfig" path="/api/v1/*">
<http:response statusCode="#[vars.httpStatus default 200]">
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:response>
<http:error-response statusCode="#[vars.httpStatus default 500]">
<http:body>#[payload]</http:body>
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
Upvotes: 3