/**
  * Retrieve a RPC message.
  *
  * @param   scriptlet.HttpScriptletResponse response
  * @return  scriptlet.rpc.AbstractRpcMessage
  */
 public function retrieve($response)
 {
     $this->cat && $this->cat->debug('<<<', $response->toString());
     $code = $response->getStatusCode();
     switch ($code) {
         case HttpConstants::STATUS_OK:
         case HttpConstants::STATUS_INTERNAL_SERVER_ERROR:
             $xml = '';
             while ($buf = $response->readData()) {
                 $xml .= $buf;
             }
             $this->cat && $this->cat->debug('<<<', $xml);
             $answer = JsonResponseMessage::fromString($xml);
             if ($answer) {
                 // Check encoding
                 if (NULL !== ($content_type = $response->getHeader('Content-Type'))) {
                     @(list($type, $charset) = explode('; charset=', $content_type));
                     if (!empty($charset)) {
                         $answer->setEncoding($charset);
                     }
                 }
             }
             // Fault?
             if (NULL !== ($fault = $answer->getFault())) {
                 throw new RpcFaultException($fault);
             }
             return $answer;
         case HttpConstants::STATUS_AUTHORIZATION_REQUIRED:
             throw new IllegalAccessException('Authorization required: ' . $response->getHeader('WWW-Authenticate'));
         default:
             throw new IllegalStateException('Unexpected return code: ' . $response->getStatusCode());
     }
 }
 public function multipleParameters()
 {
     $this->router->setMockData('{ "method" : "DummyRpcImplementation.checkMultipleParameters", "params" : [ "Lalala", 1, [ 12, "Egypt", false, -31 ], { "lowerBound" : 18, "upperBound" : 139 } ], "id" : 12 }');
     $this->router->init();
     $response = $this->router->process();
     $this->assertHasHeader($response->headers, 'Content-type: application/json; charset=utf-8');
     $this->assertEquals(200, $response->statusCode);
     $msg = JsonResponseMessage::fromString($response->getContent());
     $data = $msg->getData();
     $this->assertEquals('Lalala', (string) $data[0]);
     $this->assertEquals(1, $data[1]);
     $this->assertEquals(array(12, 'Egypt', FALSE, -31), $data[2]);
     $this->assertEquals(array('lowerBound' => 18, 'upperBound' => 139), $data[3]);
 }