Попытка де-ссылки на нулевой объект при разборе XML - PullRequest
0 голосов
/ 20 сентября 2019

Я получаю

System.NullPointerException: попытка отменить ссылку на нулевой объект При попытке запустить класс

Я пытаюсь передатьXML-строка из потока в Apex, проанализируйте ее и затем передайте обратно.

Я чувствую, что что-то маленькое, чего мне не хватает, но я не могу найти решение.

Это версия «Выполнить анонимно»:

String Str = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><DirectPaymentResponse xmlns="https://api.ewaypaymentscom/"><DirectPaymentResult><AuthorisationCode>0000C</AuthorisationCode><ResponseCode>00</ResponseCode><ResponseMessage>A2000</ResponseMessage><TransactionID>0000003</TransactionID><TransactionStatus>true</TransactionStatus><TransactionType>MOTO</TransactionType><BeagleScore>0.6</BeagleScore><Verification><CVN>Unchecked</CVN><Address>Unchecked</Address><Email>Unchecked</Email><Mobile>Unchecked</Mobile><Phone>Unchecked</Phone></Verification><Customer><TokenCustomerID>66666666</TokenCustomerID><Reference>Reference</Reference><Title>Mr.</Title><FirstName>aan</FirstName><LastName>McDat</LastName><CompanyName>Perkins</CompanyName><JobDescription>Officer</JobDescription><Street1>23 Verdun Street</Street1><Street2 /><City>Nedlands</City><State>WA</State><PostalCode>6009</PostalCode><Country>au</Country><Email>t@perkins.org.au</Email><Phone>0811111111</Phone><Mobile>0422222222</Mobile><Comments>Hi there</Comments><Fax /><Url>perkins.org.au</Url><CardDetails><Number>452012XXXXX9</Number><Name>ASd estt</Name><ExpiryMonth>1</ExpiryMonth><ExpiryYear>19</ExpiryYear><StartMonth /><StartYear /><IssueNumber /><CVN /></CardDetails></Customer><Payment><TotalAmount>200</TotalAmount><InvoiceNumber>0067F00000UmnAJ</InvoiceNumber><InvoiceDescription /><InvoiceReference /><CurrencyCode>AUD</CurrencyCode></Payment></DirectPaymentResult></DirectPaymentResponse></soap:Body></soap:Envelope>';

List<eWayOutputFlow> parsedXMlResponse = new List<eWayOutputFlow>();
    eWayOutputFlow theXMLOutput = new eWayOutputFlow();
    Dom.Document doc = new Dom.Document();
    doc.load(Str);
    Dom.XmlNode Envelope = doc.getRootElement();
    Dom.XmlNode Body = Envelope.getChildElement('Body', 'http://www.w3.org/2003/05/soap-envelope');
    Dom.XmlNode DirectPaymentResponse = Envelope.getChildElement('DirectPaymentResponse', 'https://api.ewaypayments.com/');
    Dom.XmlNode DirectPaymentResult = DirectPaymentResponse.getChildElement('DirectPaymentResult', 'https://api.ewaypayments.com/');
    Dom.XmlNode AuthorisationCode = DirectPaymentResult.getChildElement('AuthorisationCode','https://api.ewaypayments.com/' );
        theXMLOutput.AuthorisationCode = AuthorisationCode.getText();
    Dom.XmlNode ResponseCode=DirectPaymentResult.getChildElement('ResponseCode','https://api.ewaypayments.com/');
        theXMLOutput.ResponseCode = ResponseCode.getText();
    Dom.XmlNode TransactionID = DirectPaymentResult.getChildElement('TransactionID', 'https://api.ewaypayments.com/');
        theXMLOutput.TransactionID = TransactionID.getText();
        parsedXMlResponse.add(theXMLOutput);        
  System.debug('The response from invocable method is '+theXMLOutput);

Я получаю это сообщение об ошибке;

Строка: 9, Столбец: 1 System.NullPointerException: Попыткаразыменовать нулевой объект

...