Example #1
0
 /**
  * @param Request $request
  * @return mixed
  */
 public function download(RequestInterface $request)
 {
     $backoffTry = 0;
     $response = null;
     do {
         if ($backoffTry > 0) {
             sleep(pow(2, $backoffTry));
         }
         // TODO refresh request may come here
         try {
             $response = $this->client->__soapCall($request->getFunction(), $request->getParams(), $request->getOptions(), $request->getInputHeader(), $outputHeaders);
         } catch (\SoapFault $e) {
             $backoffTry++;
             $errData = array("code" => $e->getCode(), "message" => $e->getMessage(), "faultcode" => isset($e->faultcode) ? $e->faultcode : null, "faultstring" => isset($e->faultstring) ? $e->faultstring : null, "detail" => isset($e->detail) ? (array) $e->detail : null);
             // Do not retry if max. retry count is reached OR the error isn't on server(TODO?):  || $errData["faultcode"] == "SOAP-ENV:Client"
             if ($backoffTry >= $this->backoffTryCount) {
                 $e = new UserException("Soap call failed:" . $e->getCode() . ": " . $e->getMessage(), 400, $e);
                 $e->setData($errData);
                 throw $e;
             } else {
                 Logger::log("debug", "Soap call error, retrying:" . $e->getCode() . ": " . $e->getMessage(), $errData);
             }
         }
     } while ($response === null);
     return $response;
 }
Example #2
0
 /**
  * @param RequestInterface $request
  * @return GuzzleRequest
  * @throws ApplicationException
  * @throws UserException
  */
 protected function getGuzzleRequest(RequestInterface $request)
 {
     if (!$request instanceof RestRequest) {
         throw new ApplicationException("RestClient requires a RestRequest!");
     }
     switch ($request->getMethod()) {
         case 'GET':
             $method = $request->getMethod();
             $endpoint = Utils::buildUrl($request->getEndpoint(), $request->getParams());
             $options = [];
             break;
         case 'POST':
             $method = $request->getMethod();
             $endpoint = $request->getEndpoint();
             $options = ['json' => $request->getParams()];
             break;
         case 'FORM':
             $method = 'POST';
             $endpoint = $request->getEndpoint();
             $options = ['body' => $request->getParams()];
             break;
         default:
             throw new UserException("Unknown request method '" . $request->getMethod() . "' for '" . $request->getEndpoint() . "'");
             break;
     }
     if (!empty($request->getHeaders())) {
         $options['headers'] = $request->getHeaders();
     }
     return $this->client->createRequest($method, $endpoint, $options);
 }