cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marc Giger (JIRA)" <j...@apache.org>
Subject [jira] Commented: (CXF-2340) Unmarshalling Error: UndeclaredPrefix: Cannot resolve 'ns0:Xxx' as a QName: the prefix 'ns0' is not declared
Date Thu, 22 Apr 2010 08:27:05 GMT

    [ https://issues.apache.org/jira/browse/CXF-2340?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12859739#action_12859739
] 

Marc Giger commented on CXF-2340:
---------------------------------

This bug still occurs when using latest JAXB SNAPHSOT (tryied 20091103, which should be fixed)
and xerces 2.9.1
I've double checked that the correct JAXB and xerces version are used.

The following workaround/fix was developped by Yves and me to show the problem:

--- common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java.orig  2010-01-19
21:48:27.000000000 +0100
+++ common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java       2010-02-10
09:09:23.000000000 +0100
@@ -106,6 +106,9 @@
         }
 
         if (nodes != null) {
+            // flag if namespace declarations from Envelope and Body should be added to this
frame
+            boolean addEnvBodyNS = false;
+
             for (int i = 0; i < nodes.getLength(); i++) {
                 Node node = nodes.item(i);
                 String prefix = node.getPrefix();
@@ -127,10 +130,44 @@
                     prefix = name.substring(6);
                     frame.uris.add(value);
                     frame.prefixes.add(prefix);
+                } else if (prefix.length() > 0 
+                    && "http://www.w3.org/2001/XMLSchema-instance"
+                       .equals(element.lookupNamespaceURI(prefix))) {
+                    addEnvBodyNS = true;
+                    frame.attributes.add(node);
                 } else {
                     frame.attributes.add(node);
                 }
             }
+            if (addEnvBodyNS) {
+                Document doc = frame.getElement().getOwnerDocument();
+                Element envelope = 
+                    (Element) doc.getElementsByTagNameNS(
+                        "http://schemas.xmlsoap.org/soap/envelope/", "Envelope").item(0);
+                Element body = 
+                    (Element) doc.getElementsByTagNameNS(
+                        "http://schemas.xmlsoap.org/soap/envelope/", "Body").item(0);
+
+                populateCurrentFrameWithNS(envelope);
+                populateCurrentFrameWithNS(body);
+            }
+        }
+    }
+
+    private void populateCurrentFrameWithNS(Element element) {
+        // Examine namespace declarations and add them to the current frame
+        NamedNodeMap nodes = element.getAttributes();
+        if (nodes != null) {
+            for (int i = 0; i < nodes.getLength(); i++) {
+                Node node = nodes.item(i);
+                String prefix = node.getPrefix();
+                String localName = node.getLocalName();
+                String value = node.getNodeValue();
+                if ("xmlns".equals(prefix)) {
+                    getCurrentFrame().prefixes.add(localName);
+                    getCurrentFrame().uris.add(value);
+                }
+            }
         }
     }

> Unmarshalling Error: UndeclaredPrefix: Cannot resolve 'ns0:Xxx' as a QName: the prefix
'ns0' is not declared 
> -------------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-2340
>                 URL: https://issues.apache.org/jira/browse/CXF-2340
>             Project: CXF
>          Issue Type: Bug
>          Components: JAXB Databinding
>    Affects Versions: 2.2.2
>            Reporter: John Pfeifer IV
>         Attachments: cxf-test.tar, StreamReaderProblem.zip
>
>
> Please see the following thread from Nabble outlining the issue.  I have sample code
that can be used to test the scenario.
> http://www.nabble.com/Unmarshalling-Error%3A-UndeclaredPrefix%3A-Cannot-resolve-%27ns0%3AXxx%27-as-a-QName%3A-the-prefix-%27ns0%27-is-not-declared-to17918441.html#a24462568
> Basically, when specifying an xsi:type for an element that extends and Complex Type,
CXF throws the following error
> [org.xml.sax.SAXParseException: UndeclaredPrefix: Cannot resolve 'ser:getSedans' as a
QName: the prefix 'ser' is not declared.]
> 	at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:396)
> 	at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:335)
> 	at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:312)
> 	at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:607)
> 	... 29 more
> Caused by: org.xml.sax.SAXParseException: UndeclaredPrefix: Cannot resolve 'ser:getSedans'
as a QName: the prefix 'ser' is not declared.
> 	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
> 	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
> 	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
> 	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
> 	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:410)
> 	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3165)
> 	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.getAndCheckXsiType(XMLSchemaValidator.java:2435)
> 	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1922)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message