Java Code Examples for org.apache.olingo.odata2.api.exception.ODataMessageException#getMessageReference()

The following examples show how to use org.apache.olingo.odata2.api.exception.ODataMessageException#getMessageReference() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ODataExceptionWrapper.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
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);
  }

}
 
Example 2
Source File: ODataExceptionWrapper.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
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);
  }

}