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);
  • 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 '16 at 19:24
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>user@example.com</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),
     username=user@example.com,
     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

|improve this answer|||||
  • 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 '16 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. – Daniel Ballinger Mar 22 '16 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.