Remove JAF references

This commit updates the main code base to conform to the dropped JAF
dependency in MediaTypeFactory. Specifically, it

 - Removes JAF detection (JAF_PRESENT constants)
 - Deprecated useJaf properties, with no direct replacement.
 - Updated docs to remove JAF references, in favor of MediaTypeFactory.

Issue: SPR-14908
This commit is contained in:
Arjen Poutsma
2017-03-14 14:56:01 +01:00
committed by Rossen Stoyanchev
parent f0a43e5d5c
commit 0aaa6528dc
9 changed files with 67 additions and 136 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,17 +33,14 @@ import org.springframework.web.util.UriUtils;
* the request path and uses that as the media type lookup key.
*
* <p>If the file extension is not found in the explicit registrations provided
* to the constructor, the Java Activation Framework (JAF) is used as a fallback
* mechanism. The presence of the JAF is detected and enabled automatically but
* the {@link #setUseJaf(boolean)} property may be set to false.
* to the constructor, the {@link MediaTypeFactory} is used as a fallback
* mechanism.
*
* @author Rossen Stoyanchev
* @since 5.0
*/
public class PathExtensionContentTypeResolver extends AbstractMappingContentTypeResolver {
private boolean useJaf = true;
private boolean ignoreUnknownExtensions = true;
@@ -63,14 +60,6 @@ public class PathExtensionContentTypeResolver extends AbstractMappingContentType
}
/**
* Whether to use the Java Activation Framework to look up file extensions.
* <p>By default this is set to "true" but depends on JAF being present.
*/
public void setUseJaf(boolean useJaf) {
this.useJaf = useJaf;
}
/**
* Whether to ignore requests with unknown file extension. Setting this to
* {@code false} results in {@code HttpMediaTypeNotAcceptableException}.
@@ -90,11 +79,9 @@ public class PathExtensionContentTypeResolver extends AbstractMappingContentType
@Override
protected MediaType handleNoMatch(String key) throws NotAcceptableStatusException {
if (this.useJaf) {
MediaType mediaType = MediaTypeFactory.getMediaType("file." + key);
if (mediaType != null && !MediaType.APPLICATION_OCTET_STREAM.equals(mediaType)) {
return mediaType;
}
MediaType mediaType = MediaTypeFactory.getMediaType("file." + key);
if (mediaType != null) {
return mediaType;
}
if (!this.ignoreUnknownExtensions) {
throw new NotAcceptableStatusException(getAllMediaTypes());
@@ -105,7 +92,7 @@ public class PathExtensionContentTypeResolver extends AbstractMappingContentType
/**
* A public method exposing the knowledge of the path extension resolver to
* determine the media type for a given {@link Resource}. First it checks
* the explicitly registered mappings and then falls back on JAF.
* the explicitly registered mappings and then falls back on {@link MediaTypeFactory}.
* @param resource the resource
* @return the MediaType for the extension, or {@code null} if none determined
*/
@@ -120,9 +107,6 @@ public class PathExtensionContentTypeResolver extends AbstractMappingContentType
if (mediaType == null) {
mediaType = MediaTypeFactory.getMediaType(filename);
}
if (MediaType.APPLICATION_OCTET_STREAM.equals(mediaType)) {
mediaType = null;
}
return mediaType;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -74,9 +74,9 @@ import org.springframework.util.CollectionUtils;
* {@link #mediaTypes(Map)}. This will be used to resolve path extensions or a
* parameter value such as "json" to a media type such as "application/json".
*
* <p>The path extension strategy will also use the Java Activation framework
* (JAF), if available, to resolve a path extension to a MediaType. You may
* {@link #useJaf suppress} the use of JAF.
* <p>The path extension strategy will also use
* {@link org.springframework.http.MediaTypeFactory} to resolve a path extension
* to a MediaType.
*
* @author Rossen Stoyanchev
* @since 5.0
@@ -93,8 +93,6 @@ public class RequestedContentTypeResolverBuilder {
private boolean ignoreUnknownPathExtensions = true;
private Boolean useJaf;
private String parameterName = "format";
private RequestedContentTypeResolver contentTypeResolver;
@@ -119,8 +117,9 @@ public class RequestedContentTypeResolverBuilder {
* whitelisted for the purpose of Reflected File Download attack detection
* (see Spring Framework reference documentation for more details on RFD
* attack protection).
* <p>The path extension strategy will also try to use JAF (if present) to
* resolve path extensions. To change this behavior see {@link #useJaf}.
* <p>The path extension strategy will also use the
* {@link org.springframework.http.MediaTypeFactory} to resolve path
* extensions.
* @param mediaTypes media type mappings
*/
public RequestedContentTypeResolverBuilder mediaTypes(Map<String, MediaType> mediaTypes) {
@@ -153,18 +152,6 @@ public class RequestedContentTypeResolverBuilder {
return this;
}
/**
* When {@link #favorPathExtension favorPathExtension} is set, this
* property determines whether to allow use of JAF (Java Activation Framework)
* to resolve a path extension to a specific MediaType.
* <p>By default this is not set in which case
* {@code PathExtensionContentNegotiationStrategy} will use JAF if available.
*/
public RequestedContentTypeResolverBuilder useJaf(boolean useJaf) {
this.useJaf = useJaf;
return this;
}
/**
* Whether a request parameter ("format" by default) should be used to
* determine the requested media type. For this option to work you must
@@ -224,9 +211,6 @@ public class RequestedContentTypeResolverBuilder {
if (this.favorPathExtension) {
PathExtensionContentTypeResolver resolver = new PathExtensionContentTypeResolver(this.mediaTypes);
resolver.setIgnoreUnknownExtensions(this.ignoreUnknownPathExtensions);
if (this.useJaf != null) {
resolver.setUseJaf(this.useJaf);
}
resolvers.add(resolver);
}