Re: First row under header return null

"Paul Hsu" <[email protected]> Mon, 27 Sep 2004 12:46:16 -0700
Newsgroups gmane.text.xml.soap.devel
Message-ID <005601c4a4ca$ad6edf10$6500a8c0@hsuasus>
MessageI don't know which package you use to parse the soap. I use Jakata AXIS web service which adopt Jakata SOAP. I wrote a test code which it print the right information.

import javax.xml.soap.*;

import java.util.Iterator;

import org.apache.axis.message.SOAPEnvelope;

import javax.xml.soap.SOAPHeader;

import java.io.*;

import org.xml.sax.*;



public class TestSoap {

    public TestSoap() {

    }

    public static void main (String arg[])

 {



    String soap= "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" +

       "<s:Header>" +

          "<TransactionID s:mustUnderstand=\"1\" xmlns:mm7=\"http://www.3gpp.org/MMS/Rel5/MM7\">vas00001-sub</TransactionID>" +

       "</s:Header>" +

       "<s:Body>" +

          "<SubmitReq xmlns=\"urn:T-MobileAM\" orderDate=\"2004-09-01\">" +

             "<MM7Version>5.3.0</MM7Version>" +

          "</SubmitReq>" +

       "</s:Body>" +

    "</s:Envelope>";

try {

    SOAPEnvelope env = new SOAPEnvelope (new StringBufferInputStream (soap));



    SOAPHeader soaph = env.getHeader ();

    Iterator soape = soaph.getChildElements ();

    while(soape.hasNext())

    {

        SOAPElement e = (SOAPElement) soape.next();

        Name name = e.getElementName();

        System.out.println(name.getLocalName() + ":" + e.getValue());

    }

}

catch (SOAPException ex) {

}

catch (SAXException ex) {

}

 }

}

  ----- Original Message ----- 
  From: FIORAMORE, François 
  To: '[email protected]' 
  Sent: Monday, September 27, 2004 11:21 AM
  Subject: RE: First row under header return null


  Hi Paul,

  Thank for the support.  But is didn't work.
  I try what you wrote but it keep returning me null as the value.
  I just want to get the value information (TransactionID) in the following xml envelope.

  <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
     <s:Header>
        <TransactionID s:mustUnderstand="1" xmlns:mm7="http://www.3gpp.org/MMS/Rel5/MM7">vas00001-sub</TransactionID>
     </s:Header>
     <s:Body>
        <SubmitReq xmlns="urn:T-MobileAM" orderDate="2004-09-01">
           <MM7Version>5.3.0</MM7Version>
        </SubmitReq>
     </s:Body>
  </s:Envelope>

  Sound simple enough.  :)

  Here the beginning of the code:

     Envelope env
     ...
     Vector headerEntries = env.getHeader().getHeaderEntries();
     Element headerElement = (Element) headerEntries.firstElement();
     ...
     ...what next???  :)
     System.out.println(???.getNodeName()); //Will print out TransactionID
     System.out.println(???.getNodeValue()); //Will print out vas00001-sub
     // I wrote getNodeName and getNodeValue, but it could be anything...as long as it work.  :)

  Thank.

  Ciao,
  François.

    -----Original Message-----
    From: Paul Hsu [mailto:[email protected]] 
    Sent: Friday, September 24, 2004 7:19 PM
    To: [email protected]
    Subject: Re: First row under header return null


    try this, it should work. You problem is tempElement is the right level of layer already. Element is extends Node.

    Vector headerEntries = env.getHeader().getHeaderEntries(); 
    Element headerElement = (Element) headerEntries.firstElement(); 
    NodeList tempNodeList = headerElement.getElementsByTagName("TransactionID");  //I want the TransactionID. 
    Element tempElem = (Element)tempNodeList.item(0);    
    System.out.println((String)tempElem.getNodeValue().trim()); 

      ----- Original Message ----- 
      From: Paul Hsu 
      To: [email protected] 
      Sent: Friday, September 24, 2004 4:04 PM
      Subject: Re: First row under header return null


      I think you should change the code to
      NodeList tempNodeList = headerElement.getElementsByTagName("TransactionID");  //I want the TransactionID.
        ----- Original Message ----- 
        From: FIORAMORE, François 
        To: '[email protected]' 
        Sent: Friday, September 24, 2004 2:27 PM
        Subject: First row under header return null


        Hi, 

        I'm creating and sending the following xml to Apache SOAP: 

        ******************************************************************* 
        POST /soap/servlet/messagerouter HTTP/1.1 
        ... 
        ... 
        <?xml version='1.0' encoding='UTF-8'?> 
        <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
        <s:Header> 
        <mm7:TransactionID s:mustUnderstand="1" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mm7="http://www.3gpp.org/MMS/Rel5/MM7">vas00001-sub</mm7:TransactionID>

        </s:Header> 
        <s:Body> 
        <SubmitReq xmlns="urn:Something"> 
                 <MM7Version>5.3.0</MM7Version> 
        </SubmitReq> 
        </s:Body> 
        </s:Envelope> 
        ******************************************************************* 

        When I try to get the TransactionID value under the header, it doesn't work. 
        Here the code: 

        ******************************************************************* 
        env is a type Envelope. 
        Vector headerEntries = env.getHeader().getHeaderEntries(); 
        Element headerElement = (Element) headerEntries.firstElement(); 
        NodeList tempNodeList = headerElement.getElementsByTagName("*");  //I want the TransactionID. 
        Element tempElem = (Element)tempNodeList.item(0);    
        Node tempNode = tempElem.getFirstChild();    
        System.out.println((String)tempNode.getNodeValue().trim()); 
        ******************************************************************* 

        But when I use the following xml, it work: 

        ******************************************************************* 
        POST /soap/servlet/messagerouter HTTP/1.1 
        ... 
        ... 
        <?xml version='1.0' encoding='UTF-8'?> 
        <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
        <s:Header> 
        <temp> 
        <mm7:TransactionID s:mustUnderstand="1" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mm7="http://www.3gpp.org/MMS/Rel5/MM7">vas00001-sub</mm7:TransactionID>

        </temp> 
        </s:Header> 
        <s:Body> 
        <SubmitReq xmlns="urn:Something"> 
                 <MM7Version>5.3.0</MM7Version> 
        </SubmitReq> 
        </s:Body> 
        </s:Envelope> 
        ******************************************************************* 

        The only different thing, is the <temp> and </temp> tag. 
        Is seem for some reason that the first line under the header tag can never been read, but if you add a level between TransactionID and Header, everything under the temp tag is reachable.

        So how can I get the TransactionID without having to put the <temp> tag? 

        This could also be a misunderstanding from my part.  Let me know. 

        Software involve: 
        Xerces-J-bin.2.2.0.zip 
        jakarta-tomcat-4.0.3.zip 
        j2sdk-1_4_1_07-solaris-sparc.sh 
        soap-bin-2.3.1.zip 

        Thank. 

        Ciao, 
        François. 

        François Fioramore 
        Project Manager 
        airwide solutions (formerly Schlumberger Messaging) 
        T:  +1 (450) 646-7700 x210 
        M: +1 (514) 262-8540 
        F:  +1 (450) 646-7004 
        1111 St-Charles St. West, 8th Floor, East Tower 
        Longueuil, Québec, J4K 5G4, Canada 


        ________________________________________________________________________
        airwide solutions is changing its email address format to [email protected].
        Any slb.com email addresses will be valid until 30th September 2004.
        ________________________________________________________________________


  ________________________________________________________________________
  airwide solutions is changing its email address format to [email protected].
  Any slb.com email addresses will be valid until 30th September 2004.
  ________________________________________________________________________