Exemplo n.º 1
0
 /**
  * @todo add support for options to be set to the xmlrpc client
  * @todo on the other hand, the list of allowed xmlrpc server with options might be stored in settings, just like ggwebservices does...
  *
  * @param array $body
  * @return mixed
  * @throws \UnexpectedValueException
  */
 public function consume($body)
 {
     // validate members in $body
     if (!is_array($body) || empty($body['server']) || empty($body['method']) || isset($body['arguments']) && !is_array($body['arguments'])) {
         throw new \UnexpectedValueException("Message format unsupported. Received: " . json_encode($body));
     }
     $label = trim(ConsumerCommand::getLabel());
     if ($label != '') {
         $label = " '{$label}'";
     }
     if ($this->logger) {
         $this->logger->debug("XMLRPC call will be executed from MessageConsumer{$label}: " . $body['method'] . " on server: " . $body['server']);
     }
     $encoder = new XE();
     $args = array();
     foreach ($body['arguments'] as $val) {
         $args[] = $encoder->encode($val);
     }
     $client = new XC($body['server']);
     $response = $client->send(new XR($body['method'], $args));
     if ($response->faultCode() != 0 && $this->logger) {
         $this->logger->error("XMLRPC call executed from MessageConsumer{$label} failed. Retcode: " . $response->faultCode() . ", Error message: '" . $response->faultString() . "'", array());
     }
     return $response->faultCode() == 0 ? $encoder->decode($response->value()) : null;
 }
Exemplo n.º 2
0
 /**
  * Perform request to wubook api
  *
  * @param $method
  * @param $args                array, NOTICE: order is important here
  * @param bool $passToken      true if you want pass token as first parameter
  * @param bool $passPropertyId true if you want pass property id as second parameter
  * @param bool $tryAcquireNewToken
  *
  * @return mixed|Value|string
  * @internal param bool|true $useToken true if you want use token from config
  */
 public function request($method, array $args, $passToken = true, $passPropertyId = true, $tryAcquireNewToken = true)
 {
     if (!in_array($method, $this->methodWhitelist)) {
         throw new MethodNotAllowedException($this->methodWhitelist, 'Method "' . $method . '" not allowed, allowed: ' . join(', ', $this->methodWhitelist));
     }
     $requestArgs = $passToken ? [$this->tokenProvider->getToken()] : [];
     if ($passPropertyId) {
         $requestArgs[] = (string) $this->propertyId;
     }
     $encoder = new Encoder();
     $requestData = [];
     foreach (array_merge($requestArgs, $args) as $arg) {
         $requestData[] = $encoder->encode($arg);
     }
     $server = new \PhpXmlRpc\Client($this->apiUrl);
     $request = new Request($method, $requestData);
     $response = $server->send($request);
     $isResponseOK = !empty($response->value()) && (int) $response->value()->me['array'][0]->scalarval() == 0;
     if (!$isResponseOK && $tryAcquireNewToken) {
         if ($this->tokenHandler->isCurrentTokenValid()) {
             return $response;
         }
         $this->tokenHandler->acquireToken();
         return self::request($method, $args, $passToken, $passPropertyId, false);
     }
     return $response;
 }
Exemplo n.º 3
0
 /**
  * Simple wrapper to Encoder class
  * @param Response $response
  *
  * @return array
  */
 public static function decodeResponse(Response $response)
 {
     $resValue = $response->value();
     if (!empty($response) && is_object($resValue)) {
         $encoder = new Encoder();
         return $encoder->decode($resValue);
     }
     //otherwise return some default error
     return [-111, 'Undefined error (invalid response)'];
 }
Exemplo n.º 4
0
for ($i = 0; $i < $num_tests; $i++) {
    $response = $dummy->ParseResponse($in, true, 'phpvals');
    $value = $response->value();
}
end_test('Data decoding (large array)', 'automatic decoding', $value);
if (function_exists('xmlrpc_decode')) {
    begin_test('Data decoding (large array)', 'xmlrpc-epi decoding');
    for ($i = 0; $i < $num_tests; $i++) {
        $response = $dummy->ParseResponse($in, true, 'xml');
        $value = xmlrpc_decode($response->value());
    }
    end_test('Data decoding (large array)', 'xmlrpc-epi decoding', $value);
}
if (!$xd) {
    /// test multicall vs. many calls vs. keep-alives
    $encoder = new Encoder();
    $value = $encoder->encode($data1, array('auto_dates'));
    $req = new Request('interopEchoTests.echoValue', array($value));
    $reqs = array();
    for ($i = 0; $i < 25; $i++) {
        $reqs[] = $req;
    }
    $server = explode(':', $args['LOCALSERVER']);
    if (count($server) > 1) {
        $srv = $server[1] . '://' . $server[0] . $args['URI'];
        $c = new Client($args['URI'], $server[0], $server[1]);
    } else {
        $srv = $args['LOCALSERVER'] . $args['URI'];
        $c = new Client($args['URI'], $args['LOCALSERVER']);
    }
    // do not interfere with http compression
Exemplo n.º 5
0
 public static function _xmlrpcs_getCapabilities($server, $req = null)
 {
     $encoder = new Encoder();
     return new Response($encoder->encode($server->getCapabilities()));
 }