You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by "PILLAI,RANJITH (HP-PaloAlto,ex1)" <ra...@hp.com> on 2003/04/03 19:14:35 UTC

Bean data and getBodyByName()...

            Hi there,

 

Question 1) Is there any issue with getBodyByName (namespace, localpart) in
SOAPEnvelope class? .Because my method 1)(listed below) throws
NullPointerException and Method 2 (listed below) returns result.

 

                        Method 1) -> I am calling directly getBodyByName().

                        Method 2) -> I am using getBodyElements() and
iterate through the result to find localpart "MyBean". Here things work
fine.

 

Method 1)

 

SOAPEnvelope sEnlp=mess.getSOAPEnvelope();

SOAPBodyElement  sBElement=sEnlp. getBodyByName
<http://www.cs.unc.edu/Courses/comp190/docs/documentation/axis/apiDocs/org/a
pache/axis/message/SOAPEnvelope.html#getBodyByName(java.lang.String,
java.lang.String)> ("http://webservice5", "MyBean");

String name=sBElement.getName(); --> This throws NullPointerException.

 

Method 2)

 

But when I am doing this way..

SOAPEnvelope sEnlp=mess.getSOAPEnvelope();

                                    Vector v= sEnlp.getBodyElements();

                                    for(int i=0;i<v.size();i++){

                                                SOAPBodyElement
sBElement=(SOAPBodyElement)v.elementAt(i);

 
System.out.println("Name"+sBElement.getName());

                                                String
name=sBElement.getName();

                                                if(name.equals("multiRef")){

                                                           QName
qna=sBElement.getType();

                                                            String
localPart=qna.getLocalPart();

 
System.out.println("LocalPart->"+qna.getLocalPart()); -->This prints
"MyBean"

 
System.out.println("NameSpace->"+qna.getNamespaceURI()); -->This prints
"http://webservice5"

 
if(localPart.equals("MyBean")){

 
Iterator itr=sBElement.getChildElements();

 
hile(itr.hasNext()){

 
MessageElement mElement=(MessageElement)itr.next();

 
System.out.println("ElementValue->"+  mElement.getObjectValue());

                                                                        }

                                                            }

                                                 }

                                    }

 

Question 2) I am following the above procedure to get bean data at client.
Is this right? If Yes once I get my MessageElement, how do I extract "name"
and "value"?.

 

Thanks in advance for your help,

Ran