public boolean isCompatible(ContentType other) { if (other == null) { return false; } else if (getType().equals(WILDCARD) || other.getType().equals(WILDCARD)) { return true; } else if (getType().equals(other.getType())) { return getSubType().equals(WILDCARD) || other.getSubType().equals(WILDCARD) || getSubType().equals(other.getSubType()); } return false; }
private boolean matchesContentType(List<ContentType> contentTypes) { boolean contentTypeMatch = false; for (ContentType contentType : contentTypes) { if (CONTENT_TYPE.isCompatible(contentType)) { contentTypeMatch = true; break; } } return contentTypeMatch; } }
/** * Checks if either the primary type or the sub type is a wildcard. * * @return <code>true</code> if the primary type or sub type is a wildcard. */ public boolean isWildcard() { return isWildcardType() || isWildcardSubType(); }
/** * Checks if the sub type is a wildcard. * * @return <code>true</code> if the sub type is a wildcard. */ public boolean isWildcardSubType() { return getSubType().equals(WILDCARD); }
/** * Checks if the primary type is a wildcard. * * @return <code>true</code> if the primary type is a wildcard. */ public boolean isWildcardType() { return getType().equals(WILDCARD); }
private static Set<ContentType> resolveContentTypes(String[] values, Set<ContentType> fallback) { Set<ContentType> result = new HashSet<>(values.length); for (String value : values) { String[] parts = MULTIPLE_CONTENT_TYPE_PATTERN.split(value); for (String part : parts) { result.add(ContentType.valueOf(part)); } } if (result.isEmpty()) { result.addAll(fallback); } return Collections.unmodifiableSet(result); } }
public ContentType( String type, String subType, Map<String, String> parameters) { this.type = valueOrWildcard(type); this.subType = valueOrWildcard(subType); this.parameters = parameters; }
/** * Parses a content type and return an object representation. Input may look like: * <p/> * application/json; charset=utf-8; q=0.9 */ public static ContentType valueOf(String value) { String type = WILDCARD; String subType = WILDCARD; Map<String, String> parameters = new HashMap<String, String>(); if (value != null) { String[] parts = value.split(PARAMETER_DELIMITER); String[] types = parts[0].split(TYPE_DELIMITER); type = types[0]; if (types.length > 1) { subType = types[1]; } // Element 0 is type/sub-type, others are parameters for (int i = 1; i < parts.length; ++i) { String[] keyValue = parts[i].split(KEY_VALUE_DELIMITER); if (keyValue.length == 2) { parameters.put(keyValue[0].trim(), keyValue[1].trim()); } } } return new ContentType(type, subType, parameters); }
private void assignBodyFromSerialization(RequestBuilder requestBuilder, RestAction<?> action) throws ActionException { String data; if (action.hasBodyParam()) { SerializedValue serializedValue = getSerializedValue(action, action.getBodyParam()); ContentType contentType = serializedValue.getContentType(); data = serializedValue.getData(); requestBuilder.setHeader(HttpHeaders.CONTENT_TYPE, contentType.toString()); } else { // Fixes an issue for all IE versions (IE 11 is the latest at this time). If request data is not // explicitly set to 'null', the JS 'undefined' will be sent as the request body on IE. Other // browsers don't send undefined bodies. data = null; } requestBuilder.setRequestData(data); }
/** * Checks if the sub type is a wildcard. * * @return <code>true</code> if the sub type is a wildcard. */ public boolean isWildcardSubType() { return getSubType().equals(WILDCARD); }
/** * Checks if the primary type is a wildcard. * * @return <code>true</code> if the primary type is a wildcard. */ public boolean isWildcardType() { return getType().equals(WILDCARD); }
private <R> R getDeserializedResponse(RestAction<R> action, Response response) throws ActionException { String resultClass = action.getResultClass(); if (resultClass != null) { ContentType contentType = ContentType.valueOf(response.getHeader(HttpHeaders.CONTENT_TYPE)); Serialization serialization = findSerialization(resultClass, contentType); if (serialization != null) { return deserializeValue(serialization, resultClass, contentType, response.getText()); } } throw new ActionException("Unable to deserialize response. No serializer found."); }
public ContentType( String type, String subType, Map<String, String> parameters) { this.type = valueOrWildcard(type); this.subType = valueOrWildcard(subType); this.parameters = parameters; }
/** * Parses a content type and return an object representation. Input may look like: * <p/> * application/json; charset=utf-8; q=0.9 */ public static ContentType valueOf(String value) { String type = WILDCARD; String subType = WILDCARD; Map<String, String> parameters = new HashMap<>(); if (value != null) { String[] parts = value.split(PARAMETER_DELIMITER); String[] types = parts[0].split(TYPE_DELIMITER); type = types[0]; if (types.length > 1) { subType = types[1]; } // Element 0 is type/sub-type, others are parameters for (int i = 1; i < parts.length; ++i) { String[] keyValue = parts[i].split(KEY_VALUE_DELIMITER); if (keyValue.length == 2) { parameters.put(keyValue[0].trim(), keyValue[1].trim()); } } } return new ContentType(type, subType, parameters); }
public boolean isCompatible(ContentType other) { if (other == null) { return false; } else if (getType().equals(WILDCARD) || other.getType().equals(WILDCARD)) { return true; } else if (getType().equals(other.getType())) { return getSubType().equals(WILDCARD) || other.getSubType().equals(WILDCARD) || getSubType().equals(other.getSubType()); } return false; }
/** * Checks if either the primary type or the sub type is a wildcard. * * @return <code>true</code> if the primary type or sub type is a wildcard. */ public boolean isWildcard() { return isWildcardType() || isWildcardSubType(); }
@Override public boolean canDeserialize(String type, ContentType contentType) { return VOID.equals(type) || (CONTENT_TYPE.isCompatible(contentType) && jacksonMapperProvider.hasMapper(type)); }