aditya parkhe
aditya parkhe

Reputation: 39

formatting message logging policy in API manager

im trying to write dataweave inside message logging policy in API manager using syntax like #[%dw 2.0 output application/json --- {"chrome_appid": attributes.headers.chrome_appid, "blah": "blah blah"}] but that doesnt seem to work. it saves to policy but logs are not generated. simple syntax like #[payload] and #[attributes] works. how do i format my dataweave code for api manager to read it correctly? I want some key-values from the header (or payload) displayed in the message logging. I'm trying to do this for flex gateway 1.3

Upvotes: 0

Views: 274

Answers (1)

aled
aled

Reputation: 25664

Flex Gateway supports only a sub-set of the DataWeave language. Specifically it doesn't support object value construction. It seems that the intention is to use the DataWeave sub-set just to write strings.

My advise would be not to use a JSON output since it is not fully supported. Use normal strings logs and if you really need JSON logs transform them outside Flex Gateway with a script or some other tool.

If you still want to try to generate JSON you can construct it using string concatenations, which is a hack and can eventually led to invalid JSONs. Note that you also need to do all escaping by hand which is time consuming.

Example of the not recommended option:

#["{\"chrome_appid\":" ++ attributes.headers.chrome_appid ++ ", \"blah\": \"blah blah\"}"]  // Not recommended, error prone 

Upvotes: 1

Related Questions