/** * Handles the possibility of an error found in the response. * * @param response * @throws Exception */ private <T> void handlePotentialServerError(ClientResponse<T> response) throws Exception { String contentType = String.valueOf(response.getMetadata().getFirst(HttpHeaderNames.CONTENT_TYPE)); if (response.getStatus() == 500) { Exception error = new Exception(Messages.i18n.format("UNKNOWN_SRAMP_ERROR")); // $NON-NLS-1$ if (MediaType.APPLICATION_SRAMP_ATOM_EXCEPTION.equals(contentType)) { try { SrampAtomException entity = response.getEntity(SrampAtomException.class); if (entity != null) error = entity; } catch (Throwable t) { t.printStackTrace(); } } throw error; } if (response.getStatus() == 404 || response.getStatus() == 415) { SrampAtomException error = new SrampAtomException(Messages.i18n.format("ENDPOINT_NOT_FOUND")); // $NON-NLS-1$ throw error; } if (response.getStatus() == 403) { SrampAtomException error = new SrampAtomException(Messages.i18n.format("AUTHORIZATION_FAILED")); // $NON-NLS-1$ throw error; } if (response.getStatus() == 401) { SrampAtomException error = new SrampAtomException(Messages.i18n.format("AUTHENTICATION_FAILED")); // $NON-NLS-1$ throw error; } }
private String extractId(ClientResponse<Response> res) { MultivaluedMap mvm = res.getMetadata(); String uri = (String) ((ArrayList) mvm.get("Location")).get(0); String[] segments = uri.split("/"); String id = segments[segments.length - 1]; verbose("id=" + id); return id; }