Skip to main content

Problem using javax.xml.soap

1 reply [Last post]
richardg1
Offline
Joined: 2007-10-10
Points: 0

Hi,

Apologies if this is the wrong forum to ask this question !

I am trying to wrap an existing XML document into a SOAP request using the javax.xml.soap library. I have some xml which contains a default namespace + a named namespace, for example :-

<?xml version="1.0"?>

1
2

Hello World

Using code similar to the following I was hoping to be able to wrap the xml into the SOAP body :-

try
{
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance() ;

DocumentBuilder builder = docFactory.newDocumentBuilder() ;
document = builder.parse(new InputSource(new StringReader(xml)));

MessageFactory messageFactory = MessageFactory.newInstance() ;
SOAPMessage message = messageFactory.createMessage() ;

SOAPBody body = message.getSOAPBody() ;
body.addDocument(document) ;
message.writeTo(System.out);

}
catch (Exception ex)
{
ex.printStackTrace() ;
}

However when a none detault namespace is specified the following exception occurs :-

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.ElementNSImpl.setName(ElementNSImpl.java:176)
at com.sun.org.apache.xerces.internal.dom.ElementNSImpl.(ElementNSImpl.java:112)
at com.sun.xml.messaging.saaj.soap.impl.ElementImpl.(ElementImpl.java:88)
at com.sun.xml.messaging.saaj.soap.impl.ElementFactory.createElement(ElementFactory.java:81)
at com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl.createElement(SOAPDocumentImpl.java:100)
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.importNode(CoreDocumentImpl.java:1485)
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.importNode(CoreDocumentImpl.java:1688)
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.importNode(CoreDocumentImpl.java:1688)
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.importNode(CoreDocumentImpl.java:1444)
at com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl.importNode(SOAPDocumentImpl.java:147)
at com.sun.xml.messaging.saaj.soap.impl.BodyImpl.addDocument(BodyImpl.java:235)
at test1.WebSender.loadXml(WebSender.java:48)
at test1.EtonSender$ClientServerThread.run(EtonSender.java:140)

I am using 1.5.0_13 JDK running on a windows XP machine. Any help in how to get round this problem would be appreciated.

Thanks,

Richard

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
richardg1
Offline
Joined: 2007-10-10
Points: 0

Bit quick in posting to the forum, forgot to set the xml document to be namespace aware.

docFactory.setNamespaceAware(true) ;