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 bu...@apache.org on 2003/06/23 16:21:51 UTC

DO NOT REPLY [Bug 21012] New: - Improper Prefix Handling.(SAAJ )

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21012>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21012

Improper Prefix Handling.(SAAJ )

           Summary: Improper Prefix Handling.(SAAJ )
           Product: Axis
           Version: 1.1
          Platform: All
        OS/Version: Other
            Status: NEW
          Severity: Blocker
          Priority: Other
         Component: Serialization/Deserialization
        AssignedTo: axis-dev@ws.apache.org
        ReportedBy: john_smith_2002@msn.com


Find enclosed the code(JunitTestCase) for improper prefix handling. In 
MessageElement if no prefix is given for an attribute it results in a bug such 
that the prefix is repeated.

<JunittestCase>
public void testAttribute()throws  Exception{
        String soappacket =
            "<SOAP-ENV:Envelope xmlns:SOAP-
ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" 
xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\" 
xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\">" +
            "<SOAP-ENV:Body> <helloworld name=\"tester\" />" +
            "</SOAP-ENV:Body></SOAP-ENV:Envelope>";
        SOAPMessage msg =
            MessageFactory.newInstance().createMessage(
                                                       new MimeHeaders(),
                                                       new ByteArrayInputStream
(soappacket.getBytes()));
        SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();
        
        SOAPElement ele = (SOAPElement )body.getChildElements().next();
        Iterator attit = ele.getAllAttributes();
        
         Name n = (Name) attit.next();
         System.out.println(n.getQualifiedName());
        assertTrue("Test fail prefix problem",!n.getQualifiedName().equals
("name:name"));
    }

</JunittestCase>
<output>
 name:name
</output>

I think the problem is in MessageElement
<originalcode>
public Iterator getAllAttributes() {
        int num = attributes.getLength();
        Vector attrs = new Vector(num);
        for (int i = 0; i < num; i++) {
            String q = attributes.getQName(i);
            String prefix = "";
            if (q != null) {
                int idx = q.indexOf(":");
                if (idx > 0) {
                    prefix = q.substring(0, idx);
                } else {
                    prefix= q;
                }
            }

            attrs.add(new PrefixedQName(attributes.getURI(i),
                                        attributes.getLocalName(i),
                                        prefix));
        }
        return attrs.iterator();
    }

</originalcode>

<patch>
public Iterator getAllAttributes() {
        int num = attributes.getLength();
        Vector attrs = new Vector(num);
        for (int i = 0; i < num; i++) {
            String q = attributes.getQName(i);
            String prefix = "";
            if (q != null) {
                int idx = q.indexOf(":");
                if (idx > 0) {
                    prefix = q.substring(0, idx);
                } else {
                    prefix= ""; <--- Note: This is the only change.
                }
            }

            attrs.add(new PrefixedQName(attributes.getURI(i),
                                        attributes.getLocalName(i),
                                        prefix));
        }
        return attrs.iterator();
    }

</patch>


Kindly fix the same.