示例#1
0
 /**
  * Handle
  *
  * @param string $calling_component_filename Filename
  * @param string $service_description        Service description
  *
  * @return mixed
  */
 public function handle($calling_component_filename, $service_description)
 {
     SCA::$logger->log("Entering");
     try {
         $smd_filename = str_replace('.php', '.smd', $calling_component_filename);
         if (!file_exists($smd_filename)) {
             file_put_contents($smd_filename, SCA_GenerateSmd::generateSmd($service_description));
             //                    ,self::generateSMD($calling_component_filename)
             //                   );
         }
         $wsdl_filename = null;
         // create a wrapper, which in turn creates a service
         // instance and fills in all of the references
         $class_name = SCA_Helper::guessClassName($calling_component_filename);
         $instance = SCA::createInstance($class_name);
         $service_wrapper = new SCA_ServiceWrapperJson($instance, $class_name, $wsdl_filename);
         // create the jsonrpc server that will process the input message
         // and generate the result message
         $jsonrpc_server = new SCA_JsonRpcServer($service_wrapper);
         $jsonrpc_server->handle();
     } catch (Exception $ex) {
         // A catch all exception just in case something drastic goes wrong
         // This can often be the case in constructors of the JSON infsatructure
         // classes where SMD files can be read over remote connections. We
         // still want to send a sensible error back to the client
         // TODO extend the JSON service to expose this kind of function
         //      through public methods
         $response = "{\"id\":\"";
         $response = $response . SCA_JsonRpcServer::getRequest()->id;
         $response = $response . "\",\"error\":\"" . $ex->getMessage();
         $response = $response . "\",\"version\":\"1.0\"}";
         // TODO what to do about id? We can catch errors before the
         //      input is parsed
         // some debugging
         //                file_put_contents("json_messages.txt",
         //                "Response at JSONRPC server = " . $response . "\n",
         //                FILE_APPEND);
         header('Content-type: application/json-rpc');
         echo $response;
     }
     return;
 }
示例#2
0
文件: JsonRpcTest.php 项目: psagi/sdo
 /**
  * make it look to the component as if it is receiving  
  * a request for a method invocation and check the response 
  * is correct
  */
 public function testWrapperAndProxy()
 {
     $_SERVER['HTTP_HOST'] = 'localhost';
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $_SERVER['SCRIPT_FILENAME'] = 'TestService.php';
     $_SERVER['REQUEST_URI'] = 'http://localhost/TestService.php';
     $_SERVER['CONTENT_TYPE'] = 'application/json-rpc';
     SCA_JsonRpcServer::$test_request = $this->request;
     SCA_JsonRpcClient::$store_test_request = true;
     SCA_JsonRpcClient::$test_response = $this->email_response;
     ob_start();
     SCA::initComponent("TestService.php");
     $out = ob_get_contents();
     ob_end_clean();
     $this->assertContains($this->response, $out);
     $this->assertContains(SCA_JsonRpcClient::$test_request, $this->email_request);
 }