@Test public void testGetNormalisedResponseMediaType_Header() { when(request.getHeader(MessageConstants.ACCEPT_HEADER)).thenReturn("application/xml"); MediaType mediaType = ctn.getNormalisedResponseMediaType(request); assertNotNull(mediaType); assertEquals(MediaType.APPLICATION_XML_TYPE, mediaType); }
@Override public MediaType getNormalisedResponseMediaType(HttpServletRequest request) { MediaType responseMediaType; String responseFormat = getResponseFormat(request); try { List<MediaType> acceptMT = MediaTypeUtils.parseMediaTypes(responseFormat); responseMediaType = MediaTypeUtils.getResponseMediaType(allContentTypes, acceptMT); if (responseMediaType == null) { throw new CougarValidationException(ServerFaultCode.AcceptTypeNotValid, "Could not agree a response media type"); } else if (responseMediaType.isWildcardType() || responseMediaType.isWildcardSubtype()) { throw new CougarServiceException(ServerFaultCode.ResponseContentTypeNotValid, "Service configuration error - response media type must not be a wildcard - " + responseMediaType); } } catch (IllegalArgumentException e) { throw new CougarValidationException(ServerFaultCode.MediaTypeParseFailure, "Unable to parse supplied media types (" + responseFormat + ")",e); } return responseMediaType; }
ContentTypeNormaliserImpl implements ContentTypeNormaliser { @Override public MediaType getNormalisedResponseMediaType(HttpServletRequest request) { MediaType responseMediaType; String responseFormat = getResponseFormat(request); try { List<MediaType> acceptMT = MediaTypeUtils.parseMediaTypes(responseFormat); responseMediaType = MediaTypeUtils.getResponseMediaType(allContentTypes, acceptMT); if (responseMediaType == null) { throw new CougarValidationException(ServerFaultCode.AcceptTypeNotValid, "Could not agree a response media type"); } else if (responseMediaType.isWildcardType() || responseMediaType.isWildcardSubtype()) { throw new CougarServiceException(ServerFaultCode.ResponseContentTypeNotValid, "Service configuration error - response media type must not be a wildcard - " + responseMediaType); } } catch (IllegalArgumentException e) { throw new CougarValidationException(ServerFaultCode.MediaTypeParseFailure, "Unable to parse supplied media types (" + responseFormat + ")",e); } return responseMediaType; } }
ContentTypeNormaliserImpl implements ContentTypeNormaliser { @Override public MediaType getNormalisedResponseMediaType(HttpServletRequest request) { MediaType responseMediaType; String responseFormat = getResponseFormat(request); try { List<MediaType> acceptMT = MediaTypeUtils.parseMediaTypes(responseFormat); responseMediaType = MediaTypeUtils.getResponseMediaType(allContentTypes, acceptMT); if (responseMediaType == null) { throw new CougarValidationException(ServerFaultCode.AcceptTypeNotValid, "Could not agree a response media type"); } else if (responseMediaType.isWildcardType() || responseMediaType.isWildcardSubtype()) { throw new CougarServiceException(ServerFaultCode.ResponseContentTypeNotValid, "Service configuration error - response media type must not be a wildcard - " + responseMediaType); } } catch (IllegalArgumentException e) { throw new CougarValidationException(ServerFaultCode.MediaTypeParseFailure, "Unable to parse supplied media types (" + responseFormat + ")",e); } return responseMediaType; }  }
ContentTypeNormaliserImpl implements ContentTypeNormaliser { @Override public MediaType getNormalisedResponseMediaType(HttpServletRequest request) { MediaType responseMediaType; String responseFormat = getResponseFormat(request); try { List<MediaType> acceptMT = MediaTypeUtils.parseMediaTypes(responseFormat); responseMediaType = MediaTypeUtils.getResponseMediaType(allContentTypes, acceptMT); if (responseMediaType == null) { throw new CougarValidationException(ServerFaultCode.AcceptTypeNotValid, "Could not agree a response media type"); } else if (responseMediaType.isWildcardType() || responseMediaType.isWildcardSubtype()) { throw new CougarServiceException(ServerFaultCode.ResponseContentTypeNotValid, "Service configuration error - response media type must not be a wildcard - " + responseMediaType); } } catch (IllegalArgumentException e) { throw new CougarValidationException(ServerFaultCode.MediaTypeParseFailure, "Unable to parse supplied media types (" + responseFormat + ")",e); } return responseMediaType; }  @Override void addValidContentTypes(final Set<String> vct, MediaType normalisedContentType); @Override void addValidEncodings(final Set<String> validEncodings); @Override MediaType getNormalisedResponseMediaType(HttpServletRequest request); @Override MediaType getNormalisedRequestMediaType(HttpServletRequest request); void setDefaultResponseFormat(String defaultResponseFormat); @Override String getNormalisedEncoding(HttpServletRequest request); }
ContentTypeNormaliserImpl implements ContentTypeNormaliser { @Override public MediaType getNormalisedResponseMediaType(HttpServletRequest request) { MediaType responseMediaType; String responseFormat = getResponseFormat(request); try { List<MediaType> acceptMT = MediaTypeUtils.parseMediaTypes(responseFormat); responseMediaType = MediaTypeUtils.getResponseMediaType(allContentTypes, acceptMT); if (responseMediaType == null) { throw new CougarValidationException(ServerFaultCode.AcceptTypeNotValid, "Could not agree a response media type"); } else if (responseMediaType.isWildcardType() || responseMediaType.isWildcardSubtype()) { throw new CougarServiceException(ServerFaultCode.ResponseContentTypeNotValid, "Service configuration error - response media type must not be a wildcard - " + responseMediaType); } } catch (IllegalArgumentException e) { throw new CougarValidationException(ServerFaultCode.MediaTypeParseFailure, "Unable to parse supplied media types (" + responseFormat + ")",e); } return responseMediaType; }  @Override void addValidContentTypes(final Set<String> vct, MediaType normalisedContentType); @Override void addValidEncodings(final Set<String> validEncodings); @Override MediaType getNormalisedResponseMediaType(HttpServletRequest request); @Override MediaType getNormalisedRequestMediaType(HttpServletRequest request); void setDefaultResponseFormat(String defaultResponseFormat); @Override String getNormalisedEncoding(HttpServletRequest request); static final String DEFAULT_ENCODING; }