The MessageContext class stays with an XFire invocation from start to finish. It is useful for:
- Accessing Messages, their xml streams and their headers
- Storing/retrieving properties which need to be shared across different handlers
- The service being invoked
- The XFire instance being invoked
Accessing the MessageContext from your Operation
In some cases you want to be able to access XFire's MessageContext. The Invokers that come with XFire allow you to add a MessageContext variable to your operation like so:
XFire will just inject the MessageContext for you. With no ThreadLocal magic at all!
You can also access MessageContext using :
Accessing Messages and their XML
The MessageContext has some accessors that easy to access messages associated with the invocation.
- getOutMessage() retrieves the outgoing message
- getInMessage() retreives the incoming message
- getCurrentMessage() retreives the current message being worked with
- getExchange() accesses the message exchange and can provide you with more information like the current operation, and fault messages.
Getting at the XML
XFire is based on a completely streaming model. So you have two options if you want to get at the XML. The first is to use the Message Binding. This way XFire won't read the stream into Objects for you, and you can access the XMLStreamReader yourself.
The second way is to switch to "DOM Mode" by using the DOMInHandler and DOMOutHandler. These handlers can be registered with the service
Then you can access the org.w3c.dom.Document for the message: