You need to sign in to do that
Don't have an account?
shiva 463
Failed to parse XML due to: only whitespace content allowed before start tag and not P (position: START_DOCUMENT seen P... @1:1)
Hi All,
Iam trying to get the BI reports from OSC to SFDC getting an error when passing the parameters in payload.Getting an error Failed to parse XML due to: only whitespace content allowed before start tag and not P (position: START_DOCUMENT seen P... @1:1) so can anyone help me on this issue.
Here is the code.
global class ResponseclsforCACF_report{
@future(callout=true)
//public static void Responsefrom3rdparty(string syncid,String acc){
public static void Responsefrom3rdparty(string syncid,String acc){
List<String> list_report=new list<String>();
List<FIC_Reports__c> salescomision=new List<FIC_Reports__c>();
list<String> sos=new List<String>();
Boolean checkval=false;
Boolean baseco=false;
//try{
String endPointURL='https://xxxxxx.us2.oraclecloud.com:443/xmlpserver/services/ExternalReportWSSService?WSDL';
String userName = 'xxxxxxxxxx';
String password = 'xxxx';
Blob headerValue = Blob.valueOf(userName + ':' + password);
String authorizationHeader = 'BASIC ' +EncodingUtil.base64Encode(headerValue);
//Date dd=system.today();
//DOM.Document resDoc = new DOM.Document();
// Send the request
String str=+'<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:pub="http://xmlns.oracle.com/oxp/service/PublicReportService">'
+'<soap:Header/>'
+'<soap:Body>'
+'<pub:runReport>'
+'<pub:reportRequest>'
+'<pub:reportAbsolutePath>/Custom/Customer Relationship Management/pty_SC_DM_Report.xdo</pub:reportAbsolutePath>'
+'<pub:sizeOfDataChunkDownload>-1</pub:sizeOfDataChunkDownload>'
+'</pub:reportRequest>'
+'<pub:appParams/>'
+'</pub:runReport>'
+'</soap:Body>'
+'</soap:Envelope>';
//tring postXML = '{set XML body here in plain text, I only used \n for newlines}';
HttpRequest req = new HttpRequest();
req.setTimeout(120000);
req.setMethod('GET');
req.setEndpoint(endPointURL);
req.setHeader('Authorization', authorizationHeader);
//req.setHeader('Content-Type', 'text/xml; charset=UTF-8');
req.setHeader('Content-Type', 'application/soap+xml;charset=UTF-8');
//req.setHeader('Content-length',string.valueof(postXML.length()));
req.setBody(str);
Http http = new Http();
Transient HttpResponse res = new HttpResponse();
//res = http.send(req);
//HttpResponse res = http.send(request);
res = http.send(req);
//system.debug('res.......'+res.getbody());
cacfQuot__c sfintegrate = new cacfQuot__c();
/*--------syncid-----*/
sfintegrate.SFDCQuot__c=syncid;
sfintegrate.Name=acc;
sfintegrate.Request_Status__c=res.getStatus();
sfintegrate.Status_Code__c=string.valueof(res.getStatusCode());
sfintegrate.FIC_response__c=res.getbody();
if(sfintegrate.Status_Code__c!='200'){
sfintegrate.FIC_response__c=res.getbody();
system.debug('00000000000'+res.getbody());
}
sfintegrate.Execution_time__c=string.valueof(System.now());
sfintegrate.Request_Body__c=str;
if(res.getStatusCode() ==200){
String encodedvalue;
string decodedstring ;
Dom.Document docx = new Dom.Document();
docx.load(res.getbody());
system.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+res.getbody());
dom.XmlNode xroot = docx.getrootelement() ;
//system.debug('xroot..'+xroot);
dom.XmlNode [] xrec = xroot.getchildelements() ;
for(Dom.XMLNode child : xrec) {
//system.debug('child..'+child);
for (dom.XmlNode awr : child.getchildren() ) {
//System.debug('awr...'+awr);
for(dom.XmlNode xy:awr.getchildren()){
// system.debug('xy...'+xy);
for(dom.XmlNode anc :xy.getchildren()){
//if(anc.gettext() != null ){
baseco=true;
encodedvalue=anc.gettext();
//encodedvalue=encodedvalue.replace(';',' ');
/*Blob d = EncodingUtil.base64Decode(encodedvalue);
//system.debug('d...'+d);
decodedstring = d.tostring();*/
Blob d= Blob.valueof(encodedvalue);
decodedstring =d.tostring();
system.debug('@@@@@@@@@@'+decodedstring );
/* }
}
}
}*/
/******************this Dom.XMLstring***************/
Dom.Document docxxml = new Dom.Document();
docxxml.load(decodedstring);
dom.XmlNode xrootxml = docxxml.getrootelement() ;
for(Dom.XMLNode child_rep: xrootxml.getChildElements()) {
// System.debug('head....'+child);
for(Dom.XMLNode child1:child_rep.getChildElements()){
// system.debug('body..'+child1);
for(Dom.XMLNode child2:child1.getChildElements()){
//list_report.clear();
FIC_Reports__c salescom = new FIC_Reports__c();
// System.debug('tr....'+child2);
for(Dom.XMLNode child3:child2.getChildElements()){
// System.debug('td...'+child3);
for(Dom.XMLNode child4:child3.getChildElements()){
// System.debug('p....'+child4);
for(Dom.XMLNode child5:child4.getChildElements()){
system.debug('@@@@@'+child5.getname());
if(child5.getname() == 'span'){
checkval=true;
system.debug('child5...'+child5.gettext());
list_report.add(child5.gettext());
system.debug('#########'+list_report);
}
}
}
}
for(string ss:list_report){
if(list_report.size()==2)
{
checkval=true;
}
else{
checkval=false;
}
}
if(checkval==true){
system.debug('Valuestoaddintrue.........'+list_report);
salescom.Name=list_report[1];
salescom.Description__c=list_report[0];
salescomision.add(salescom);
//insert salescom;
//checkval=false;
system.debug('^^^^^^salescommision'+salescomision);
system.debug('^^^^^^salescommision'+salescomision.size());
}
}
insert salescomision;
system.debug('salescomisionsales.............'+salescomision);
}
}
}}}}
system.debug('salescomisionsales.............'+salescomision);
}
}
}
Iam trying to get the BI reports from OSC to SFDC getting an error when passing the parameters in payload.Getting an error Failed to parse XML due to: only whitespace content allowed before start tag and not P (position: START_DOCUMENT seen P... @1:1) so can anyone help me on this issue.
Here is the code.
global class ResponseclsforCACF_report{
@future(callout=true)
//public static void Responsefrom3rdparty(string syncid,String acc){
public static void Responsefrom3rdparty(string syncid,String acc){
List<String> list_report=new list<String>();
List<FIC_Reports__c> salescomision=new List<FIC_Reports__c>();
list<String> sos=new List<String>();
Boolean checkval=false;
Boolean baseco=false;
//try{
String endPointURL='https://xxxxxx.us2.oraclecloud.com:443/xmlpserver/services/ExternalReportWSSService?WSDL';
String userName = 'xxxxxxxxxx';
String password = 'xxxx';
Blob headerValue = Blob.valueOf(userName + ':' + password);
String authorizationHeader = 'BASIC ' +EncodingUtil.base64Encode(headerValue);
//Date dd=system.today();
//DOM.Document resDoc = new DOM.Document();
// Send the request
String str=+'<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:pub="http://xmlns.oracle.com/oxp/service/PublicReportService">'
+'<soap:Header/>'
+'<soap:Body>'
+'<pub:runReport>'
+'<pub:reportRequest>'
+'<pub:reportAbsolutePath>/Custom/Customer Relationship Management/pty_SC_DM_Report.xdo</pub:reportAbsolutePath>'
+'<pub:sizeOfDataChunkDownload>-1</pub:sizeOfDataChunkDownload>'
+'</pub:reportRequest>'
+'<pub:appParams/>'
+'</pub:runReport>'
+'</soap:Body>'
+'</soap:Envelope>';
//tring postXML = '{set XML body here in plain text, I only used \n for newlines}';
HttpRequest req = new HttpRequest();
req.setTimeout(120000);
req.setMethod('GET');
req.setEndpoint(endPointURL);
req.setHeader('Authorization', authorizationHeader);
//req.setHeader('Content-Type', 'text/xml; charset=UTF-8');
req.setHeader('Content-Type', 'application/soap+xml;charset=UTF-8');
//req.setHeader('Content-length',string.valueof(postXML.length()));
req.setBody(str);
Http http = new Http();
Transient HttpResponse res = new HttpResponse();
//res = http.send(req);
//HttpResponse res = http.send(request);
res = http.send(req);
//system.debug('res.......'+res.getbody());
cacfQuot__c sfintegrate = new cacfQuot__c();
/*--------syncid-----*/
sfintegrate.SFDCQuot__c=syncid;
sfintegrate.Name=acc;
sfintegrate.Request_Status__c=res.getStatus();
sfintegrate.Status_Code__c=string.valueof(res.getStatusCode());
sfintegrate.FIC_response__c=res.getbody();
if(sfintegrate.Status_Code__c!='200'){
sfintegrate.FIC_response__c=res.getbody();
system.debug('00000000000'+res.getbody());
}
sfintegrate.Execution_time__c=string.valueof(System.now());
sfintegrate.Request_Body__c=str;
if(res.getStatusCode() ==200){
String encodedvalue;
string decodedstring ;
Dom.Document docx = new Dom.Document();
docx.load(res.getbody());
system.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+res.getbody());
dom.XmlNode xroot = docx.getrootelement() ;
//system.debug('xroot..'+xroot);
dom.XmlNode [] xrec = xroot.getchildelements() ;
for(Dom.XMLNode child : xrec) {
//system.debug('child..'+child);
for (dom.XmlNode awr : child.getchildren() ) {
//System.debug('awr...'+awr);
for(dom.XmlNode xy:awr.getchildren()){
// system.debug('xy...'+xy);
for(dom.XmlNode anc :xy.getchildren()){
//if(anc.gettext() != null ){
baseco=true;
encodedvalue=anc.gettext();
//encodedvalue=encodedvalue.replace(';',' ');
/*Blob d = EncodingUtil.base64Decode(encodedvalue);
//system.debug('d...'+d);
decodedstring = d.tostring();*/
Blob d= Blob.valueof(encodedvalue);
decodedstring =d.tostring();
system.debug('@@@@@@@@@@'+decodedstring );
/* }
}
}
}*/
/******************this Dom.XMLstring***************/
Dom.Document docxxml = new Dom.Document();
docxxml.load(decodedstring);
dom.XmlNode xrootxml = docxxml.getrootelement() ;
for(Dom.XMLNode child_rep: xrootxml.getChildElements()) {
// System.debug('head....'+child);
for(Dom.XMLNode child1:child_rep.getChildElements()){
// system.debug('body..'+child1);
for(Dom.XMLNode child2:child1.getChildElements()){
//list_report.clear();
FIC_Reports__c salescom = new FIC_Reports__c();
// System.debug('tr....'+child2);
for(Dom.XMLNode child3:child2.getChildElements()){
// System.debug('td...'+child3);
for(Dom.XMLNode child4:child3.getChildElements()){
// System.debug('p....'+child4);
for(Dom.XMLNode child5:child4.getChildElements()){
system.debug('@@@@@'+child5.getname());
if(child5.getname() == 'span'){
checkval=true;
system.debug('child5...'+child5.gettext());
list_report.add(child5.gettext());
system.debug('#########'+list_report);
}
}
}
}
for(string ss:list_report){
if(list_report.size()==2)
{
checkval=true;
}
else{
checkval=false;
}
}
if(checkval==true){
system.debug('Valuestoaddintrue.........'+list_report);
salescom.Name=list_report[1];
salescom.Description__c=list_report[0];
salescomision.add(salescom);
//insert salescom;
//checkval=false;
system.debug('^^^^^^salescommision'+salescomision);
system.debug('^^^^^^salescommision'+salescomision.size());
}
}
insert salescomision;
system.debug('salescomisionsales.............'+salescomision);
}
}
}}}}
system.debug('salescomisionsales.............'+salescomision);
}
}
}
Usually, this error occurs if there is a problem in the XML file.
Similar issue resolved for me
Earlier I was saving the content of the WSDL file by copying all data and pasting it into a text file.
Instead, the right attempt was to the right click on the WSDL link and choose 'save link as' option to save the WSDL file.
Below is the link with similar issue
http://salesforce.stackexchange.com/questions/76262/error-converting-httpresponse-to-dom-document
If this helps you please mark it as solved
Thanks and Regards
Sandhya
Regards,
Anurag