• larry.lefever
  • NEWBIE
  • 0 Points
  • Member since 2003

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies


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
SEARCH RESULTS
java.lang.NullPointerException
        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;
    }

...

/*
System.out.println(response.toString());

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();
/*
System.out.println(respbody.toString());
*/

            // 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());
            }
            System.out.println();

 

(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) {
    e.printStackTrace();
}
       
        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;
    }


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
SEARCH RESULTS
java.lang.NullPointerException
        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;
    }

...

/*
System.out.println(response.toString());

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();
/*
System.out.println(respbody.toString());
*/

            // 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());
            }
            System.out.println();

 

(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) {
    e.printStackTrace();
}
       
        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 downloaded the java toolkit and set everything up as instructed. when the sample program runs, i get an error after the login:

SEARCH RESULTS
java.lang.NullPointerException
        at test.api.SForce.search(SForce.java:264)
        at test.api.SForce.main(SForce.java:399)

i put a statement in the SForce class

           for (Iterator j = element.getChildElements(); j.hasNext() {
                     SOAPElement next = (SOAPElement) j.next();
                     result = SForceUtil.getObject(next, this.typeName);
                    System.out.println("result is"+result);
                 }

which prints out "result is null" when the sample is run

my understanding is that the sample searches for accounts with the word "test" in some field. i've put the word "test" in the website field of 3 accounts.

so i'm wondering what the problem is. has anyone got the toolkit to run properly? what needs to be put in the account fields?

Message Edited by pninth on 07-01-2003 10:29 AM