I'm having issues correctly getting Salesforce to connect to one of our external systems. I They recently whitelisted the range of Salesforce addresses (At least so they said). Our Sandbox is coming from cs7.
96.43.144.0/20 _ subnet mask: 255.255.240.0
136.146.0.0/15 _ subnet mask: 255.254.0.0
182.50.76.0/22 _ subnet mask: 255.255.252.0
204.14.232.0/21 _ subnet mask: 255.255.248.0
I have 2 different Chrome plugin REST clients that are managing the login call fine.
Advanced REST Client:
Postman REST Client:
I was given some Java code that is being used to connect but I'm having a hard time converting this to Salesforce.
URL url = new URL("https://testweb1.somesystem.com/system2SOME_URL + '/etc/authentication/Login?_contenttype=text/xml");
String username = "userid";
String password = "userpw";
String urlParams = "username=" + username + "&password=" + password;
HttpsURLConnection uc = (HttpsURLConnection) url.openConnection();
uc.setRequestMethod("POST");
uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
uc.setRequestProperty("Content-Length", "" + Integer.toString(urlParams.getBytes().length));
uc.setUseCaches (false);
uc.setDoInput(true);
uc.setDoOutput(true);
//Send request
DataOutputStream wr = new DataOutputStream (uc.getOutputStream());
wr.writeBytes (urlParams);
wr.flush ();
wr.close ();
if(uc.getContent()!=null) {
InputStream in = (InputStream) uc.getContent();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(in);
NodeList recordSet = doc.getDocumentElement().getElementsByTagName("recordset");
String sessionId = recordSet.item(0).getChildNodes().item(1).getAttributes().getNamedItem("UserSessionID").getNodeValue();
}
The code I have so farcreated in Apex to replicate these calls:
HttpRequest req = new HttpRequest();
req.setEndpoint('https://testweb1.somesystem.com/system2SOME_URL + '/etc/authentication/Login?_contenttype=text/xml');
String params//?' =+ 'username=userid&password=userpw';params);
req.setMethod('POST');
req.setHeader('Content-Type', 'application/x-www-form-urlencoded');
//Content-LengthI istried requiredall in3 thisversions callbelow. as well
req.setHeader('Content-Length', //String.valueOf( params.length()));
req = 'username=' + EncodingUtil.setHeaderurlEncode('username''userid1', 'userid''UTF-8');
req + '&password=' + EncodingUtil.setHeaderurlEncode('password''P@ssword1', 'userpw''UTF-8');
String params = 'username=userid1&password=P@ssword1';
DOM//This version gives a different error that says 'Both username and password are required.Document'
//String docparams = new DOMEncodingUtil.DocumenturlEncode('username=userid1&password=P@ssword1', 'UTF-8');
req.setBody(params);
Http hp = new Http();
HTTPResponse res = hp.send(req);
System.debug('response'body = ' + res.getBody());
I thought about trying to pass some form of DOM through as the body but it doesn't appear like that is what they are doing withMy code always returns the Javamessage: 'Invalid stored procedure name. On top of' I am thinking that potentially the documentation doesn't seem to be helping me very well to build an example. Does anyoneSalesforce IP isn't correctly whitelisted but I really have any recommendations forno proof since they told me?
Using the postman REST client I can create a successful connection as of this morning it was now whitelisted.
Any ideas?