SAAJ's DOM error

Discussion in 'Java' started by Son KwonNam, Dec 15, 2004.

  1. Son KwonNam

    Son KwonNam Guest

    I have the following java SAAJ source code.
    ----------------------------------------------------------------------
    import javax.xml.soap.*;

    public class SoapBodyTest {
    /// Field
    /// Constructor
    /// Method
    public static void main(String args[]) throws Exception {
    //SOAPMessage
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage requestMessage = messageFactory.createMessage();
    //SOAPPart
    SOAPPart soapPart = requestMessage.getSOAPPart();
    //SOAPEnvelope
    SOAPEnvelope envelope = soapPart.getEnvelope();

    //SOAPFactory
    SOAPFactory soapFactory = SOAPFactory.newInstance();

    //SOAPBody
    SOAPBody body = envelope.getBody();

    //Body Entry
    Name bodyName = soapFactory.createName("sayHello", "ns0", null);
    SOAPBodyElement bodyElement = body.addBodyElement(bodyName);

    // Body Entry's children
    Name childName = soapFactory.createName("String_1");
    SOAPElement childElement = bodyElement.addChildElement(childName);
    Name typeName = soapFactory.createName("xsi:type");
    childElement.addAttribute(typeName, "xsd:string"); // ## LINE 30 ##
    childElement.addTextNode("mincheol");

    //SOAPConnection
    SOAPConnectionFactory soapConnectionFactory =
    SOAPConnectionFactory.newInstance();
    SOAPConnection connection = soapConnectionFactory.createConnection();

    // send message
    SOAPMessage responseMessage = connection.call(requestMessage,
    "http://localhost:9000/hello/webservice");
    }
    }

    ----------------------------------------------------------------------

    This program works nicely with JWSDP 1.1's jar libraries.
    But with JWSDP 1.5's jar libraries, This program does not work and shows
    the following Exception.
    ----------------------------------------------------------------------
    Exception in thread "main" org.w3c.dom.DOMException: NAMESPACE_ERR: An
    attempt is made to create or change an object in a way which is
    incorrect with regard to namespaces.
    at
    com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.checkDOMNSErr(CoreDocumentImpl.java:2327)
    at
    com.sun.org.apache.xerces.internal.dom.AttrNSImpl.setName(AttrNSImpl.java:151)
    at
    com.sun.org.apache.xerces.internal.dom.AttrNSImpl.<init>(AttrNSImpl.java:112)
    at
    com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.createAttributeNS(CoreDocumentImpl.java:1959)
    at
    com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl.createAttributeNS(SOAPDocumentImpl.java:142)
    at
    com.sun.org.apache.xerces.internal.dom.ElementImpl.setAttributeNS(ElementImpl.java:680)
    at
    com.sun.xml.messaging.saaj.soap.impl.ElementImpl.addAttributeBare(ElementImpl.java:298)
    at
    com.sun.xml.messaging.saaj.soap.impl.ElementImpl.addAttribute(ElementImpl.java:282)
    at SoapBodyTest.main(SoapBodyTest.java:30)
    ----------------------------------------------------------------------

    How to get this program work with JWSDP 1.5??


    Thank you in advance.
    KwonNam.
     
    Son KwonNam, Dec 15, 2004
    #1
    1. Advertising

  2. Son KwonNam

    Son KwonNam Guest

    This problem occurred because I did not add Namespace Declaration to
    SOAPEnvelope object with addNamespaceDeclaration() method.

    After adding Namespace Declarations, the I change line 29 to
    "Name typeName = soapFactory.createName("type", "xsi", null);"

    It works.

    Son KwonNam wrote:
    > I have the following java SAAJ source code.
    > ----------------------------------------------------------------------
    > import javax.xml.soap.*;
    >
    > public class SoapBodyTest {
    > /// Field
    > /// Constructor
    > /// Method
    > public static void main(String args[]) throws Exception {
    > //SOAPMessage
    > MessageFactory messageFactory = MessageFactory.newInstance();
    > SOAPMessage requestMessage = messageFactory.createMessage();
    > //SOAPPart
    > SOAPPart soapPart = requestMessage.getSOAPPart();
    > //SOAPEnvelope
    > SOAPEnvelope envelope = soapPart.getEnvelope();
    >
    > //SOAPFactory
    > SOAPFactory soapFactory = SOAPFactory.newInstance();
    >
    > //SOAPBody
    > SOAPBody body = envelope.getBody();
    >
    > //Body Entry
    > Name bodyName = soapFactory.createName("sayHello", "ns0", null);
    > SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
    >
    > // Body Entry's children
    > Name childName = soapFactory.createName("String_1");
    > SOAPElement childElement = bodyElement.addChildElement(childName);
    > Name typeName = soapFactory.createName("xsi:type");
    > childElement.addAttribute(typeName, "xsd:string"); // ## LINE 30 ##
    > childElement.addTextNode("mincheol");
    >
    > //SOAPConnection
    > SOAPConnectionFactory soapConnectionFactory =
    > SOAPConnectionFactory.newInstance();
    > SOAPConnection connection = soapConnectionFactory.createConnection();
    >
    > // send message
    > SOAPMessage responseMessage = connection.call(requestMessage,
    > "http://localhost:9000/hello/webservice");
    > }
    > }
    >
    > ----------------------------------------------------------------------
    >
    > This program works nicely with JWSDP 1.1's jar libraries.
    > But with JWSDP 1.5's jar libraries, This program does not work and shows
    > the following Exception.
    > ----------------------------------------------------------------------
    > Exception in thread "main" org.w3c.dom.DOMException: NAMESPACE_ERR: An
    > attempt is made to create or change an object in a way which is
    > incorrect with regard to namespaces.
    > at
    > com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.checkDOMNSErr(CoreDocumentImpl.java:2327)
    >
    > at
    > com.sun.org.apache.xerces.internal.dom.AttrNSImpl.setName(AttrNSImpl.java:151)
    >
    > at
    > com.sun.org.apache.xerces.internal.dom.AttrNSImpl.<init>(AttrNSImpl.java:112)
    >
    > at
    > com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.createAttributeNS(CoreDocumentImpl.java:1959)
    >
    > at
    > com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl.createAttributeNS(SOAPDocumentImpl.java:142)
    >
    > at
    > com.sun.org.apache.xerces.internal.dom.ElementImpl.setAttributeNS(ElementImpl.java:680)
    >
    > at
    > com.sun.xml.messaging.saaj.soap.impl.ElementImpl.addAttributeBare(ElementImpl.java:298)
    >
    > at
    > com.sun.xml.messaging.saaj.soap.impl.ElementImpl.addAttribute(ElementImpl.java:282)
    >
    > at SoapBodyTest.main(SoapBodyTest.java:30)
    > ----------------------------------------------------------------------
    >
    > How to get this program work with JWSDP 1.5??
    >
    >
    > Thank you in advance.
    > KwonNam.
     
    Son KwonNam, Dec 15, 2004
    #2
    1. Advertising

  3. Son KwonNam

    jddr70

    Joined:
    Apr 12, 2011
    Messages:
    1
    I have similar problem I made a handler to procces incoming soap message in ws
    but when I try to make getEnvelope() shows the same error

    private void logToSystemOut(SOAPMessageContext smc) {

    try {

    Boolean outboundProperty = (Boolean) smc.get (MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (outboundProperty.booleanValue()) {
    HttpServletRequest req = (HttpServletRequest) smc.get("javax.xml.ws.servlet.request");

    SOAPMessage msg = ((SOAPMessageContext) smc).getMessage();
    //SOAPMessageContext smc = (SOAPMessageContext) context;
    //SOAPMessage msg = smc.getMessage();
    SOAPPart sp = msg.getSOAPPart();

    SOAPEnvelope se = sp.getEnvelope();


    Show the same error
     
    jddr70, Apr 12, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sunil

    to saaj or not to saaj

    Sunil, Jan 12, 2004, in forum: Java
    Replies:
    0
    Views:
    338
    Sunil
    Jan 12, 2004
  2. M. Turner
    Replies:
    0
    Views:
    610
    M. Turner
    Jun 25, 2004
  3. Jannar Molden

    SAAJ XML SOAP and element parameters

    Jannar Molden, Sep 2, 2004, in forum: Java
    Replies:
    1
    Views:
    1,014
    iksrazal
    Sep 3, 2004
  4. frank
    Replies:
    0
    Views:
    401
    frank
    Apr 16, 2005
  5. chris_isima

    SOAP/SAAJ error

    chris_isima, Mar 1, 2007, in forum: Java
    Replies:
    1
    Views:
    688
    chris_isima
    Mar 1, 2007
Loading...

Share This Page