How do I make message contexts available to my service impl class?
Submitted on May 29, 2006 - 23:25. Story : Project :
Q: How do I make message contexts available to my service impl class?
Applies To:
Apache Axis2/Java 1.1 or later
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);
- Login or register to post comments
- Printer friendly version
- 3009 reads











when is setOperationContext() called?
In terms of axis2 1.0 is setOperationContext() called for every invocation of a Web service method, or once the service object is instantiated? I guess the latter is most appropriate, since otherwise this wouldn't be thread-safe for application scoped service objects. Am I correct?
when the setOperationContext() called
The setOperationContext() method is called just before the service objects business logic gets invoked. When and how often the service object gets initialized depends on the scope of the service and the init method is called only when the service object initializes.
As for thread safety, if you implement the setOperationContext() method in a service class having 'application scope', then you should be managing the thread synchronization by your self!
Have a look at the getTheImplementationObject(..) method and the configureBusinessLogicProvider(...) method of the org.apache.axis2.receivers.AbstractMessageReceiver and org.apache.axis2.engine.DependencyManager respectively that lives in the axis2-core module.
Is 'MessageContext.getCurrentMessageContext()' synchronized?
If the Message Receiver receives two Requests at the same time, will the method
MessageContext.getCurrentMessageContext()
always return the correct MessageContext in the Web Service logic implementation?
I can 't see whether the invoke-logic method is sychronized.
Yes it will
MessageContext.getCurrentMessageContext() will always return the correct MessageContext. The current message context is held within a ThreadLocal object.
Regards
Afkham Azeez