2

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);
1
  • it would be great if you can post your code with this question. but in simple manner you can put a debug statement as req.getHeader('username'); before making the callout
    – Himanshu
    Mar 21, 2016 at 19:24

1 Answer 1

3

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>[email protected]</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),
     [email protected],
     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

2
  • Thanks @Daniel. Actually we are making a callout to SAP with login credentials for the SAP system and not the salesforce credentials. Moreover, the SAP service WSDL and the generated class does not have any entries for username/password. We just added the username and password in the headers Map<string, string> of the generated class while making the callout to SAP. But i can see the "interesting part here..." as you referred in the JSON in callout_request in debug log. Am i missing anything? Please advice
    – Bforce
    Mar 22, 2016 at 4:31
  • @BaskaranS I didn't have your full WSDL to work with, so just through any old SOAP callout together. As you noted, the important part is that the outbound headers are visible in the CALLOUT_REQUEST that contains JSON. Mar 22, 2016 at 7:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .