org.apache.olingo.odata2.api.processor.ODataErrorCallback Java Examples

The following examples show how to use org.apache.olingo.odata2.api.processor.ODataErrorCallback. 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: JPAServiceFactory.java    From lemonaid with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T extends ODataCallback> T getCallback(final Class<T> callbackInterface) {
	if (setDetailErrors == true) {
		if (callbackInterface.isAssignableFrom(ODataErrorCallback.class)) {
			return (T) new ODataJPAErrorCallback();
		}
	}
	if (onJPAWriteContent != null) {
		if (callbackInterface.isAssignableFrom(OnJPAWriteContent.class)) {
			return (T) onJPAWriteContent;
		}
	}
	if (oDataJPATransaction != null) {
		if (callbackInterface.isAssignableFrom(ODataJPATransaction.class)) {
			return (T) oDataJPATransaction;
		}
	}
	return null;
}
 
Example #2
Source File: ODataJPAServiceFactory.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T extends ODataCallback> T getCallback(final Class<T> callbackInterface) {
  if (setDetailErrors == true) {
    if (callbackInterface.isAssignableFrom(ODataErrorCallback.class)) {
      return (T) new ODataJPAErrorCallback();
    }
  }
  if (onJPAWriteContent != null) {
    if (callbackInterface.isAssignableFrom(OnJPAWriteContent.class)) {
      return (T) onJPAWriteContent;
    }
  }
  if (oDataJPATransaction != null) {
    if (callbackInterface.isAssignableFrom(ODataJPATransaction.class)) {
      return (T) oDataJPATransaction;
    }
  }
  return null;
}
 
Example #3
Source File: ODataExceptionWrapper.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #4
Source File: ODataExceptionWrapper.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #5
Source File: ODataExceptionWrapper.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #6
Source File: ODataExceptionWrapper.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private ODataErrorCallback getErrorHandlerCallbackFromContext(final ODataContext context)
    throws ClassNotFoundException, InstantiationException, IllegalAccessException {
  ODataErrorCallback cback = null;
  ODataServiceFactory serviceFactory = context.getServiceFactory();
  cback = serviceFactory.getCallback(ODataErrorCallback.class);
  return cback;
}
 
Example #7
Source File: ODataExceptionMapperImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private ODataResponse handleWebApplicationException(final Exception exception) throws ClassNotFoundException,
    InstantiationException, IllegalAccessException, EntityProviderException {
  ODataErrorContext errorContext = createErrorContext((WebApplicationException) exception);
  ODataErrorCallback callback = getErrorHandlerCallback();
  return callback == null ?
      new ProviderFacadeImpl().writeErrorDocument(errorContext) : executeErrorCallback(errorContext, callback);
}
 
Example #8
Source File: ODataExceptionMapperImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private ODataResponse executeErrorCallback(final ODataErrorContext errorContext, final ODataErrorCallback callback) {
  ODataResponse oDataResponse;
  try {
    oDataResponse = callback.handleError(errorContext);
  } catch (ODataApplicationException e) {
    oDataResponse = handleException(e);
  }
  return oDataResponse;
}
 
Example #9
Source File: ODataExceptionWrapperTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testCallbackWithLocales1() throws Exception {
  UriInfo uriInfo = getMockedUriInfo();
  HttpHeaders httpHeaders = Mockito.mock(HttpHeaders.class);
  List<Locale> locales = new ArrayList<Locale>();
  locales.add(Locale.GERMANY);
  locales.add(Locale.FRANCE);
  when(httpHeaders.getAcceptableLanguages()).thenReturn(locales);
  
  ODataErrorCallback errorCallback = new ODataErrorCallback() {
    @Override
    public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException {
      assertEquals("de", context.getLocale().getLanguage());
      assertEquals("DE", context.getLocale().getCountry());
      return ODataResponse.entity("bla").status(HttpStatusCodes.BAD_REQUEST).contentHeader("text/html").build();
    }
  };

  ODataExceptionWrapper exceptionWrapper = createWrapper1(uriInfo, httpHeaders, errorCallback);
  ODataResponse response = exceptionWrapper.wrapInExceptionResponse(
      new ODataApplicationException("Error",Locale.GERMANY));

  // verify
  assertNotNull(response);
  assertEquals(HttpStatusCodes.BAD_REQUEST.getStatusCode(), response.getStatus().getStatusCode());
  String errorMessage = (String) response.getEntity();
  assertEquals("bla", errorMessage);
  String contentTypeHeader = response.getContentHeader();
  assertEquals("text/html", contentTypeHeader);
}
 
Example #10
Source File: ODataExceptionWrapperTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T extends ODataCallback> T getCallback(final Class<T> callbackInterface) {
  if (callbackInterface == ODataErrorCallback.class) {
    if (errorCallback == null) {
      return (T) new ODataErrorHandlerCallbackImpl();
    }
    return (T) errorCallback;
  }
  // only error callbacks are handled here
  return null;
}
 
Example #11
Source File: ODataServiceFactoryWithCallbackImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T extends ODataCallback> T getCallback(final Class<T> callbackInterface) {
  T callback = null;

  if (callbackInterface == ODataErrorCallback.class) {
    callback = (T) new ODataErrorHandlerCallbackImpl();
  }

  return callback;
}
 
Example #12
Source File: BenefitsODataServiceFactory.java    From cloud-sfsf-benefits-ext with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T extends ODataCallback> T getCallback(final Class<? extends ODataCallback> callbackInterface) {
	setDetailErrors(true);

	if (callbackInterface.isAssignableFrom(ODataErrorCallback.class)) {
		return (T) new SimpleODataErrorCallback();
	}
	return null;
}
 
Example #13
Source File: ODataExceptionMapperImpl.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private ODataErrorCallback getErrorHandlerCallback() {
  final ODataServiceFactory serviceFactory =
      ODataRootLocator.createServiceFactoryFromContext(app, servletRequest, servletConfig);
  return serviceFactory.getCallback(ODataErrorCallback.class);
}
 
Example #14
Source File: ODataExceptionWrapperTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private ODataExceptionWrapper createWrapper1(final UriInfo uriInfo,
    final HttpHeaders httpHeaders, ODataErrorCallback errorCallback) throws URISyntaxException {
  ODataExceptionWrapper exceptionWrapper = new ODataExceptionWrapper(uriInfo, httpHeaders, errorCallback);

  return exceptionWrapper;
}
 
Example #15
Source File: ODataExceptionWrapperTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
public MapperServiceFactory(final ODataErrorCallback callback) {
  errorCallback = callback;
}