Top Description Constructors Methods
org.springframework.web.servlet.mvc.method.annotation

public Class HttpEntityMethodProcessor

extends AbstractMessageConverterMethodProcessor
Class Inheritance
Imports
java.io.IOException, java.lang.reflect.ParameterizedType, .Type, java.net.URI, java.util.ArrayList, .Collections, .List, .Map, jakarta.servlet.http.HttpServletRequest, .HttpServletResponse, org.springframework.core.MethodParameter, .ResolvableType, org.springframework.http.HttpEntity, .HttpHeaders, .HttpMethod, .ProblemDetail, .RequestEntity, .ResponseEntity, org.springframework.http.converter.HttpMessageConverter, org.springframework.http.server.ServletServerHttpRequest, .ServletServerHttpResponse, org.springframework.lang.Nullable, org.springframework.ui.ModelMap, org.springframework.util.Assert, .CollectionUtils, .StringUtils, org.springframework.web.ErrorResponse, .HttpMediaTypeNotSupportedException, org.springframework.web.accept.ContentNegotiationManager, org.springframework.web.bind.support.WebDataBinderFactory, org.springframework.web.context.request.NativeWebRequest, .ServletWebRequest, org.springframework.web.method.support.ModelAndViewContainer, org.springframework.web.servlet.mvc.support.RedirectAttributes, org.springframework.web.servlet.support.RequestContextUtils

Resolves HttpEntity and RequestEntity method argument values, as well as return values of type HttpEntity, ResponseEntity, ErrorResponse and ProblemDetail.

An HttpEntity return type has a specific purpose. Therefore, this handler should be configured ahead of handlers that support any return value type annotated with @ModelAttribute or @ResponseBody to ensure they don't take over.

Authors
Arjen Poutsma, Rossen Stoyanchev, Brian Clozel, Sam Brannen
Since
3.1

Constructor Summary

AccessConstructor and Description
public
HttpEntityMethodProcessor(List<HttpMessageConverter<?>> converters)

Basic constructor with converters only.

public
HttpEntityMethodProcessor(List<HttpMessageConverter<?>> converters, ContentNegotiationManager manager)

Basic constructor with converters and ContentNegotiationManager.

public
HttpEntityMethodProcessor(List<HttpMessageConverter<?>> converters, List<Object> requestResponseBodyAdvice)

Complete constructor for resolving HttpEntity method arguments.

public
HttpEntityMethodProcessor(List<HttpMessageConverter<?>> converters, ContentNegotiationManager manager, List<Object> requestResponseBodyAdvice)

Complete constructor for resolving HttpEntity and handling ResponseEntity.

Method Summary

Modifier and TypeMethod and Description
private Type
protected Class<?>
private List<String>
getVaryRequestHeadersToAdd(HttpHeaders responseHeaders, HttpHeaders entityHeaders)

public void
handleReturnValue(Object
the value returned from the handler method
returnValue
,
MethodParameter
the type of the return value. This type must have previously been passed to supportsReturnType which must have returned true.
returnType
,
ModelAndViewContainer
the ModelAndViewContainer for the current request
mavContainer
,
NativeWebRequest
the current request
webRequest
)

Implements org.springframework.web.method.support.HandlerMethodReturnValueHandler.handleReturnValue.

Handle the given return value by adding attributes to the model and setting a view or setting the ModelAndViewContainer#setRequestHandled flag to true to indicate the response has been handled directly.

private boolean
public Object
resolveArgument(MethodParameter
the method parameter to resolve. This parameter must have previously been passed to supportsParameter which must have returned true.
parameter
,
ModelAndViewContainer
the ModelAndViewContainer for the current request
mavContainer
,
NativeWebRequest
the current request
webRequest
,
WebDataBinderFactory
a factory for creating WebDataBinder instances
binderFactory
)

Implements org.springframework.web.method.support.HandlerMethodArgumentResolver.resolveArgument.

Resolves a method parameter into an argument value from a given request.

private void
public boolean
supportsParameter(MethodParameter
the method parameter to check
parameter
)

Implements org.springframework.web.method.support.HandlerMethodArgumentResolver.supportsParameter.

Whether the given method parameter is supported by this resolver.

public boolean
supportsReturnType(MethodParameter
the method return type to check
returnType
)

Implements org.springframework.web.method.support.HandlerMethodReturnValueHandler.supportsReturnType.

Whether the given method return type is supported by this handler.

Inherited from org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor:
createOutputMessagegetProducibleMediaTypesgetProducibleMediaTypesisResourceTypewriteWithMessageConverterswriteWithMessageConverters

Constructor Detail

HttpEntityMethodProcessorback to summary
public HttpEntityMethodProcessor(List<HttpMessageConverter<?>> converters)

Basic constructor with converters only. Suitable for resolving HttpEntity. For handling ResponseEntity consider also providing a ContentNegotiationManager.

HttpEntityMethodProcessorback to summary
public HttpEntityMethodProcessor(List<HttpMessageConverter<?>> converters, ContentNegotiationManager manager)

Basic constructor with converters and ContentNegotiationManager. Suitable for resolving HttpEntity and handling ResponseEntity without Request~ or ResponseBodyAdvice.

HttpEntityMethodProcessorback to summary
public HttpEntityMethodProcessor(List<HttpMessageConverter<?>> converters, List<Object> requestResponseBodyAdvice)

Complete constructor for resolving HttpEntity method arguments. For handling ResponseEntity consider also providing a ContentNegotiationManager.

Since
4.2
HttpEntityMethodProcessorback to summary
public HttpEntityMethodProcessor(List<HttpMessageConverter<?>> converters, ContentNegotiationManager manager, List<Object> requestResponseBodyAdvice)

Complete constructor for resolving HttpEntity and handling ResponseEntity.

Method Detail

getHttpEntityTypeback to summary
private Type getHttpEntityType(MethodParameter parameter)
Annotations
@Nullable
getReturnValueTypeback to summary
protected Class<?> getReturnValueType(Object returnValue, MethodParameter returnType)

Overrides org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.getReturnValueType.

Doc from org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.getReturnValueType.

Return the type of the value to be written to the response. Typically this is a simple check via getClass on the value but if the value is null, then the return type needs to be examined possibly including generic type determination (e.g. ResponseEntity<T>).

Annotations
@Override
getVaryRequestHeadersToAddback to summary
private List<String> getVaryRequestHeadersToAdd(HttpHeaders responseHeaders, HttpHeaders entityHeaders)
handleReturnValueback to summary
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception

Implements org.springframework.web.method.support.HandlerMethodReturnValueHandler.handleReturnValue.

Doc from org.springframework.web.method.support.HandlerMethodReturnValueHandler.handleReturnValue.

Handle the given return value by adding attributes to the model and setting a view or setting the ModelAndViewContainer#setRequestHandled flag to true to indicate the response has been handled directly.

Parameters
returnValue:Object

the value returned from the handler method

returnType:MethodParameter

the type of the return value. This type must have previously been passed to supportsReturnType which must have returned true.

mavContainer:ModelAndViewContainer

the ModelAndViewContainer for the current request

webRequest:NativeWebRequest

the current request

Annotations
@Override
Exceptions
Exception:
if the return value handling results in an error
isResourceNotModifiedback to summary
private boolean isResourceNotModified(ServletServerHttpRequest request, ServletServerHttpResponse response)
resolveArgumentback to summary
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws IOException, HttpMediaTypeNotSupportedException

Implements org.springframework.web.method.support.HandlerMethodArgumentResolver.resolveArgument.

Doc from org.springframework.web.method.support.HandlerMethodArgumentResolver.resolveArgument.

Resolves a method parameter into an argument value from a given request. A ModelAndViewContainer provides access to the model for the request. A WebDataBinderFactory provides a way to create a WebDataBinder instance when needed for data binding and type conversion purposes.

Parameters
parameter:MethodParameter

the method parameter to resolve. This parameter must have previously been passed to supportsParameter which must have returned true.

mavContainer:ModelAndViewContainer

the ModelAndViewContainer for the current request

webRequest:NativeWebRequest

the current request

binderFactory:WebDataBinderFactory

a factory for creating WebDataBinder instances

Returns:Object

the resolved argument value, or null if not resolvable

Annotations
@Override
@Nullable
saveFlashAttributesback to summary
private void saveFlashAttributes(ModelAndViewContainer mav, NativeWebRequest request, String location)
supportsParameterback to summary
public boolean supportsParameter(MethodParameter parameter)

Implements org.springframework.web.method.support.HandlerMethodArgumentResolver.supportsParameter.

Doc from org.springframework.web.method.support.HandlerMethodArgumentResolver.supportsParameter.

Whether the given method parameter is supported by this resolver.

Parameters
parameter:MethodParameter

the method parameter to check

Returns:boolean

true if this resolver supports the supplied parameter; false otherwise

Annotations
@Override
supportsReturnTypeback to summary
public boolean supportsReturnType(MethodParameter returnType)

Implements org.springframework.web.method.support.HandlerMethodReturnValueHandler.supportsReturnType.

Doc from org.springframework.web.method.support.HandlerMethodReturnValueHandler.supportsReturnType.

Whether the given method return type is supported by this handler.

Parameters
returnType:MethodParameter

the method return type to check

Returns:boolean

true if this handler supports the supplied return type; false otherwise

Annotations
@Override