You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by "Shahi, Ashutosh" <As...@ca.com> on 2005/04/13 11:20:07 UTC

[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


Re: [Axis2] getBody() method in SOAPEnvelopeImpl

Posted by jayachandra <ja...@gmail.com>.
On 4/26/05, Eran Chinthaka <ch...@opensource.lk> wrote:
> Hi,
> 
> >
> > I too feel Option2 is good. But instead of what Ashu was saying to
> > throw an OMException in case of Body already being present, I would
> > say we add a warning or debug log info sort of thing and still proceed
> > with detaching and adding the new body.
> 
> Great. One more thing. We are now changing the functionality of the detach
> method too. Earlier detach() not only detached the node from the tree, but
> also discard the events thrown within that.
> Meaning, say
> 
> <a>
>         <b>
>                 <c>
>                 <d>
>         </b>
>         <e>
> </a>
> 
> If the parser's cursor is @ b, when we say b.discard() it will proceed the
> parser till end of b and will not build the object structure. That means we
> lose c and d altogether.
> 
> So now what we will be doing is we have two methods, discard() and detach().
> 
> Discard() will do the above functionality. But detach() will just disconnect
> b from a and adjust the other links.

How would you adjust the links... Will <c> and <d> be now children of
<a> acting as siblings to <e>? or choose one amongst the children
candidates to act as the parent of the remaining children.
The first case appears intuitive somehow but then, all the child nodes
statures get elevated by one level with the dissolving of parent. As a
side effect, if you want to restrict some namespaces prefixes etc only
to the scope of <c> and <d>, they either now become global if we want
to keep the order of adjustment O(1) or otherwise this operation
complexity should become O(no. of child nodes of <b> ).
Do you see a use case anywhere that would need this 'dissolving' <b>
kind of functionality. I'm just inquiring.

Bye
Jayachandra
-- 
-- Jaya

RE: [Axis2] getBody() method in SOAPEnvelopeImpl

Posted by Eran Chinthaka <ch...@opensource.lk>.
Hi,

> 
> I too feel Option2 is good. But instead of what Ashu was saying to
> throw an OMException in case of Body already being present, I would
> say we add a warning or debug log info sort of thing and still proceed
> with detaching and adding the new body. 

Great. One more thing. We are now changing the functionality of the detach
method too. Earlier detach() not only detached the node from the tree, but
also discard the events thrown within that.
Meaning, say

<a>
	<b>	
		<c>
		<d>
	</b>
	<e>
</a>

If the parser's cursor is @ b, when we say b.discard() it will proceed the
parser till end of b and will not build the object structure. That means we
lose c and d altogether.

So now what we will be doing is we have two methods, discard() and detach().

Discard() will do the above functionality. But detach() will just disconnect
b from a and adjust the other links.

>Eran! is there any standard
> out there that can tell us as to whether reassinging of a different
> body is acceptable or not? Or we may ask the author of 1.2 version
> code where SOAPException is being thrown, if that is the standard
> behaviour one is expected to follow.

I can quote one use case when we need to add a new soap body. Consider the
security case. One might encrypt the body and send. Then the security
handler will get the encrypted body, decrypt it and add the decrypted body.

My point is not how we should do that. But I want a soap message to *always*
have a SOAPBody. Giving user the flexibility to remove the body will
definitely violate that.

So I strongly prefer option 2.

> In fact, in OM when trying to reassign a node to a different parent, I
> once noticed similar kind of programming construct being employed. It
> then appeared logical to me for some reason I don't exactly remember
> now :D

Re-assigning node to a different parent is very common in XML world. I
myself found very difficult to handle this with w3c implementation. But this
can be easily done with JDom. 

> 
> Thanks
> Jayachandra
> 
> On 4/26/05, Eran Chinthaka <ch...@opensource.lk> wrote:
> > 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:Ashutosh.Shahi@ca.com]
> > Sent: Wednesday, April 13, 2005 3:20 PM
> > To: axis-dev@ws.apache.org
> > 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
> >
> >
> 
> 
> --
> -- Jaya
> 




Re: [Axis2] getBody() method in SOAPEnvelopeImpl

Posted by jayachandra <ja...@gmail.com>.
I too feel Option2 is good. But instead of what Ashu was saying to
throw an OMException in case of Body already being present, I would
say we add a warning or debug log info sort of thing and still proceed
with detaching and adding the new body. Eran! is there any standard
out there that can tell us as to whether reassinging of a different
body is acceptable or not? Or we may ask the author of 1.2 version
code where SOAPException is being thrown, if that is the standard
behaviour one is expected to follow.
In fact, in OM when trying to reassign a node to a different parent, I
once noticed similar kind of programming construct being employed. It
then appeared logical to me for some reason I don't exactly remember
now :D

Thanks
Jayachandra

On 4/26/05, Eran Chinthaka <ch...@opensource.lk> wrote:
> 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:Ashutosh.Shahi@ca.com]
> Sent: Wednesday, April 13, 2005 3:20 PM
> To: axis-dev@ws.apache.org
> 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
> 
> 


-- 
-- Jaya

RE: [Axis2] getBody() method in SOAPEnvelopeImpl

Posted by Eran Chinthaka <ch...@opensource.lk>.
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:Ashutosh.Shahi@ca.com] 
Sent: Wednesday, April 13, 2005 3:20 PM
To: axis-dev@ws.apache.org
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