@Test public void testExtendedODataErrorContext() throws Exception { MultivaluedMap<String, String> value = new MultivaluedHashMap<String, String>(); value.putSingle("Accept", "AcceptValue"); value.put("AcceptMulti", Arrays.asList("AcceptValue_1", "AcceptValue_2")); when(exceptionMapper.httpHeaders.getRequestHeaders()).thenReturn(value); when(exceptionMapper.servletConfig.getInitParameter(ODataServiceFactory.FACTORY_LABEL)).thenReturn( ODataServiceFactoryWithCallbackImpl.class.getName()); when(exceptionMapper.servletRequest.getAttribute(ODataServiceFactory.FACTORY_CLASSLOADER_LABEL)).thenReturn(null); Response response = exceptionMapper.toResponse(new Exception()); assertNotNull(response); assertEquals(HttpStatusCodes.BAD_REQUEST.getStatusCode(), response.getStatus()); String errorMessage = (String) response.getEntity(); assertEquals("bla", errorMessage); String contentTypeHeader = response.getHeaderString(org.apache.olingo.odata2.api.commons.HttpHeaders.CONTENT_TYPE); assertEquals("text/html", contentTypeHeader); assertEquals(uri.toASCIIString(), response.getHeaderString("RequestUri")); assertEquals("[AcceptValue]", response.getHeaderString("Accept")); assertEquals("[AcceptValue_1, AcceptValue_2]", response.getHeaderString("AcceptMulti")); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }  }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }  @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }  @Override Response toResponse(final Exception exception);  }