com.github.datalking.web.http.accept.HeaderContentNegotiationStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of play-mvc Show documentation
Show all versions of play-mvc Show documentation
simple mvc framework based on java servlet.
The newest version!
package com.github.datalking.web.http.accept;
import com.github.datalking.util.StringUtils;
import com.github.datalking.web.context.request.WebRequest;
import com.github.datalking.web.http.MediaType;
import java.util.Collections;
import java.util.List;
public class HeaderContentNegotiationStrategy implements ContentNegotiationStrategy {
private static final String ACCEPT_HEADER = "Accept";
public List resolveMediaTypes(WebRequest webRequest) {
String acceptHeader = webRequest.getHeader(ACCEPT_HEADER);
try {
if (StringUtils.hasText(acceptHeader)) {
List mediaTypes = MediaType.parseMediaTypes(acceptHeader);
// MediaType.sortBySpecificityAndQuality(mediaTypes);
return mediaTypes;
}
} catch (IllegalArgumentException ex) {
// throw new HttpMediaTypeNotAcceptableException("Could not parse accept header [" + acceptHeader + "]: " + ex.getMessage());
ex.printStackTrace();
}
return Collections.emptyList();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy