Hi Srinath!

> I look at message, encoding packages in src. But the SOAP 
> Header ect depend on 
> serializingContext,DesializingContext which in turn depend on 
> MessageContext which is not avalible to me. (This is my 
> custom application).

Depending on how you do this, it might be a bit of a problem.  The Axis message 
classes are pretty dependent on Axis constructs like the *Contexts, and it's 
appropriate that they are written this way.  You can always move up the stack to the 
SAAJ interfaces and rewrite the implementations yourself if you want.  But 
manipulating the Axis classes is easier than you might think.

> public static void main(String[] args)throws Exception {
> // create SOAPHeader from the response rq.xml(SOAP message)
>   SOAPHeader h = new SOAPHeader("opensource.lk/axis/v2", 
> "Transaction", "t", 
>    null, new DeserializationContextImpl(
>             new InputSource(
>                         new FileInputStream(".//samples//rq.xml")),
>             null,
>             Constants.URI_SOAP12_RPC),
>             SOAPConstants.SOAP11_CONSTANTS);
>          System.out.println("h = " + h.getName());
>          System.out.println("h = " + h.getValue());
>          Writer w = new FileWriter(".//samples//rs.xml"); 
> //write the header back to the res.xml
>          h.output(new SerializationContextImpl(w ));
>          w.flush();
>          w.close();

OK, first off - the SOAPHeader class represents the <SOAP:Header> element, not an 
individual header inside it (personally I've never really seen the need to have a 
class for this - we used to have a "SOAPHeader" class which represented individual 
headers, and you'd have a list of those in the SOAPEnvelope, but then JAX-RPC/SAAJ 
changed that, making it more complicated without, IMHO, buying you much of anything).  
So you probably want to be using SOAPHeaderElement instead.

Second, if you want to take an existing SOAP message in your rq.xml file, parse it, 
and then operate on it, you'll need to construct the DeserializationContextImpl first, 
then call parse() on it to set up the envelope object tree.  After that you can create 
SOAPHeaderElements and add/remove them to your heart's content.

All the constructors for the axis.message.* classes which take DeserializationContext 
arguments are meant to be used ONLY by the deserialization system.  So when you're 
creating these things yourself, use the other constructors instead.  So you can do 
something like:

  SOAPHeaderElement myHeader = new SOAPHeaderElement("http://my-namespace/";, 
"CustomHeader");
  myHeader.setMustUnderstand(true);  // etc...
  myEnvelope.addHeader(myHeader);

There are examples of dynamically creating SOAP envelopes scattered throughout our 
tests - for instance, test.encoding.TestDOM, test.soap.TestFaultHandler, 
test.message.TestSOAPEnvelope, etc....

Hope this helps,
--Glen

Reply via email to