Search code examples
wso2http-headerswso2-api-managerrequest-headers

How to log request headers within script mediator in Wso2 API Manager 3.2?


I am trying to get all transport headers used when calling a specific API and log that for debugging, since we do not know what the name of the headers will be I want to log them all.

I know this can be done via a class mediator as well as by enabling wire logs but I am looking for an option to achieve this without having to do either of those.

I have tried using script mediator and then using: mc.getProperty("org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS") to fetch them from message context but it just returns null.

Any suggestions?


Solution

  • You are trying to get a property with the name "org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS" from the default Context, hence it's returning null. You can't really access TRANSPORT_HEADERS from the Axis2Context within a ScriptMediator. Your best option is to write a class mediator.