$errMessage = VMware_VCloud_SDK_Helper::getObjByXml($e->getMessage()); echo $errMessage->get_majorErrorCode() . ' : ' . $errMessage->get_message() . "\n"; } // client 1 and client 2 performing operation after logout. try { echo "\n\n VcloudClient 1 \n"; echo "\n " . $vcloudClient1->createSDKAdminObj()->getVCloud()->getDescription(); } catch (Exception $e) { $errMessage = VMware_VCloud_SDK_Helper::getObjByXml($e->getMessage()); echo " " . $errMessage->get_majorErrorCode() . ' : ' . $errMessage->get_message() . "\n"; } try { echo "\n VcloudClient 2\n"; echo "\n " . $vcloudClient2->createSDKAdminObj()->getVCloud()->getDescription(); } catch (Exception $e) { $errMessage = VMware_VCloud_SDK_Helper::getObjByXml($e->getMessage()); echo " " . $errMessage->get_majorErrorCode() . ' : ' . $errMessage->get_message() . "\n"; } } else { echo "\n\nLogin Failed due to certification mismatch."; return; } function usage() { echo "Usage:\n\n"; echo " [Description]\n"; echo " This sample illustrates the session management capabilities using the VcloudClient.\n"; echo "\n"; echo " [Usage]\n"; echo " # php sessionmanagement.php -s <server> -u <username> -p <password> -v <sdkversion> [Options]\n"; echo "\n";
/** * Send an HTTP PUT request. * * @param string $url URL to send an HTTP request * @param int $expect Expected HTTP status code on a successful request * @param string $type HTTP request Content-Type * @param mixed $data A VMware vCloud data object, which has export() * method defined, or an XML data which will be used * as HTTP request body * @return mixed A VMware vCloud data object * @throws VMware_VCloud_SDK_Exception * @since Version 1.0.0 */ public function put($url, $expect = null, $type = null, $data = null) { $len = 0; if (!is_null($data)) { if (method_exists($data, 'export')) { $data = $data->export(); } $len = strlen($data); } $headers = array('Content-Type' => $type, 'Content-Length' => $len); $response = $this->httpClient->put($url, $headers, $data); $code = $response->getStatus(); $body = $response->getBody(); $status = $response->getReasonPhrase(); $responseHeaders = $response->getHeader(); $file = $this->getLogger(); $file->log("Put Request URL: {$url}", PEAR_LOG_INFO); $file->log("Put Content-Type: " . $type, PEAR_LOG_INFO); $file->log("Put Request Headers: " . var_export($headers, true), PEAR_LOG_INFO); $file->log("Put Request Body: " . var_export($data, true), PEAR_LOG_DEBUG); $file->log("Status Code: {$code}", PEAR_LOG_INFO); $file->log("Status: {$status}", PEAR_LOG_INFO); $file->log("Response Header: " . var_export($responseHeaders, true), PEAR_LOG_DEBUG); $file->log("Response: {$body}", PEAR_LOG_DEBUG); if (isset($expect) && $expect != $code) { throw new VMware_VCloud_SDK_Exception("PUT {$url} failed, error " . "code: {$code}, error: {$body}, request data:\n{$data}\n"); } return VMware_VCloud_SDK_Helper::getObjByXml($body); }
/** * Send an HTTP PUT request. * * @param string $url URL to send an HTTP request * @param int $expect Expected HTTP status code on a successful request * @param string $type HTTP request Content-Type * @param mixed $data A VMware vCloud data object, which has export() * method defined, or an XML data which will be used * as HTTP request body * @return mixed A VMware vCloud data object * @throws VMware_VCloud_SDK_Exception * @since Version 1.0.0 */ public function put($url, $expect = null, $type = null, $data = null) { $len = 0; if (!is_null($data)) { if (method_exists($data, 'export')) { $data = $data->export(); } $len = strlen($data); } $headers = array('Content-Type' => $type, 'Content-Length' => $len); $response = $this->httpClient->put($url, $headers, $data); $code = $response->getStatus(); $body = $response->getBody(); if (isset($expect) && $expect != $code) { throw new VMware_VCloud_SDK_Exception("PUT {$url} failed, error " . "code: {$code}, error: {$body}, request data:\n{$data}\n"); } return VMware_VCloud_SDK_Helper::getObjByXml($body); }