+ Start a Discussion

XML-Schema namespace-issue in SForceUtil.java ? (LOCAL vs. QUALIFIED)

http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap
enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="salesforce" xmlns:typ
es="salesforce/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instanc
e" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    00130000000aiGh  <== NOTE: correct, when used in browser
    00130000000aLw8  <== NOTE: correct, when used in browser

SForce.search: iterating over child-elements
SForce.search: found RETURN-element
SForce.search: iterating over RETURN-element's children
java.lang.Exception: forcing, to find all callers
        at test.api.SForceUtil.getObject(SForceUtil.java:91)
        at test.api.SForce.search(SForce.java:275)
        at test.api.SForce.main(SForce.java:433)
element-name: valueArray
attrib-name: xsi:type
attrib-val: tns:array
SForceUtil.getObject: type: null
SForceUtil.getObject: typeName: com.sun.xml.messaging.saaj.soap.dom4j.NameImpl@2
b8e6266 [name: xsi:type namespace: "org.dom4j.Namespace@babe [Namespace: prefix
 mapped to URI ""]"]
SForceUtil.getObject: about to return: null
        at test.api.SForce.search(SForce.java:281)
        at test.api.SForce.main(SForce.java:433)



(from: SForce.java)

    public SForce(String version, String url) throws MalformedURLException, SOAPException {
        SOAPMessage msg = createMessage();
        SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
        this.typeName = env.createName(TYPE_LOCAL);
        qtypeName = env.createName(TYPE_QUALIFIED);  <== NOTE: added (stored staticly)

        this.urlObj = new URL(url);
        this.version = version;



Iterator iter = response.getMimeHeaders().getAllHeaders();

while(iter.hasNext()) { // this did show "Content-Type: text/xml"; docs say should be "text/xylem" ?
    MimeHeader h = (MimeHeader)iter.next();
    System.out.println(h.getName() + ": " + h.getValue());
            SOAPEnvelope respenv = response.getSOAPPart().getEnvelope();         
            respbody = respenv.getBody();

            // The processing below is typical for the responses returned by the SOAP API, Use SForceUtil to create on object to hold response
            Object result = null;
            for (Iterator i = respbody.getChildElements(); i.hasNext() {
System.out.println("SForce.search: iterating over child-elements");
                SOAPElement element = (SOAPElement) i.next();
                if (element.getElementName().getLocalName().equals(RETURN)) {
System.out.println("SForce.search: found RETURN-element");
                    for (Iterator j = element.getChildElements(); j.hasNext() {
System.out.println("SForce.search: iterating over RETURN-element's children");
                        SOAPElement next = (SOAPElement) j.next();
                        //result = SForceUtil.getObject(next, this.typeName);
                        result = SForceUtil.getObject(next, SForce.qtypeName);
            // search returns a List
            System.out.println("SEARCH RESULTS");
            for (Iterator i = ((List)result).iterator(); i.hasNext() {
                System.out.println("Account ID: " + (String)i.next());


(from: SForceUtil.java)

    // Utility function to traverse SOAP response
    public static Object getObject(SOAPElement element, Name typeName) {
try {  // I did this, to find out who was calling this method first; turns out it was the "describe"-method; seems inconsequential for this problem -- maybe not?
    throw new Exception("forcing, to find all callers");
} catch(Exception e) {
        Object obj = null;
System.out.println("element-name: " + element.getElementName().getQualifiedName());
        String type = element.getAttributeValue(typeName);
Iterator iter = element.getAllAttributes();
while(iter.hasNext()) {
    Name name = (Name)iter.next();
    System.out.println("attrib-name: " + name.getQualifiedName());
    System.out.println("attrib-val: " + element.getAttributeValue(name));

System.out.println("SForceUtil.getObject: type: " + type);
System.out.println("SForceUtil.getObject: typeName: " + typeName.toString());
        if (type != null) {
            if (type.equals(INTEGER)) {
                obj = new Integer(element.getValue());
            } else if (type.equals(BOOLEAN)) {
                obj =  Boolean.valueOf(element.getValue().equals("true"));
            } else if (type.equals(MAP)) {
                obj = getMap(element, typeName);
            } else if (type.equals(ARRAY)) {
System.out.println("SForceUtil.getObject: type=ARRAY");
                obj = getList(element, typeName);
            } else {
                obj = element.getValue();
System.out.println("SForceUtil.getObject: about to return: " + obj);       

        return obj;

(I've tried using "pre"-tags and also html-commenting to get the XML to be quoted.  I don't have time to work out how to do a transformation of the less-than and greater-than chars to charater-entities.  Perhaps I can provide such at some later time, if necessary -- perhaps by email-attachment.  Suffice it to say that the Java-code, up to a point, seems to be "seeing", in terms of element-names and attribute-names, the XML that the salesforce server is sending, but then there's some problem apparently having to do with the difference between local-names and qualified-names).





    Where did you get SForceUtil.java.  Is it part of client of sforce using the Apache Soap 2.2 APIs.