|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2015 the original author or authors. |
|
|
|
* Copyright 2002-2016 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -27,18 +27,15 @@ import org.springframework.web.HttpMediaTypeNotAcceptableException; |
|
|
|
import org.springframework.web.context.request.NativeWebRequest; |
|
|
|
import org.springframework.web.context.request.NativeWebRequest; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* A {@code ContentNegotiationStrategy} that resolves a query parameter to a |
|
|
|
* A {@code ContentNegotiationStrategy} that resolves a query parameter to a key |
|
|
|
* key to be used to look up a media type. The default parameter name is |
|
|
|
* to be used to look up a media type. The default parameter name is {@code format}. |
|
|
|
* {@code format}. |
|
|
|
* |
|
|
|
*s |
|
|
|
|
|
|
|
* @author Rossen Stoyanchev |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
* @since 3.2 |
|
|
|
* @since 3.2 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class ParameterContentNegotiationStrategy |
|
|
|
public class ParameterContentNegotiationStrategy extends AbstractMappingContentNegotiationStrategy { |
|
|
|
extends AbstractMappingContentNegotiationStrategy { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Log logger = LogFactory.getLog( |
|
|
|
private static final Log logger = LogFactory.getLog(ParameterContentNegotiationStrategy.class); |
|
|
|
ParameterContentNegotiationStrategy.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String parameterName = "format"; |
|
|
|
private String parameterName = "format"; |
|
|
|
|
|
|
|
|
|
|
|
@ -56,7 +53,7 @@ public class ParameterContentNegotiationStrategy |
|
|
|
* <p>By default this is set to {@code "format"}. |
|
|
|
* <p>By default this is set to {@code "format"}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setParameterName(String parameterName) { |
|
|
|
public void setParameterName(String parameterName) { |
|
|
|
Assert.notNull(parameterName, "parameterName is required"); |
|
|
|
Assert.notNull(parameterName, "'parameterName' is required"); |
|
|
|
this.parameterName = parameterName; |
|
|
|
this.parameterName = parameterName; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -64,6 +61,7 @@ public class ParameterContentNegotiationStrategy |
|
|
|
return this.parameterName; |
|
|
|
return this.parameterName; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected String getMediaTypeKey(NativeWebRequest request) { |
|
|
|
protected String getMediaTypeKey(NativeWebRequest request) { |
|
|
|
return request.getParameter(getParameterName()); |
|
|
|
return request.getParameter(getParameterName()); |
|
|
|
@ -72,8 +70,8 @@ public class ParameterContentNegotiationStrategy |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void handleMatch(String mediaTypeKey, MediaType mediaType) { |
|
|
|
protected void handleMatch(String mediaTypeKey, MediaType mediaType) { |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
logger.debug("Requested media type is '" + mediaType + |
|
|
|
logger.debug("Requested media type: '" + mediaType + "' based on '" + |
|
|
|
"' based on '" + getParameterName() + "'='" + mediaTypeKey + "'."); |
|
|
|
getParameterName() + "'='" + mediaTypeKey + "'"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|