示例#1
0
 /**
  * Process the $expand and $select option and update the request description.
  * 
  * @return void
  * 
  * @throws ODataException Throws bad request error in the following cases
  *                          (1) If $expand or select cannot be applied to the
  *                              requested resource.
  *                          (2) If projection is disabled by the developer
  *                          (3) If some error occurs while parsing the options
  */
 private function _processExpandAndSelect()
 {
     $expand = $this->_dataService->getHost()->getQueryStringItem(ODataConstants::HTTPQUERY_STRING_EXPAND);
     if (!is_null($expand)) {
         $this->_checkExpandOrSelectApplicable(ODataConstants::HTTPQUERY_STRING_EXPAND);
     }
     $select = $this->_dataService->getHost()->getQueryStringItem(ODataConstants::HTTPQUERY_STRING_SELECT);
     if (!is_null($select)) {
         if (!$this->_dataService->getServiceConfiguration()->getAcceptProjectionRequests()) {
             ODataException::createBadRequestError(Messages::dataServiceConfigurationProjectionsNotAccepted());
         }
         $this->_checkExpandOrSelectApplicable(ODataConstants::HTTPQUERY_STRING_SELECT);
     }
     // We will generate RootProjectionNode in case of $link request also, but
     // expand and select in this case must be null (we are ensuring this above)
     // 'RootProjectionNode' is required while generating next page Link
     if ($this->_expandSelectApplicable || $this->_requestDescription->isLinkUri()) {
         try {
             $rootProjectionNode = ExpandProjectionParser::parseExpandAndSelectClause($this->_requestDescription->getTargetResourceSetWrapper(), $this->_requestDescription->getTargetResourceType(), $this->_requestDescription->getInternalOrderByInfo(), $this->_requestDescription->getSkipCount(), $this->_requestDescription->getTopCount(), $expand, $select, $this->_dataService->getMetadataQueryProviderWrapper());
             if ($rootProjectionNode->isSelectionSpecified()) {
                 $this->_requestDescription->raiseMinimumVersionRequirement(2, 0, $this->_dataService);
             }
             if ($rootProjectionNode->hasPagedExpandedResult()) {
                 $this->_requestDescription->raiseResponseVersion(2, 0, $this->_dataService);
             }
             $this->_requestDescription->setRootProjectionNode($rootProjectionNode);
         } catch (ODataException $odataException) {
             throw $odataException;
         }
     }
 }
示例#2
0
 /**
  * Gets the response format for the requested resource.
  * 
  * @param RequestDescription &$requestDescription  The request submitted by 
  *                                                 client and it's execution 
  *                                                 result.
  * @param UriProcessor       &$uriProcessor        The reference to the 
  *                                                 UriProcessor.
  * @param DataService        &$dataService         Reference to the data 
  *                                                 service instance
  * @param string             &$responseContentType On Return, this will hold
  * the response content-type, a null value means the requested resource
  * is named stream and IDSSP2::getStreamContentType returned null.
  * 
  * @return ResponseFormat The format in which response needs to be serialized.
  * 
  * @throws ODataException, HttpHeaderFailure
  */
 public static function getResponseFormat(RequestDescription &$requestDescription, UriProcessor &$uriProcessor, DataService &$dataService, &$responseContentType)
 {
     // The Accept request-header field specifies media types which are
     // acceptable for the response
     $requestAcceptText = $dataService->getHost()->getRequestAccept();
     $responseFormat = ResponseFormat::UNSUPPORTED;
     $requestTargetKind = $requestDescription->getTargetKind();
     if ($requestDescription->isLinkUri()) {
         $requestTargetKind = RequestTargetKind::LINK;
     }
     if ($requestTargetKind == RequestTargetKind::METADATA) {
         $responseContentType = HttpProcessUtility::selectMimeType($requestAcceptText, array(ODataConstants::MIME_APPLICATION_XML));
         if (!is_null($responseContentType)) {
             $responseFormat = ResponseFormat::METADATA_DOCUMENT;
         }
     } else {
         if ($requestTargetKind == RequestTargetKind::SERVICE_DIRECTORY) {
             $responseContentType = HttpProcessUtility::selectMimeType($requestAcceptText, array(ODataConstants::MIME_APPLICATION_XML, ODataConstants::MIME_APPLICATION_ATOMSERVICE, ODataConstants::MIME_APPLICATION_JSON));
             if (!is_null($responseContentType)) {
                 $responseFormat = self::_getContentFormat($responseContentType);
             }
         } else {
             if ($requestTargetKind == RequestTargetKind::PRIMITIVE_VALUE) {
                 $supportedResponseMimeTypes = array(ODataConstants::MIME_TEXTPLAIN);
                 $responseFormat = ResponseFormat::TEXT;
                 if ($requestDescription->getIdentifier() != '$count') {
                     $projectedProperty = $requestDescription->getProjectedProperty();
                     self::assert(!is_null($projectedProperty), '!is_null($projectedProperty)');
                     $type = $projectedProperty->getInstanceType();
                     self::assert(!is_null($type) && array_search('ODataProducer\\Providers\\Metadata\\Type\\IType', class_implements($type)) !== false, '!is_null($type) && array_search(\'ODataProducer\\Providers\\Metadata\\Type\\IType\', class_implements($type)) !== false');
                     if ($type instanceof Binary) {
                         $supportedResponseMimeTypes = array(ODataConstants::MIME_APPLICATION_OCTETSTREAM);
                         $responseFormat = ResponseFormat::BINARY;
                     }
                 }
                 $responseContentType = HttpProcessUtility::selectMimeType($requestAcceptText, $supportedResponseMimeTypes);
                 if (is_null($responseContentType)) {
                     $responseFormat = ResponseFormat::UNSUPPORTED;
                 }
             } else {
                 if ($requestTargetKind == RequestTargetKind::PRIMITIVE || $requestTargetKind == RequestTargetKind::COMPLEX_OBJECT || $requestTargetKind == RequestTargetKind::BAG || $requestTargetKind == RequestTargetKind::LINK) {
                     $responseContentType = HttpProcessUtility::selectMimeType($requestAcceptText, array(ODataConstants::MIME_APPLICATION_XML, ODataConstants::MIME_TEXTXML, ODataConstants::MIME_APPLICATION_JSON));
                     if (!is_null($responseContentType)) {
                         $responseFormat = self::_getContentFormat($responseContentType);
                     }
                 } else {
                     if ($requestTargetKind == RequestTargetKind::RESOURCE) {
                         $responseContentType = HttpProcessUtility::selectMimeType($requestAcceptText, array(ODataConstants::MIME_APPLICATION_ATOM, ODataConstants::MIME_APPLICATION_JSON));
                         if (!is_null($responseContentType)) {
                             $responseFormat = self::_getContentFormat($responseContentType);
                         }
                     } else {
                         if ($requestTargetKind == RequestTargetKind::MEDIA_RESOURCE) {
                             $responseFormat = ResponseFormat::BINARY;
                             if ($requestDescription->isNamedStream() || $requestDescription->getTargetResourceType()->isMediaLinkEntry()) {
                                 $streamInfo = $requestDescription->getResourceStreamInfo();
                                 //Execute the query as we need media resource instance for
                                 //further processing
                                 $uriProcessor->execute();
                                 $requestDescription->setExecuted();
                                 // DSSW::getStreamContentType can throw error in 2 cases
                                 // 1. If the required stream implementation not found
                                 // 2. If IDSSP::getStreamContentType returns NULL for MLE
                                 $contentType = $dataService->getStreamProvider()->getStreamContentType($requestDescription->getTargetResult(), $streamInfo);
                                 if (!is_null($contentType)) {
                                     $responseContentType = HttpProcessUtility::selectMimeType($requestAcceptText, array($contentType));
                                     if (is_null($responseContentType)) {
                                         $responseFormat = ResponseFormat::UNSUPPORTED;
                                     }
                                 } else {
                                     // For NamedStream StreamWrapper::getStreamContentType
                                     // can return NULL if the requested named stream has not
                                     // yet been uploaded. But for an MLE if
                                     // IDSSP::getStreamContentType
                                     // returns NULL then StreamWrapper will throw error
                                     $responseContentType = null;
                                 }
                             } else {
                                 ODataException::createBadRequestError(Messages::badRequestInvalidUriForMediaResource($dataService->getHost()->getAbsoluteRequestUri()->getUrlAsString()));
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($responseFormat == ResponseFormat::UNSUPPORTED) {
         throw new ODataException(Messages::dataServiceExceptionUnsupportedMediaType(), 415);
     }
     return $responseFormat;
 }