private ODataResponse handleException(final Exception exception) { ODataExceptionWrapper exceptionWrapper = new ODataExceptionWrapper(uriInfo, httpHeaders, getErrorHandlerCallback()); ODataResponse oDataResponse = exceptionWrapper.wrapInExceptionResponse(exception); return oDataResponse; }
private ODataResponse handleErrorCallback(final ODataErrorCallback callback) throws EntityProviderException { ODataResponse oDataResponse; try { oDataResponse = callback.handleError(errorContext); } catch (ODataApplicationException e) { fillErrorContext(e); enhanceContextWithApplicationException(e); oDataResponse = new ProviderFacadeImpl().writeErrorDocument(errorContext); } return oDataResponse; }
private ContentType getContentType(final Map<String, String> queryParameters, final List<String> acceptHeaderContentTypes) { ContentType cntType = getContentTypeByUriInfo(queryParameters); if (cntType == null) { cntType = getContentTypeByAcceptHeader(acceptHeaderContentTypes); } return cntType; }
public ODataResponse wrapInExceptionResponse(final Exception exception) { try { final Exception toHandleException = extractException(exception); fillErrorContext(toHandleException); if (toHandleException instanceof ODataApplicationException) { enhanceContextWithApplicationException((ODataApplicationException) toHandleException); } else if (toHandleException instanceof ODataRuntimeApplicationException) { enhanceContextWithRuntimeApplicationException((ODataRuntimeApplicationException) toHandleException); } else if (toHandleException instanceof ODataMessageException) { enhanceContextWithMessageException((ODataMessageException) toHandleException); } ODataResponse oDataResponse; if (callback != null) { oDataResponse = handleErrorCallback(callback); } else { oDataResponse = EntityProvider.writeErrorDocument(errorContext); } if (!oDataResponse.containsHeader(org.apache.olingo.odata2.api.commons.HttpHeaders.CONTENT_TYPE)) { oDataResponse = ODataResponse.fromResponse(oDataResponse).contentHeader(contentType).build(); } return oDataResponse; } catch (Exception e) { ODataResponse response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); return response; } }
public ODataExceptionWrapper(final ODataContext context, final Map<String, String> queryParameters, final List<String> acceptHeaderContentTypes) { contentType = getContentType(queryParameters, acceptHeaderContentTypes).toContentTypeString(); messageLocale = MessageService.getSupportedLocale(getLanguages(context), DEFAULT_RESPONSE_LOCALE); httpRequestHeaders = context.getRequestHeaders(); try { requestUri = context.getPathInfo().getRequestUri(); errorContext.setPathInfo(context.getPathInfo()); callback = getErrorHandlerCallbackFromContext(context); } catch (Exception e) { throw new ODataRuntimeException("Exception occurred", e); } }
public ODataExceptionWrapper(final UriInfo uriInfo, final HttpHeaders httpHeaders, final ODataErrorCallback errorCallback) { contentType = getContentType(uriInfo, httpHeaders).toContentTypeString(); messageLocale = MessageService.getSupportedLocale(getLanguages(httpHeaders), DEFAULT_RESPONSE_LOCALE); httpRequestHeaders = httpHeaders.getRequestHeaders(); requestUri = uriInfo.getRequestUri(); callback = errorCallback; }
private void enhanceContextWithMessageException(final ODataMessageException toHandleException) { errorContext.setErrorCode(toHandleException.getErrorCode()); MessageReference messageReference = toHandleException.getMessageReference(); Message localizedMessage = messageReference == null ? null : extractEntity(messageReference); if (localizedMessage != null) { errorContext.setMessage(localizedMessage.getText()); errorContext.setLocale(localizedMessage.getLocale()); } if (toHandleException instanceof ODataHttpException) { errorContext.setHttpStatus(((ODataHttpException) toHandleException).getHttpStatus()); } else if (toHandleException instanceof EntityProviderException) { errorContext.setHttpStatus(HttpStatusCodes.BAD_REQUEST); } else if (toHandleException instanceof BatchException) { errorContext.setHttpStatus(HttpStatusCodes.BAD_REQUEST); } }
public ODataResponse wrapInExceptionResponse(final Exception exception) { try { final Exception toHandleException = extractException(exception); fillErrorContext(toHandleException); if (toHandleException instanceof ODataApplicationException) { enhanceContextWithApplicationException((ODataApplicationException) toHandleException); } else if (toHandleException instanceof ODataRuntimeApplicationException) { enhanceContextWithRuntimeApplicationException((ODataRuntimeApplicationException) toHandleException); } else if (toHandleException instanceof ODataMessageException) { enhanceContextWithMessageException((ODataMessageException) toHandleException); } ODataResponse oDataResponse; if (callback != null) { oDataResponse = handleErrorCallback(callback); } else { oDataResponse = EntityProvider.writeErrorDocument(errorContext); } if (!oDataResponse.containsHeader(org.apache.olingo.odata2.api.commons.HttpHeaders.CONTENT_TYPE)) { oDataResponse = ODataResponse.fromResponse(oDataResponse).contentHeader(contentType).build(); } return oDataResponse; } catch (Exception e) { ODataResponse response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); return response; } }
public ODataExceptionWrapper(final ODataContext context, final Map<String, String> queryParameters, final List<String> acceptHeaderContentTypes) { contentType = getContentType(queryParameters, acceptHeaderContentTypes).toContentTypeString(); messageLocale = MessageService.getSupportedLocale(getLanguages(context), DEFAULT_RESPONSE_LOCALE); httpRequestHeaders = context.getRequestHeaders(); try { requestUri = context.getPathInfo().getRequestUri(); errorContext.setPathInfo(context.getPathInfo()); callback = getErrorHandlerCallbackFromContext(context); } catch (Exception e) { throw new ODataRuntimeException("Exception occurred", e); } }
public ODataExceptionWrapper(final UriInfo uriInfo, final HttpHeaders httpHeaders, final ODataErrorCallback errorCallback) { try { contentType = getContentType(uriInfo, httpHeaders).toContentTypeString(); requestUri = uriInfo != null ? uriInfo.getRequestUri() : null; } catch (IllegalArgumentException e) { contentType = null; requestUri = null; } messageLocale = MessageService.getSupportedLocale(getLanguages(httpHeaders), DEFAULT_RESPONSE_LOCALE); httpRequestHeaders = httpHeaders.getRequestHeaders(); callback = errorCallback; }
private void enhanceContextWithMessageException(final ODataMessageException toHandleException) { errorContext.setErrorCode(toHandleException.getErrorCode()); MessageReference messageReference = toHandleException.getMessageReference(); Message localizedMessage = messageReference == null ? null : extractEntity(messageReference); if (localizedMessage != null) { errorContext.setMessage(localizedMessage.getText()); errorContext.setLocale(localizedMessage.getLocale()); } if (toHandleException instanceof ODataHttpException) { errorContext.setHttpStatus(((ODataHttpException) toHandleException).getHttpStatus()); } else if (toHandleException instanceof EntityProviderException) { if(toHandleException instanceof EntityProviderProducerException){ /* * As per OLINGO-763 serializer exceptions are produced by the server and must therefore result * in a 500 internal server error */ errorContext.setHttpStatus(HttpStatusCodes.INTERNAL_SERVER_ERROR); }else{ errorContext.setHttpStatus(HttpStatusCodes.BAD_REQUEST); } } else if (toHandleException instanceof BatchException) { errorContext.setHttpStatus(HttpStatusCodes.BAD_REQUEST); } }
public ODataResponse wrapInExceptionResponse(final Exception exception) { try { final Exception toHandleException = extractException(exception); fillErrorContext(toHandleException); if (toHandleException instanceof ODataApplicationException) { enhanceContextWithApplicationException((ODataApplicationException) toHandleException); } else if (toHandleException instanceof ODataMessageException) { enhanceContextWithMessageException((ODataMessageException) toHandleException); } ODataResponse oDataResponse; if (callback != null) { oDataResponse = handleErrorCallback(callback); } else { oDataResponse = EntityProvider.writeErrorDocument(errorContext); } if (!oDataResponse.containsHeader(org.apache.olingo.odata2.api.commons.HttpHeaders.CONTENT_TYPE)) { oDataResponse = ODataResponse.fromResponse(oDataResponse).contentHeader(contentType).build(); } return oDataResponse; } catch (Exception e) { ODataResponse response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); return response; } }
private ODataResponse handleException(final Exception exception) { ODataExceptionWrapper exceptionWrapper = new ODataExceptionWrapper(uriInfo, httpHeaders, getErrorHandlerCallback()); return exceptionWrapper.wrapInExceptionResponse(exception); }
public ODataExceptionWrapper(final ODataContext context, final Map<String, String> queryParameters, final List<String> acceptHeaderContentTypes) { contentType = getContentType(queryParameters, acceptHeaderContentTypes).toContentTypeString(); messageLocale = MessageService.getSupportedLocale(getLanguages(context), DEFAULT_RESPONSE_LOCALE); httpRequestHeaders = context.getRequestHeaders(); try { requestUri = context.getPathInfo().getRequestUri(); errorContext.setPathInfo(context.getPathInfo()); callback = getErrorHandlerCallbackFromContext(context); } catch (Exception e) { throw new ODataRuntimeException("Exception occurred", e); } }
private ContentType getContentType(final UriInfo uriInfo, final HttpHeaders httpHeaders) { ContentType cntType = getContentTypeByUriInfo(uriInfo); if (cntType == null) { cntType = getContentTypeByAcceptHeader(httpHeaders); } return cntType; }
private ODataResponse handleErrorCallback(final ODataErrorCallback callback) throws EntityProviderException { ODataResponse oDataResponse; try { oDataResponse = callback.handleError(errorContext); } catch (ODataApplicationException e) { fillErrorContext(e); enhanceContextWithApplicationException(e); oDataResponse = new ProviderFacadeImpl().writeErrorDocument(errorContext); } return oDataResponse; }
public ODataExceptionWrapper(final UriInfo uriInfo, final HttpHeaders httpHeaders, final ODataErrorCallback errorCallback) { try { contentType = getContentType(uriInfo, httpHeaders).toContentTypeString(); requestUri = uriInfo != null ? uriInfo.getRequestUri() : null; } catch (IllegalArgumentException e) { contentType = null; requestUri = null; } messageLocale = MessageService.getSupportedLocale(getLanguages(httpHeaders), DEFAULT_RESPONSE_LOCALE); httpRequestHeaders = httpHeaders.getRequestHeaders(); callback = errorCallback; }
private void enhanceContextWithMessageException(final ODataMessageException toHandleException) { errorContext.setErrorCode(toHandleException.getErrorCode()); MessageReference messageReference = toHandleException.getMessageReference(); Message localizedMessage = messageReference == null ? null : extractEntity(messageReference); if (localizedMessage != null) { errorContext.setMessage(localizedMessage.getText()); errorContext.setLocale(localizedMessage.getLocale()); } if (toHandleException instanceof ODataHttpException) { errorContext.setHttpStatus(((ODataHttpException) toHandleException).getHttpStatus()); } else if (toHandleException instanceof EntityProviderException) { if(toHandleException instanceof EntityProviderProducerException){ /* * As per OLINGO-763 serializer exceptions are produced by the server and must therefore result * in a 500 internal server error */ errorContext.setHttpStatus(HttpStatusCodes.INTERNAL_SERVER_ERROR); }else{ errorContext.setHttpStatus(HttpStatusCodes.BAD_REQUEST); } } else if (toHandleException instanceof BatchException) { errorContext.setHttpStatus(HttpStatusCodes.BAD_REQUEST); } }
private ODataResponse handleException(final Exception exception) { ODataExceptionWrapper exceptionWrapper = new ODataExceptionWrapper(uriInfo, httpHeaders, getErrorHandlerCallback()); return exceptionWrapper.wrapInExceptionResponse(exception); }
private ContentType getContentType(final Map<String, String> queryParameters, final List<String> acceptHeaderContentTypes) { ContentType cntType = getContentTypeByUriInfo(queryParameters); if (cntType == null) { cntType = getContentTypeByAcceptHeader(acceptHeaderContentTypes); } return cntType; }