use of javax.ws.rs.ext.ExceptionMapper in project cxf by apache.
the class ProviderFactoryTest method testRegisterFeatureInFeature.
@Test
public void testRegisterFeatureInFeature() {
ServerProviderFactory pf = ServerProviderFactory.getInstance();
final Object provider = new WebApplicationExceptionMapper();
pf.registerUserProvider((Feature) context -> {
context.register((Feature) context2 -> {
context2.register(provider);
return true;
});
return true;
});
ExceptionMapper<WebApplicationException> em = pf.createExceptionMapper(WebApplicationException.class, new MessageImpl());
assertSame(provider, em);
}
use of javax.ws.rs.ext.ExceptionMapper in project minijax by minijax.
the class MinijaxApplication method toResponse.
@SuppressWarnings({ "unchecked", "rawtypes" })
private Response toResponse(final MinijaxRequestContext context, final Exception ex) {
final MinijaxResourceMethod rm = context.getResourceMethod();
final List<MediaType> mediaTypes;
if (rm != null) {
mediaTypes = rm.getProduces();
} else {
mediaTypes = context.getAcceptableMediaTypes();
}
for (final MediaType mediaType : mediaTypes) {
final ExceptionMapper mapper = providers.getExceptionMapper(ex.getClass(), mediaType);
if (mapper != null) {
return mapper.toResponse(ex);
}
}
return ExceptionUtils.toWebAppException(ex).getResponse();
}
use of javax.ws.rs.ext.ExceptionMapper in project tomee by apache.
the class EJBExceptionMapper method toResponse.
@Override
public Response toResponse(final EJBException ejbException) {
final Exception cause = ejbException.getCausedByException();
if (cause != null) {
final Class causeClass = cause.getClass();
final ExceptionMapper exceptionMapper = providers.getExceptionMapper(causeClass);
if (exceptionMapper == null) {
return defaultResponse(cause);
}
return exceptionMapper.toResponse(cause);
} else if (EJBAccessException.class.isInstance(ejbException)) {
return Response.status(Response.Status.FORBIDDEN).build();
}
return defaultResponse(ejbException);
}
use of javax.ws.rs.ext.ExceptionMapper in project cxf by apache.
the class ProviderFactoryTest method testRegisterInFeature.
@Test
public void testRegisterInFeature() {
ServerProviderFactory pf = ServerProviderFactory.getInstance();
final Object provider = new WebApplicationExceptionMapper();
pf.registerUserProvider((Feature) context -> {
context.register(provider);
return true;
});
ExceptionMapper<WebApplicationException> em = pf.createExceptionMapper(WebApplicationException.class, new MessageImpl());
assertSame(provider, em);
}
Aggregations