/**
  * {@inheritdoc}
  */
 public function fromResponse(RequestInterface $request, Response $response)
 {
     COMMONLOG(DEBUG, "receive msg:%s", $response);
     $parts = $this->parser->parse($request, $response);
     // Removing leading 'AWS.' and embedded periods
     $className = $this->baseNamespace . '\\' . str_replace(array('AWS.', '.'), '', $parts['code']);
     if (substr($className, -9) !== 'Exception') {
         $className .= 'Exception';
     }
     $className = class_exists($className) ? $className : $this->defaultException;
     return $this->createException($className, $request, $response, $parts);
 }
 /**
  * Signs requests before they are sent
  *
  * @param Event $event Event emitted
  */
 public function onRequestBeforeSend(Event $event)
 {
     if (!$this->credentials instanceof NullCredentials) {
         $this->signature->signRequest($event['request'], $this->credentials);
         $request = $event['request'];
         COMMONLOG(DEBUG, "send header:%s", $request->getRawHeaders());
         if (S3Signature::$isFile) {
             if (S3Signature::$filePath) {
                 COMMONLOG(DEBUG, "souce file:%s", S3Signature::$filePath);
             }
         } else {
             if (get_class($request) === 'Guzzle\\Http\\Message\\EntityEnclosingRequest' && get_class($request->getBody()) === 'Guzzle\\Http\\EntityBody' && $request->getBody()->getContentLength() != 0) {
                 COMMONLOG(DEBUG, "send msg:%s", $request->getBody());
             }
         }
     }
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 protected function process()
 {
     $request = $this->getRequest();
     $response = $this->getResponse();
     // Dispatch an error if a 301 redirect occurred
     if ($response->getStatusCode() == 301) {
         $this->getClient()->getEventDispatcher()->dispatch('request.error', new Event(array('request' => $this->getRequest(), 'response' => $response)));
     }
     parent::process();
     // Set the GetObject URL if using the PutObject operation
     if ($this->result instanceof Model && $this->getName() == 'PutObject') {
         $this->result->set('ObjectURL', $request->getUrl());
     }
     if ($this->result instanceof Model && $this->getName() == 'GetObject') {
         $npos = strpos($response, "\n\r");
         $head = substr($response, 0, $npos);
         COMMONLOG(DEBUG, "receive head:%s", $head);
     } else {
         COMMONLOG(DEBUG, "receive msg:%s", $response);
     }
     COMMONLOG(INFO, "http request:status:%d, code:, message:", $response->getStatusCode());
 }
 /**
  * Cast to a string
  *
  * @return string
  */
 public function __toString()
 {
     $message = get_class($this) . ': ' . 'OBS Error Code: ' . $this->getExceptionCode() . ', ' . 'Status Code: ' . $this->getStatusCode() . ', ' . 'OBS Error Type: ' . $this->getExceptionType() . ', ' . 'OBS Error Message: ' . $this->getMessage();
     // Add the User-Agent if available
     if ($this->request) {
         $message .= ', ' . 'User-Agent: ' . $this->request->getHeader('User-Agent');
     }
     COMMONLOG(INFO, "http request:status:%d, %s", $this->getStatusCode(), "code:" . $this->getExceptionCode() . ", message:" . $this->getMessage());
     return $message;
 }
예제 #5
0
 private function TransFile($mothed, $args)
 {
     include_once 'Obs/S3/Model/MultipartUpload/SetObjectHead.php';
     $head = new \SetObjectHead();
     $head->setObject($args[0]);
     $head->setAK(ObsClient::$configArr['key']);
     $head->setSK(ObsClient::$configArr['secret']);
     $head->setMothed('PUT');
     if (array_key_exists("region", ObsClient::$configArr)) {
         $head->setregion(ObsClient::$configArr['region']);
     }
     if (array_key_exists("signature", ObsClient::$configArr)) {
         if (get_class(ObsClient::$configArr['signature']) == 'Obs\\S3\\S3Signature') {
             $head->setSignature('s3');
         } elseif (get_class(ObsClient::$configArr['signature']) == 'Obs\\S3\\S3SignatureV4') {
             $head->setSignature('v4');
         }
     }
     $endPointArr = explode('//', ObsClient::$configArr['endpoint']);
     $ssl = $endPointArr[0] === 'https:' ? true : false;
     $head->setHost($endPointArr[1], ObsClient::$configArr['path_style'], $ssl);
     include_once 'Obs/S3/Model/MultipartUpload/TransLargeFile.php';
     $arr = \TransLargeFile::TransFile($args[0]['SourceFile'], $head, $this->sourceFile);
     include_once 'Obs/S3/Model/MultipartUpload/GetResult.php';
     $a = new \GetResult($arr, ucfirst($mothed));
     COMMONLOG(INFO, "http request:status:" . $a->status . ", code:" . $a->errCode . ", message:" . $a->errMsg);
     if (intval($a->status) > 300) {
         $S3Except = new S3Exception($a->errMsg);
         $S3Except->setExceptionCode($a->errCode);
         $S3Except->setExceptionType("Client");
         $S3Except->setRequestId($a->requestId);
         $S3Except->setResponse(new Response($a->status));
         throw $S3Except;
         // 			throw new \Exception("MOS Error Code: $a->errCode, Status Code: $a->status, MOS Request ID: $a->requestId, MOS Error Message:$a->errMsg ");
     }
     return new Model($a->requst);
 }
예제 #6
0
 private function getResult()
 {
     $result = array();
     $res = "";
     $contentlength = 0;
     while ($this->fp && !feof($this->fp)) {
         $line = fgets($this->fp, 2048);
         if (!$line) {
             throw new Exception("recive data from service " . $this->host . " error");
         }
         $res .= $line;
         $arr = explode(':', $line);
         if (count($arr) == 1) {
             if ($line === "\r\n") {
                 if ($contentlength > 0) {
                     $line = fread($this->fp, $contentlength);
                     if (!$line) {
                         throw new Exception("recive data from service " . $this->host . " error");
                     }
                     $result['xml'] = str_replace(PHP_EOL, "", $line);
                     $res .= $line;
                 }
                 break;
             }
             $result[0] = str_replace(PHP_EOL, "", $arr[0]);
         } else {
             $result[$arr[0]] = str_replace(PHP_EOL, "", $arr[1]);
         }
         if ($arr[0] === 'Content-Length') {
             $contentlength = intval($result['Content-Length']);
             // 				if(intval($result['Content-Length']) != 0)
             // 				{
             // 					$line = fread($this->fp, intval($result['Content-Length']+2));
             // 					if(!$line)
             // 						throw new Exception("recive data from service ".$this->host."error");
             // 					$result['xml'] = str_replace(PHP_EOL, "",$line);
             // 					$res .= $line;
             // 				}
             // 				break;
         }
     }
     COMMONLOG(DEBUG, "receve msg:%s", $res);
     return $result;
 }