Skip to content

io microsphere spring webflux util SpringWebFluxHelper

github-actions[bot] edited this page Jun 18, 2026 · 18 revisions

SpringWebFluxHelper

Type: Class | Module: microsphere-spring-webflux | Package: io.microsphere.spring.webflux.util | Since: 1.0.0

Source: microsphere-spring-webflux/src/main/java/io/microsphere/spring/webflux/util/SpringWebFluxHelper.java

Overview

SpringWebHelper for Spring WebFlux

Declaration

public class SpringWebFluxHelper implements SpringWebHelper

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.2.27-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

Method Examples

getMethod

SpringWebFluxHelper helper = new SpringWebFluxHelper();
  String method = helper.getMethod(serverWebRequest); // e.g. "GET"

setHeader

SpringWebFluxHelper helper = new SpringWebFluxHelper();
  helper.setHeader(serverWebRequest, "Content-Type", "application/json");

addHeader

SpringWebFluxHelper helper = new SpringWebFluxHelper();
  helper.addHeader(serverWebRequest, "Accept", "text/html", "application/json");

getCookieValue

SpringWebFluxHelper helper = new SpringWebFluxHelper();
  String sessionId = helper.getCookieValue(serverWebRequest, "JSESSIONID");

addCookie

SpringWebFluxHelper helper = new SpringWebFluxHelper();
  helper.addCookie(serverWebRequest, "session", "abc123");

getBestMatchingHandler

SpringWebFluxHelper helper = new SpringWebFluxHelper();
  Object handler = helper.getBestMatchingHandler(serverWebRequest);

getPathWithinHandlerMapping

SpringWebFluxHelper helper = new SpringWebFluxHelper();
  String path = helper.getPathWithinHandlerMapping(serverWebRequest); // e.g. "/users/123"

getBestMatchingPattern

SpringWebFluxHelper helper = new SpringWebFluxHelper();
  String pattern = helper.getBestMatchingPattern(serverWebRequest); // e.g. "/users/{id}"

getProducibleMediaTypes

SpringWebFluxHelper helper = new SpringWebFluxHelper();
  // For a request matching "/users/{id}", returns {"id": "123"}
  Map<String, String> vars = helper.getUriTemplateVariables(serverWebRequest);
SpringWebFluxHelper helper = new SpringWebFluxHelper();
  // For a request like "/users;color=red;size=10"
  Map<String, MultiValueMap<String, String>> matrix = helper.getMatrixVariables(serverWebRequest);
SpringWebFluxHelper helper = new SpringWebFluxHelper();
  Set<MediaType> mediaTypes = helper.getProducibleMediaTypes(serverWebRequest);

getType

SpringWebFluxHelper helper = new SpringWebFluxHelper();
  SpringWebType type = helper.getType(); // returns SpringWebType.WEB_FLUX

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-spring-webflux</artifactId>
    <version>${microsphere-spring.version}</version>
</dependency>

Tip: Use the BOM (microsphere-spring-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.spring.webflux.util.SpringWebFluxHelper;

API Reference

Public Methods

Method Description
getMethod Gets the HTTP method from the given NativeWebRequest by extracting it from
setHeader Sets a response header on the underlying ServerHttpResponse.
addHeader Adds one or more values to a response header on the underlying ServerHttpResponse.
getCookieValue Gets the value of a cookie with the specified name from the underlying ServerHttpRequest.
addCookie Adds a cookie with the specified name and value to the underlying ServerHttpResponse.
getBestMatchingHandler Gets the best matching handler from the request attributes, as resolved by Spring WebFlux's
getPathWithinHandlerMapping Gets the path within the handler mapping from the request attributes.
getBestMatchingPattern Gets the best matching URL pattern from the request attributes, as resolved by Spring WebFlux's
getProducibleMediaTypes Gets the URI template variables from the request attributes, as resolved by Spring WebFlux's
getType Returns the SpringWebType indicating this helper is for Spring WebFlux.

Method Details

getMethod

public String getMethod(NativeWebRequest request)

Gets the HTTP method from the given NativeWebRequest by extracting it from the underlying ServerHttpRequest.

Example Usage

`SpringWebFluxHelper helper = new SpringWebFluxHelper();
  String method = helper.getMethod(serverWebRequest); // e.g. "GET"
`

setHeader

public void setHeader(NativeWebRequest request, String headerName, String headerValue)

Sets a response header on the underlying ServerHttpResponse. If the header already exists, its value is replaced.

Example Usage

`SpringWebFluxHelper helper = new SpringWebFluxHelper();
  helper.setHeader(serverWebRequest, "Content-Type", "application/json");
`

addHeader

public void addHeader(NativeWebRequest request, String headerName, String... headerValues)

Adds one or more values to a response header on the underlying ServerHttpResponse. Unlike #setHeader, this appends values rather than replacing existing ones.

Example Usage

`SpringWebFluxHelper helper = new SpringWebFluxHelper();
  helper.addHeader(serverWebRequest, "Accept", "text/html", "application/json");
`

getCookieValue

public String getCookieValue(NativeWebRequest request, String cookieName)

Gets the value of a cookie with the specified name from the underlying ServerHttpRequest.

Example Usage

`SpringWebFluxHelper helper = new SpringWebFluxHelper();
  String sessionId = helper.getCookieValue(serverWebRequest, "JSESSIONID");
`

addCookie

public void addCookie(NativeWebRequest request, String cookieName, String cookieValue)

Adds a cookie with the specified name and value to the underlying ServerHttpResponse. The cookie is created with secure and httpOnly flags enabled.

Example Usage

`SpringWebFluxHelper helper = new SpringWebFluxHelper();
  helper.addCookie(serverWebRequest, "session", "abc123");
`

getBestMatchingHandler

public Object getBestMatchingHandler(NativeWebRequest request)

Gets the best matching handler from the request attributes, as resolved by Spring WebFlux's HandlerMapping.

Example Usage

`SpringWebFluxHelper helper = new SpringWebFluxHelper();
  Object handler = helper.getBestMatchingHandler(serverWebRequest);
`

getPathWithinHandlerMapping

public String getPathWithinHandlerMapping(NativeWebRequest request)

Gets the path within the handler mapping from the request attributes.

Example Usage

`SpringWebFluxHelper helper = new SpringWebFluxHelper();
  String path = helper.getPathWithinHandlerMapping(serverWebRequest); // e.g. "/users/123"
`

getBestMatchingPattern

public String getBestMatchingPattern(NativeWebRequest request)

Gets the best matching URL pattern from the request attributes, as resolved by Spring WebFlux's HandlerMapping. The PathPattern is converted to its string representation.

Example Usage

`SpringWebFluxHelper helper = new SpringWebFluxHelper();
  String pattern = helper.getBestMatchingPattern(serverWebRequest); // e.g. "/users/{id`"
}

getProducibleMediaTypes

public Set<MediaType> getProducibleMediaTypes(NativeWebRequest request)

Gets the URI template variables from the request attributes, as resolved by Spring WebFlux's HandlerMapping.

Example Usage

`SpringWebFluxHelper helper = new SpringWebFluxHelper();
  // For a request matching "/users/{id`", returns {"id": "123"}
  Map vars = helper.getUriTemplateVariables(serverWebRequest);
}

getType

public SpringWebType getType()

Returns the SpringWebType indicating this helper is for Spring WebFlux.

Example Usage

`SpringWebFluxHelper helper = new SpringWebFluxHelper();
  SpringWebType type = helper.getType(); // returns SpringWebType.WEB_FLUX
`

See Also

  • SpringWebHelper

This documentation was auto-generated from the source code of microsphere-spring.

Home

spring-context

spring-guice

spring-jdbc

spring-test

spring-web

spring-webflux

spring-webmvc

Clone this wiki locally