예제 #1
0
파일: Wrapper.php 프로젝트: psagi/sdo
 /**
  * Class constructor
  *
  * @param string $class_name Class name
  * @param string $handler    Handler
  */
 public function __construct($class_name, $handler)
 {
     SCA::$logger->log('Entering');
     SCA::$logger->log("class name = {$class_name}");
     $this->class_name = $class_name;
     $this->xmldas = $handler->getXmlDas();
     $this->instance_of_the_base_class = SCA::createInstance($class_name);
     SCA::fillInReferences($this->instance_of_the_base_class);
     SCA::$logger->log('Exiting');
 }
예제 #2
0
파일: Wrapper.php 프로젝트: psagi/sdo
 public function __construct($class_name, $service_description, $mapper)
 {
     SCA::$logger->log('Entering');
     SCA::$logger->log("class name = {$class_name}");
     $this->mapper = $mapper;
     $this->service_description = $service_description;
     $this->instance_of_the_base_class = SCA::createInstance($class_name);
     SCA::fillInReferences($this->instance_of_the_base_class);
     SCA::$logger->log('Exiting');
 }
예제 #3
0
 /**
  * Create the service wrapper for a SCA Component. In the event that the
  * mapping of the SCA Component methods the base_class and xmldas types are
  * set to null.
  *
  * @param string $class_name Class name
  */
 public function __construct($class_name)
 {
     SCA::$logger->log("Entering constructor");
     SCA::$logger->log("class_name = {$class_name}");
     $this->class_name = $class_name;
     $this->instance_of_the_base_class = SCA::createInstance($class_name);
     SCA::fillInReferences($this->instance_of_the_base_class);
     //need an xmldas
     //want to have the xsds in here. do xmldas only here then do add types.
     $this->xml_das = self::getXmldasForAtom($class_name, "");
     SCA::$logger->log("Exiting Constructor");
 }
예제 #4
0
파일: Wrapper.php 프로젝트: psagi/sdo
 /**
  * Create the service wrapper for an SCA Component. In the event that the
  * mapping of the SCA Component methods the base_class and xmldas types are
  * set to null.
  *
  * @param string $class_name Class name
  */
 public function __construct($class_name)
 {
     //TODO: get rid of the wsdl filename here
     SCA::$logger->log("Entering constructor");
     SCA::$logger->log("class_name = {$class_name}");
     $this->class_name = $class_name;
     $this->class_instance = SCA::createInstance($class_name);
     SCA::fillInReferences($this->class_instance);
     //need an xmldas
     //want to have the xsds in here. do xmldas only here then do add types.
     $this->xml_das = SCA_Helper::getXmldas($class_name, "");
     SCA::$logger->log("Exiting Constructor");
 }
예제 #5
0
파일: Wrapper.php 프로젝트: psagi/sdo
 /**
  * Create the service wrapper for an SCA Component. In the event that the
  * mapping of the SCA Component methods the base_class and xmldas types are
  * set to null.
  *
  * @param string $class_name Class name
  */
 public function __construct($class_name)
 {
     //TODO: get rid of the wsdl filename here
     SCA::$logger->log("Entering constructor");
     SCA::$logger->log("class_name = {$class_name}");
     $this->class_name = $class_name;
     $this->class_instance = SCA::createInstance($class_name);
     SCA::fillInReferences($this->class_instance);
     // Get an xmldas to handle the SDOs passing in and
     // out of the wrapped service. This call creates the das
     // and adds all of the service types to it.
     $this->xml_das = SCA_Helper::getXmldas($class_name, "");
     SCA::$logger->log("Exiting Constructor");
 }
예제 #6
0
 /**
  * Create the service wrapper for a SCA Component. In the event that the mapping
  * of the SCA Component methods the base_class and xmldas types are set to
  * null.
  *
  * @param string $class_name
  * @param string $wsdl_filename
  */
 public function __construct($instance, $class_name, $wsdl_filename)
 {
     SCA::$logger->log("Entering");
     $this->class_name = $class_name;
     $this->instance_of_the_base_class = $instance;
     SCA::fillInReferences($this->instance_of_the_base_class);
     // create a JSON DAS and populate it with the valid types
     // that this service can create. Not strinctly required
     // for json encoding but the JSON Server uses this
     // DAS for decoding
     $xsds = SCA_Helper::getAllXsds($class_name);
     $this->json_das = new SDO_DAS_Json();
     foreach ($xsds as $index => $xsds) {
         list($namespace, $xsdfile) = $xsds;
         if (SCA_Helper::isARelativePath($xsdfile)) {
             $xsd = SCA_Helper::constructAbsolutePath($xsdfile, $class_name);
             $this->json_das->addTypesXsdFile($xsd);
         }
     }
 }
예제 #7
0
파일: Wrapper.php 프로젝트: psagi/sdo
 /**
  * Create the service wrapper for a SCA Component.
  *
  * @param object $instance      Instance
  * @param string $class_name    Class
  * @param string $wsdl_filename WSDL
  */
 public function __construct($instance, $class_name, $wsdl_filename)
 {
     SCA::$logger->log("Wrapper {$class_name}");
     $this->class_name = $class_name;
     $this->instance_of_the_base_class = $instance;
     SCA::fillInReferences($this->instance_of_the_base_class);
     $this->annotations = new SCA_AnnotationReader($this->instance_of_the_base_class);
     // create an XML-RPC DAS and populate it with the valid types
     // that this service can create.
     $xsds = SCA_Helper::getAllXsds($class_name);
     $this->xmlrpc_das = new SCA_Bindings_Xmlrpc_DAS();
     foreach ($xsds as $index => $xsds) {
         list($namespace, $xsdfile) = $xsds;
         if (SCA_Helper::isARelativePath($xsdfile)) {
             $xsd = SCA_Helper::constructAbsolutePath($xsdfile, $class_name);
             $this->xmlrpc_das->addTypesXsdFile($xsd);
         }
     }
     $this->xmlrpc_server = xmlrpc_server_create();
     $service_description = $this->annotations->reflectService();
     $serviceDescGen = new SCA_Bindings_Xmlrpc_ServiceDescriptionGenerator();
     $serviceDescGen->addIntrospectionData($this->xmlrpc_server, $service_description, $this->method_aliases, $this->xmlrpc_das);
 }
예제 #8
0
파일: Proxy.php 프로젝트: psagi/sdo
 /**
  * Invoke the method name in the target service.
  *
  * @param string $method_name Method
  * @param array  $arguments   Arguments
  *
  * @return mixed
  */
 public function __call($method_name, $arguments)
 {
     if ($this->instance_of_the_component === null) {
         $this->instance_of_the_component = SCA::createInstance($this->component_class_name);
         SCA::fillInReferences($this->instance_of_the_component);
     }
     if (SCA_Helper::checkMethods($method_name, $this->instance_of_the_component)) {
         $arguments_by_value_array = array();
         foreach ($arguments as $arg) {
             $arguments_by_value_array[] = is_object($arg) ? clone $arg : $arg;
         }
         $return = call_user_func_array(array(&$this->instance_of_the_component, $method_name), $arguments_by_value_array);
     } else {
         $classname = get_class($this->instance_of_the_component);
         $msg = "Method '{$method_name}' not found in class {$classname}";
         throw new SCA_RuntimeException($msg);
     }
     return $return;
 }
예제 #9
0
 /**
  * Handle
  *
  * @param string $calling_component_filename Filename
  *
  * @return null
  */
 public function handle($calling_component_filename)
 {
     SCA::$logger->log("Entering");
     $actions = array('POST' => array('create', 1), 'GET' => array('retrieve', 1), 'PUT' => array('update', 2), 'DELETE' => array('delete', 1));
     if (array_key_exists($_SERVER['REQUEST_METHOD'], $actions)) {
         $methodWithNumberOfParams = $actions[$_SERVER['REQUEST_METHOD']];
         $method = $methodWithNumberOfParams[0];
     } else {
         //TODO find out correct response
         header("HTTP/1.1 404 ");
         echo $_SERVER['REQUEST_METHOD'] . " Not Supported.";
         return;
     }
     //*handle situations where we have the id in the url.*/
     /**
     These look like the variables to use:
        [REQUEST_URI] => /Samples/RSS/Contact.php/12
        [SCRIPT_NAME] => /Samples/RSS/Contact.php
        [PATH_INFO] => /12
     */
     /*
      * Note, if the PATH_INFO is not working, and you are using Apache 2.0,
      * check the AcceptPathInfo directive for php files.
      * See http://httpd.apache.org/docs/2.0/mod/core.html#acceptpathinfo
      */
     //Set $id - works for non-selector style, but not for selector style.
     if (isset($_SERVER['PATH_INFO'])) {
         $param = $_SERVER['PATH_INFO'];
         //test different length of param
         //$param = "/344656";
         //TODO: is there a case where there will not be a slash in [PATH_INFO]?
         //strip slash
         $lengthOfParam = strlen($param);
         $id = substr($param, 1, $lengthOfParam);
     } else {
         if (isset($_GET['id'])) {
             $id = $_GET['id'];
             //left so that our rewrite test still works
         } else {
             $id = null;
         }
     }
     try {
         //always give the component an sdo, but handle sdo or xml back from it.
         if ($method === 'create') {
             SCA::$logger->log("{$method} == create");
             // Can only do GET (retrieve) on RSS
             // return http method not allowed status
             header("HTTP/1.1 405");
         } else {
             if ($method === 'retrieve') {
                 $call_response = null;
                 try {
                     if ($id === null) {
                         $method = 'enumerate';
                     }
                     SCA::$logger->log("Calling {$method} on the RSS service wrapper, passing in the id {$id}");
                     $class_name = SCA_Helper::guessClassName($calling_component_filename);
                     $service_component = SCA::createInstance($class_name);
                     SCA::fillInReferences($service_component);
                     $call_response = call_user_func_array(array(&$service_component, $method), $id);
                     SCA::$logger->log("Response from calling the method {$method} is: {$call_response}");
                     //TODO: make sure these tests reflect the correct return values.
                     if ($call_response !== null) {
                         $response_xml;
                         // Handle the different types of response (SDO, PHP Class, Raw XML)
                         if ($call_response instanceof SDO_DataObjectImpl) {
                             //if the thing received is an sdo...
                             //convert it to xml
                             $response_xml = SCA_Bindings_Rss_RssDas::toXml($call_response);
                         } else {
                             if ($call_response instanceof Channel) {
                                 // TODO: write the mapping from php classes to XML...
                                 SCA::$logger->log("TODO: write the mapping from php rss classes to xml.");
                                 $response_xml = null;
                             } else {
                                 if (is_string($call_response)) {
                                     $response_xml = $call_response;
                                 }
                             }
                         }
                         header("HTTP/1.1 200");
                         header("Content-Type: application/xml");
                         echo $response_xml;
                     } else {
                         SCA::$logger->log("Caught call_response is null exception in RSSServer");
                         //TODO find out the right response
                         header("HTTP/1.1 500");
                         //echo "The requested resource <em>$id</em> does not exist on this database";
                     }
                 } catch (SCA_ServiceUnavailableException $ex) {
                     header("HTTP/1.1 503");
                 } catch (SCA_ConflictException $ex) {
                     header("HTTP/1.1 409");
                 } catch (SCA_AuthenticationException $ex) {
                     header("HTTP/1.1 407");
                 } catch (SCA_BadRequestException $ex) {
                     header("HTTP/1.1 400");
                 } catch (SCA_InternalServerErrorException $ex) {
                     SCA::$logger->log("Caught SCA_InternalServerErrorException in RSSServer");
                     header("HTTP/1.1 500");
                 } catch (SCA_MethodNotAllowedException $ex) {
                     //note  - this one is more likely to be thrown by the server code than the component code.
                     header("HTTP/1.1 405");
                 } catch (SCA_UnauthorizedException $ex) {
                     header("HTTP/1.1 401");
                 } catch (SCA_RuntimeException $ex) {
                     SCA::$logger->log("Caught SCA_RuntimeException in RSSServer\n");
                     header("HTTP/1.1 500");
                 } catch (Exception $ex) {
                     SCA::$logger->log("Caught an exception in RSSServer: " . $ex->getMessage() . "\n");
                     $call_response['error'] = $ex->getMessage();
                     //TODO find out the right response
                     header("HTTP/1.1 500");
                 }
             } else {
                 if ($method === 'update') {
                     // Can only do GET (retrieve) on RSS
                     // return http method not allowed status
                     header("HTTP/1.1 405");
                 } else {
                     if ($method === 'delete') {
                         // Can only do GET (retrieve) on RSS
                         // return http method not allowed status
                         header("HTTP/1.1 405");
                     }
                 }
             }
         }
     } catch (SCA_MethodNotAllowedException $ex) {
         //catch problem finding the method encountered by the service wrapper.
         header("HTTP/1.1 405");
     } catch (SCA_RuntimeException $ex) {
         //TODO: output exceptions correctly.
         header("HTTP/1.1 500");
     }
     return;
 }