* Building of the {@link ODataContext} takes place outside of this method.</p>
* @param request the incoming request
* @return the corresponding result
*/
public ODataResponse handle(final ODataRequest request) {
UriInfoImpl uriInfo = null;
Exception exception = null;
ODataResponse odataResponse;
final int timingHandle = context.startRuntimeMeasurement("ODataRequestHandler", "handle");
try {
UriParser uriParser = new UriParserImpl(service.getEntityDataModel());
Dispatcher dispatcher = new Dispatcher(serviceFactory, service);
final String serverDataServiceVersion = getServerDataServiceVersion();
final String requestDataServiceVersion = context.getRequestHeader(ODataHttpHeaders.DATASERVICEVERSION);
validateDataServiceVersion(serverDataServiceVersion, requestDataServiceVersion);
final List<PathSegment> pathSegments = context.getPathInfo().getODataSegments();
int timingHandle2 = context.startRuntimeMeasurement("UriParserImpl", "parse");
uriInfo = (UriInfoImpl) uriParser.parse(pathSegments, request.getQueryParameters());
context.stopRuntimeMeasurement(timingHandle2);
final ODataHttpMethod method = request.getMethod();
validateMethodAndUri(method, uriInfo);
if (method == ODataHttpMethod.POST || method == ODataHttpMethod.PUT || method == ODataHttpMethod.PATCH
|| method == ODataHttpMethod.MERGE) {
checkRequestContentType(uriInfo, request.getContentType());
}
List<String> supportedContentTypes = getSupportedContentTypes(uriInfo, method);
ContentType acceptContentType =
new ContentNegotiator().doContentNegotiation(request, uriInfo, supportedContentTypes);
checkConditions(method, uriInfo,
context.getRequestHeader(HttpHeaders.IF_MATCH),
context.getRequestHeader(HttpHeaders.IF_NONE_MATCH),
context.getRequestHeader(HttpHeaders.IF_MODIFIED_SINCE),
context.getRequestHeader(HttpHeaders.IF_UNMODIFIED_SINCE));
timingHandle2 = context.startRuntimeMeasurement("Dispatcher", "dispatch");
odataResponse =
dispatcher.dispatch(method, uriInfo, request.getBody(), request.getContentType(), acceptContentType
.toContentTypeString());
context.stopRuntimeMeasurement(timingHandle2);
ODataResponseBuilder extendedResponse = ODataResponse.fromResponse(odataResponse);
final UriType uriType = uriInfo.getUriType();
final String location =
(method == ODataHttpMethod.POST && (uriType == UriType.URI1 || uriType == UriType.URI6B)) ? odataResponse
.getIdLiteral() : null;
final HttpStatusCodes s = getStatusCode(odataResponse, method, uriType);
extendedResponse = extendedResponse.idLiteral(location).status(s);