10 Replies Latest reply on Feb 24, 2005 8:17 AM by Gabor Dolla

    NullPointerException in SOAPBodyAxisImpl.addDocument

    Gabor Dolla Newbie

      Hi
      My app works with Axis1.2RC2 and now I try to port it under Jboss-4.0.1.
      The following piece of code fails:
      MessageFactory messageFactory = MessageFactory.newInstance();
      SOAPMessage soapMessage = messageFactory.createMessage();
      SOAPPart sp = soapMessage.getSOAPPart();
      SOAPEnvelope se = sp.getEnvelope();
      SOAPBody main = se.getBody();
      main.addDocument(body);

      where body is a org.w3c.dom.Document (created with XMLBeans)
      the stack trace is:

      2005-02-18 14:13:42,958 INFO [STDOUT] java.lang.NullPointerException
      2005-02-18 14:13:42,959 INFO [STDOUT] at org.xml.sax.helpers.AttributesImpl.getIndex(Unknown Source)
      2005-02-18 14:13:42,959 INFO [STDOUT] at org.apache.axis.message.SOAPElementAxisImpl.setAttribute(SOAPElementAxisImpl.java:1170)
      2005-02-18 14:13:42,960 INFO [STDOUT] at org.apache.axis.message.SOAPBodyAxisImpl.importDOMElement(SOAPBodyAxisImpl.java:329)
      2005-02-18 14:13:42,960 INFO [STDOUT] at org.apache.axis.message.SOAPBodyAxisImpl.importDOMElement(SOAPBodyAxisImpl.java:339)
      2005-02-18 14:13:42,960 INFO [STDOUT] at org.apache.axis.message.SOAPBodyAxisImpl.addDocument(SOAPBodyAxisImpl.java:265)

      please help, TIA

      Gabor Dolla
      Budapest, Hungary

        • 1. Re: NullPointerException in SOAPBodyAxisImpl.addDocument
          Ole Matzura Novice

          Hi..

          Our experience is that addDocument is pretty buggy in the current jbossws implementation, for example it doesnt seem to handle entities correctly, etc..

          We have created our own method to convert a DOM element to a SOAPElement, which works fine with XmlBeans as well ..

          good luck!

          /Ole

          • 2. Re: NullPointerException in SOAPBodyAxisImpl.addDocument
            Gabor Dolla Newbie

             

            "omatzura" wrote:

            We have created our own method to convert a DOM element to a SOAPElement, which works fine with XmlBeans as well ..


            Hi

            how do you do that ???
            addDocument works with plain axis....

            thanks

            Gabor


            • 3. Re: NullPointerException in SOAPBodyAxisImpl.addDocument
              Thomas Diesler Master

              SOAPBody.addDocument(Document) is suposed to work.

              Could you create a jira issue with simple test cases that show your problem?

              thanks

              • 4. Re: NullPointerException in SOAPBodyAxisImpl.addDocument
                Gabor Dolla Newbie

                 

                "thomas.diesler@jboss.com" wrote:

                SOAPBody.addDocument(Document) is suposed to work.
                Could you create a jira issue with simple test cases that show your problem?


                Hi

                OK I can try that but I'm not sure if I can create a simple test case.
                I have a complex schema (3gpp MMS) and I created java classes from
                xsd with XMLBeans.
                When I try to post it via SOAP I create a new SAAJ message, and
                tried to use the addDocument() function. Then I received the nullpointerexception, and I'm not sure if it can be reproduced with a simple Document.
                The strange thing is that I created a private addDocument method by copying code from jboss and that code works.

                SOAPMessage soapMessage = messageFactory.createMessage();
                SOAPPart sp = soapMessage.getSOAPPart();
                SOAPEnvelope se = sp.getEnvelope();
                SOAPHeader sh = se.getHeader();
                Name name = se.createName("TransactionID","tr",
                "http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0");
                SOAPHeaderElement she = sh.addHeaderElement(name);
                she.setMustUnderstand(true);
                she.setValue(trid);
                SOAPBody main = se.getBody();
                myAddDocument(se, main, body.getDocumentElement());
                // main.addDocument(body);

                private static SOAPElement myAddDocument(SOAPEnvelope se, SOAPElement soapParent, Element domElement) {
                try
                {
                Name name = se.createName(domElement.getLocalName(), domElement.getPrefix(), domElement.getNamespaceURI());
                SOAPElement soapChild = soapParent.addChildElement(name);
                NamedNodeMap attrs = ((Element)domElement).getAttributes();
                for (int i = 0; i < attrs.getLength(); i++)
                {
                Node att = attrs.item(i);
                soapChild.setAttributeNS(att.getNamespaceURI(), att.getLocalName(), att.getPrefix());
                }
                StringBuffer content = new StringBuffer();
                NodeList children = domElement.getChildNodes();
                for (int i = 0; i < children.getLength(); i++)
                {
                Node domChild = children.item(i);
                if (domChild.getNodeType() == Node.ELEMENT_NODE)
                myAddDocument(se, soapChild, (Element)domChild);

                if (domChild.getNodeType() == Node.TEXT_NODE && domChild.getNodeValue().trim().length() > 0)
                content.append(domChild.getNodeValue());
                }
                if (content.length() > 0)
                {
                String value = content.toString();
                soapChild.addTextNode(value);
                }
                return soapChild;
                }
                catch (Exception e)
                {
                e.printStackTrace(System.err);
                }
                return null;
                }

                the difference between my method and jboss's addDocument is that
                my method uses classes from standard packages while jboss's addDocument/importDOMElement uses NameImpl and SOAPElementAxisImpl and so on....

                Gabor



                • 7. Re: NullPointerException in SOAPBodyAxisImpl.addDocument
                  Ole Matzura Novice

                  Hi!

                  we had a null-pointer issue in this method; in

                  ..
                  Name name = se.createName(domElement.getLocalName(), domElement.getPrefix(), domElement.getNamespaceURI());
                  ..
                  


                  domElement.getPrefix() sometimes returned null which havoced createName(..)

                  maybe this is the same NullPointer you are getting?

                  regards!

                  /Ole

                  • 8. Re: NullPointerException in SOAPBodyAxisImpl.addDocument
                    Gabor Dolla Newbie

                    Hi

                    From the stack trace the problem is in:
                    org.apache.axis.message.SOAPElementAxisImpl.setAttribute(SOAPElementAxisImpl.java:1170)

                    It might related to your problem, though

                    Gabor

                    • 9. Re: NullPointerException in SOAPBodyAxisImpl.addDocument
                      Thomas Diesler Master

                      Where do you see this code? It is probably incorrect to assume that the element the name is created from will be qualified.

                      The current implementation in Branch_4_0 is like this

                       /** Recursive function
                       */
                       private SOAPElementAxisImpl importDOMElement(SOAPElementAxisImpl soapParent, Element domElement)
                       {
                       try
                       {
                       NameImpl name;
                       if (domElement.getNamespaceURI() != null)
                       name = new NameImpl(domElement.getLocalName(), domElement.getPrefix(), domElement.getNamespaceURI());
                       else
                       name = new NameImpl(domElement.getLocalName());
                      
                      ...
                      


                      You might find that this issue is already fixed with this change.

                      cvs co -r Branch_4_0 jboss-4.0

                      • 10. Re: NullPointerException in SOAPBodyAxisImpl.addDocument
                        Gabor Dolla Newbie

                        I'd like to try that version but cvs cannot check it out
                        cvs checkout: [13:15:54] waiting for jboss-build's lock in /cvsroot/jboss/jbosstest/src/main/org/jboss/test/webservice/hello

                        4.0.1SP1 also contains this modification ?

                        Gabor