gdaniels    2002/09/22 10:26:29

  Modified:    java     TODO.txt
               java/src/org/apache/axis/encoding
                        SerializationContextImpl.java
               java/src/org/apache/axis/encoding/ser ElementSerializer.java
               java/src/org/apache/axis/message SOAPHeaderElement.java
               java/test/encoding TestSer.java
               java/test/message TestMessageElement.java
  Log:
  Fix bug http://nagoya.apache.org/bugzilla/show_bug.cgi?id=10605, and do a
  little cleanup.
  
  * Allow xmlns="" mapping in SerializationContextImpl (why was this disallowed?)
  
  * Use XMLUtils.newDocument() in TestSer to ensure correct namespace processing.
  
  * Add new test in TestSer to confirm default namespaces are working as designed
  
  * Remove MessageElement and SOAPHeaderElement default constructors, since they
    don't really make sense and were only being used from 1 place (a test)
  
  * Make sure we don't remap xmlns="" multiple times by checking for "" as well
    as null in SerializationContextImpl
  
  * Remove bogus code in ElementSerializer to "suppress <any> elements".  This
    would cause us to fail to serialize any XML with an element <any> in it,
    which was broken.
  
  Revision  Changes    Path
  1.77      +0 -2      xml-axis/java/TODO.txt
  
  Index: TODO.txt
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/TODO.txt,v
  retrieving revision 1.76
  retrieving revision 1.77
  diff -u -r1.76 -r1.77
  --- TODO.txt  20 Sep 2002 20:55:02 -0000      1.76
  +++ TODO.txt  22 Sep 2002 17:26:28 -0000      1.77
  @@ -35,8 +35,6 @@
   10365 - B
   10479 - B
   10512 - B
  -10605 - B - Glen
  -10847 - A - Glen
   10944 - B - Glen
   11766 - If this is real, it looks like an "A".  need to confirm.
   12167 - Glen will confirm
  
  
  
  1.72      +2 -4      
xml-axis/java/src/org/apache/axis/encoding/SerializationContextImpl.java
  
  Index: SerializationContextImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/SerializationContextImpl.java,v
  retrieving revision 1.71
  retrieving revision 1.72
  diff -u -r1.71 -r1.72
  --- SerializationContextImpl.java     18 Sep 2002 16:10:37 -0000      1.71
  +++ SerializationContextImpl.java     22 Sep 2002 17:26:28 -0000      1.72
  @@ -420,9 +420,7 @@
           }
   
           if ((uri != null) && (prefix != null)) {
  -            if (uri.length()>0 || prefix.length()>0) {
  -                nsStack.add(uri, prefix);
  -            }
  +            nsStack.add(uri, prefix);
           }
       }
   
  @@ -458,7 +456,7 @@
                   // If this is unqualified (i.e. prefix ""), set the default
                   // namespace to ""
                   String defaultNS = nsStack.getNamespaceURI("");
  -                if (defaultNS != null) {
  +                if (defaultNS != null && defaultNS.length() > 0) {
                       registerPrefixForURI("", "");
                   }
               }
  
  
  
  1.10      +2 -10     
xml-axis/java/src/org/apache/axis/encoding/ser/ElementSerializer.java
  
  Index: ElementSerializer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/ElementSerializer.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ElementSerializer.java    18 Sep 2002 16:10:35 -0000      1.9
  +++ ElementSerializer.java    22 Sep 2002 17:26:28 -0000      1.10
  @@ -66,7 +66,6 @@
   import org.apache.axis.wsdl.fromJava.Types;
   import org.apache.axis.encoding.Serializer;
   import org.apache.axis.encoding.SerializationContext;
  -import org.apache.axis.utils.JavaUtils;
   import org.apache.axis.utils.Messages;
   
   /**
  @@ -87,16 +86,9 @@
           if (!(value instanceof Element))
               throw new IOException(Messages.getMessage("cantSerialize01"));
   
  -        // suppress xsd:any namespace="##any" elements
  -        boolean suppressElement = (!context.getMessageContext().isEncoded() && 
  -                                   name.getNamespaceURI().equals("") &&
  -                                   name.getLocalPart().equals("any")); 
  -
  -        if (!suppressElement)
  -            context.startElement(name, attributes);
  +        context.startElement(name, attributes);
           context.writeDOMElement((Element)value);
  -        if (!suppressElement)
  -            context.endElement();
  +        context.endElement();
       }
   
       public String getMechanismType() { return Constants.AXIS_SAX; }
  
  
  
  1.13      +0 -4      xml-axis/java/src/org/apache/axis/message/SOAPHeaderElement.java
  
  Index: SOAPHeaderElement.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/message/SOAPHeaderElement.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- SOAPHeaderElement.java    18 Sep 2002 16:10:28 -0000      1.12
  +++ SOAPHeaderElement.java    22 Sep 2002 17:26:29 -0000      1.13
  @@ -81,10 +81,6 @@
       protected String    actor = "";
       protected boolean   mustUnderstand = false;
   
  -    public SOAPHeaderElement() {
  -        super();
  -    }
  -
       public SOAPHeaderElement(String namespace, String localPart)
       {
           super(namespace, localPart);
  
  
  
  1.35      +105 -35   xml-axis/java/test/encoding/TestSer.java
  
  Index: TestSer.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/encoding/TestSer.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- TestSer.java      16 Aug 2002 11:07:10 -0000      1.34
  +++ TestSer.java      22 Sep 2002 17:26:29 -0000      1.35
  @@ -10,6 +10,7 @@
   import org.apache.axis.encoding.TypeMappingRegistry;
   import org.apache.axis.encoding.TypeMapping;
   import org.apache.axis.Constants;
  +import org.apache.axis.utils.XMLUtils;
   import org.apache.axis.message.RPCElement;
   import org.apache.axis.message.RPCParam;
   import org.apache.axis.message.SOAPEnvelope;
  @@ -20,6 +21,9 @@
   
   import org.xml.sax.InputSource;
   import org.w3c.dom.Document;
  +import org.w3c.dom.Element;
  +import org.w3c.dom.NodeList;
  +import org.w3c.dom.Node;
   
   import javax.xml.namespace.QName;
   import javax.xml.parsers.DocumentBuilder;
  @@ -112,7 +116,7 @@
                                                  "method",
                                                  new Object [] { "argument" });
               env.addBodyElement(method);
  -            String soapStr = env.toString();
  +            env.toString();
           } catch (Exception e) {
               fail(e.getMessage());
           }
  @@ -120,41 +124,107 @@
           // If there was no exception, we succeeded in serializing it.
       }
   
  -    public void testEmptyXMLNS()
  +    public void testEmptyXMLNS() throws Exception
       {
  -        try {
  -            MessageContext msgContext = new MessageContext(new AxisServer());
  -            String req =
  -                "<xsd1:A xmlns:xsd1='urn:myNamespace'>"
  -                    + "<xsd1:B>"
  -                    + "<xsd1:C>foo bar</xsd1:C>"
  -                    + "</xsd1:B>"
  -                    + "</xsd1:A>";
  -
  -            StringWriter stringWriter=new StringWriter();
  -            StringReader reqReader = new StringReader(req);
  -            InputSource reqSource = new InputSource(reqReader);
  -
  -            DocumentBuilder xdb = 
DocumentBuilderFactory.newInstance().newDocumentBuilder();
  -            Document document = xdb.parse(reqSource );
  -
  -            String msgString = null;
  -
  -            SOAPEnvelope msg = new SOAPEnvelope();
  -            RPCParam arg1 = new RPCParam("urn:myNamespace", "testParam", 
document.getFirstChild());
  -            arg1.setXSITypeGeneration(Boolean.FALSE);
  -
  -            RPCElement body = new RPCElement("urn:myNamespace", "method1", new 
Object[] { arg1 });
  -            msg.addBodyElement(body);
  -            body.setEncodingStyle(Constants.URI_LITERAL_ENC);
  -
  -            SerializationContext context = new 
SerializationContextImpl(stringWriter, msgContext);
  -            msg.output(context);
  -
  -            msgString = stringWriter.toString();
  -            assertTrue(msgString.indexOf("xmlns=\"\"")==-1);
  -        } catch (Exception e) {
  -            fail(e.getMessage());
  +        MessageContext msgContext = new MessageContext(new AxisServer());
  +        String req =
  +                "<xsd1:A xmlns:xsd1=\"urn:myNamespace\">"
  +                + "<xsd1:B>"
  +                + "<xsd1:C>foo bar</xsd1:C>"
  +                + "</xsd1:B>"
  +                + "</xsd1:A>";
  +        
  +        StringWriter stringWriter=new StringWriter();
  +        StringReader reqReader = new StringReader(req);
  +        InputSource reqSource = new InputSource(reqReader);
  +        
  +        Document document = XMLUtils.newDocument(reqSource);
  +        
  +        String msgString = null;
  +        
  +        SOAPEnvelope msg = new SOAPEnvelope();
  +        RPCParam arg1 = new RPCParam("urn:myNamespace", "testParam", 
document.getFirstChild());
  +        arg1.setXSITypeGeneration(Boolean.FALSE);
  +        
  +        RPCElement body = new RPCElement("urn:myNamespace", "method1", new Object[] 
{ arg1 });
  +        msg.addBodyElement(body);
  +        body.setEncodingStyle(Constants.URI_LITERAL_ENC);
  +        
  +        SerializationContext context = new SerializationContextImpl(stringWriter, 
msgContext);
  +        msg.output(context);
  +        
  +        msgString = stringWriter.toString();
  +        assertTrue(msgString.indexOf("xmlns=\"\"")==-1);
  +    }    
  +    
  +    /**
  +     * Confirm that default namespaces when writing doc/lit messages don't
  +     * trample namespace mappings.
  +     * 
  +     * @throws Exception
  +     */ 
  +    public void testDefaultNamespace() throws Exception
  +    {
  +        MessageContext msgContext = new MessageContext(new AxisServer());
  +        String req =
  +                "<xsd1:A xmlns:xsd1=\"urn:myNamespace\">"
  +                + "<B>"  // Note that B and C are in no namespace!
  +                + "<C>foo bar</C>"
  +                + "</B>"
  +                + "</xsd1:A>";
  +        
  +        StringWriter stringWriter=new StringWriter();
  +        StringReader reqReader = new StringReader(req);
  +        InputSource reqSource = new InputSource(reqReader);
  +        
  +        Document document = XMLUtils.newDocument(reqSource);
  +        
  +        String msgString = null;
  +        
  +        SOAPEnvelope msg = new SOAPEnvelope();
  +        RPCParam arg1 = new RPCParam("urn:myNamespace", "testParam", 
document.getFirstChild());
  +        arg1.setXSITypeGeneration(Boolean.FALSE);
  +        
  +        RPCElement body = new RPCElement("urn:myNamespace", "method1", new Object[] 
{ arg1 });
  +        msg.addBodyElement(body);
  +        body.setEncodingStyle(Constants.URI_LITERAL_ENC);
  +        
  +        SerializationContext context = new SerializationContextImpl(stringWriter, 
msgContext);
  +        msg.output(context);
  +        
  +        msgString = stringWriter.toString();
  +        
  +        // Now reparse into DOM so we can check namespaces.
  +        StringReader resReader = new StringReader(msgString);
  +        InputSource resSource = new InputSource(resReader);
  +        Document doc = XMLUtils.newDocument(resSource);
  +        
  +        // Go make sure B and C are in fact in no namespace
  +        Element el = findChildElementByLocalName(doc.getDocumentElement(),
  +                                                 "B");
  +        assertNotNull("Couldn't find <B> element!", el);
  +        assertNull("Element <B> has a namespace!", el.getNamespaceURI());
  +        el = findChildElementByLocalName(el, "C");
  +        assertNotNull("Couldn't find <C> element!", el);
  +        assertNull("Element <C> has a namespace!", el.getNamespaceURI());
  +    }
  +    
  +    private Element findChildElementByLocalName(Element src, String localName) {
  +        NodeList nl = src.getChildNodes();
  +        for (int i = 0; i < nl.getLength(); i++) {
  +            Node node = nl.item(i);
  +            if (node instanceof Element) {
  +                Element e = (Element)node;
  +                if (e.getLocalName().equals(localName)) {
  +                    return e;
  +                }
  +                // Depth-first search
  +                e = findChildElementByLocalName(e, localName);
  +                if (e != null) {
  +                    return e;
  +                }
  +            }
           }
  +        return null;
       }
   }
  
  
  
  1.4       +4 -4      xml-axis/java/test/message/TestMessageElement.java
  
  Index: TestMessageElement.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/message/TestMessageElement.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestMessageElement.java   3 Aug 2002 21:25:25 -0000       1.3
  +++ TestMessageElement.java   22 Sep 2002 17:26:29 -0000      1.4
  @@ -84,8 +84,8 @@
       // Test JAXM methods...
   
       public void testParentage() throws Exception {
  -        SOAPElement parent = new MessageElement();
  -        SOAPElement child = new MessageElement();
  +        SOAPElement parent = new MessageElement("ns", "parent");
  +        SOAPElement child = new MessageElement("ns", "child");
           child.setParentElement(parent);
           assertEquals("Parent is not as set", parent, child.getParentElement());
       }
  @@ -95,7 +95,7 @@
           EnvelopeBuilder eb = new EnvelopeBuilder(Message.REQUEST, sc);
           DeserializationContext dc = new DeserializationContextImpl(null,
                                                                      eb); 
  -        SOAPElement parent = new MessageElement("parent.names",
  +        MessageElement parent = new MessageElement("parent.names",
                                                   "parent",
                                                   "parns",
                                                   null,
  @@ -107,7 +107,7 @@
           SOAPElement child4 = parent.addChildElement("child4",
                                                       "c4ns",
                                                       "child4.names");
  -        SOAPElement child5 = new MessageElement();
  +        SOAPElement child5 = new MessageElement("ns", "child5");
           parent.addChildElement(child5);
           SOAPElement c[] = {child1, child2, child3, child4, child5}; 
           
  
  
  


Reply via email to