public function __construct($message, RequestInterface $request, ResponseInterface $response = null, \Exception $previous = null)
 {
     $code = $response ? $response->getStatusCode() : 0;
     parent::__construct($message, $code, $previous);
     $this->request = $request;
     $this->response = $response;
 }
Example #2
0
 public function connect()
 {
     $this->open();
     $sendData = $this->serializeParams($this->getParameters());
     curl_setopt($this->curl, CURLOPT_URL, "{$this->url}?{$sendData}");
     //curl_setopt($this->curl, CURLOPT_POST, true); // HTTP POST
     //curl_setopt($this->curl, CURLOPT_POSTFIELDS, $sendData);
     $response = curl_exec($this->curl);
     if ($response === false) {
         $errno = @curl_errno($this->curl);
         $error = @curl_strerror($errno);
         $this->close();
         throw TransferException::couldNotTransferData($this->url . ($this->isProxy() ? ' (usando proxy)' : ''), "[{$errno}] {$error}");
     }
     list($response_headers_str, $response) = explode("\r\n\r\n", $response);
     /*$response_headers = $this->_readHeaders($response_headers_str);
       if (!$this->checkResponseToken($response_headers['X-FW-Response'])) {
           throw new WrongDataTransferException('Resposta inv�lida do servidor, entre em contato com a Furac�o');
       }*/
     $this->close();
     if (empty($response)) {
         throw TransferException::emptyDataReturned();
     }
     return $response;
 }
Example #3
0
 public function connect()
 {
     $this->open();
     try {
         if (!$this->getFunction()) {
             throw TransferException::functionMandatory();
         }
         $response = $this->soapClient->__call($this->getFunction(), $this->getParameters());
         /*$response_headers_str = $this->pointer->__getLastResponseHeaders();
           $response_headers = $this->_readHeaders($response_headers_str);
           if (!$this->checkResponseToken($response_headers['X-FW-Response'])) {
               throw new WrongDataTransferException('Resposta inv�lida do servidor, entre em contato com a Furac�o');
           }*/
     } catch (TransferException $e) {
         throw $e;
         // se for exception de transfer, lançar do jeito que está
     } catch (\Exception $e) {
         throw TransferException::couldNotTransferData($this->url . ($this->isProxy() ? ' (usando proxy)' : ''), $e->getMessage());
     }
     $this->soapClient = null;
     if (empty($response)) {
         throw TransferException::emptyDataReturned();
     }
     return $response;
 }
Example #4
0
 public function __construct($message, RequestInterface $request, ResponseInterface $response = null, \Exception $previous = null)
 {
     // Set the code of the exception if the response is set and not future.
     $code = $response && !$response instanceof FutureInterface ? $response->getStatusCode() : 0;
     parent::__construct($message, $code, $previous);
     $this->request = $request;
     $this->response = $response;
 }
Example #5
0
 public function connect()
 {
     $sendData = $this->serializeParams($this->getParameters());
     $context = stream_context_create(array('http' => array('timeout' => $this->timeout, 'header' => "X-Fw-Transfer: file\r\n")));
     $response = @file_get_contents("{$this->url}?{$sendData}", false, $context);
     if ($response === false) {
         throw TransferException::unknownError();
     }
     if (empty($response)) {
         throw TransferException::emptyDataReturned();
     }
     return $response;
 }
Example #6
0
 public function connect()
 {
     $throwEx = null;
     foreach ($this->adapters as $adapter) {
         try {
             var_dump('tentou por ' . get_class($adapter));
             return $adapter->connect();
         } catch (TransferException $ex) {
             $throwEx = TransferException::chain($throwEx, $ex);
         }
     }
     // se todos derem erro, lança exception de todos erros
     if (null !== $throwEx) {
         throw $throwEx;
     }
 }
Example #7
0
 public function __construct($message = '', ResponseInterface $response = null, \Exception $previous = null)
 {
     parent::__construct($message, 0, $previous);
     $this->response = $response;
 }
Example #8
0
 /**
  * Constructs RequestException
  *
  * @param string           $message  The message
  * @param RequestInterface $request  The request
  * @param \Exception|null  $previous The previous exception
  */
 public function __construct(string $message, RequestInterface $request, \Exception $previous = null)
 {
     $this->request = $request;
     parent::__construct($message, 0, $previous);
 }
Example #9
0
 public function connect()
 {
     $this->normalizeUrl();
     $this->open();
     $sendData = $this->serializeParams($this->getParameters());
     $headers = array();
     if ($this->isProxy()) {
         //$headers[] = "POST $this->url HTTP/1.1";
         $headers[] = "GET {$this->url}?{$sendData} HTTP/1.1";
         $headers[] = "Host: {$this->proxyHost}";
         if ($this->isAuthProxy()) {
             $headers[] = "Proxy-Authorization: Basic " . base64_encode("{$this->proxyLogin}:{$this->proxyPass}");
         }
     } else {
         //$headers[] = "POST $this->uri HTTP/1.1";
         $headers[] = "GET {$this->uri}?{$sendData} HTTP/1.1";
         $headers[] = "Host: {$this->host}";
     }
     //$headers[] = "X-FW-Token: " . $this->getToken();
     $headers[] = "X-FW-Transfer: socket";
     $headers[] = "Content-Type: application/x-www-form-urlencoded";
     $headers[] = "Content-Length: " . strlen($sendData);
     $headers[] = "Connection: close";
     $headers[] = "";
     // enter necessario
     $headers[] = $sendData;
     // dados a serem passados
     $header_data = implode("\r\n", $headers);
     // manda no stream o header com os dados
     fwrite($this->sck, $header_data);
     // le primeiro o header de response
     do {
         $responseHeader .= fread($this->sck, 1);
     } while (!preg_match('/\\r\\n\\r\\n$/', $responseHeader));
     // depois le o conteudo do response
     if (!strstr($responseHeader, "Transfer-Encoding: chunked")) {
         // se nao veio chunkado, ler tudo
         $response = '';
         while (!feof($this->sck)) {
             $response .= fgets($this->sck, 128);
         }
     } else {
         // veio chunkado, ler os pedaços
         $response = '';
         while ($chunk_length = hexdec(fgets($this->sck))) {
             $response_chunk = '';
             $read_length = 0;
             while ($read_length < $chunk_length) {
                 $response_chunk .= fread($this->sck, $chunk_length - $read_length);
                 $read_length = strlen($response_chunk);
             }
             $response .= $response_chunk;
             fgets($this->sck);
         }
     }
     $response = chop($response);
     $this->close();
     if (empty($response)) {
         throw TransferException::emptyDataReturned();
     }
     return $response;
 }