Skip to content

Conversation

@mercyblitz
Copy link
Contributor

This pull request introduces significant refactoring and modularization of the Microsphere Gateway project, primarily by splitting the original gateway implementation into commons, WebFlux, and WebMVC modules. It also updates documentation, dependencies, and introduces new utility and conditional annotations for improved configuration and extensibility.

Module restructuring and renaming:

  • The original microsphere-spring-cloud-gateway module is renamed and refactored into microsphere-spring-cloud-gateway-commons, and two new modules are introduced: microsphere-spring-cloud-gateway-server-webflux (for reactive/WebFlux) and microsphere-spring-cloud-gateway-server-webmvc (for servlet/MVC). This is reflected across all POM files and documentation. [1] [2] [3] [4]

Dependency and configuration updates:

  • Dependency management is updated to reflect the new module structure, including adding new dependencies for validation and test support, and removing or updating Spring Cloud Gateway and related dependencies. The parent POM is updated to use a newer version of microsphere-spring-cloud. [1] [2] [3] [4]
  • The Spring Cloud Alibaba dependency import is commented out in the parent POM, possibly for compatibility or simplification reasons.

Documentation improvements:

  • The README.md is updated to reflect the new module names, usage instructions, and JavaDoc links, ensuring clarity for users on how to consume the new modules. [1] [2] [3] [4] [5]

New utility and annotation classes:

  • Adds ConfigUtils, a utility class for binding and validating configuration objects from the environment or metadata, supporting the new modular structure.
  • Introduces ConditionalOnMicrosphereGatewayEnabled and ConditionalOnMicrosphereWebEndpointMappingEnabled annotations to simplify conditional configuration based on gateway properties. [1] [2]

These changes lay the groundwork for a more maintainable and extensible gateway project, with clear separation between shared logic and specific server implementations.

  • Module Restructuring

    • Refactored the original gateway module into microsphere-spring-cloud-gateway-commons, and introduced microsphere-spring-cloud-gateway-server-webflux and microsphere-spring-cloud-gateway-server-webmvc modules. Updated all references and dependencies accordingly. [1] [2] [3] [4]
    • Updated the parent and dependencies POMs to manage the new modules and version upgrades. [1] [2]
  • Documentation Updates

    • Revised README.md to reflect new module names, usage instructions, and JavaDoc links. [1] [2] [3] [4] [5]
  • Dependency and Configuration Enhancements

    • Added validation and test dependencies to the commons module; removed direct dependency on Spring Cloud Gateway from commons. [1] [2] [3]
  • New Utility and Annotations

    • Added ConfigUtils for configuration binding and validation.
    • Introduced ConditionalOnMicrosphereGatewayEnabled and ConditionalOnMicrosphereWebEndpointMappingEnabled for conditional bean registration based on properties. [1] [2]

Bump project revision to 0.2.1-SNAPSHOT and set Java version to 17. Remove distributionManagement and repositories sections from the pom.xml.
Updated the microsphere-spring-cloud BOM version from 0.2.4 to 0.2.5 in the parent POM to use the latest features and fixes.
Added spring-cloud-loadbalancer, spring-cloud-gateway-proxyexchange-webmvc, and microsphere-spring-test dependencies to the microsphere-spring-cloud-gateway-mvc module. The microsphere-spring-test dependency includes exclusions for several Tomcat components.
Introduces WebEndpointMappingHandlerFilterFunction and related auto-configuration to enable web endpoint mapping in Spring Cloud Gateway MVC. Adds conditional annotation, property constants, and comprehensive tests to ensure correct auto-configuration and filter behavior. Updates auto-configuration imports to register the new configuration.
Split and refactor the Spring Cloud Gateway module into 'microsphere-spring-cloud-gateway-commons', 'microsphere-spring-cloud-gateway-server-webflux', and 'microsphere-spring-cloud-gateway-server-webmvc'. Added new commons annotations, configuration, and property constants for shared gateway logic. Updated dependencies and moved or renamed related source and test files to align with the new modular structure.
Introduces ConfigUtils to simplify and validate binding of WebEndpointConfig from Environment. Refactors WebEndpointConfigTest to use ConfigUtils and extends test coverage for route metadata in test.yaml.
Replaces single 'exclude' with a list of 'excludes' in WebEndpointConfig, updating YAML and related code to support multiple exclusion rules. Refactors WebEndpointMappingGlobalFilter to cache and match excluded request mappings per route, removes legacy Config class, and updates tests accordingly. Adds GATEWAY_ROUTES_PROPERTY_NAME_PREFIX constant and enhances auto-configuration to bind web-endpoint config to route metadata.
Added support for ServiceInstancesChangedEvent and improved EnvironmentChangeEvent handling in WebEndpointMappingGlobalFilter. Refactored property constant naming for consistency in MVC modules. Updated related tests to cover new event handling logic and renamed test methods for clarity.
Introduced RouteConstants interface to define keys for route ID, metadata, and web endpoint. Added RouteConstantsTest to verify the constant values.
Introduces new test routes in the test.yaml for RequestSize and Retry filters under both 'gateway.routes' and 'server.webflux.routes'. These additions support testing of request size limits and retry logic with various arguments and metadata.
Replaces hardcoded route metadata keys with constants from RouteConstants for improved maintainability. Also adds a null check before adding web endpoint config to metadata.
Introduced getWebEndpointRoutes() to filter only web endpoint routes, improving clarity and efficiency in refresh and event matching logic. Updated constant imports and usages to use RouteConstants, and added trace logging for event listening.
Introduced new constants SCHEME and ALL_SERVICES to the RouteConstants interface for use with WebEndpointMapping routes and service mapping.
Added assertions for the SCHEME and ALL_SERVICES constants in RouteConstantsTest to improve test coverage of RouteConstants.
Introduces CommonConstants interface to hold shared constants, including APPLICATION_NAME_URI_TEMPLATE_VARIABLE_NAME for use in URI templates. This helps centralize and standardize constant values across the project.
Introduces CommonConstantsTest to verify the value of APPLICATION_NAME_URI_TEMPLATE_VARIABLE_NAME in the CommonConstants class.
Eliminated duplicate constant definitions for SCHEME, ALL_SERVICES, and APPLICATION_NAME_URI_TEMPLATE_VARIABLE_NAME in WebEndpointMappingGlobalFilter. These constants are now imported from their respective common constants classes to improve maintainability and avoid redundancy.
Replaces the hardcoded ".id" string with the ID_KEY constant from RouteConstants when searching for route property keys. This improves maintainability and reduces the risk of typos or inconsistencies.
Introduces a new ConfigurationPropertiesBindHandlerAdvisor implementation for WebEndpointConfig. This advisor injects WebEndpointConfig into route metadata during property binding, enabling enhanced configuration handling for gateway routes.
Removed direct implementation of ConfigurationPropertiesBindHandlerAdvisor and EnvironmentAware from WebEndpointMappingGatewayAutoConfiguration. Introduced a static @bean method to provide WebEndpointConfigurationPropertiesBindHandlerAdvisor, simplifying the configuration and reducing class responsibilities.
Introduced getWebEndpointConfig(Map<String, Object>) to retrieve a WebEndpointConfig instance from a metadata map using the WEB_ENDPOINT_KEY constant.
Introduces ConfigUtilsTest to verify the behavior of getWebEndpointConfig and related configuration parsing logic using mock environments and YAML property sources.
Deleted the WebEndpointConfigTest.java file from the test suite. This change may be part of a test cleanup or refactoring effort.
Replaces direct metadata access for WebEndpointConfig with the getWebEndpointConfig utility method, improving encapsulation and consistency.
Introduced WEB_ENDPOINT_REWRITE_PATH_ATTRIBUTE_NAME to RouteConstants for referencing the web endpoint rewrite path attribute in route metadata.
Replaces 'request_size_route' and 'retry_test' with 'add_response_header_route_all' and updates filter configurations to use AddResponseHeader. Simplifies test route definitions and aligns them with current testing requirements.
Adds a null check for WebEndpointConfig in buildExcludedRequestMappingInfoSet to return an empty set when the config is absent, preventing potential NullPointerExceptions.
Moved the registration of WebEndpointConfigurationPropertiesBindHandlerAdvisor from @bean methods in auto-configuration classes to ApplicationContextInitializer implementations for both WebFlux and WebMvc modules. Added corresponding ApplicationContextInitializer classes and registered them in spring.factories. Introduced a BEAN_NAME constant for the advisor. This change improves bean registration consistency and leverages Spring's context initialization mechanism.
Extracted environment creation logic into a static createEnvironment() method for reuse and clarity in ConfigUtilsTest. The setUp method now uses this helper to initialize the environment.
Replaces the 'web-endpoint-mapping' route with 'request_size_route', updating the URI and metadata. Removes web-endpoint specific metadata and predicates, simplifying the test configuration.
Introduces a unit test to verify the behavior of WebEndpointConfigurationPropertiesBindHandlerAdvisor, ensuring correct binding of web endpoint configuration properties using a custom BindHandler.
Simplified the event type check for ServiceInstancesChangedEvent by removing the explicit instance check and handling all other events in the else branch.
Changed several private methods and an inner class method to package-private in WebEndpointMappingHandlerFilterFunction. This allows for improved testability or access within the package.
Added a private testInternalMethods() method to cover internal methods of WebEndpointMappingHandlerFilterFunction, including buildExcludedRequestMappingInfoSet, getSubscribedServices, isExcludedRequest, and getMatchingRequestMappingContext. This improves test coverage for internal logic.
Simplified the testGetWebEndpointConfigOnMissing test by removing an unnecessary assertion and focusing on the case where the config should be null.
Updated the 'refresh' and 'findWebEndpointMappingRouteProperties' methods to have package-private visibility instead of private. This allows these methods to be accessed within the package, potentially for testing or use by other classes.
Expanded the test to cover RouteProperties refresh and validation of findWebEndpointMappingRouteProperties with different key sets. This improves test coverage for route property mapping logic.
Extended the test to include checks for the third route's id and metadata in the set of gateway route property keys.
Added a test case to verify the refresh method of WebEndpointMappingHandlerFilterFunction using RouteProperties. This enhances test coverage for route refresh logic.
Replaces old module names with new ones (server-webflux, server-webmvc, commons), updates documentation and usage examples to reflect the new structure, and removes outdated badges. Also updates JavaDoc links and module table for clarity.
Uncommented the spring-cloud-alibaba-dependencies import in the parent POM to include Spring Cloud Alibaba BOM. This change allows for managed dependency versions for Spring Cloud Alibaba components.
@codecov
Copy link

codecov bot commented Nov 12, 2025

Codecov Report

❌ Patch coverage is 99.13043% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ilter/WebEndpointMappingHandlerFilterFunction.java 96.74% 3 Missing and 1 partial ⚠️
Files with missing lines Coverage Δ Complexity Δ
...ring/cloud/gateway/commons/config/ConfigUtils.java 100.00% <100.00%> (ø) 4.00 <4.00> (?)
...loud/gateway/commons/config/WebEndpointConfig.java 100.00% <100.00%> (ø) 3.00 <3.00> (?)
...ointConfigurationPropertiesBindHandlerAdvisor.java 100.00% <100.00%> (ø) 3.00 <3.00> (?)
...ebflux/autoconfigure/GatewayAutoConfiguration.java 100.00% <ø> (ø) 1.00 <0.00> (?)
...re/WebEndpointMappingGatewayAutoConfiguration.java 100.00% <100.00%> (ø) 2.00 <1.00> (?)
...text/WebEndpointApplicationContextInitializer.java 100.00% <100.00%> (ø) 2.00 <2.00> (?)
...HeartbeatEventRouteRefreshListenerInterceptor.java 100.00% <ø> (ø) 8.00 <0.00> (?)
...pagatingRefreshRoutesEventApplicationListener.java 100.00% <ø> (ø) 7.00 <0.00> (?)
...rver/webflux/filter/DefaultGatewayFilterChain.java 100.00% <ø> (ø) 4.00 <0.00> (?)
...webflux/filter/WebEndpointMappingGlobalFilter.java 100.00% <100.00%> (ø) 74.00 <74.00> (?)
... and 7 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request refactors the Microsphere Gateway project for version 0.2.1 by splitting the original monolithic gateway module into three distinct modules: microsphere-spring-cloud-gateway-commons (shared logic), microsphere-spring-cloud-gateway-server-webflux (reactive/WebFlux implementation), and microsphere-spring-cloud-gateway-server-webmvc (servlet/MVC implementation). The changes include dependency updates, new configuration utilities, conditional annotations for feature enablement, and comprehensive documentation updates to reflect the new modular structure.

Key Changes

  • Module restructuring: Split original gateway into commons, webflux, and webmvc modules
  • New utility classes: ConfigUtils and WebEndpointConfig for configuration binding and validation
  • New conditional annotations: ConditionalOnMicrosphereGatewayEnabled and ConditionalOnMicrosphereWebEndpointMappingEnabled for feature toggles
  • Documentation updates: README, JavaDoc links, and usage instructions reflect new module names

Reviewed Changes

Copilot reviewed 64 out of 69 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pom.xml Updated root POM with incorrect name/description, version bump to 0.2.1, and new module references
README.md Updated module names, usage instructions, and JavaDoc links
microsphere-gateway-parent/pom.xml Updated microsphere-spring-cloud dependency version, commented out Spring Cloud Alibaba
microsphere-gateway-dependencies/pom.xml Updated dependency coordinates for new module structure
microsphere-spring-cloud-gateway-commons/* New commons module with shared configuration, constants, and utilities
microsphere-spring-cloud-gateway-server-webflux/* Refactored webflux module with updated package names and enhanced functionality
microsphere-spring-cloud-gateway-server-webmvc/* New webmvc module implementation with similar structure to webflux
Comments suppressed due to low confidence (2)

microsphere-spring-cloud-gateway-server-webflux/src/main/java/io/microsphere/spring/cloud/gateway/server/webflux/filter/WebEndpointMappingGlobalFilter.java:232

  • The matchesEvent(EnvironmentChangeEvent) method performs expensive operations including iterating through routes and checking property values for every environment change event. Consider caching route information or implementing a more efficient property change detection mechanism to avoid unnecessary refreshes.
    microsphere-spring-cloud-gateway-server-webflux/src/main/java/io/microsphere/spring/cloud/gateway/server/webflux/filter/WebEndpointMappingGlobalFilter.java:169
  • This method overrides ApplicationListener.supportsAsyncExecution; it is advisable to add an Override annotation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 24 to 30
/**
* TODO
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @see TODO
* @since 1.0.0
*/
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class-level JavaDoc contains placeholder 'TODO' comments that should be replaced with actual documentation describing the test application's purpose and functionality.

Copilot uses AI. Check for mistakes.
Refactored variable names in the refresh() method for clarity, changing 'routedRequestMappingContextsCache' and 'routedExcludedRequestMappingInfoCache' to 'routedRequestMappingContextsMap' and 'routedExcludedRequestMappingInfoMap' respectively.
Moved buildRequestMappingInfo and buildRequestMethods from WebEndpointMappingGlobalFilter to the RequestMappingContext inner class for better encapsulation and code organization.
Changed the synchronization block in WebEndpointMappingHandlerFilterFunction from 'routeProperties' to 'this' to ensure thread safety when updating requestMappingContexts and excludedRequestMappingInfoSet.
Updated WebEndpointMappingHandlerFilterFunction to handle cases where no service instances are found by returning null and skipping mapping creation. Added a test to verify that buildRequestMappingContexts returns empty when no instances are available.
Added tests to verify that GATEWAY_ENABLED_PROPERTY_NAME and GATEWAY_ROUTES_PROPERTY_NAME_PREFIX are correctly constructed from their component constants.
@sonarqubecloud
Copy link

@mercyblitz mercyblitz merged commit 7b16321 into release Nov 12, 2025
70 of 86 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants