SAAJ's DOM error

S

Son KwonNam

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.
 
S

Son KwonNam

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 said:
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.
 
Joined
Apr 12, 2011
Messages
1
Reaction score
0
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top