Java Code Examples for org.apache.olingo.odata2.api.ep.EntityProvider#writeErrorDocument()

The following examples show how to use org.apache.olingo.odata2.api.ep.EntityProvider#writeErrorDocument() . 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: SimpleODataErrorCallback.java    From cloud-sfsf-benefits-ext with Apache License 2.0 6 votes vote down vote up
@Override
public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException {
	Throwable rootCause = context.getException();
	LOGGER.error("Error in the OData. Reason: " + rootCause.getMessage(), rootCause); //$NON-NLS-1$

	Throwable innerCause = rootCause.getCause();
	if (rootCause instanceof ODataJPAException && innerCause != null && innerCause instanceof AppODataException) {
		context.setMessage(innerCause.getMessage());
		Throwable childInnerCause = innerCause.getCause();
		context.setInnerError(childInnerCause != null ? childInnerCause.getMessage() : ""); //$NON-NLS-1$
	} else {
		context.setMessage(HttpStatusCodes.INTERNAL_SERVER_ERROR.getInfo());
		context.setInnerError(rootCause.getMessage());
	}

	context.setHttpStatus(HttpStatusCodes.INTERNAL_SERVER_ERROR);
	return EntityProvider.writeErrorDocument(context);
}
 
Example 2
Source File: AnnotationRefServiceFactory.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException {
  if (context.getHttpStatus() == HttpStatusCodes.INTERNAL_SERVER_ERROR) {
    LOG.error("Internal Server Error", context.getException());
  }

  return EntityProvider.writeErrorDocument(context);
}
 
Example 3
Source File: ODataJPAErrorCallback.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException {

  final String SEPARATOR = " : ";

  Throwable t = context.getException();
  if (t instanceof ODataJPAException && t.getCause() != null) {
    StringBuilder errorBuilder = new StringBuilder();
    errorBuilder.append(t.getCause().getClass().toString());
    errorBuilder.append(SEPARATOR);
    errorBuilder.append(t.getCause().getMessage());
    context.setInnerError(errorBuilder.toString());
  }
  return EntityProvider.writeErrorDocument(context);
}
 
Example 4
Source File: ODataExceptionWrapper.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
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;
  }
}
 
Example 5
Source File: ODataExceptionWrapper.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
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;
  }
}
 
Example 6
Source File: XmlErrorProducerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void viaRuntimeDelegate() throws Exception {
  ODataErrorContext context = new ODataErrorContext();
  context.setContentType(contentType);
  context.setHttpStatus(expectedStatus);
  context.setErrorCode(null);
  context.setMessage(null);
  context.setLocale(null);
  context.setInnerError(null);
  ODataResponse response = EntityProvider.writeErrorDocument(context);
  String errorXml = verifyResponse(response);
  verifyXml(null, null, null, null, errorXml);

  context.setErrorCode("a");
  context.setMessage("a");
  context.setLocale(Locale.GERMAN);
  context.setInnerError("a");
  response = EntityProvider.writeErrorDocument(context);
  errorXml = verifyResponse(response);
  verifyXml("a", "a", Locale.GERMAN, "a", errorXml);

  context.setErrorCode(null);
  context.setInnerError(null);
  response = EntityProvider.writeErrorDocument(context);
  errorXml = verifyResponse(response);
  verifyXml(null, "a", Locale.GERMAN, null, errorXml);
}
 
Example 7
Source File: ScenarioErrorCallback.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException {
  if (context.getHttpStatus() == HttpStatusCodes.INTERNAL_SERVER_ERROR) {
    LOG.error("Internal Server Error", context.getException());
  }

  return EntityProvider.writeErrorDocument(context);
}
 
Example 8
Source File: FitErrorCallback.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException {
  if (context.getHttpStatus() == HttpStatusCodes.INTERNAL_SERVER_ERROR) {
    LOG.error("Internal Server Error", context.getException());
  }
  return EntityProvider.writeErrorDocument(context);
}
 
Example 9
Source File: AnnotationSampleServiceFactory.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException {
  if (context.getHttpStatus() == HttpStatusCodes.INTERNAL_SERVER_ERROR) {
    LOG.error("Internal Server Error", context.getException());
  }

  return EntityProvider.writeErrorDocument(context);
}