@NotNull private String readContentType(Response response) throws WebApplicationException { String contentType = null; List<Object> contentTypes = response.getHeaders().get("Content-Type"); if (contentTypes != null && !contentTypes.isEmpty()) { contentType = String.valueOf(contentTypes.get(0)); } if (contentType == null) { String msg = "Missing Content-Type in response"; //throw new WebApplicationException(msg, 500); throw new BadResponseServiceException( new RestFaultInfo("BadResponse", Blame.SERVER, msg, ""+ErrorCodes.Server.BAD_RESPONSE.getCode(), null, Retry.no(), Retry.no(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase() ) ); } return contentType; }
@NotNull @Override public Exception translate(@NotNull Throwable t) throws Exception { SoapFaultInfo faultInfo = extractFaultInfo(t); switch (faultInfo.getFaultCause()) { case "BadRequest": throw new BadRequestServiceException(faultInfo); case "AccessDenied": throw new AccessDeniedServiceException(faultInfo); case "Protocol": throw new ProtocolServiceException(faultInfo); case "InternalServerError": throw new InternalServerErrorServiceException(faultInfo); case "ServiceTemporarilyUnavailable": throw new ServiceTemporarilyUnavailableServiceException(faultInfo); case "BadResponse": throw new BadResponseServiceException(faultInfo); default: throw new UnsupportedOperationException("Unhandled case: "+faultInfo.getFaultCause()+"!"); } }
return new ServiceTemporarilyUnavailableServiceException(faultInfo); case "BadResponse": return new BadResponseServiceException(faultInfo);
throw new ServiceTemporarilyUnavailableServiceException(faultInfo); case "BadResponse": throw new BadResponseServiceException(faultInfo); default: Blame.assertSize(4);
String msg = "Client requested content type >>>"+ACCEPT+"<<< but server sent >>>\"" + contentType + "\">>> and that is not supported for type: " + returnType.getType(); throw new BadResponseServiceException( new RestFaultInfo("BadResponse", Blame.SERVER, msg, ""+ErrorCodes.Server.BAD_RESPONSE.getCode(),