I had the same problem with the web service provider style of web 
service. I am using jbossas 5 beta two with jbossws 1.2.1. It appears that 
jboss beta two uses xerces-2.7.1. After assembling all of the sources I found 
the ?real? cause of the NAMESPACE_ERR exception to be of mixing DOM 1 vs DOM 2 
APIs. 

When a document is set for the SOAP body the dom tree for that document is 
copied into the soap body. If that document is made up of ElementImpl nodes 
rather than ElementNSImpl the call into Xerces fails with the now familiar 
NAMESPACE_ERR. To work around this issue change your code to use 
?createElementNS?. 

I happen to be using Castor, which creates documents composed of ElementImpl 
nodes. I have a work around using the TransformerFactory of Xalan to create a 
new doc tree but would rather not have to copy the document twice. 

The details:

SOAPBodyImpl
SOAPBodyElement addDocument(Document doc)

creates a soapFactory and begins the copy of elements from the document into 
the soapBody with the default as deep through 
soapFactory.createElement(rootElement). In SOAPFactoryImpl 
createElement(Element domElement, boolean deep) an assumption is made that the 
element passed in is an ElementNSImpl (has a localName). 

SOAPFactoryImpl
?
  | public SOAPElement createElement(Element domElement, boolean deep) throws 
SOAPException
  |    {
  |       if (domElement == null)
  |          throw new IllegalArgumentException("Source node cannot be null");
  | 
  |       if (domElement instanceof SOAPElement)
  |          return (SOAPElement)domElement;
  | 
  |       String localName = domElement.getLocalName();
  |       String prefix = domElement.getPrefix() != null ? 
domElement.getPrefix() : "";
  |       String nsURI = domElement.getNamespaceURI() != null ? 
domElement.getNamespaceURI() : "";
  | ?

In the case of an ElementImpl the localName is null as well as the prefix, 
ElementImpl will have the field name set. Thus when DOMUtils 
createElement(String localPart, String prefix, String url) is called the 
localPart == null but the prefix is an empty string. 

DOMUtils

public static Element createElement(String localPart, String prefix, String uri)
  |    {
  |       Document doc = getOwnerDocument();
  |       if (prefix == null || prefix.length() == 0)
  |       {
  |          log.trace("createElement {" + uri + "}" + localPart);
  |          return doc.createElementNS(uri, localPart);
  |       }
  |       else
  |       {
  |          log.trace("createElement {" + uri + "}" + prefix + ":" + 
localPart);
  |          return doc.createElementNS(uri, prefix + ":" + localPart);
  |       }
  |    }
?

So the call into Xerces for createElementNS fails on setName(String 
namespaceURI, String qname) in ElementNSImpl as noted in the comment in the 
Xerces code:

anonymous wrote : //NAMESPACE_ERR:
  |         //1. if the qualified name is 'null' it is malformed.
  |         //2. or if the qualifiedName is null and the namespaceURI is 
different from null,
  |         // We dont need to check for namespaceURI != null, if qualified 
name is null throw DOMException.

ElementNSImpl.java

        private void setName(String namespaceURI, String qname) {
  | 
  |             String prefix;
  |             // DOM Level 3: namespace URI is never empty string.
  |             this.namespaceURI = namespaceURI;
  |             if (namespaceURI != null) {
  |             //convert the empty string to 'null'
  |                     this.namespaceURI =     (namespaceURI.length() == 0) ? 
null : namespaceURI;
  |             }
  | 
  |         int colon1, colon2 ;
  | 
  |         //NAMESPACE_ERR:
  |         //1. if the qualified name is 'null' it is malformed.
  |         //2. or if the qualifiedName is null and the namespaceURI is 
different from null,
  |         // We dont need to check for namespaceURI != null, if qualified 
name is null throw DOMException.
  |         if(qname == null){
  |                             String msg =
  |                                     DOMMessageFormatter.formatMessage(
  |                                             DOMMessageFormatter.DOM_DOMAIN,
  |                                             "NAMESPACE_ERR",
  |                                             null);
  |                             throw new 
DOMException(DOMException.NAMESPACE_ERR, msg);
  |         }

Test Code:

The following snippet shows the exception. 

        boolean createNS = false;
  |     DocumentBuilderFactory documentBuilderFactory = 
DocumentBuilderFactory.newInstance();
  |     documentBuilderFactory.setNamespaceAware(true);
  |     DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
  |     document = builder.newDocument();
  |     
  |     if(createNS){
  |             Element element = document.createElementNS(null, "Moo");
  |             document.appendChild(element);
  |     }
  |     else
  |     {
  |             // Causes the NAMESPACE_ERR to be thrown
  |             Element element = document.createElement("Moo");
  |             element.appendChild(document.createTextNode(messageType));
  |     }
  | 
  |                     
  |     MessageFactory messageFactory = 
MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
  |     message = messageFactory.createMessage();
  |                     
  |        SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
  |        SOAPBody body = envelope.getBody();
  |             
  |     body.addDocument(document);

Documentation: 
        
http://xerces.apache.org/xerces-j/apiDocs/org/apache/xerces/dom/ElementNSImpl.html
        vs
        
http://xerces.apache.org/xerces-j/apiDocs/org/apache/xerces/dom/ElementImpl.html


View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4098072#4098072

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4098072
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to