Well, the way it works in Axis 1.2 is if we already have a SOAPBody present 
which has not been removed, we throw a SOAPException saying Body is already 
present.
I feel that should be the correct way to do this. So for me 2 is fine where if 
SoapBody!= null, we throw an exception rather than calling the detach() method. 
That will make 1 also work correctly.

Thanks,
Ashutosh

-----Original Message-----
From: Eran Chinthaka [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, April 26, 2005 8:27 AM
To: [email protected]
Subject: RE: [Axis2] getBody() method in SOAPEnvelopeImpl

Agreed. 

But there is a small catch here. Can someone call detach() method of
SOAPBody as SOAP messages must always have a body element. 

For me this is a chicken and egg problem. Lets say you have a SOAP Envelope
with a SOAPBody. Now you need to put a different SOAPBody. How can you do
this ??

1. envelope.getBody().detach();
envelope.addChild(newSOAPBodyElement);

2. envelope.addBody(newSOAPBody);

   public class SOAPEnvelopeImpl{
      private SOAPBody soapBody;

        public void addBody(SOAPBody newSOAPBody){
                if(soapBody != null){
                        soapBody.detach();
                }
                this.addChild(newSOAPBody);
                this.soapBody = newSOAPBody;
        }

  }

So Shahi, what do u think ? Shall we not expose the detach() method of
SOAPBody and use the option 2 .


Regards,
Chinthaka
      

________________________________________
From: Shahi, Ashutosh [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, April 13, 2005 3:20 PM
To: [email protected]
Subject: [Axis2] getBody() method in SOAPEnvelopeImpl


Hi Eran,
����������� �In getBody() method of SOAPEnvelopeImpl we do a
getNextSiblingElement() call on SOAPHeader expecting to get a SOAPBody. But
the SOAPBody might have already been removed through the detach() method and
we are not taking care of that. As a result we get a NullPointerException
from the method. A simple If() test on 'element' to see if it is null should
solve the issue.

Thanks,
Ashutosh



Reply via email to