force.com callout exception无法通过代理进行隧道传输

时间:2012-12-13 20:53:59

标签: rest exception force.com callout

我们使用REST API从一个Salesforce组织向另一个Salesforce组织发出标注。这工作到11月底。我们没有在受影响的类或配置中进行任何更改。 现在,在向其余api发送请求时,将抛出一个标注异常,并显示以下消息:“无法通过代理隧道。代理返回”HTTP / 1.0 503服务不可用“。 对其余api的授权由会话ID完成。 有谁知道问题是什么?

这里代码剪断了:

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;
   }            
}

1 个答案:

答案 0 :(得分:1)

我怀疑这与其中一个未正确列入白名单(或添加到“网络访问”对象)的组织的IP地址更改有关。有了Salesforce到Salesforce,我希望Salesforce.com支持可以提供帮助吗?