adding contentType matching independent of Charset to non-strict method
@@ -23,6 +23,7 @@ package ca.uhn.fhir.rest.api;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.parser.IParser;
import org.apache.commons.lang3.ObjectUtils;
+
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -155,7 +156,12 @@ public enum EncodingEnum {
* </p>
*/
public static EncodingEnum forContentType(String theContentType) {
- return ourContentTypeToEncoding.get(theContentType);
+ String contentTypeSplitted = getTypeWithoutCharset(theContentType);
+ if (contentTypeSplitted == null) {
+ return null;
+ } else {
+ return ourContentTypeToEncoding.get(contentTypeSplitted );
+ }
}
@@ -169,18 +175,33 @@ public enum EncodingEnum {
* @see #forContentType(String)
*/
public static EncodingEnum forContentTypeStrict(String theContentType) {
- if (theContentType == null) {
+ String contentTypeSplitted = getTypeWithoutCharset(theContentType);
+ if (contentTypeSplitted == null) {
return null;
+ } else {
+ return ourContentTypeToEncodingStrict.get(contentTypeSplitted);
+ }
}
+
+ private static String getTypeWithoutCharset(String theContentType) {
+ if (theContentType == null) {
+ return null;
+ } else {
String[] contentTypeSplitted = theContentType.split(";");
- return ourContentTypeToEncodingStrict.get(contentTypeSplitted[0]);
+ return contentTypeSplitted[0];
+ }
}
/**
* Is the given type a FHIR legacy (pre-DSTU3) content type?
*/
- public static boolean isLegacy(String theFormat) {
- return ourContentTypeToEncodingLegacy.containsKey(theFormat);
+ public static boolean isLegacy(String theContentType) {
+ String contentTypeSplitted = getTypeWithoutCharset(theContentType);
+ if (contentTypeSplitted == null) {
+ return false;
+ } else {
+ return ourContentTypeToEncodingLegacy.containsKey(contentTypeSplitted);
+ }
}
