What is the difference between variables in MessageContext versus MessageContext.Message?

I am creating a java call out to read variables that is being created. I have found out that we can call the

MessageContext.getVariable("variableX") 

and we could also do the following.

MessageContext.getMessage().getVariable("variableX")

What is the difference between the two? When should we get variable at MessageContext level versus getting variable at Message level?

I couldn't find any historical post on the topic nor any product documentation about what I have mentioned.

I found the following documentation from your sample codes: https://github.com/apigee/api-platform-samples

MessageContext.getVariable(String)Gets the named flow variable from Edge.

Message.getVariable(String)Gets a specific property associated with the message.

What is the difference between a flow variable and a message variable property?

0 1 449
1 REPLY 1

I don't know the official answer to that, sorry! It's not documented AFAIK.

I think in general you should use MessageContext.getVariable().

This information is not official, it's not guaranteed. Please don't depend on it. I think that with Message.getVariable() you can ask for and receive these things:

version The HTTP Version string (1.1 or 1.0, I suppose)
transportid this will always return "http"
formstring the full string of the form, if the content-type is application/x-www-form-urlencoded
content the message payload, if any

...whereas with MessageContext you can get most of that, except maybe the version string, and much more. Therefore I think in general you should use MessageContext.getVariable().