public function querySync(QueryMessage $msg)
 {
     $json = $msg->serialize();
     $json = '[' . $json . ']';
     $curl = $this->getCurl();
     curl_setopt($curl, CURLOPT_POST, true);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     $headers = array('Content-Type: x-application/jamp-rpc');
     curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
     log('querySync sent: ' . $json);
     $data = curl_exec($curl);
     if ($data === false) {
         throw new \Exception('error submitting message: ' . curl_error($curl));
     }
     log('querySync response: ' . $data);
     $responses = array();
     if ($data !== '') {
         $list = json_decode($data);
         if ($list == null) {
             throw new \Exception($data);
         }
         foreach ($list as $array) {
             $msg = Jamp::unserializeArray($array);
             $responses[] = $msg;
         }
     }
     return $responses;
 }
Пример #2
0
 public function query(QueryMessage $msg)
 {
     if ($this->curl === null) {
         throw new \Exception('connection already closed');
     }
     $url = $msg->toUrl($this->url);
     $curl = $this->curl;
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     /*
     $msg = $request->msg;
     
     $json = $msg->serialize();
     $json = '[' . $json . ']';
     
     $curl = curl_init($this->url);
     curl_setopt($curl, CURLOPT_POST, true);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: x-application/jamp-push'));
     curl_setopt($curl, CURLOPT_POSTFIELDS, array($json));
     */
     $json = curl_exec($curl);
     if ($json === false) {
         throw new \Exception('error submitting message: ' . curl_error($curl));
     }
     $response = \json_decode($json);
     if (!isset($response->status)) {
         throw new \Exception('status not found in response: ' . $json);
     } else {
         if ($response->status != 'ok') {
             $error = $json;
             //if (isset($response->error)) {
             //  $error = $response->error;
             //}
             throw new \Exception('error response: ' . $error);
         }
     }
     $value = @$response->value;
     return $value;
 }
Пример #3
0
if (!$realmId) {
    exit("Please add realm to App.Config before running this sample.\n");
}
// Prep Service Context
$requestValidator = new OAuthRequestValidator(ConfigurationManager::AppSettings('AccessToken'), ConfigurationManager::AppSettings('AccessTokenSecret'), ConfigurationManager::AppSettings('ConsumerKey'), ConfigurationManager::AppSettings('ConsumerSecret'));
$serviceContext = new ServiceContext($realmId, $serviceType, $requestValidator);
if (!$serviceContext) {
    exit("Problem while initializing ServiceContext.\n");
}
// Prep Data Services
$dataService = new DataService($serviceContext);
if (!$dataService) {
    exit("Problem while initializing DataService.\n");
}
// Build a query
$oneQuery = new QueryMessage();
$oneQuery->sql = "SELECT";
$oneQuery->entity = "Customer";
$oneQuery->orderByClause = "FamilyName";
$oneQuery->startposition = "1";
$oneQuery->maxresults = "4";
// Run a query
$queryString = $oneQuery->getString();
$entities = $dataService->Query($queryString);
// Echo some formatted output
$i = 0;
if ($entities) {
    foreach ($entities as $oneCustomer) {
        echo "Customer[{$i}] GivenName: {$oneCustomer->GivenName}\t(Created at {$oneCustomer->MetaData->CreateTime})\n";
        $i++;
    }
Пример #4
0
 private function initQuery($service, $method, Result $result = null, array $args = null, array $headerMap = null)
 {
     $queryId = $this->queryCount++;
     $msg = new QueryMessage($headerMap, '/client', $queryId, $service, $method, $args);
     $listeners = $msg->getListeners();
     if ($listeners !== null) {
         foreach ($listeners as $address => $listener) {
             $this->listenerMap[$address] = $listener;
         }
     }
     if ($result !== null) {
         $this->resultMap[$queryId] = $result;
     }
     return $msg;
 }