title: force.com callout exception Unable to tunnel through proxy
body: <p>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?</p>
  
  <p>Here the code snipped:</p>
  
  <pre><code>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 = '&lt;?xml version="1.0" encoding="UTF-8"?&gt;';    
  loginSoap += '&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com"&gt;';     
  loginSoap += '&lt;soapenv:Body&gt;';     
  loginSoap += '&lt;urn:login&gt;'; 
  loginSoap += '&lt;urn:username&gt;' + USERNAME + '&lt;/urn:username&gt;';     
  loginSoap += '&lt;urn:password&gt;' + PASSWORD + '&lt;/urn:password&gt;'; 
  loginSoap += '&lt;/urn:login&gt;';     
  loginSoap += '&lt;/soapenv:Body&gt;';     
  loginSoap += '&lt;/soapenv:Envelope&gt;';     
  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;
     }            
  }
  </code></pre>