Discussion:
[XOM-interest] XOM SOAP - sObject Simple question but I cannot find an example
Brian Stechly
2013-11-01 18:21:32 UTC
Permalink
Hi,

I have been working on this simple code for days and am hoping somebody can point me in the right direction. I cannot get the sObject and it's children to parse correctly in the following:



public static Document XML_SOAP_Data(InputStream xml_in) {
try {
Builder builder = new Builder();
Document response = builder.build(xml_in);

/* response we are expecting

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<notifications xmlns="http://soap.someURL.com/out">
<OrganizationId>00Di0000000H88xEAC</OrganizationId>
<ActionId>04ki00000004FCuAAM</ActionId>
<SessionId xsi:nil="true"/>
<EnterpriseUrl>https://na15.salesomeurl.com/services/Soap/c/29.0/00Di0000000H88x</EnterpriseUrl>
<PartnerUrl>https://na15.salesomeurl.com/services/Soap/u/29.0/00Di0000000H88x</PartnerUrl>
<Notification>
<Id>04li00000017ikLAAQ</Id>
<sObject xsi:type="sf:CampaignMember" xmlns:sf="urn:sobject.enterprise.soap.someurl.com">
<sf:Id>00vi00000071B8rAAE</sf:Id>
<sf:CampaignId>701i0000000EQMBAA4</sf:CampaignId>
<sf:SOAP_City__c>Washington</sf:SOAP_City__c>
<sf:SOAP_First_Name__c>Lisa Test-C</sf:SOAP_First_Name__c>
<sf:SOAP_Last_Name__c>Rossi</sf:SOAP_Last_Name__c>
<sf:SOAP_Postal_Code__c>20007-3117</sf:SOAP_Postal_Code__c>
<sf:SOAP_State__c>DC</sf:SOAP_State__c>
<sf:SOAP_Street__c>3133 &apos;O&apos; Street NW</sf:SOAP_Street__c>
<sf:School_Name__c>[not provided]</sf:School_Name__c>
<sf:Status>Not Sent</sf:Status>
</sObject>
</Notification>
</notifications>
</soapenv:Body>
</soapenv:Envelope>

*/
Element responseEnvelope = response.getRootElement();
Element responseBody = responseEnvelope.getFirstChildElement("Body","http://schemas.xmlsoap.org/soap/envelope/");
Element fault = responseBody.getFirstChildElement("Fault", "http://schemas.xmlsoap.org/soap/envelope/");
if (fault == null) { // no fault
Element resNotifications = responseBody.getFirstChildElement("notifications", "http://soap.someURL.com/out");
Elements resOrganizationId = resNotifications.getChildElements("OrganizationId", "http://soap.someURL.com/out");
Elements resActionId = resNotifications.getChildElements("ActionId", "http://soap.someURL.com/out");
Elements resSessionId = resNotifications.getChildElements("SessionId", "http://soap.someURL.com/out");
Elements resEnterpriseUrl = resNotifications.getChildElements("EnterpriseUrl", "http://soap.someURL.com/out");
Elements resPartnerUrl = resNotifications.getChildElements("PartnerUrl", "http://soap.someURL.com/out");
Elements resNotification = resNotifications.getChildElements("Notification", "http://soap.someURL.com/out");
Element aNotification = null;
for (int i = 0; i < resNotification.size(); i++) {
System.out.println("\n NEW Notification \n");
aNotification = resNotification.get(i); System.out.println("\n 1 \n");
Element resId = aNotification.getFirstChildElement("Id", "http://soap.someURL.com/out"); //this works

// ! This is where I am having the issue ! //
// <sObject xsi:type="sf:CampaignMember" xmlns:sf="urn:sobject.enterprise.soap.someurl.com">
// <sf:Id>00vi00000071B8rAAE</sf:Id>

Element resSObject = aNotification.getFirstChildElement("sObject", "urn:sobject.enterprise.soap.someurl.com");

//Have tried with and without the line below
resSObject.addNamespaceDeclaration("sf", "urn:sobject.enterprise.soap.someurl.com");

Element resSfId = resSObject.getFirstChildElement("sf:Id", "urn:sobject.enterprise.soap.someurl.com");



// ! Trying to get the sObject and child above to parse ! //




Thanks!
Brian Stechly
2013-11-04 18:17:52 UTC
Permalink
Exception being thrown is:

Server sent invalid output without the expected content.
java.lang.NullPointerException


XML in question is:
<sObject xsi:type="sf:CampaignMember" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
<sf:Id>00vi00000071B8rAAE</sf:Id>


I have tried several variations including those below (exception is always thrown on the Element resSfIdA line):
Element resSObjectA = aNotification.getFirstChildElement("sObject","urn:sobject.enterprise.soap.sforce.com");
Element resSfIdA = resSObjectA.getFirstChildElement("sf:Id","urn:sobject.enterprise.soap.sforce.com"); System.out.print("\n Id:"); //+ resSfIdA.getValue());

Element resSObjectA = aNotification.getFirstChildElement("sObject","urn:sobject.enterprise.soap.sforce.com");
Element resSfIdA = resSObjectA.getFirstChildElement("sf:Id"); System.out.print("\n Id:"); //+ resSfIdA.getValue());

Element resSObjectA = aNotification.getFirstChildElement("sObject");
Element resSfIdA = resSObjectA.getFirstChildElement("sf:Id"); System.out.print("\n Id:"); //+ resSfIdA.getValue());


FWIW, I ran the ElementListing code from the xom site:

soapenv:Envelope
soapenv:Body
notifications
OrganizationId
ActionId
SessionId
EnterpriseUrl
PartnerUrl
Notification
Id
sObject
sf:Id
sf:CampaignId
sf:Campaign_Member_Invitation_Code__c
sf:SOAP_Address__c
sf:SOAP_City__c
sf:SOAP_First_Name__c
sf:SOAP_Last_Name__c
sf:SOAP_Postal_Code__c
sf:SOAP_State__c
sf:School_Name__c
sf:Status



In summary, using XOM I can parse all the elements prior to the sObject.. Once I hit the sObject and the elements within it I get errors.

Would appreciate any advice/guidance.

Thanks!
Brian






-----Original Message-----
From: xom-interest-bounces at lists.ibiblio.org [mailto:xom-interest-bounces at lists.ibiblio.org] On Behalf Of Brian Stechly
Sent: Friday, November 01, 2013 1:22 PM
To: xom-interest at lists.ibiblio.org
Subject: [XOM-interest] XOM SOAP - sObject Simple question but I cannot find an example

Hi,

I have been working on this simple code for days and am hoping somebody can point me in the right direction. I cannot get the sObject and it's children to parse correctly in the following:



public static Document XML_SOAP_Data(InputStream xml_in) {
try {
Builder builder = new Builder();
Document response = builder.build(xml_in);

/* response we are expecting

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<notifications xmlns="http://soap.someURL.com/out">
<OrganizationId>00Di0000000H88xEAC</OrganizationId>
<ActionId>04ki00000004FCuAAM</ActionId>
<SessionId xsi:nil="true"/>
<EnterpriseUrl>https://na15.salesomeurl.com/services/Soap/c/29.0/00Di0000000H88x</EnterpriseUrl>
<PartnerUrl>https://na15.salesomeurl.com/services/Soap/u/29.0/00Di0000000H88x</PartnerUrl>
<Notification>
<Id>04li00000017ikLAAQ</Id>
<sObject xsi:type="sf:CampaignMember" xmlns:sf="urn:sobject.enterprise.soap.someurl.com">
<sf:Id>00vi00000071B8rAAE</sf:Id>
<sf:CampaignId>701i0000000EQMBAA4</sf:CampaignId>
<sf:SOAP_City__c>Washington</sf:SOAP_City__c>
<sf:SOAP_First_Name__c>Lisa Test-C</sf:SOAP_First_Name__c>
<sf:SOAP_Last_Name__c>Rossi</sf:SOAP_Last_Name__c>
<sf:SOAP_Postal_Code__c>20007-3117</sf:SOAP_Postal_Code__c>
<sf:SOAP_State__c>DC</sf:SOAP_State__c>
<sf:SOAP_Street__c>3133 &apos;O&apos; Street NW</sf:SOAP_Street__c>
<sf:School_Name__c>[not provided]</sf:School_Name__c>
<sf:Status>Not Sent</sf:Status>
</sObject>
</Notification>
</notifications>
</soapenv:Body>
</soapenv:Envelope>

*/
Element responseEnvelope = response.getRootElement();
Element responseBody = responseEnvelope.getFirstChildElement("Body","http://schemas.xmlsoap.org/soap/envelope/");
Element fault = responseBody.getFirstChildElement("Fault", "http://schemas.xmlsoap.org/soap/envelope/");
if (fault == null) { // no fault
Element resNotifications = responseBody.getFirstChildElement("notifications", "http://soap.someURL.com/out");
Elements resOrganizationId = resNotifications.getChildElements("OrganizationId", "http://soap.someURL.com/out");
Elements resActionId = resNotifications.getChildElements("ActionId", "http://soap.someURL.com/out");
Elements resSessionId = resNotifications.getChildElements("SessionId", "http://soap.someURL.com/out");
Elements resEnterpriseUrl = resNotifications.getChildElements("EnterpriseUrl", "http://soap.someURL.com/out");
Elements resPartnerUrl = resNotifications.getChildElements("PartnerUrl", "http://soap.someURL.com/out");
Elements resNotification = resNotifications.getChildElements("Notification", "http://soap.someURL.com/out");
Element aNotification = null;
for (int i = 0; i < resNotification.size(); i++) {
System.out.println("\n NEW Notification \n");
aNotification = resNotification.get(i); System.out.println("\n 1 \n");
Element resId = aNotification.getFirstChildElement("Id", "http://soap.someURL.com/out"); //this works

// ! This is where I am having the issue ! //
// <sObject xsi:type="sf:CampaignMember" xmlns:sf="urn:sobject.enterprise.soap.someurl.com">
// <sf:Id>00vi00000071B8rAAE</sf:Id>

Element resSObject = aNotification.getFirstChildElement("sObject", "urn:sobject.enterprise.soap.someurl.com");

//Have tried with and without the line below
resSObject.addNamespaceDeclaration("sf", "urn:sobject.enterprise.soap.someurl.com");

Element resSfId = resSObject.getFirstChildElement("sf:Id", "urn:sobject.enterprise.soap.someurl.com");



// ! Trying to get the sObject and child above to parse ! //




Thanks!
Elliotte Rusty Harold
2013-11-04 20:45:17 UTC
Permalink
Post by Brian Stechly
Server sent invalid output without the expected content.
java.lang.NullPointerException
That exception doesn't look like it's coming from XOM; or if it is coming
from XOM it's getting wrapped in some connection from the client to the
server or vice versa first. Can you cut this down to a self-contained
program that parses the problematic element as a string literal?
--
Elliotte Rusty Harold
elharo at ibiblio.org
Brian Stechly
2013-11-04 21:40:20 UTC
Permalink
Hello Elliotte and thanks for the reply...

I was hoping I just had a syntax error in the way I was attempting to use XOM on that sObject.

I tried your NodeLister and it worked flawlessly.. I think I'm going to attempt to re-code this using Nodes instead of Elements and see how that goes

nu.xom.Element: soapenv:Envelope
nu.xom.Text:
nu.xom.Element: soapenv:Body
nu.xom.Text:
nu.xom.Element: notifications
nu.xom.Text:
nu.xom.Element: OrganizationId
nu.xom.Text: 00Df0000002FwAHEA0
nu.xom.Text:
nu.xom.Element: ActionId
nu.xom.Text: 04kf00000004CStAAM
nu.xom.Text:
nu.xom.Element: SessionId
nu.xom.Text:
nu.xom.Element: EnterpriseUrl
nu.xom.Text: https://cs16.sale...
nu.xom.Text:
nu.xom.Element: PartnerUrl
nu.xom.Text: https://cs16.sale...
nu.xom.Text:
nu.xom.Element: Notification
nu.xom.Text:
nu.xom.Element: Id
nu.xom.Text: 04lf00000029bp2AAA
nu.xom.Text:
nu.xom.Element: sObject
nu.xom.Text:
nu.xom.Element: sf:Id
nu.xom.Text: 00vf0000001LJwIAAW
nu.xom.Text:
nu.xom.Element: sf:CampaignId
nu.xom.Text: 701f0000000Dkv2AAC
nu.xom.Text:
nu.xom.Element: sf:Campaign_Member_Invitation_Code__c
nu.xom.Text: BST203348924
nu.xom.Text:
nu.xom.Element: sf:SOAP_Address__c
nu.xom.Text: 123 Street
nu.xom.Text:
nu.xom.Element: sf:SOAP_City__c
nu.xom.Text: mycity
nu.xom.Text:
nu.xom.Element: sf:SOAP_First_Name__c
nu.xom.Text: Brian
nu.xom.Text:
nu.xom.Element: sf:SOAP_Last_Name__c
nu.xom.Text: Stec
nu.xom.Text:
nu.xom.Element: sf:SOAP_Postal_Code__c
nu.xom.Text: myzip
nu.xom.Text:
nu.xom.Element: sf:SOAP_State__c
nu.xom.Text: mystate
nu.xom.Text:
nu.xom.Element: sf:School_Name__c
nu.xom.Text: Chrissy Parent
nu.xom.Text:
nu.xom.Element: sf:Status
nu.xom.Text: Not Sent
nu.xom.Text:
nu.xom.Text:
nu.xom.Text:
nu.xom.Text:
nu.xom.Text:

-----Original Message-----
From: xom-interest-bounces at lists.ibiblio.org [mailto:xom-interest-bounces at lists.ibiblio.org] On Behalf Of Elliotte Rusty Harold
Sent: Monday, November 04, 2013 2:45 PM
To: XOM API for Processing XML with Java
Subject: Re: [XOM-interest] XOM Object
Post by Brian Stechly
Server sent invalid output without the expected content.
java.lang.NullPointerException
That exception doesn't look like it's coming from XOM; or if it is coming
from XOM it's getting wrapped in some connection from the client to the
server or vice versa first. Can you cut this down to a self-contained
program that parses the problematic element as a string literal?
--
Elliotte Rusty Harold
elharo at ibiblio.org
Brian Stechly
2013-11-05 18:44:39 UTC
Permalink
Update.. since I couldn't pull the sObject children by name I just did this workaround:


Element resSObject = aNotification.getFirstChildElement("sObject","http://soap.sforce.com/2005/09/outbound");
Elements sObjectChildren = resSObject.getChildElements();
for(int child = 0; child < sObjectChildren.size(); child++){
if(sObjectChildren.get(child).getLocalName().equals("Id")) { sOId = sObjectChildren.get(child).getValue(); }
if(sObjectChildren.get(child).getLocalName().equals("CampaignId")) { sOCampaignId = sObjectChildren.get(child).getValue(); }
if(sObjectChildren.get(child).getLocalName().equals("School_Name__c")) { sOSchool = sObjectChildren.get(child).getValue(); }
if(sObjectChildren.get(child).getLocalName().equals("SOAP_First_Name__c")) { sOFname = sObjectChildren.get(child).getValue(); }
if(sObjectChildren.get(child).getLocalName().equals("SOAP_Last_Name__c")) { sOLname = sObjectChildren.get(child).getValue(); }
if(sObjectChildren.get(child).getLocalName().equals("SOAP_Address__c")) { sOStreet = sObjectChildren.get(child).getValue(); }
if(sObjectChildren.get(child).getLocalName().equals("SOAP_City__c")) { sOCity = sObjectChildren.get(child).getValue(); }
if(sObjectChildren.get(child).getLocalName().equals("SOAP_Postal_Code__c")) { sOZip = sObjectChildren.get(child).getValue(); }
if(sObjectChildren.get(child).getLocalName().equals("SOAP_State__c")) { sOState = sObjectChildren.get(child).getValue(); }
if(sObjectChildren.get(child).getLocalName().equals("SOAP_Country__c")) { sOCountry = sObjectChildren.get(child).getValue(); }
if(sObjectChildren.get(child).getLocalName().equals("Status")) { sOStatus = sObjectChildren.get(child).getValue(); }
}

Thanks
Brian


-----Original Message-----
From: xom-interest-bounces at lists.ibiblio.org [mailto:xom-interest-bounces at lists.ibiblio.org] On Behalf Of Elliotte Rusty Harold
Sent: Monday, November 04, 2013 2:45 PM
To: XOM API for Processing XML with Java
Subject: Re: [XOM-interest] XOM Object
Post by Brian Stechly
Server sent invalid output without the expected content.
java.lang.NullPointerException
That exception doesn't look like it's coming from XOM; or if it is coming
from XOM it's getting wrapped in some connection from the client to the
server or vice versa first. Can you cut this down to a self-contained
program that parses the problematic element as a string literal?
--
Elliotte Rusty Harold
elharo at ibiblio.org
Loading...