Ejemplo n.º 1
0
Archivo: RssDas.php Proyecto: psagi/sdo
 /**
  * Get DAS
  *
  * @return object
  */
 public static function getXmlDas()
 {
     if (is_null(self::$xmldas)) {
         self::$xmldas = SDO_DAS_XML::create(dirname(__FILE__) . '/rss2.0.xsd');
     }
     return self::$xmldas;
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
Archivo: Proxy.php Proyecto: psagi/sdo
 /**
  * Enumerate
  *
  * @return SDO
  */
 public function enumerate()
 {
     SCA::$logger->log("Entering enumerate()");
     //TODO these should all be building a setopts array not sending a lot.
     $handle = curl_init($this->target);
     curl_setopt($handle, CURLOPT_HEADER, false);
     curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($handle, CURLOPT_HTTPGET, true);
     curl_setopt($handle, CURLOPT_ENCODING, '');
     curl_setopt($handle, CURLOPT_HEADERFUNCTION, array($this, '_headerCallback'));
     $result = curl_exec($handle);
     $response_http_code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
     SCA::$logger->log("Http response code: {$response_http_code}");
     curl_close($handle);
     //convert the result into an sdo.
     $sdo = SCA_Bindings_Rss_RssDas::fromXml($result);
     //TODO: confirm the correct response code for retrieve.
     if ($response_http_code != 200) {
         switch ($response_http_code) {
             // Temporary redirects
             case 302:
             case 307:
                 // FOLLOWLOCATION is on, so we should not get here
                 throw new SCA_RuntimeException('enumerate() status code ' . $response_http_code . ' when 200 expected');
             case 503:
                 //TODO: pick out the message from the response if there is one
                 //for now just pass back a one liner.
                 throw new SCA_ServiceUnavailableException("Service Unavailable");
             case 409:
                 throw new SCA_ConflictException("Conflict");
             case 407:
                 throw new SCA_AuthenticationException("Authentication Required");
             case 400:
                 throw new SCA_BadRequestException("Bad Request");
             case 500:
                 throw new SCA_InternalServerErrorException("Internal Server Error");
             case 405:
                 throw new SCA_MethodNotAllowedException("Method Not Allowed");
             case 401:
                 throw new SCA_UnauthorizedException("Unauthorized");
             default:
                 throw new SCA_RuntimeException('enumerate() status code ' . $response_http_code . ' when 200 expected');
         }
     } else {
         return $sdo;
     }
 }