org.springframework.mock.web.reactive.function.server

Class MockServerRequest

  • java.lang.Object
    • org.springframework.mock.web.reactive.function.server.MockServerRequest
  • All Implemented Interfaces:
    ServerRequest


    public final class MockServerRequest
    extends java.lang.Object
    implements ServerRequest
    Mock implementation of ServerRequest.
    Since:
    5.0
    Author:
    Arjen Poutsma
    • Method Detail

      • method

        public HttpMethod method()
        Description copied from interface: ServerRequest
        Get the HTTP method.
        Specified by:
        method in interface ServerRequest
        Returns:
        the HTTP method as an HttpMethod enum value, or null if not resolvable (e.g. in case of a non-standard HTTP method)
      • methodName

        public java.lang.String methodName()
        Description copied from interface: ServerRequest
        Get the name of the HTTP method.
        Specified by:
        methodName in interface ServerRequest
        Returns:
        the HTTP method as a String
      • uri

        public java.net.URI uri()
        Description copied from interface: ServerRequest
        Get the request URI.
        Specified by:
        uri in interface ServerRequest
      • uriBuilder

        public UriBuilder uriBuilder()
        Description copied from interface: ServerRequest
        Get a UriBuilderComponents from the URI associated with this ServerRequest.

        Note: as of 5.1 this method ignores "Forwarded" and "X-Forwarded-*" headers that specify the client-originated address. Consider using the ForwardedHeaderFilter to extract and use, or to discard such headers.

        Specified by:
        uriBuilder in interface ServerRequest
        Returns:
        a URI builder
      • remoteAddress

        public java.util.Optional<java.net.InetSocketAddress> remoteAddress()
        Description copied from interface: ServerRequest
        Get the remote address to which this request is connected, if available.
        Specified by:
        remoteAddress in interface ServerRequest
      • body

        public <S> S body(BodyExtractor<S,? super ServerHttpRequest> extractor,
                          java.util.Map<java.lang.String,java.lang.Object> hints)
        Description copied from interface: ServerRequest
        Extract the body with the given BodyExtractor and hints.
        Specified by:
        body in interface ServerRequest
        Type Parameters:
        S - the type of the body returned
        Parameters:
        extractor - the BodyExtractor that reads from the request
        hints - the map of hints like Jackson2CodecSupport.JSON_VIEW_HINT to use to customize body extraction
        Returns:
        the extracted body
      • bodyToMono

        public <S> reactor.core.publisher.Mono<S> bodyToMono(java.lang.Class<? extends S> elementClass)
        Description copied from interface: ServerRequest
        Extract the body to a Mono.
        Specified by:
        bodyToMono in interface ServerRequest
        Type Parameters:
        S - the element type
        Parameters:
        elementClass - the class of element in the Mono
        Returns:
        the body as a mono
      • bodyToMono

        public <S> reactor.core.publisher.Mono<S> bodyToMono(ParameterizedTypeReference<S> typeReference)
        Description copied from interface: ServerRequest
        Extract the body to a Mono.
        Specified by:
        bodyToMono in interface ServerRequest
        Type Parameters:
        S - the element type
        Parameters:
        typeReference - a type reference describing the expected response request type
        Returns:
        a mono containing the body of the given type T
      • bodyToFlux

        public <S> reactor.core.publisher.Flux<S> bodyToFlux(java.lang.Class<? extends S> elementClass)
        Description copied from interface: ServerRequest
        Extract the body to a Flux.
        Specified by:
        bodyToFlux in interface ServerRequest
        Type Parameters:
        S - the element type
        Parameters:
        elementClass - the class of element in the Flux
        Returns:
        the body as a flux
      • bodyToFlux

        public <S> reactor.core.publisher.Flux<S> bodyToFlux(ParameterizedTypeReference<S> typeReference)
        Description copied from interface: ServerRequest
        Extract the body to a Flux.
        Specified by:
        bodyToFlux in interface ServerRequest
        Type Parameters:
        S - the element type
        Parameters:
        typeReference - a type reference describing the expected request body type
        Returns:
        a flux containing the body of the given type T
      • attributes

        public java.util.Map<java.lang.String,java.lang.Object> attributes()
        Description copied from interface: ServerRequest
        Get a mutable map of request attributes.
        Specified by:
        attributes in interface ServerRequest
        Returns:
        the request attributes
      • pathVariables

        public java.util.Map<java.lang.String,java.lang.String> pathVariables()
        Description copied from interface: ServerRequest
        Get all path variables for this request.
        Specified by:
        pathVariables in interface ServerRequest
      • session

        public reactor.core.publisher.Mono<WebSession> session()
        Description copied from interface: ServerRequest
        Get the web session for this request.

        Always guaranteed to return an instance either matching 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.

        Specified by:
        session in interface ServerRequest
      • principal

        public reactor.core.publisher.Mono<? extends java.security.Principal> principal()
        Description copied from interface: ServerRequest
        Get the authenticated user for the request, if any.
        Specified by:
        principal in interface ServerRequest
      • formData

        public reactor.core.publisher.Mono<MultiValueMap<java.lang.String,java.lang.String>> formData()
        Description copied from interface: ServerRequest
        Get 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:
        formData in interface ServerRequest
      • multipartData

        public reactor.core.publisher.Mono<MultiValueMap<java.lang.String,Part>> multipartData()
        Description copied from interface: ServerRequest
        Get 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.

        Specified by:
        multipartData in interface ServerRequest
      • exchange

        public ServerWebExchange exchange()
        Description copied from interface: ServerRequest
        Get the web exchange that this request is based on.

        Note: Manipulating the exchange directly (instead of using the methods provided on ServerRequest and ServerResponse) can lead to irregular results.

        Specified by:
        exchange in interface ServerRequest