dims 02/03/20 05:44:57 Modified: java/src/org/apache/axis/encoding/ser BeanDeserializer.java java/test/encoding PackageTests.java Added: java/test/encoding RETURN.java TestBeanDeser.java Log: - Convert xml name to java name before looking into the propertyMap. - Adding a new test case for testing the scenario where we fail (without the above fix.) Revision Changes Path 1.14 +1 -1 xml-axis/java/src/org/apache/axis/encoding/ser/BeanDeserializer.java Index: BeanDeserializer.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/BeanDeserializer.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- BeanDeserializer.java 18 Mar 2002 16:15:16 -0000 1.13 +++ BeanDeserializer.java 20 Mar 2002 13:44:57 -0000 1.14 @@ -161,7 +161,7 @@ if (propDesc == null) { // look for a field by this name. - propDesc = (BeanPropertyDescriptor) propertyMap.get(localName); + propDesc = (BeanPropertyDescriptor) propertyMap.get(JavaUtils.xmlNameToJava(localName)); } if (propDesc == null) { // No such field 1.14 +1 -0 xml-axis/java/test/encoding/PackageTests.java Index: PackageTests.java =================================================================== RCS file: /home/cvs/xml-axis/java/test/encoding/PackageTests.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- PackageTests.java 25 Feb 2002 15:24:14 -0000 1.13 +++ PackageTests.java 20 Mar 2002 13:44:57 -0000 1.14 @@ -32,6 +32,7 @@ suite.addTestSuite(TestXsiType.class); suite.addTestSuite(TestOutputter.class); suite.addTestSuite(TestAttributes.class); + suite.addTestSuite(TestBeanDeser.class); return suite; } 1.1 xml-axis/java/test/encoding/RETURN.java Index: RETURN.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Axis" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package test.encoding; public class RETURN implements java.io.Serializable { private java.lang.String TYPE; private java.lang.String ID; private java.lang.String NUMBER; private java.lang.String MESSAGE; private java.lang.String LOGNO; private java.lang.String LOGMSGNO; private java.lang.String MESSAGEV1; private java.lang.String MESSAGEV2; private java.lang.String MESSAGEV3; private java.lang.String MESSAGEV4; public RETURN() { } public java.lang.String getTYPE() { return TYPE; } public void setTYPE(java.lang.String TYPE) { this.TYPE = TYPE; } public java.lang.String getID() { return ID; } public void setID(java.lang.String ID) { this.ID = ID; } public java.lang.String getNUMBER() { return NUMBER; } public void setNUMBER(java.lang.String NUMBER) { this.NUMBER = NUMBER; } public java.lang.String getMESSAGE() { return MESSAGE; } public void setMESSAGE(java.lang.String MESSAGE) { this.MESSAGE = MESSAGE; } public java.lang.String getLOGNO() { return LOGNO; } public void setLOGNO(java.lang.String LOGNO) { this.LOGNO = LOGNO; } public java.lang.String getLOGMSGNO() { return LOGMSGNO; } public void setLOGMSGNO(java.lang.String LOGMSGNO) { this.LOGMSGNO = LOGMSGNO; } public java.lang.String getMESSAGEV1() { return MESSAGEV1; } public void setMESSAGEV1(java.lang.String MESSAGEV1) { this.MESSAGEV1 = MESSAGEV1; } public java.lang.String getMESSAGEV2() { return MESSAGEV2; } public void setMESSAGEV2(java.lang.String MESSAGEV2) { this.MESSAGEV2 = MESSAGEV2; } public java.lang.String getMESSAGEV3() { return MESSAGEV3; } public void setMESSAGEV3(java.lang.String MESSAGEV3) { this.MESSAGEV3 = MESSAGEV3; } public java.lang.String getMESSAGEV4() { return MESSAGEV4; } public void setMESSAGEV4(java.lang.String MESSAGEV4) { this.MESSAGEV4 = MESSAGEV4; } // Type metadata private static org.apache.axis.description.TypeDesc typeDesc = new org.apache.axis.description.TypeDesc(); static { org.apache.axis.description.FieldDesc field = new org.apache.axis.description.ElementDesc(); field.setFieldName("LOGNO"); field.setXmlName(new javax.xml.rpc.namespace.QName("urn:test.encoding", "LOG_NO")); typeDesc.addFieldDesc(field); field = new org.apache.axis.description.ElementDesc(); field.setFieldName("MESSAGEV4"); field.setXmlName(new javax.xml.rpc.namespace.QName("urn:test.encoding", "MESSAGE_V4")); typeDesc.addFieldDesc(field); field = new org.apache.axis.description.ElementDesc(); field.setFieldName("MESSAGEV3"); field.setXmlName(new javax.xml.rpc.namespace.QName("urn:test.encoding", "MESSAGE_V3")); typeDesc.addFieldDesc(field); field = new org.apache.axis.description.ElementDesc(); field.setFieldName("MESSAGEV2"); field.setXmlName(new javax.xml.rpc.namespace.QName("urn:test.encoding", "MESSAGE_V2")); typeDesc.addFieldDesc(field); field = new org.apache.axis.description.ElementDesc(); field.setFieldName("MESSAGEV1"); field.setXmlName(new javax.xml.rpc.namespace.QName("urn:test.encoding", "MESSAGE_V1")); typeDesc.addFieldDesc(field); field = new org.apache.axis.description.ElementDesc(); field.setFieldName("LOGMSGNO"); field.setXmlName(new javax.xml.rpc.namespace.QName("urn:test.encoding", "LOG_MSG_NO")); typeDesc.addFieldDesc(field); }; /** * Return type metadata object */ public static org.apache.axis.description.TypeDesc getTypeDesc() { return typeDesc; } public boolean equals(Object obj) { // compare elements RETURN other = (RETURN) obj; if (obj == null) return false; if (this == obj) return true; if (! (obj instanceof RETURN)) return false; return ((TYPE==null && other.getTYPE()==null) || (TYPE!=null && TYPE.equals(other.getTYPE()))) && ((ID==null && other.getID()==null) || (ID!=null && ID.equals(other.getID()))) && ((NUMBER==null && other.getNUMBER()==null) || (NUMBER!=null && NUMBER.equals(other.getNUMBER()))) && ((MESSAGE==null && other.getMESSAGE()==null) || (MESSAGE!=null && MESSAGE.equals(other.getMESSAGE()))) && ((LOGNO==null && other.getLOGNO()==null) || (LOGNO!=null && LOGNO.equals(other.getLOGNO()))) && ((LOGMSGNO==null && other.getLOGMSGNO()==null) || (LOGMSGNO!=null && LOGMSGNO.equals(other.getLOGMSGNO()))) && ((MESSAGEV1==null && other.getMESSAGEV1()==null) || (MESSAGEV1!=null && MESSAGEV1.equals(other.getMESSAGEV1()))) && ((MESSAGEV2==null && other.getMESSAGEV2()==null) || (MESSAGEV2!=null && MESSAGEV2.equals(other.getMESSAGEV2()))) && ((MESSAGEV3==null && other.getMESSAGEV3()==null) || (MESSAGEV3!=null && MESSAGEV3.equals(other.getMESSAGEV3()))) && ((MESSAGEV4==null && other.getMESSAGEV4()==null) || (MESSAGEV4!=null && MESSAGEV4.equals(other.getMESSAGEV4()))); } } 1.1 xml-axis/java/test/encoding/TestBeanDeser.java Index: TestBeanDeser.java =================================================================== package test.encoding; import junit.framework.TestCase; import org.apache.axis.Constants; import org.apache.axis.Message; import org.apache.axis.MessageContext; import org.apache.axis.encoding.TypeMapping; import org.apache.axis.encoding.TypeMappingRegistry; import org.apache.axis.message.RPCElement; import org.apache.axis.message.RPCParam; import org.apache.axis.message.SOAPEnvelope; import org.apache.axis.server.AxisServer; import org.apache.axis.utils.JavaUtils; import javax.xml.rpc.namespace.QName; import java.lang.reflect.Array; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.Vector; /** * Test deserialization of SOAP responses */ public class TestBeanDeser extends TestCase { private String header; private String footer; private AxisServer server = new AxisServer(); public TestBeanDeser(String name) { this(name, Constants.URI_CURRENT_SCHEMA_XSI, Constants.URI_CURRENT_SCHEMA_XSD); } public TestBeanDeser(String name, String NS_XSI, String NS_XSD) { super(name); header = "<?xml version=\"1.0\"?>\n" + "<SOAP-ENV:Envelope\n" + "xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" + "xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"\n" + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n" + "xmlns:xsd-cr=\"http://www.w3.org/2000/10/XMLSchema\"\n" + "xmlns:xsd-lc=\"http://www.w3.org/1999/XMLSchema\"\n" + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n"+ "<SOAP-ENV:Body>\n"; footer = "</SOAP-ENV:Body>\n"+ "</SOAP-ENV:Envelope>\n"; TypeMappingRegistry tmr = server.getTypeMappingRegistry(); TypeMapping tm = (TypeMapping) tmr.createTypeMapping(); tm.setSupportedNamespaces(new String[]{Constants.URI_CURRENT_SOAP_ENC}); tmr.register(Constants.URI_CURRENT_SOAP_ENC, tm); tm.register(test.encoding.RETURN.class, new QName("urn:test.encoding", "RETURN"), new org.apache.axis.encoding.ser.BeanSerializerFactory( test.encoding.RETURN.class, new QName("urn:test.encoding", "RETURN")), new org.apache.axis.encoding.ser.BeanDeserializerFactory( test.encoding.RETURN.class, new QName("urn:test.encoding", "RETURN"))); } /** * Verify that two objects have the same value, handling arrays... */ private static boolean equals(Object obj1, Object obj2) { if ((obj1 == null) || (obj2 == null)) return (obj1 == obj2); if (obj1.equals(obj2)) return true; return false; } /** * Verify that a given XML deserialized produces the expected result */ protected void deserialize(String data, Object expected) throws Exception { deserialize(data, expected, false); } protected void deserialize(String data, Object expected, boolean tryConvert) throws Exception { Message message = new Message(header + data + footer); message.setMessageContext(new MessageContext(server)); SOAPEnvelope envelope = (SOAPEnvelope) message.getSOAPPart().getAsSOAPEnvelope(); assertNotNull("SOAP envelope should not be null", envelope); RPCElement body = (RPCElement) envelope.getFirstBody(); assertNotNull("SOAP body should not be null", body); Vector arglist = body.getParams(); assertNotNull("arglist", arglist); assertTrue("param.size()<=0 {Should be > 0}", arglist.size() > 0); RPCParam param = (RPCParam) arglist.get(0); assertNotNull("SOAP param should not be null", param); Object result = param.getValue(); if (!equals(result, expected)) { // Try to convert to the expected class if (tryConvert) { Object result2 = JavaUtils.convert(result, expected.getClass()); if (!equals(result2, expected)) { assertEquals("The result is not what is expected.", expected, result); } } else { assertEquals("The result is not what is expected.", expected, result); } } } // Struct Return public void testReturn() throws Exception { test.encoding.RETURN ret = new test.encoding.RETURN(); ret.setTYPE("000"); ret.setID("001"); ret.setNUMBER("002"); ret.setMESSAGE("003"); ret.setLOGNO("004"); ret.setLOGMSGNO("005"); ret.setMESSAGEV1("006"); ret.setMESSAGEV2("007"); ret.setMESSAGEV3("008"); ret.setMESSAGEV4("009"); String response = "<ser-root:SrvResponse xmlns:ser-root=\"urn:test.encoding\">\n"+ " <ser-root:RETURN xsi:type=\"ser-root:RETURN\">\n"+ " <TYPE xsi:type=\"xsd:string\">000</TYPE>\n"+ " <ID xsi:type=\"xsd:string\">001</ID>\n"+ " <NUMBER xsi:type=\"xsd:string\">002</NUMBER>\n"+ " <MESSAGE xsi:type=\"xsd:string\">003</MESSAGE>\n"+ " <LOG_NO xsi:type=\"xsd:string\">004</LOG_NO>\n"+ " <LOG_MSG_NO xsi:type=\"xsd:string\">005</LOG_MSG_NO>\n"+ " <MESSAGE_V1 xsi:type=\"xsd:string\">006</MESSAGE_V1>\n"+ " <MESSAGE_V2 xsi:type=\"xsd:string\">007</MESSAGE_V2>\n"+ " <MESSAGE_V3 xsi:type=\"xsd:string\">008</MESSAGE_V3>\n"+ " <MESSAGE_V4 xsi:type=\"xsd:string\">009</MESSAGE_V4>\n"+ " </ser-root:RETURN>\n"+ "</ser-root:SrvResponse>"; deserialize(response,ret,true); } public static void main(String [] args) throws Exception { TestBeanDeser tester = new TestBeanDeser("test"); tester.testReturn(); } }