Q:

WSO2 ESB read OperationName property in a mediator

I want to read the properties OperationName and To in my custom mediator written in Java. with this line of code 
(String) context.getProperty("OperationName")
and
(String) context.getProperty("To")
I get null as a result. How can I get the correct value? I tried most of the property contexts but I got nothing than null.

A:

Looks like the properties 'To' and 'OperationName' are accessible only via the 'get-property' function and not really set in the message context [1]. To achieve your requirement, there are two options.
Option 1
In your class mediator you can use these lines to extract the To and the OperationName like in the method [2].
String opName = ((Axis2MessageContext) context).getAxis2MessageContext().getAxisOperation().getName().getLocalPart();
String to = context.getTo().getAddress();

PS : Please handle the NPEs.
Option 2
In the proxy service or sequence where this class mediator is used, prior to its usage, define two properties like the following.
<property expression="get-property('To')" name="To"/>
<property expression="get-property('OperationName')" name="OperationName"/>

So then, you can access these properties in the class mediator like the way you mentioned.
(String) context.getProperty("OperationName") and (String) context.getProperty("To")

