/** * 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->service->getHost()->getQueryStringItem(ODataConstants::HTTPQUERY_STRING_EXPAND); if (!is_null($expand)) { $this->_checkExpandOrSelectApplicable(ODataConstants::HTTPQUERY_STRING_EXPAND); } $select = $this->service->getHost()->getQueryStringItem(ODataConstants::HTTPQUERY_STRING_SELECT); if (!is_null($select)) { if (!$this->service->getConfiguration()->getAcceptProjectionRequests()) { throw ODataException::createBadRequestError(Messages::configurationProjectionsNotAccepted()); } $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->request->isLinkUri()) { $rootProjectionNode = ExpandProjectionParser::parseExpandAndSelectClause($this->request->getTargetResourceSetWrapper(), $this->request->getTargetResourceType(), $this->request->getInternalOrderByInfo(), $this->request->getSkipCount(), $this->request->getTopCount(), $expand, $select, $this->service->getProvidersWrapper()); if ($rootProjectionNode->isSelectionSpecified()) { $this->request->raiseMinVersionRequirement(2, 0); } if ($rootProjectionNode->hasPagedExpandedResult()) { $this->request->raiseResponseVersion(2, 0); } $this->request->setRootProjectionNode($rootProjectionNode); } }
/** * Gets the response format for the requested resource. * * @param RequestDescription $request The request submitted by client and it's execution result. * @param UriProcessor $uriProcessor The reference to the UriProcessor. * @param IService $service Reference to the service implementation instance * * @return string the response content-type, a null value means the requested resource * is named stream and IDSSP2::getStreamContentType returned null * * @throws ODataException, HttpHeaderFailure */ public static function getResponseContentType(RequestDescription $request, UriProcessor $uriProcessor, IService $service) { // The Accept request-header field specifies media types which are acceptable for the response $host = $service->getHost(); $requestAcceptText = $host->getRequestAccept(); $requestVersion = $request->getResponseVersion(); //if the $format header is present it overrides the accepts header $format = $host->getQueryStringItem(ODataConstants::HTTPQUERY_STRING_FORMAT); if (!is_null($format)) { //There's a strange edge case..if application/json is supplied and it's V3 if ($format == MimeTypes::MIME_APPLICATION_JSON && $requestVersion == Version::v3()) { //then it's actual minimalmetadata //TODO: should this be done with the header text too? $format = MimeTypes::MIME_APPLICATION_JSON_MINIMAL_META; } $requestAcceptText = ServiceHost::translateFormatToMime($requestVersion, $format); } //The response format can be dictated by the target resource kind. IE a $value will be different then expected //getTargetKind doesn't deal with link resources directly and this can change things $targetKind = $request->isLinkUri() ? TargetKind::LINK() : $request->getTargetKind(); switch ($targetKind) { case TargetKind::METADATA(): return HttpProcessUtility::selectMimeType($requestAcceptText, array(MimeTypes::MIME_APPLICATION_XML)); case TargetKind::SERVICE_DIRECTORY(): return HttpProcessUtility::selectMimeType($requestAcceptText, array(MimeTypes::MIME_APPLICATION_XML, MimeTypes::MIME_APPLICATION_ATOMSERVICE, MimeTypes::MIME_APPLICATION_JSON, MimeTypes::MIME_APPLICATION_JSON_FULL_META, MimeTypes::MIME_APPLICATION_JSON_NO_META, MimeTypes::MIME_APPLICATION_JSON_MINIMAL_META, MimeTypes::MIME_APPLICATION_JSON_VERBOSE)); case TargetKind::PRIMITIVE_VALUE(): $supportedResponseMimeTypes = array(MimeTypes::MIME_TEXTPLAIN); if ($request->getIdentifier() != '$count') { $projectedProperty = $request->getProjectedProperty(); self::assert(!is_null($projectedProperty), '!is_null($projectedProperty)'); $type = $projectedProperty->getInstanceType(); self::assert(!is_null($type) && $type instanceof IType, '!is_null($type) && $type instanceof IType'); if ($type instanceof Binary) { $supportedResponseMimeTypes = array(MimeTypes::MIME_APPLICATION_OCTETSTREAM); } } return HttpProcessUtility::selectMimeType($requestAcceptText, $supportedResponseMimeTypes); case TargetKind::PRIMITIVE(): case TargetKind::COMPLEX_OBJECT(): case TargetKind::BAG(): case TargetKind::LINK(): return HttpProcessUtility::selectMimeType($requestAcceptText, array(MimeTypes::MIME_APPLICATION_XML, MimeTypes::MIME_TEXTXML, MimeTypes::MIME_APPLICATION_JSON, MimeTypes::MIME_APPLICATION_JSON_FULL_META, MimeTypes::MIME_APPLICATION_JSON_NO_META, MimeTypes::MIME_APPLICATION_JSON_MINIMAL_META, MimeTypes::MIME_APPLICATION_JSON_VERBOSE)); case TargetKind::RESOURCE(): return HttpProcessUtility::selectMimeType($requestAcceptText, array(MimeTypes::MIME_APPLICATION_ATOM, MimeTypes::MIME_APPLICATION_JSON, MimeTypes::MIME_APPLICATION_JSON_FULL_META, MimeTypes::MIME_APPLICATION_JSON_NO_META, MimeTypes::MIME_APPLICATION_JSON_MINIMAL_META, MimeTypes::MIME_APPLICATION_JSON_VERBOSE)); case TargetKind::MEDIA_RESOURCE(): if (!$request->isNamedStream() && !$request->getTargetResourceType()->isMediaLinkEntry()) { throw ODataException::createBadRequestError(Messages::badRequestInvalidUriForMediaResource($host->getAbsoluteRequestUri()->getUrlAsString())); } $uriProcessor->execute(); $request->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 $responseContentType = $service->getStreamProviderWrapper()->getStreamContentType($request->getTargetResult(), $request->getResourceStreamInfo()); // Note 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 if (!is_null($responseContentType)) { $responseContentType = HttpProcessUtility::selectMimeType($requestAcceptText, array($responseContentType)); } return $responseContentType; } //If we got here, we just don't know what it is... throw new ODataException(Messages::unsupportedMediaType(), 415); }