Q: How do I make message contexts available to my service impl class?
Applies To:
Apache Axis2/Java 1.0 [0]
Apache Axis2/Java 1.1 or later [0]
A: Apache Axis2/Java 1.0 :
There are two ways you can implement this.
1. Add the following method in to your service implementation class.
public void setOperationContext(OperationContext opContext){
................
................
}
2. Implement the org.apache.axis2.Service to your service implementation class. Then by using the setOperationContext() in that you will get access to the message contexts. Thats it!
To access the IN message context :
MessageContext inContext = opContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN)
To access the OUT message context :
MessageContext outContext = opContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT)
Note:This method will only work if you are using one of in-built message receivers coming with Axis2 distribution, such as RPCMessageReceiver, RawXMLINOutMessageReceiver etc.
A: Apache Axis2/Java 1.1 or above:
For Axis2 1.1 or above use the following from your service implementation class instead of the setOperationContext(..)
To get incoming message context:
MessageContext inContext =
MessageContext.getCurrentMessageContext();
To get outgoing message context:
OperationContext operationContext
=inMessageContext.getOperationContext();
MessageContext outMessageContext =
operationContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);