}
return oDataResponse;
}
private ODataErrorContext createErrorContext(final WebApplicationException exception) {
ODataErrorContext context = new ODataErrorContext();
if (uriInfo != null) {
context.setRequestUri(uriInfo.getRequestUri());
}
if (httpHeaders != null && httpHeaders.getRequestHeaders() != null) {
MultivaluedMap<String, String> requestHeaders = httpHeaders.getRequestHeaders();
Set<Entry<String, List<String>>> entries = requestHeaders.entrySet();
for (Entry<String, List<String>> entry : entries) {
context.putRequestHeader(entry.getKey(), entry.getValue());
}
}
context.setContentType(getContentType().toContentTypeString());
context.setException(exception);
context.setErrorCode(null);
context.setMessage(exception.getMessage());
context.setLocale(DEFAULT_RESPONSE_LOCALE);
HttpStatusCodes statusCode = HttpStatusCodes.fromStatusCode(exception.getResponse().getStatus());
context.setHttpStatus(statusCode);
if (statusCode == HttpStatusCodes.METHOD_NOT_ALLOWED) {
// RFC 2616, 5.1.1: " An origin server SHOULD return the status code
// 405 (Method Not Allowed) if the method is known by the origin server
// but not allowed for the requested resource, and 501 (Not Implemented)
// if the method is unrecognized or not implemented by the origin server."
// Since all recognized methods are handled elsewhere, we unconditionally
// switch to 501 here for not-allowed exceptions thrown directly from
// JAX-RS implementations.
context.setHttpStatus(HttpStatusCodes.NOT_IMPLEMENTED);
context.setMessage("The request dispatcher does not allow the HTTP method used for the request.");
context.setLocale(Locale.ENGLISH);
}
return context;
}