3

We make a callout from one Salesforce org to another Salesforce org using the REST API. That worked until end of november. We didn't make any changes at the affected classes or configuration. Now, while sending a request to the rest api a callout exception will be thrown with the message : "Unable to tunnel through proxy. Proxy returns "HTTP/1.0 503 Service Unavailable". The authorisation to the rest api is done by session id. Does anyone have any idea what the problem is?

Here the code snipped:

final String WS_ENDPOINT = 'https://login.salesforce.com/services/Soap/c/24.0'; 
final String REST_ENDPOINT = 'https://eu2.salesforce.com/services/apexrest/UsageReporterService';
final String USERNAME = '*****'; 
final String PASSWORD = '*****'; 

HTTP h = new HTTP();
HTTPRequest req = new HTTPRequest();
req.setMethod('POST');
req.setEndpoint(REST_ENDPOINT);
req.setHeader('Content-Type', 'application/json');
req.setTimeout(60000);
HTTP hLogin = new HTTP(); 
HTTPRequest reqLogin = new HTTPRequest(); 
reqLogin.setMethod('POST'); 
reqLogin.setEndpoint(WS_ENDPOINT);
reqLogin.setHeader('Content-Type', 'text/xml'); 
reqLogin.setHeader('SOAPAction', 'login'); 
reqLogin.setTimeout(60000); 

reqLogin.setCompressed(false); 
// get a valid session id
String sessionId;
String loginSoap = '<?xml version="1.0" encoding="UTF-8"?>';    
loginSoap += '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com">';     
loginSoap += '<soapenv:Body>';     
loginSoap += '<urn:login>'; 
loginSoap += '<urn:username>' + USERNAME + '</urn:username>';     
loginSoap += '<urn:password>' + PASSWORD + '</urn:password>'; 
loginSoap += '</urn:login>';     
loginSoap += '</soapenv:Body>';     
loginSoap += '</soapenv:Envelope>';     
reqLogin.setBody(loginSoap); 

HTTPResponse respLogin; 
try {
    respLogin = hLogin.send(reqLogin);
} catch(CalloutException c){        
    return null;
}       

System.debug('++++++'+respLogin.getStatus() + ': ' + respLogin.getBody());
Dom.Document doc = new Dom.Document();
doc.load(respLogin.getBody());
Dom.XMLNode root = doc.getRootElement();
String ns = root.getNamespace();
Dom.XMLNode bodyEl = root.getChildElements()[0];


 if(bodyEl.getChildElements()[0].getName().equals('loginResponse')){
      sessionId = bodyEl.getChildElements()[0].getChildElement('result', ns).getChildElement('sessionId', ns).getText();
}


 // finished getting session Id     
  if(sessionId != null){ // login was successfull
    req.setHeader('Authorization', 'Bearer ' + sessionId);  
   // serialize data into json string
   UsageReporterModel usageReporterData = new UsageReporterModel();
   String inputStr = usageReporterData.serialize();
   req.setBody('{ "usageReportData" : ' + inputStr + '}');       
   // fire!
   HTTPResponse resp;
   try {
    resp = h.send(req);
   } catch(CalloutException c){             
        return null;
   }            
}
user1902191
  • 31
  • 1
  • 2

1 Answers1

1

I suspect this will relate to a change of IP addresses for one of the org's which haven't been whitelisted correctly (or added to the "network access" object). With it being Salesforce to Salesforce I would hope that Salesforce.com support can assist?