@SuppressWarnings("deprecation") public static <T> Response copyResponseAndClose(Response source, Class<T> type) { int status = -1; Headers<Object> headers = new Headers<Object>(); Object entity = null; try { status = source.getStatus(); if (source instanceof org.jboss.resteasy.client.core.BaseClientResponse) headers.putAll(((org.jboss.resteasy.client.core.BaseClientResponse<?>)source).getMetadata()); if (source instanceof org.jboss.resteasy.client.ClientResponse) { entity = ((org.jboss.resteasy.client.ClientResponse<?>)source).getEntity(type); } else { entity = source.getEntity(); } return new BuiltResponsePreservingError(status, headers, entity, new Annotation[0], null); } catch (Exception e) { Exceptions.propagateIfFatal(e); return new BuiltResponsePreservingError(status, headers, entity, new Annotation[0], e); } finally { if (source instanceof org.jboss.resteasy.client.core.BaseClientResponse) ((org.jboss.resteasy.client.core.BaseClientResponse<?>)source).close(); } }