You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by du...@apache.org on 2007/03/20 00:23:26 UTC

svn commit: r520166 - in /webservices/axis/trunk/proposals/dug/java/src/org/apache/axis: AxisEngine.java encoding/SerializationContext.java message/MessageElement.java message/SAXOutputter.java

Author: dug
Date: Mon Mar 19 16:23:26 2007
New Revision: 520166

URL: http://svn.apache.org/viewvc?view=rev&rev=520166
Log:
Sync with HEAD
Fix a situation where an element has a default namespace (xmlns=...)
but it also has a prefix that points to the same namespace.  In these
case Axis tosses out the prefix.  This is bad when DSig is turned on
as the signatures don't match.  So, when the enableNamespacePrefixOptimization
option is turned off we won't do this any more.

Modified:
    webservices/axis/trunk/proposals/dug/java/src/org/apache/axis/AxisEngine.java
    webservices/axis/trunk/proposals/dug/java/src/org/apache/axis/encoding/SerializationContext.java
    webservices/axis/trunk/proposals/dug/java/src/org/apache/axis/message/MessageElement.java
    webservices/axis/trunk/proposals/dug/java/src/org/apache/axis/message/SAXOutputter.java

Modified: webservices/axis/trunk/proposals/dug/java/src/org/apache/axis/AxisEngine.java
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/proposals/dug/java/src/org/apache/axis/AxisEngine.java?view=diff&rev=520166&r1=520165&r2=520166
==============================================================================
--- webservices/axis/trunk/proposals/dug/java/src/org/apache/axis/AxisEngine.java (original)
+++ webservices/axis/trunk/proposals/dug/java/src/org/apache/axis/AxisEngine.java Mon Mar 19 16:23:26 2007
@@ -439,8 +439,7 @@
      */
     private static final String [] BOOLEAN_OPTIONS = new String [] {
                         PROP_DOMULTIREFS, PROP_SEND_XSI, PROP_XML_DECL,
-                        PROP_DISABLE_PRETTY_XML,
-                        PROP_ENABLE_NAMESPACE_PREFIX_OPTIMIZATION
+                        PROP_DISABLE_PRETTY_XML
     };
 
     /**

Modified: webservices/axis/trunk/proposals/dug/java/src/org/apache/axis/encoding/SerializationContext.java
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/proposals/dug/java/src/org/apache/axis/encoding/SerializationContext.java?view=diff&rev=520166&r1=520165&r2=520166
==============================================================================
--- webservices/axis/trunk/proposals/dug/java/src/org/apache/axis/encoding/SerializationContext.java (original)
+++ webservices/axis/trunk/proposals/dug/java/src/org/apache/axis/encoding/SerializationContext.java Mon Mar 19 16:23:26 2007
@@ -270,13 +270,13 @@
             if (shouldDisablePrettyXML != null)
                 disablePrettyXML = shouldDisablePrettyXML.booleanValue();
             
-            Boolean shouldDisableNamespacePrefixOptimization =
-                  (Boolean)msgContext.getProperty(AxisEngine.PROP_ENABLE_NAMESPACE_PREFIX_OPTIMIZATION);
-            if (shouldDisableNamespacePrefixOptimization != null) {
-                enableNamespacePrefixOptimization = shouldDisableNamespacePrefixOptimization.booleanValue();
+            String shouldEnableNamespacePrefixOptimization =
+                (String) msgContext.getProperty(AxisEngine.PROP_ENABLE_NAMESPACE_PREFIX_OPTIMIZATION);
+            if (shouldEnableNamespacePrefixOptimization != null) {
+                enableNamespacePrefixOptimization = JavaUtils.isTrue(shouldEnableNamespacePrefixOptimization, false);
             } else {
                 enableNamespacePrefixOptimization = JavaUtils.isTrue(AxisProperties.getProperty(AxisEngine.PROP_ENABLE_NAMESPACE_PREFIX_OPTIMIZATION,
-                                "true"));
+                                "false"));
             }
             boolean sendTypesDefault = sendXSIType;
 
@@ -314,7 +314,7 @@
 //            }
         } else {
             enableNamespacePrefixOptimization = JavaUtils.isTrue(AxisProperties.getProperty(AxisEngine.PROP_ENABLE_NAMESPACE_PREFIX_OPTIMIZATION,
-                            "true"));
+                            "false"));
             disablePrettyXML = JavaUtils.isTrue(AxisProperties.getProperty(AxisEngine.PROP_DISABLE_PRETTY_XML,
                             "true"));
         }
@@ -976,7 +976,7 @@
                 attrs.addAttribute("", soapConstants.getAttrHref(), soapConstants.getAttrHref(),
                                    "CDATA", '#' + id);
 
-                startElement(elemQName, attrs);
+                startElement( elemQName, attrs);
                 endElement();
                 this.sendNull = sendNullCache;
                 return;
@@ -1104,7 +1104,19 @@
      * @param qName is the name of the element
      * @param attributes are the attributes to write
      */
-    public void startElement(QName qName, Attributes attributes)
+    public void startElement(QName qName, Attributes attributes) 
+        throws IOException {
+      startElement( null, qName, attributes );
+    }
+
+    /**
+     * Writes (using the Writer) the start tag for element QName along with the
+     * indicated attributes and namespace mappings.
+     * @param oldPrefix is the prefix on the original Element
+     * @param qName is the name of the element
+     * @param attributes are the attributes to write
+     */
+    public void startElement(String oldPrefix, QName qName, Attributes attributes)
         throws IOException
     {
         java.util.ArrayList vecQNames = null;
@@ -1125,6 +1137,19 @@
 
         if (pretty) for (int i=0; i<indent; i++) writer.write(' ');
         String elementQName = qName2String(qName, true);
+
+        /* If we don't have a prefix, but the original version of the XML  */
+        /* did have one (meaning 'oldPrefix' is not null) then use that    */
+        /* one.We don't want to change the XML too much due to security.   */
+        /* However, let enableNamespacePrefixOptimization override.        */
+        /*******************************************************************/
+        if ( !enableNamespacePrefixOptimization &&
+             oldPrefix != null && !"".equals(oldPrefix) &&
+             elementQName.indexOf(":") < 0 )
+        {
+          elementQName = oldPrefix + ":" + elementQName ;
+        }
+
         writer.write('<');
 
         writer.write(elementQName);
@@ -1353,7 +1378,23 @@
             localPart = el.getNodeName();
         QName qName = new QName(namespaceURI, localPart);
 
-        startElement(qName, attributes);
+        startElement(el.getPrefix(), qName, attributes);
+
+        /* At some point figure out why we don't just use the following
+        /* code which is much easier.  
+        /****************************************************************/
+        /*
+        String prefix = el.getPrefix();
+        String name   = el.getNodeName();
+
+        writer.write( "<" + (prefix!=null?(prefix+":"):"") + name );
+        NamedNodeMap map = el.getAttributes();
+        for ( int i = 0 ; i < map.getLength() ; i++ ) {
+          Attr attr = (Attr) map.item( i );
+          writer.write( " " + attr.getName() + "=\"" + attr.getValue() + "\"");
+        }
+        writer.write( ">" );
+        */
 
         NodeList children = el.getChildNodes();
         for (int i = 0; i < children.getLength(); i++) {
@@ -1372,6 +1413,9 @@
                 writeSafeString(((Text)child).getData());
             }
         }
+        /*
+        writer.write( "</" + (prefix!=null?(prefix+":"):"") + name + ">" );
+        */
 
         endElement();
     }

Modified: webservices/axis/trunk/proposals/dug/java/src/org/apache/axis/message/MessageElement.java
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/proposals/dug/java/src/org/apache/axis/message/MessageElement.java?view=diff&rev=520166&r1=520165&r2=520166
==============================================================================
--- webservices/axis/trunk/proposals/dug/java/src/org/apache/axis/message/MessageElement.java (original)
+++ webservices/axis/trunk/proposals/dug/java/src/org/apache/axis/message/MessageElement.java Mon Mar 19 16:23:26 2007
@@ -1250,7 +1250,7 @@
             return;
         }
 
-        outputContext.startElement(new QName(namespaceURI, name), attributes);
+        outputContext.startElement(this.prefix, new QName(namespaceURI, name), attributes);
         if (children != null) {
             for (Iterator it = children.iterator(); it.hasNext();) {
                 ((NodeImpl)it.next()).output(outputContext);

Modified: webservices/axis/trunk/proposals/dug/java/src/org/apache/axis/message/SAXOutputter.java
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/proposals/dug/java/src/org/apache/axis/message/SAXOutputter.java?view=diff&rev=520166&r1=520165&r2=520166
==============================================================================
--- webservices/axis/trunk/proposals/dug/java/src/org/apache/axis/message/SAXOutputter.java (original)
+++ webservices/axis/trunk/proposals/dug/java/src/org/apache/axis/message/SAXOutputter.java Mon Mar 19 16:23:26 2007
@@ -96,7 +96,11 @@
         }
 
         try {
-            context.startElement(new QName(namespace,localName), attributes);
+            String prefix = null ;
+            int i = qName.indexOf(":");
+            if ( i >=0 ) prefix = qName.substring(0,i);
+
+            context.startElement(prefix, new QName(namespace,localName), attributes);
         } catch (IOException e) {
             throw new SAXException(e);
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org