Class ServerWebExchangeDecorator

java.lang.Object
org.springframework.web.server.ServerWebExchangeDecorator
All Implemented Interfaces:
ServerWebExchange

public class ServerWebExchangeDecorator extends Object implements ServerWebExchange
A convenient base class for classes that need to wrap another ServerWebExchange. Pre-implements all methods by delegating to the wrapped instance.

Note: if the purpose for using a decorator is to override properties like getPrincipal(), consider using ServerWebExchange.mutate() instead.

Since:
5.0
Author:
Rossen Stoyanchev
See Also:
  • Constructor Details

    • ServerWebExchangeDecorator

      protected ServerWebExchangeDecorator(ServerWebExchange delegate)
  • Method Details

    • getDelegate

      public ServerWebExchange getDelegate()
    • getRequest

      public ServerHttpRequest getRequest()
      Description copied from interface: ServerWebExchange
      Return the current HTTP request.
      Specified by:
      getRequest in interface ServerWebExchange
    • getResponse

      public ServerHttpResponse getResponse()
      Description copied from interface: ServerWebExchange
      Return the current HTTP response.
      Specified by:
      getResponse in interface ServerWebExchange
    • getAttributes

      public Map<String,Object> getAttributes()
      Description copied from interface: ServerWebExchange
      Return a mutable map of request attributes for the current exchange.
      Specified by:
      getAttributes in interface ServerWebExchange
    • getSession

      public reactor.core.publisher.Mono<WebSession> getSession()
      Description copied from interface: ServerWebExchange
      Return the web session for the current request.

      Always guaranteed to return either an instance matching the session id requested by the client, or a new session either because the client did not specify a session id or because the underlying session expired.

      Use of this method does not automatically create a session. See WebSession for more details.

      Specified by:
      getSession in interface ServerWebExchange
    • getPrincipal

      public <T extends Principal> reactor.core.publisher.Mono<T> getPrincipal()
      Description copied from interface: ServerWebExchange
      Return the authenticated user for the request, if any.
      Specified by:
      getPrincipal in interface ServerWebExchange
    • getLocaleContext

      public org.springframework.context.i18n.LocaleContext getLocaleContext()
      Description copied from interface: ServerWebExchange
      Return the LocaleContext using the configured LocaleContextResolver.
      Specified by:
      getLocaleContext in interface ServerWebExchange
    • getApplicationContext

      public @Nullable org.springframework.context.ApplicationContext getApplicationContext()
      Description copied from interface: ServerWebExchange
      Return the ApplicationContext associated with the web application, if it was initialized with one via WebHttpHandlerBuilder.applicationContext(ApplicationContext).
      Specified by:
      getApplicationContext in interface ServerWebExchange
      See Also:
    • getFormData

      public reactor.core.publisher.Mono<org.springframework.util.MultiValueMap<String,String>> getFormData()
      Description copied from interface: ServerWebExchange
      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.

      Specified by:
      getFormData in interface ServerWebExchange
    • getMultipartData

      public reactor.core.publisher.Mono<org.springframework.util.MultiValueMap<String,Part>> getMultipartData()
      Description copied from interface: ServerWebExchange
      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.

      Specified by:
      getMultipartData in interface ServerWebExchange
    • cleanupMultipart

      public reactor.core.publisher.Mono<Void> cleanupMultipart()
      Description copied from interface: ServerWebExchange
      Cleans up any storage used for multipart handling.
      Specified by:
      cleanupMultipart in interface ServerWebExchange
      See Also:
    • isNotModified

      public boolean isNotModified()
      Description copied from interface: ServerWebExchange
      Returns true if the one of the checkNotModified methods in this contract were used and they returned true.
      Specified by:
      isNotModified in interface ServerWebExchange
    • checkNotModified

      public boolean checkNotModified(Instant lastModified)
      Description copied from interface: ServerWebExchange
      An overloaded variant of ServerWebExchange.checkNotModified(String, Instant) with a last-modified timestamp only.
      Specified by:
      checkNotModified in interface ServerWebExchange
      Parameters:
      lastModified - the last-modified time
      Returns:
      whether the request qualifies as not modified
    • checkNotModified

      public boolean checkNotModified(String etag)
      Description copied from interface: ServerWebExchange
      An overloaded variant of ServerWebExchange.checkNotModified(String, Instant) with an ETag (entity tag) value only.
      Specified by:
      checkNotModified in interface ServerWebExchange
      Parameters:
      etag - the entity tag for the underlying resource.
      Returns:
      true if the request does not require further processing.
    • checkNotModified

      public boolean checkNotModified(@Nullable String etag, Instant lastModified)
      Description copied from interface: ServerWebExchange
      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 ServerWebExchange.checkNotModified(Instant).

      Specified by:
      checkNotModified in interface ServerWebExchange
      Parameters:
      etag - the entity tag that the application determined for the underlying resource. This parameter will be padded with quotes (") if necessary.
      lastModified - the last-modified timestamp that the application determined for the underlying resource
      Returns:
      true if the request does not require further processing.
    • transformUrl

      public String transformUrl(String url)
      Description copied from interface: ServerWebExchange
      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 ServerWebExchange.addUrlTransformer(Function)
      Specified by:
      transformUrl in interface ServerWebExchange
      Parameters:
      url - the URL to transform
      Returns:
      the transformed URL
    • addUrlTransformer

      public void addUrlTransformer(Function<String,String> transformer)
      Description copied from interface: ServerWebExchange
      Register an additional URL transformation function for use with ServerWebExchange.transformUrl(String). 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.

      Specified by:
      addUrlTransformer in interface ServerWebExchange
      Parameters:
      transformer - a URL transformation function to add
    • getLogPrefix

      public String getLogPrefix()
      Description copied from interface: ServerWebExchange
      Return a log message prefix to use to correlate messages for this exchange. The prefix is based on the value of the attribute ServerWebExchange.LOG_ID_ATTRIBUTE along with some extra formatting so that the prefix can be conveniently prepended with no further formatting no separators required.
      Specified by:
      getLogPrefix in interface ServerWebExchange
      Returns:
      the log message prefix or an empty String if the ServerWebExchange.LOG_ID_ATTRIBUTE is not set.
    • toString

      public String toString()
      Overrides:
      toString in class Object