@Test public void testContentTypesWhenNeedsSplit() { when(req.getHeaders(ACCEPT_HEADER)).thenReturn( enumeration(asList("text/html,application/xhtml+xml,application/xml;q=0.9"))); assertEquals(asList("text/html", "application/xhtml+xml", "application/xml;q=0.9"), contentNegotiator.contentTypes()); }
@Override public List<String> contentTypes() { List<String> contentTypes = null; final HttpServletRequest request = getHttpRequest(); if (favorParameterOverAcceptHeader) { contentTypes = getFavoredParameterValueAsList(request); } else { contentTypes = getAcceptHeaderValues(request); } if (isEmpty(contentTypes)) { logger.debug("Setting content types to default: {}.", DEFAULT_SUPPORTED_CONTENT_TYPES); contentTypes = DEFAULT_SUPPORTED_CONTENT_TYPES; } return unmodifiableList(contentTypes); }
DefaultContentNegotiator implements ContentNegotiator { @Override public List<String> contentTypes() { List<String> contentTypes = null; final HttpServletRequest request = getHttpRequest(); if (favorParameterOverAcceptHeader) { contentTypes = getFavoredParameterValueAsList(request); } else { contentTypes = getAcceptHeaderValues(request); } if (isEmpty(contentTypes)) { logger.debug("Setting content types to default: {}.", DEFAULT_SUPPORTED_CONTENT_TYPES); contentTypes = DEFAULT_SUPPORTED_CONTENT_TYPES; } return unmodifiableList(contentTypes); } }
DefaultContentNegotiator implements ContentNegotiator { @Override public List<String> contentTypes() { List<String> contentTypes = null; final HttpServletRequest request = getHttpRequest(); if (favorParameterOverAcceptHeader) { contentTypes = getFavoredParameterValueAsList(request); } else { contentTypes = getAcceptHeaderValues(request); } if (isEmpty(contentTypes)) { logger.debug("Setting content types to default: {}.", DEFAULT_SUPPORTED_CONTENT_TYPES); contentTypes = DEFAULT_SUPPORTED_CONTENT_TYPES; } return unmodifiableList(contentTypes); } DefaultContentNegotiator(); }
DefaultContentNegotiator implements ContentNegotiator { @Override public List<String> contentTypes() { List<String> contentTypes = null; final HttpServletRequest request = getHttpRequest(); if (favorParameterOverAcceptHeader) { contentTypes = getFavoredParameterValueAsList(request); } else { contentTypes = getAcceptHeaderValues(request); } if (isEmpty(contentTypes)) { logger.debug("Setting content types to default: {}.", DEFAULT_SUPPORTED_CONTENT_TYPES); contentTypes = DEFAULT_SUPPORTED_CONTENT_TYPES; } return unmodifiableList(contentTypes); } DefaultContentNegotiator(); List<String> getSupportedContentTypes(); void setSupportedContentTypes(final List<String> supportedContentTypes); boolean isFavorParameterOverAcceptHeader(); void setFavorParameterOverAcceptHeader(final boolean favorParameterOverAcceptHeader); String getFavoredParameterName(); void setFavoredParameterName(final String parameterName); Comparator<List<String>> getContentTypeComparator(); void setContentTypeComparator(final Comparator<List<String>> contentTypeComparator); @Override boolean isSupportedContentTypes(final List<String> contentTypes); @Override List<String> contentTypes(); }
DefaultContentNegotiator implements ContentNegotiator { @Override public List<String> contentTypes() { List<String> contentTypes = null; final HttpServletRequest request = getHttpRequest(); if (favorParameterOverAcceptHeader) { contentTypes = getFavoredParameterValueAsList(request); } else { contentTypes = getAcceptHeaderValues(request); } if (isEmpty(contentTypes)) { logger.debug("Setting content types to default: {}.", DEFAULT_SUPPORTED_CONTENT_TYPES); contentTypes = DEFAULT_SUPPORTED_CONTENT_TYPES; } return unmodifiableList(contentTypes); } DefaultContentNegotiator(); List<String> getSupportedContentTypes(); void setSupportedContentTypes(final List<String> supportedContentTypes); boolean isFavorParameterOverAcceptHeader(); void setFavorParameterOverAcceptHeader(final boolean favorParameterOverAcceptHeader); String getFavoredParameterName(); void setFavoredParameterName(final String parameterName); Comparator<List<String>> getContentTypeComparator(); void setContentTypeComparator(final Comparator<List<String>> contentTypeComparator); @Override boolean isSupportedContentTypes(final List<String> contentTypes); @Override List<String> contentTypes(); static final String DEFAULT_FAVORED_PARAMETER_NAME; static final List<String> DEFAULT_SUPPORTED_CONTENT_TYPES; static final String ACCEPT_HEADER; }