@Override public int score(ODataRequestContext requestContext, QueryResult data) { if (data == null || data.getType() == NOTHING || data.getType() != EXCEPTION) { return DEFAULT_SCORE; } // Try the types that should be allowed according to the OData specification // See: OData JSON Format Version 4.0, chapter 19: Error Response List<MediaType> accept = requestContext.getRequest().getAccept(); int jsonAcceptScore = scoreByMediaType(accept, JSON); int contentTypeScore = scoreByContentType(requestContext, JSON); int resultScore = max(jsonAcceptScore, contentTypeScore); return resultScore > 0 ? (resultScore + ERROR_EXTRA_SCORE) : DEFAULT_SCORE; }
@Override public int score(ODataRequestContext requestContext, QueryResult data) { // Try scoring against the $format query parameter int formatScore = scoreByFormat(getFormatOption(requestContext.getUri()), JSON); // Try the types that should be allowed according to the OData specification // See: OData Atom Format Version 4.0, chapter 3: Requesting the Atom Format List<MediaType> accept = requestContext.getRequest().getAccept(); int acceptScore = scoreByMediaType(accept, JSON); int totalScore = Math.max(formatScore, acceptScore); if (isRequestedContentTypeSupported(requestContext)) { totalScore = Math.max(totalScore, scoreByContentType(requestContext, JSON)); } LOG.debug("Renderer score is {}", totalScore); return totalScore > 0 ? totalScore : DEFAULT_SCORE; } }
@Override public int score(ODataRequestContext requestContext, QueryResult data) { if (data == null || data.getType() == NOTHING || data.getType() != EXCEPTION) { return DEFAULT_SCORE; } // Try the types that should be allowed according to the OData specification // See: OData JSON Format Version 4.0, chapter 19: Error Response List<MediaType> accept = requestContext.getRequest().getAccept(); int jsonAcceptScore = scoreByMediaType(accept, JSON); int contentTypeScore = scoreByContentType(requestContext, JSON); int resultScore = max(jsonAcceptScore, contentTypeScore); return resultScore > 0 ? (resultScore + ERROR_EXTRA_SCORE) : DEFAULT_SCORE; }
@Override public int score(ODataRequestContext requestContext, QueryResult data) { // Try scoring against the $format query parameter int formatScore = scoreByFormat(getFormatOption(requestContext.getUri()), JSON); // Try the types that should be allowed according to the OData specification // See: OData Atom Format Version 4.0, chapter 3: Requesting the Atom Format List<MediaType> accept = requestContext.getRequest().getAccept(); int acceptScore = scoreByMediaType(accept, JSON); int totalScore = Math.max(formatScore, acceptScore); if (isRequestedContentTypeSupported(requestContext)) { totalScore = Math.max(totalScore, scoreByContentType(requestContext, JSON)); } LOG.debug("Renderer score is {}", totalScore); return totalScore > 0 ? totalScore : DEFAULT_SCORE; } }
@Override public int score(ODataRequestContext requestContext, QueryResult data) { if (data == null || data.getType() == NOTHING || data.getType() != EXCEPTION) { return DEFAULT_SCORE; } // Try the types that should be allowed according to the OData specification // See: OData Atom Format Version 4.0, chapter 19: Error Response List<MediaType> accept = requestContext.getRequest().getAccept(); // Accept header score calculation int atomXmlAcceptScore = scoreByMediaType(accept, ATOM_XML); int xmlAcceptScore = scoreByMediaType(accept, XML); int totalAcceptScore = max(atomXmlAcceptScore, xmlAcceptScore); // Content type score calculation int xmlContentTypeScore = scoreByContentType(requestContext, XML); int atomXmlContentTypeScore = scoreByContentType(requestContext, ATOM_XML); int totalContentTypeScore = max(xmlContentTypeScore, atomXmlContentTypeScore); int totalScore = max(totalAcceptScore, totalContentTypeScore); // This is very ugly but if you want to default to XML then score should be little more in case of wildcard if (totalScore == WILDCARD_MATCH_SCORE || totalScore == DEFAULT_SCORE) { totalScore += PRIORITY_SCORE; } return totalScore > 0 ? (totalScore + ERROR_EXTRA_SCORE) : DEFAULT_SCORE; }
@Override public int score(ODataRequestContext requestContext, QueryResult data) { if (data == null || data.getType() == NOTHING || data.getType() != EXCEPTION) { return DEFAULT_SCORE; } // Try the types that should be allowed according to the OData specification // See: OData Atom Format Version 4.0, chapter 19: Error Response List<MediaType> accept = requestContext.getRequest().getAccept(); // Accept header score calculation int atomXmlAcceptScore = scoreByMediaType(accept, ATOM_XML); int xmlAcceptScore = scoreByMediaType(accept, XML); int totalAcceptScore = max(atomXmlAcceptScore, xmlAcceptScore); // Content type score calculation int xmlContentTypeScore = scoreByContentType(requestContext, XML); int atomXmlContentTypeScore = scoreByContentType(requestContext, ATOM_XML); int totalContentTypeScore = max(xmlContentTypeScore, atomXmlContentTypeScore); int totalScore = max(totalAcceptScore, totalContentTypeScore); // This is very ugly but if you want to default to XML then score should be little more in case of wildcard if (totalScore == WILDCARD_MATCH_SCORE || totalScore == DEFAULT_SCORE) { totalScore += PRIORITY_SCORE; } return totalScore > 0 ? (totalScore + ERROR_EXTRA_SCORE) : DEFAULT_SCORE; }
@Override public int score(ODataRequestContext requestContext, QueryResult data) { // Try scoring against the $format query parameter int atomXmlFormatScore = scoreByFormat(getFormatOption(requestContext.getUri()), ATOM_XML); int xmlFormatScore = scoreByFormat(getFormatOption(requestContext.getUri()), XML); // Try the types that should be allowed according to the OData specification // See: OData Atom Format Version 4.0, chapter 3: Requesting the Atom Format List<MediaType> accept = requestContext.getRequest().getAccept(); int atomXmlAcceptScore = scoreByMediaType(accept, ATOM_XML); int xmlAcceptScore = scoreByMediaType(accept, XML); int totalScore = max(atomXmlFormatScore, max(xmlFormatScore, max(atomXmlAcceptScore, xmlAcceptScore))); // accept header or format option not specified and content type is specified then // response should be rendered based on content type (either json or xml). if (isRequestedContentTypeSupported(requestContext)) { totalScore = max(totalScore, scoreByContentType(requestContext, ATOM_XML)); } else { if (totalScore == WILDCARD_MATCH_SCORE || totalScore == DEFAULT_SCORE) { return DEFAULT_XML_RENDER_SCORE; } } return totalScore > 0 ? totalScore : DEFAULT_SCORE; } }
@Override public int score(ODataRequestContext requestContext, QueryResult data) { // Try scoring against the $format query parameter int atomXmlFormatScore = scoreByFormat(getFormatOption(requestContext.getUri()), ATOM_XML); int xmlFormatScore = scoreByFormat(getFormatOption(requestContext.getUri()), XML); // Try the types that should be allowed according to the OData specification // See: OData Atom Format Version 4.0, chapter 3: Requesting the Atom Format List<MediaType> accept = requestContext.getRequest().getAccept(); int atomXmlAcceptScore = scoreByMediaType(accept, ATOM_XML); int xmlAcceptScore = scoreByMediaType(accept, XML); int totalScore = max(atomXmlFormatScore, max(xmlFormatScore, max(atomXmlAcceptScore, xmlAcceptScore))); // accept header or format option not specified and content type is specified then // response should be rendered based on content type (either json or xml). if (isRequestedContentTypeSupported(requestContext)) { totalScore = max(totalScore, scoreByContentType(requestContext, ATOM_XML)); } else { if (totalScore == WILDCARD_MATCH_SCORE || totalScore == DEFAULT_SCORE) { return DEFAULT_XML_RENDER_SCORE; } } return totalScore > 0 ? totalScore : DEFAULT_SCORE; } }
/** * Calculate a score for a 'Service Document Renderer' based on * a given OData request context and required media type. * * @param requestContext The given OData request context. * @param requiredMediaType The required media type. * @return The calculated score. */ protected int scoreServiceDocument(ODataRequestContext requestContext, MediaType requiredMediaType) { if (isServiceDocument(requestContext.getUri())) { int scoreByFormat = scoreByFormat(getFormatOption(requestContext.getUri()), requiredMediaType); int scoreByMediaType = scoreByMediaType(requestContext.getRequest().getAccept(), requiredMediaType); return max(scoreByFormat, scoreByMediaType); } else { return DEFAULT_SCORE; } } }
/** * Calculate a score for a 'Service Document Renderer' based on * a given OData request context and required media type. * * @param requestContext The given OData request context. * @param requiredMediaType The required media type. * @return The calculated score. */ protected int scoreServiceDocument(ODataRequestContext requestContext, MediaType requiredMediaType) { if (isServiceDocument(requestContext.getUri())) { int scoreByFormat = scoreByFormat(getFormatOption(requestContext.getUri()), requiredMediaType); int scoreByMediaType = scoreByMediaType(requestContext.getRequest().getAccept(), requiredMediaType); return max(scoreByFormat, scoreByMediaType); } else { return DEFAULT_SCORE; } } }
/** * Batch score mechanism exists not only for simple rendering, but also * for computing batch error scores. * * @param requestContext The request context. * @param data The data to render. * @return batch score */ @Override public int score(ODataRequestContext requestContext, QueryResult data) { if (data.getType() == QueryResult.ResultType.NOTHING || data.getType() != QueryResult.ResultType.EXCEPTION) { return DEFAULT_SCORE; } if (data.getData() instanceof ODataBatchException) { return MAXIMUM_FORMAT_SCORE; } List<MediaType> accept = requestContext.getRequest().getAccept(); int batchAcceptScore = scoreByMediaType(accept, MediaType.MULTIPART); int contentTypeScore = scoreByContentType(requestContext, MULTIPART); int resultScore = max(batchAcceptScore, contentTypeScore); return resultScore > 0 ? (resultScore + ERROR_EXTRA_SCORE) : DEFAULT_SCORE; }
/** * Batch score mechanism exists not only for simple rendering, but also * for computing batch error scores. * * @param requestContext The request context. * @param data The data to render. * @return batch score */ @Override public int score(ODataRequestContext requestContext, QueryResult data) { if (data.getType() == QueryResult.ResultType.NOTHING || data.getType() != QueryResult.ResultType.EXCEPTION) { return DEFAULT_SCORE; } if (data.getData() instanceof ODataBatchException) { return MAXIMUM_FORMAT_SCORE; } List<MediaType> accept = requestContext.getRequest().getAccept(); int batchAcceptScore = scoreByMediaType(accept, MediaType.MULTIPART); int contentTypeScore = scoreByContentType(requestContext, MULTIPART); int resultScore = max(batchAcceptScore, contentTypeScore); return resultScore > 0 ? (resultScore + ERROR_EXTRA_SCORE) : DEFAULT_SCORE; }