we are integrating Salesforce and SAP systems. For that we are making a callout to SAP with username and password in the header. When i checked the debug log the callout_request entry contains an xml request. But i did not find the header information which is the username and password in that request XML. Where can i find it? How could i ensure that i am sending the headers correctly? Experts please suggest. Thanks
sap1.inputHttpHeaders_x = new Map<String, String>(); //Setting a basic authentication header String username = 'SFDCUSER'; String password = 'xxxxxxc1'; Blob headerValue = Blob.valueOf(username + ':' + password); String authorizationHeader = 'BASIC ' +EncodingUtil.base64Encode(headerValue); sap1.inputHttpHeaders_x.put('Authorization',authorizationHeader);
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
The DEBUG logging will have two CALLOUT_REQUEST entries.
The first will have the SOAP formatted POST body. I.e. the <env:Envelope ...>
<?xml version="1.0" encoding="utf-8"?> <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <env:Header /> <env:Body> <login xmlns="urn:partner.soap.sforce.com"> <username><a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="760305130436130e171b061a135815191b">[email protected]</a></username> <password>PasswordAndSecurityToken</password> </login> </env:Body> </env:Envelope>
The second will have the same details, but JSON formatted. This will also end with the Request headers.
login_element: [ apex_schema_type_info=(urn: partner.soap.sforce.com, true, false), field_order_type_info=(username, password), password=PasswordAndSecurityToken, password_type_info=(password, urn: partner.soap.sforce.com, string, 1, 1, false), <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b4c1c7d1c6dad5d9d189c1c7d1c6f4d1ccd5d9c4d8d19ad7dbd9">[email protected]</a>, username_type_info=(username, urn: partner.soap.sforce.com, string, 1, 1, false) ]: : Authorization=BASIC U0ZEQ1VTRVI6eHh4eHh4YzE= SOAPAction="" Accept=text/xml User-Agent=SFDC-Callout/36.0 SFDC_STACK_DEPTH=1 Content-Type=text/xml; charset=UTF-8
The interesting part here is the trailing:
Authorization=BASIC U0ZEQ1VTRVI6eHh4eHh4YzE= SOAPAction=”” Accept=text/xml User-Agent=SFDC-Callout/36.0 SFDC_STACK_DEPTH=1 Content-Type=text/xml; charset=UTF-8
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0