Top Description Fields Constructors Methods
org.springframework.web.server.adapter

public Class DefaultServerWebExchange

extends Object
implements ServerWebExchange
Class Inheritance
All Implemented Interfaces
org.springframework.web.server.ServerWebExchange
Imports
java.security.Principal, java.time.Instant, java.time.temporal.ChronoUnit, java.util.List, .Map, .Set, java.util.concurrent.ConcurrentHashMap, java.util.function.Function, reactor.core.publisher.Mono, org.springframework.context.ApplicationContext, org.springframework.context.i18n.LocaleContext, org.springframework.core.ResolvableType, org.springframework.core.codec.Hints, org.springframework.http.HttpHeaders, .HttpMethod, .HttpStatus, .HttpStatusCode, .InvalidMediaTypeException, .MediaType, org.springframework.http.codec.HttpMessageReader, .ServerCodecConfigurer, org.springframework.http.codec.multipart.Part, org.springframework.http.server.reactive.ServerHttpRequest, .ServerHttpResponse, org.springframework.lang.Nullable, org.springframework.util.Assert, .CollectionUtils, .LinkedMultiValueMap, .MultiValueMap, .StringUtils, org.springframework.web.server.ServerWebExchange, .WebSession, org.springframework.web.server.i18n.LocaleContextResolver, org.springframework.web.server.session.WebSessionManager

Default implementation of ServerWebExchange.
Authors
Rossen Stoyanchev, Brian Clozel
Since
5.0

Field Summary

Modifier and TypeField and Description
private final ApplicationContext
private final Map<String, Object>
private static final Mono<MultiValueMap<String, String>>
private static final Mono<MultiValueMap<String, Part>>
private static final ResolvableType
private final Mono<MultiValueMap<String, String>>
private final LocaleContextResolver
private Object
private String
private static final ResolvableType
private final Mono<MultiValueMap<String, Part>>
private volatile boolean
private volatile boolean
private final ServerHttpRequest
private final ServerHttpResponse
private static final Set<HttpMethod>
private final Mono<WebSession>
private Function<String, String>

Constructor Summary

AccessConstructor and Description
public
DefaultServerWebExchange(ServerHttpRequest request, ServerHttpResponse response, WebSessionManager sessionManager, ServerCodecConfigurer codecConfigurer, LocaleContextResolver localeContextResolver)

pack-priv
DefaultServerWebExchange(ServerHttpRequest request, ServerHttpResponse response, WebSessionManager sessionManager, ServerCodecConfigurer codecConfigurer, LocaleContextResolver localeContextResolver, ApplicationContext applicationContext)

Method Summary

Modifier and TypeMethod and Description
private void
public void
addUrlTransformer(Function<String, String>
a URL transformation function to add
transformer
)

Implements org.springframework.web.server.ServerWebExchange.addUrlTransformer.

Register an additional URL transformation function for use with transformUrl.

public boolean
checkNotModified(Instant
the last-modified time
lastModified
)

Implements org.springframework.web.server.ServerWebExchange.checkNotModified.

An overloaded variant of checkNotModified(String, Instant) with a last-modified timestamp only.

public boolean
checkNotModified(String
the entity tag for the underlying resource.
etag
)

Implements org.springframework.web.server.ServerWebExchange.checkNotModified.

An overloaded variant of checkNotModified(String, Instant) with an ETag (entity tag) value only.

public boolean
checkNotModified(String
the entity tag that the application determined for the underlying resource. This parameter will be padded with quotes (") if necessary.
eTag
,
Instant
the last-modified timestamp that the application determined for the underlying resource
lastModified
)

Implements org.springframework.web.server.ServerWebExchange.checkNotModified.

Check whether the requested resource has been modified given the supplied ETag (entity tag) and last-modified timestamp as determined by the application.

public Mono<Void>
cleanupMultipart()

Overrides default org.springframework.web.server.ServerWebExchange.cleanupMultipart.

Cleans up any storage used for multipart handling.

private boolean
eTagStrongMatch(String first, String second)

private boolean
eTagWeakMatch(String first, String second)

public ApplicationContext
public Map<String, Object>
getAttributes()

Implements org.springframework.web.server.ServerWebExchange.getAttributes.

Return a mutable map of request attributes for the current exchange.

private static MediaType
public Mono<MultiValueMap<String, String>>
getFormData()

Implements org.springframework.web.server.ServerWebExchange.getFormData.

Return the form data from the body of the request if the Content-Type is "application/x-www-form-urlencoded" or an empty map otherwise.

public LocaleContext
public String
getLogPrefix()

Implements org.springframework.web.server.ServerWebExchange.getLogPrefix.

Return a log message prefix to use to correlate messages for this exchange.

public Mono<MultiValueMap<String, Part>>
getMultipartData()

Implements org.springframework.web.server.ServerWebExchange.getMultipartData.

Return the parts of a multipart request if the Content-Type is "multipart/form-data" or an empty map otherwise.

public <T extends Principal> Mono<T>
getPrincipal()

Implements org.springframework.web.server.ServerWebExchange.getPrincipal.

Return the authenticated user for the request, if any.

private static <E> HttpMessageReader<E>
getReader(ServerCodecConfigurer configurer, MediaType contentType, ResolvableType targetType)

public ServerHttpRequest
getRequest()

Implements org.springframework.web.server.ServerWebExchange.getRequest.

Return the current HTTP request.

private HttpHeaders
public ServerHttpResponse
getResponse()

Implements org.springframework.web.server.ServerWebExchange.getResponse.

Return the current HTTP response.

private HttpHeaders
public Mono<WebSession>
getSession()

Implements org.springframework.web.server.ServerWebExchange.getSession.

Return the web session for the current request.

private static Mono<MultiValueMap<String, String>>
private Mono<MultiValueMap<String, Part>>
public boolean
isNotModified()

Implements org.springframework.web.server.ServerWebExchange.isNotModified.

Returns true if the one of the checkNotModified methods in this contract were used and they returned true.

private boolean
matchRequestedETags(List<String> requestedETags, String eTag, boolean weakCompare)

private String
public String
transformUrl(String
the URL to transform
url
)

Implements org.springframework.web.server.ServerWebExchange.transformUrl.

Transform the given url according to the registered transformation function(s).

private void
private void
private boolean
private void
private boolean
private boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

applicationContextback to summary
private final ApplicationContext applicationContext
Annotations
@Nullable
attributesback to summary
private final Map<String, Object> attributes
EMPTY_FORM_DATAback to summary
private static final Mono<MultiValueMap<String, String>> EMPTY_FORM_DATA
EMPTY_MULTIPART_DATAback to summary
private static final Mono<MultiValueMap<String, Part>> EMPTY_MULTIPART_DATA
FORM_DATA_TYPEback to summary
private static final ResolvableType FORM_DATA_TYPE
formDataMonoback to summary
private final Mono<MultiValueMap<String, String>> formDataMono
localeContextResolverback to summary
private final LocaleContextResolver localeContextResolver
logIdback to summary
private Object logId
Annotations
@Nullable
logPrefixback to summary
private String logPrefix
MULTIPART_DATA_TYPEback to summary
private static final ResolvableType MULTIPART_DATA_TYPE
multipartDataMonoback to summary
private final Mono<MultiValueMap<String, Part>> multipartDataMono
multipartReadback to summary
private volatile boolean multipartRead
notModifiedback to summary
private volatile boolean notModified
requestback to summary
private final ServerHttpRequest request
responseback to summary
private final ServerHttpResponse response
SAFE_METHODSback to summary
private static final Set<HttpMethod> SAFE_METHODS
sessionMonoback to summary
private final Mono<WebSession> sessionMono
urlTransformerback to summary
private Function<String, String> urlTransformer

Constructor Detail

DefaultServerWebExchangeback to summary
public DefaultServerWebExchange(ServerHttpRequest request, ServerHttpResponse response, WebSessionManager sessionManager, ServerCodecConfigurer codecConfigurer, LocaleContextResolver localeContextResolver)
DefaultServerWebExchangeback to summary
pack-priv DefaultServerWebExchange(ServerHttpRequest request, ServerHttpResponse response, WebSessionManager sessionManager, ServerCodecConfigurer codecConfigurer, LocaleContextResolver localeContextResolver, ApplicationContext applicationContext)

Method Detail

addCachingResponseHeadersback to summary
private void addCachingResponseHeaders(String eTag, Instant lastModified)
addUrlTransformerback to summary
public void addUrlTransformer(Function<String, String> transformer)

Implements org.springframework.web.server.ServerWebExchange.addUrlTransformer.

Doc from org.springframework.web.server.ServerWebExchange.addUrlTransformer.

Register an additional URL transformation function for use with transformUrl. The given function can be used to insert an id for authentication, a nonce for CSRF protection, etc.

Note that the given function is applied after any previously registered functions.

Parameters
transformer:Function<String, String>

a URL transformation function to add

Annotations
@Override
checkNotModifiedback to summary
public boolean checkNotModified(Instant lastModified)

Implements org.springframework.web.server.ServerWebExchange.checkNotModified.

Doc from org.springframework.web.server.ServerWebExchange.checkNotModified.

An overloaded variant of checkNotModified(String, Instant) with a last-modified timestamp only.

Parameters
lastModified:Instant

the last-modified time

Returns:boolean

whether the request qualifies as not modified

Annotations
@Override
checkNotModifiedback to summary
public boolean checkNotModified(String etag)

Implements org.springframework.web.server.ServerWebExchange.checkNotModified.

Doc from org.springframework.web.server.ServerWebExchange.checkNotModified.

An overloaded variant of checkNotModified(String, Instant) with an ETag (entity tag) value only.

Parameters
etag:String

the entity tag for the underlying resource.

Returns:boolean

true if the request does not require further processing.

Annotations
@Override
checkNotModifiedback to summary
public boolean checkNotModified(String eTag, Instant lastModified)

Implements org.springframework.web.server.ServerWebExchange.checkNotModified.

Doc from org.springframework.web.server.ServerWebExchange.checkNotModified.

Check whether the requested resource has been modified given the supplied ETag (entity tag) and last-modified timestamp as determined by the application. Also transparently prepares the response, setting HTTP status, and adding "ETag" and "Last-Modified" headers when applicable. This method works with conditional GET/HEAD requests as well as with conditional POST/PUT/DELETE requests.

Note

The HTTP specification recommends setting both ETag and Last-Modified values, but you can also use #checkNotModified(String) or checkNotModified(Instant).

Parameters
eTag:String

the entity tag that the application determined for the underlying resource. This parameter will be padded with quotes (") if necessary.

lastModified:Instant

the last-modified timestamp that the application determined for the underlying resource

Returns:boolean

true if the request does not require further processing.

Annotations
@Override
cleanupMultipartback to summary
public Mono<Void> cleanupMultipart()

Overrides default org.springframework.web.server.ServerWebExchange.cleanupMultipart.

Doc from org.springframework.web.server.ServerWebExchange.cleanupMultipart.

Cleans up any storage used for multipart handling.

Annotations
@Override
eTagStrongMatchback to summary
private boolean eTagStrongMatch(String first, String second)
eTagWeakMatchback to summary
private boolean eTagWeakMatch(String first, String second)
getApplicationContextback to summary
public ApplicationContext getApplicationContext()

Implements org.springframework.web.server.ServerWebExchange.getApplicationContext.

Doc from org.springframework.web.server.ServerWebExchange.getApplicationContext.

Return the ApplicationContext associated with the web application, if it was initialized with one via org.springframework.web.server.adapter.WebHttpHandlerBuilder#applicationContext(ApplicationContext).

Annotations
@Override
@Nullable
getAttributesback to summary
public Map<String, Object> getAttributes()

Implements org.springframework.web.server.ServerWebExchange.getAttributes.

Doc from org.springframework.web.server.ServerWebExchange.getAttributes.

Return a mutable map of request attributes for the current exchange.

Annotations
@Override
getContentTypeback to summary
private static MediaType getContentType(ServerHttpRequest request)
Annotations
@Nullable
getFormDataback to summary
public Mono<MultiValueMap<String, String>> getFormData()

Implements org.springframework.web.server.ServerWebExchange.getFormData.

Doc from org.springframework.web.server.ServerWebExchange.getFormData.

Return the form data from the body of the request if the Content-Type is "application/x-www-form-urlencoded" or an empty map otherwise.

Note

calling this method causes the request body to be read and parsed in full and the resulting MultiValueMap is cached so that this method is safe to call more than once.

Annotations
@Override
getLocaleContextback to summary
public LocaleContext getLocaleContext()

Implements org.springframework.web.server.ServerWebExchange.getLocaleContext.

Doc from org.springframework.web.server.ServerWebExchange.getLocaleContext.

Return the LocaleContext using the configured org.springframework.web.server.i18n.LocaleContextResolver.

Annotations
@Override
getLogPrefixback to summary
public String getLogPrefix()

Implements org.springframework.web.server.ServerWebExchange.getLogPrefix.

Doc from org.springframework.web.server.ServerWebExchange.getLogPrefix.

Return a log message prefix to use to correlate messages for this exchange. The prefix is based on the value of the attribute LOG_ID_ATTRIBUTE along with some extra formatting so that the prefix can be conveniently prepended with no further formatting no separators required.

Returns:String

the log message prefix or an empty String if the LOG_ID_ATTRIBUTE is not set.

Annotations
@Override
getMultipartDataback to summary
public Mono<MultiValueMap<String, Part>> getMultipartData()

Implements org.springframework.web.server.ServerWebExchange.getMultipartData.

Doc from org.springframework.web.server.ServerWebExchange.getMultipartData.

Return the parts of a multipart request if the Content-Type is "multipart/form-data" or an empty map otherwise.

Note

calling this method causes the request body to be read and parsed in full and the resulting MultiValueMap is cached so that this method is safe to call more than once.

Note

the contents of each part is not cached, and can only be read once.

Annotations
@Override
getPrincipalback to summary
public <T extends Principal> Mono<T> getPrincipal()

Implements org.springframework.web.server.ServerWebExchange.getPrincipal.

Doc from org.springframework.web.server.ServerWebExchange.getPrincipal.

Return the authenticated user for the request, if any.

Annotations
@Override
getReaderback to summary
private static <E> HttpMessageReader<E> getReader(ServerCodecConfigurer configurer, MediaType contentType, ResolvableType targetType)
Annotations
@SuppressWarnings:unchecked
@Nullable
getRequestback to summary
public ServerHttpRequest getRequest()

Implements org.springframework.web.server.ServerWebExchange.getRequest.

Doc from org.springframework.web.server.ServerWebExchange.getRequest.

Return the current HTTP request.

Annotations
@Override
getRequestHeadersback to summary
private HttpHeaders getRequestHeaders()
getResponseback to summary
public ServerHttpResponse getResponse()

Implements org.springframework.web.server.ServerWebExchange.getResponse.

Doc from org.springframework.web.server.ServerWebExchange.getResponse.

Return the current HTTP response.

Annotations
@Override
getResponseHeadersback to summary
private HttpHeaders getResponseHeaders()
getSessionback to summary
public Mono<WebSession> getSession()

Implements org.springframework.web.server.ServerWebExchange.getSession.

Doc from org.springframework.web.server.ServerWebExchange.getSession.

Return the web session for the current request. Always guaranteed to return an instance either matching to the session id requested by the client, or with a new session id either because the client did not specify one or because the underlying session had expired. Use of this method does not automatically create a session. See WebSession for more details.

Annotations
@Override
initFormDataback to summary
private static Mono<MultiValueMap<String, String>> initFormData(ServerHttpRequest request, ServerCodecConfigurer configurer, String logPrefix)
initMultipartDataback to summary
private Mono<MultiValueMap<String, Part>> initMultipartData(ServerCodecConfigurer configurer, String logPrefix)
isNotModifiedback to summary
public boolean isNotModified()

Implements org.springframework.web.server.ServerWebExchange.isNotModified.

Doc from org.springframework.web.server.ServerWebExchange.isNotModified.

Returns true if the one of the checkNotModified methods in this contract were used and they returned true.

Annotations
@Override
matchRequestedETagsback to summary
private boolean matchRequestedETags(List<String> requestedETags, String eTag, boolean weakCompare)
padEtagIfNecessaryback to summary
private String padEtagIfNecessary(String etag)
Annotations
@Nullable
transformUrlback to summary
public String transformUrl(String url)

Implements org.springframework.web.server.ServerWebExchange.transformUrl.

Doc from org.springframework.web.server.ServerWebExchange.transformUrl.

Transform the given url according to the registered transformation function(s). By default, this method returns the given url, though additional transformation functions can be registered with addUrlTransformer

Parameters
url:String

the URL to transform

Returns:String

the transformed URL

Annotations
@Override
updateResponseIdempotentback to summary
private void updateResponseIdempotent(String eTag, Instant lastModified)
updateResponseStateChangingback to summary
private void updateResponseStateChanging(String eTag, Instant lastModified)
validateIfMatchback to summary
private boolean validateIfMatch(String eTag)
validateIfModifiedSinceback to summary
private void validateIfModifiedSince(Instant lastModified)
validateIfNoneMatchback to summary
private boolean validateIfNoneMatch(String eTag)
validateIfUnmodifiedSinceback to summary
private boolean validateIfUnmodifiedSince(Instant lastModified)