Tuesday, 1 December 2015

Identify IP address in Salesforce.com Outbound Web Services

Last time with introduction of new SAP/PI client for our existing interface betweeen SFDC-SAP/PI, there was a need to re-establish the interface connection between the two systems. While making outbound callouts SFDC started getting; Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found ':html' error.
We all know very well when this type of exception happens. Usually this error occurs if there is some issue in communication with the external web service, there are a few things you can check.
  • Check if external webservice is really available and working.
  • Check if Salesforce's IP addresses are included in white list on the firewall of the network where the external web service is located.
  • Validate the endpoint address of the webservice.
  • Check if the endpoint's server is enabled as a Remote Site in Salesforce.
  • Remember that web service must be accessible from Internet to a public and valid IP address.


I suspected point #2. While troubleshooting network connection between Salesforce.com and SAP/PI, SAP says that they have white listed all SFDC recommended IP ranges in their firewall which prompted the question to identify which IP address SFDC instance was using to send request payload to the PI middleware. And this is very important task to do.
Go to your developer console and execute the below piece of code after setting remote site for the mentioned endpoint.
     HttpRequest req = new HttpRequest();
     req.setEndpoint('http://icanhazip.com/');
     req.setMethod('GET');
     Http httpReq = new Http();
     HttpResponse res = httpReq.send(req);
     System.debug(res.getBody());
For example, you will get something like this screen shot. Look for USER_DEBUG displaying the intended IP address, highlighted in yellow.

Later it was found out that this IP address was not white listed in PI firewall and thereby the issue was resolved. 
Some more info on icanhazip**
icanhazip.com is a service which can help you to find out your system's current external IP address. While setting endpoint; you can have a few options to choose from:
  • icanhazip.com – returns your IP address
  • icanhazptr.com – returns the reverse DNS record (PTR) for your IP
  • icanhaztrace.com – returns a traceroute from my servers to your IP address
  • icanhaztraceroute.com – returns a traceroute from my servers to your IP address
  • icanhazepoch.com – returns the epoch time (also called Unix time)
  • icanhazproxy.com – can determine if your traffic is being proxied

NOTE: If you want to force an IPv4 lookup, use ipv4.icanhazip.com. For IPv6, use ipv6.icanhazip.com.
Happy Apex debugging.. :) 
**referenced

No comments:

Post a Comment

Thank you for visiting. Your comments are highly appreciated.