Hi Jen Ya,
Let me know from where you want to get hold of the message context.
1. If you want to do this in the stub level : I'm sorry you can't do
it. Actually I don't think its a good idea to get hold of the the msgctx
in the stub level. But you can use one of the MEP clients to access the
message contexts.
2. If you want to do this in the handler level : no problem, you will
get the msgctx as a param in the invoke method of the handle. I hope
this is not the place you have the problem.
3. If its in the service impl class : I hope Ruchith's answer is great
in that. But I prefer to write my own message receiver and inject both
the message contexts in the invokeBusinessLogic method. But see you have
different ways of doing that.
And in Axis2, we have a clearly defined hierarchy of contexts. See the
archi guide for more information. So msgctx is not the only context.
HTH. If you still have the problem, feel free to post it here.
-- Chinthaka
Gregor Urbanek wrote:
Hi Jen-Ya,
looking at the code generated by the wsdl2java tool reveals, where
the soap envelope gets stored
org.apache.axis2.context.MessageContext _messageContext =
getMessageContext();
_messageContext.setEnvelope(env);
The _messageContext object, which seems to be connected to the
_configurationContext object ( everything in context of the stub
object ) has the method
getEnvelope to get hold of the soap envelope.
org.apache.axis2.soap.SOAPEnvelope env = _messageContext.getEnvelope();
Once you have the soap envelope, you hold in your hands all the options
- like get all headers
env.getHeader().extractAllHeaderBlocks
- insert a new header
env.getHeader()..addChild( OMNode );
Remember, the soap specific objects like SOAPEnvelope or SOAPheader
are derived from the generic OM objects, with all their flexibility.
Jen-Ya Ku wrote:
Hi, All:
In Axis, we can use following to get headers: However, for Axis2
service, how to get/set header?
Thanks for your info.
Thanks,
Jen-Ya
---------------------------------------------------------------------------------------------------------------------------------
// Axis1x Get current message context
MessageContext ctx =
org.apache.axis.MessageContext.getCurrentContext();
// Get SOAP envelope of request
SOAPEnvelope env = ctx.getRequestMessage().getSOAPEnvelope();
// Get Header
SOAPHeaderElement soapHeaderElement =
env.getHeaderByName(headerNamespace, headerName);
-----------------------------------------------------------------------------------------------------