MarkyMark
MarkyMark

Reputation: 219

Mule 4 set HTTP status in Dataweave

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

Answers (2)

Sanoajul
Sanoajul

Reputation: 287

Define a variable like below and it should work.

<set-variable value="404" doc:name="httpStatus" variableName="httpStatus" />

Upvotes: 1

Ryan Carter
Ryan Carter

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

Related Questions