return cls == null ? defaultExceptionType : cls;
}
@SuppressWarnings("unchecked")
public static <T extends Throwable> Response convertFaultToResponse(T ex, Message inMessage) {
ProviderFactory factory = ProviderFactory.getInstance(inMessage);
ExceptionMapper<T> mapper = factory.createExceptionMapper(ex, inMessage);
if (mapper != null) {
if (ex.getClass() == WebApplicationException.class
&& mapper.getClass() != WebApplicationExceptionMapper.class) {
WebApplicationException webEx = (WebApplicationException)ex;
Class<?> exceptionClass = getWebApplicationExceptionClass(webEx.getResponse(),
WebApplicationException.class);
if (exceptionClass != WebApplicationException.class) {
try {
Constructor<?> ctr = exceptionClass.getConstructor(Response.class);
ex = (T)ctr.newInstance(webEx.getResponse());
} catch (Exception ex2) {
ex2.printStackTrace();
return Response.serverError().build();
}
}
}
try {
return mapper.toResponse(ex);
} catch (Exception mapperEx) {
mapperEx.printStackTrace();
return Response.serverError().build();
} finally {
factory.clearExceptionMapperProxies();
}
}
return null;