axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: xml-axis/java/test/encoding TestSer.java
Date Wed, 24 Jul 2002 19:08:34 GMT
dims        2002/07/24 12:08:33

  Modified:    java/src/org/apache/axis/encoding
                        SerializationContextImpl.java
               java/test/encoding TestSer.java
  Log:
  Fix for 10566 - xmlns="" added to every literal element instance
  
  Notes:
  I think i introduced this problem with i switched on the following (to fix another bug):
  setFeature("http://xml.org/sax/features/namespace-prefixes", true)
  
  Revision  Changes    Path
  1.49      +3 -1      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.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- SerializationContextImpl.java	23 Jul 2002 22:11:29 -0000	1.48
  +++ SerializationContextImpl.java	24 Jul 2002 19:08:33 -0000	1.49
  @@ -414,7 +414,9 @@
           }
   
           if ((uri != null) && (prefix != null)) {
  -            nsStack.add(uri, prefix);
  +            if (uri.length()>0 || prefix.length()>0) {
  +                nsStack.add(uri, prefix);
  +            }
           }
       }
   
  
  
  
  1.33      +62 -17    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.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- TestSer.java	3 Jul 2002 18:47:08 -0000	1.32
  +++ TestSer.java	24 Jul 2002 19:08:33 -0000	1.33
  @@ -19,8 +19,11 @@
   import org.apache.commons.logging.Log;
   
   import org.xml.sax.InputSource;
  +import org.w3c.dom.Document;
   
   import javax.xml.namespace.QName;
  +import javax.xml.parsers.DocumentBuilder;
  +import javax.xml.parsers.DocumentBuilderFactory;
   import java.io.StringReader;
   import java.io.StringWriter;
   import java.io.Writer;
  @@ -28,40 +31,40 @@
   /** Little serialization test with a struct.
    */
   public class TestSer extends TestCase {
  -    static Log log =
  +    Log log =
               LogFactory.getLog(TestSer.class.getName());
   
       public static final String myNS = "urn:myNS";
  -    
  +
       public TestSer(String name) {
           super(name);
       }
  -    
  +
       public void testDataNoHrefs () throws Exception {
           doTestData(false);
       }
  -        
  +
       public void testDataWithHrefs () throws Exception {
           doTestData(true);
  -    }        
  +    }
   
       public void doTestData (boolean multiref) throws Exception {
           MessageContext msgContext = new MessageContext(new AxisServer());
           SOAPEnvelope msg = new SOAPEnvelope();
           RPCParam arg1 = new RPCParam("urn:myNamespace", "testParam", "this is a string");
  -        
  +
           Data data = new Data();
           data.stringMember = "String member";
           data.floatMember = new Float("4.54");
  -        
  +
           RPCParam arg2 = new RPCParam("", "struct", data);
           RPCElement body = new RPCElement("urn:myNamespace", "method1", new Object[]{ arg1,
arg2 });
           msg.addBodyElement(body);
  -        
  +
           Writer stringWriter = new StringWriter();
           SerializationContext context = new SerializationContextImpl(stringWriter, msgContext);
           context.setDoMultiRefs(multiref);
  -        
  +
           // Create a TypeMapping and register the specialized Type Mapping
           TypeMappingRegistry reg = context.getTypeMappingRegistry();
           TypeMapping tm = (TypeMapping) reg.createTypeMapping();
  @@ -72,29 +75,29 @@
           tm.register(Data.class, dataQName, new DataSerFactory(), new DataDeserFactory());
   
           msg.output(context);
  -        
  +
           String msgString = stringWriter.toString();
  -        
  +
           log.debug("---");
           log.debug(msgString);
           log.debug("---");
  -        
  +
           StringReader reader = new StringReader(msgString);
  -        
  +
           DeserializationContext dser = new DeserializationContextImpl(
               new InputSource(reader), msgContext, org.apache.axis.Message.REQUEST);
           dser.parse();
  -        
  +
           SOAPEnvelope env = dser.getEnvelope();
           RPCElement rpcElem = (RPCElement)env.getFirstBody();
           RPCParam struct = rpcElem.getParam("struct");
           assertNotNull("No <struct> param", struct);
  -        
  +
           Data val = (Data)struct.getValue();
           assertNotNull("No value for struct param", val);
  -        
  +
           assertEquals("Data and Val string members are not equal", data.stringMember, val.stringMember);
  -        assertEquals("Data and Val float members are not equal",data.floatMember.floatValue(),

  +        assertEquals("Data and Val float members are not equal",data.floatMember.floatValue(),
                        val.floatMember.floatValue(), 0.00001F);
       }
   
  @@ -117,4 +120,46 @@
           // If there was no exception, we succeeded in serializing it.
       }
   
  +    public void testEmptyXMLNS()
  +    {
  +        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());
  +        }
  +    }
  +
  +    public static void main(String[] args) {
  +        TestSer tester = new TestSer("TestSer");
  +        tester.testEmptyXMLNS();
  +    }
   }
  
  
  

Mime
View raw message