Skip to content

Commit 7b16321

Browse files
authored
Merge pull request #6 from microsphere-projects/dev
Release 0.2.1
2 parents 65706f5 + ac1a1f8 commit 7b16321

File tree

70 files changed

+3357
-749
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+3357
-749
lines changed

README.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
[![Codecov](https://codecov.io/gh/microsphere-projects/microsphere-gateway/branch/dev/graph/badge.svg)](https://app.codecov.io/gh/microsphere-projects/microsphere-gateway)
99
![Maven](https://img.shields.io/maven-central/v/io.github.microsphere-projects/microsphere-gateway.svg)
1010
![License](https://img.shields.io/github/license/microsphere-projects/microsphere-gateway.svg)
11-
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/microsphere-projects/microsphere-gateway.svg)](http://isitmaintained.com/project/microsphere-projects/microsphere-gateway "Average time to resolve an issue")
12-
[![Percentage of issues still open](http://isitmaintained.com/badge/open/microsphere-projects/microsphere-gateway.svg)](http://isitmaintained.com/project/microsphere-projects/microsphere-gateway "Percentage of issues still open")
1311

1412
Microsphere Gateway is a sophisticated extension of the Spring Cloud Gateway ecosystem, providing enhanced API gateway
1513
capabilities with a focus on discovery, routing, and resilience. It offers two complementary implementations: a reactive
@@ -20,21 +18,24 @@ solution based on Spring Cloud Gateway and a servlet-based solution using Spring
2018
The microsphere-gateway project extends Spring Cloud Gateway with enhanced features including:
2119

2220
- Dual Implementation Strategy: Provides both
23-
reactive ([microsphere-spring-cloud-gateway](microsphere-spring-cloud-gateway)) and MVC-based (
24-
[microsphere-spring-cloud-gateway-mvc](microsphere-spring-cloud-gateway-mvc)) gateway implementations
21+
reactive ([microsphere-spring-cloud-gateway-server-webflux](microsphere-spring-cloud-gateway-server-webflux)) and
22+
MVC-based (
23+
[microsphere-spring-cloud-gateway-server-webmvc](microsphere-spring-cloud-gateway-server-webmvc)) gateway
24+
implementations
2525
- Enhanced Configuration Management: Centralized dependency management and auto-configuration capabilities
2626
- Service Discovery Integration: Support for multiple service discovery systems including Eureka, Nacos, Consul, and
2727
Kubernetes
2828
- Enterprise Features: Built-in fault tolerance, caching, and monitoring capabilities
2929

3030
## Modules
3131

32-
| **Module** | **Purpose** |
33-
|------------------------------------------|-------------------------------------------------------------------------------------|
34-
| **microsphere-gateway-parent** | Defines the parent POM with dependency management and Spring Cloud version profiles |
35-
| **microsphere-gateway-dependencies** | Centralizes dependency management for all project modules |
36-
| **microsphere-spring-cloud-gateway** | Reactive WebFlux-based gateway implementation |
37-
| **microsphere-spring-cloud-gateway-mvc** | Servlet-based MVC gateway implementation |
32+
| **Module** | **Purpose** |
33+
|-----------------------------------------------------|-------------------------------------------------------------------------------------|
34+
| **microsphere-gateway-parent** | Defines the parent POM with dependency management and Spring Cloud version profiles |
35+
| **microsphere-gateway-dependencies** | Centralizes dependency management for all project modules |
36+
| **microsphere-spring-cloud-gateway-commons** | Gateway commons module |
37+
| **microsphere-spring-cloud-gateway-server-webflux** | Reactive WebFlux-based gateway implementation |
38+
| **microsphere-spring-cloud-gateway-server-webmvc** | Servlet-based MVC gateway implementation |
3839

3940
## Getting Started
4041

@@ -69,23 +70,25 @@ pom.xml:
6970
Then add the specific modules you need:
7071

7172
```xml
73+
7274
<dependencies>
73-
<!-- Microsphere Spring Cloud Gateway (Reactive) -->
75+
<!-- Microsphere Spring Cloud Gateway WebFlux -->
7476
<dependency>
7577
<groupId>io.github.microsphere-projects</groupId>
76-
<artifactId>microsphere-spring-cloud-gateway</artifactId>
78+
<artifactId>microsphere-spring-cloud-gateway-server-webflux</artifactId>
7779
</dependency>
7880
</dependencies>
7981
```
8082

8183
Using the MVC module if you are using Spring MVC:
8284

8385
```xml
86+
8487
<dependencies>
85-
<!-- Microsphere Spring Cloud Gateway MVC -->
88+
<!-- Microsphere Spring Cloud Gateway WebMVC -->
8689
<dependency>
8790
<groupId>io.github.microsphere-projects</groupId>
88-
<artifactId>microsphere-spring-cloud-gateway-mvc</artifactId>
91+
<artifactId>microsphere-spring-cloud-gateway-server-webmvc</artifactId>
8992
</dependency>
9093
</dependencies>
9194
```
@@ -143,8 +146,8 @@ We welcome your contributions! Please read [Code of Conduct](./CODE_OF_CONDUCT.m
143146

144147
### JavaDoc
145148

146-
- [microsphere-spring-cloud-gateway](https://javadoc.io/doc/io.github.microsphere-projects/microsphere-spring-cloud-gateway)
147-
- [microsphere-spring-cloud-gateway-mvc](https://javadoc.io/doc/io.github.microsphere-projects/microsphere-spring-cloud-gateway-mvc)
149+
- [microsphere-spring-cloud-gateway-server-webflux](https://javadoc.io/doc/io.github.microsphere-projects/microsphere-spring-cloud-gateway-server-webflux)
150+
- [microsphere-spring-cloud-gateway-server-webmvc](https://javadoc.io/doc/io.github.microsphere-projects/microsphere-spring-cloud-gateway-server-webmvc)
148151

149152
## License
150153

microsphere-gateway-dependencies/pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,19 @@
2323

2424
<dependency>
2525
<groupId>io.github.microsphere-projects</groupId>
26-
<artifactId>microsphere-spring-cloud-gateway</artifactId>
26+
<artifactId>microsphere-spring-cloud-gateway-commons</artifactId>
2727
<version>${revision}</version>
2828
</dependency>
2929

3030
<dependency>
3131
<groupId>io.github.microsphere-projects</groupId>
32-
<artifactId>microsphere-spring-cloud-gateway-mvc</artifactId>
32+
<artifactId>microsphere-spring-cloud-gateway-server-webflux</artifactId>
33+
<version>${revision}</version>
34+
</dependency>
35+
36+
<dependency>
37+
<groupId>io.github.microsphere-projects</groupId>
38+
<artifactId>microsphere-spring-cloud-gateway-server-webmvc</artifactId>
3339
<version>${revision}</version>
3440
</dependency>
3541

microsphere-gateway-parent/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
<properties>
2222
<!-- BOM versions -->
23-
<microsphere-spring-cloud.version>0.2.4</microsphere-spring-cloud.version>
23+
<microsphere-spring-cloud.version>0.2.5</microsphere-spring-cloud.version>
2424
<testcontainers.version>2.0.1</testcontainers.version>
2525
</properties>
2626

microsphere-spring-cloud-gateway/pom.xml renamed to microsphere-spring-cloud-gateway-commons/pom.xml

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,21 @@
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>
1212

13-
<artifactId>microsphere-spring-cloud-gateway</artifactId>
13+
<artifactId>microsphere-spring-cloud-gateway-commons</artifactId>
1414
<version>${revision}</version>
1515

16-
<name>Microsphere :: Gateway :: Spring Cloud Gateway</name>
17-
<description>Microsphere Spring Cloud Gateway Reactive Server</description>
16+
<name>Microsphere :: Gateway :: Spring Cloud Gateway Commons</name>
17+
<description>Microsphere Spring Cloud Gateway Commons</description>
1818

1919
<dependencies>
2020

21+
<!-- Bean Validation API -->
22+
<dependency>
23+
<groupId>jakarta.validation</groupId>
24+
<artifactId>jakarta.validation-api</artifactId>
25+
<optional>true</optional>
26+
</dependency>
27+
2128
<!-- Microsphere -->
2229
<dependency>
2330
<groupId>io.github.microsphere-projects</groupId>
@@ -26,7 +33,7 @@
2633

2734
<dependency>
2835
<groupId>io.github.microsphere-projects</groupId>
29-
<artifactId>microsphere-spring-webflux</artifactId>
36+
<artifactId>microsphere-spring-web</artifactId>
3037
</dependency>
3138

3239
<!-- Spring Boot -->
@@ -62,16 +69,10 @@
6269
<optional>true</optional>
6370
</dependency>
6471

65-
<!-- Spring Cloud Gateway -->
66-
<dependency>
67-
<groupId>org.springframework.cloud</groupId>
68-
<artifactId>spring-cloud-starter-gateway</artifactId>
69-
<optional>true</optional>
70-
</dependency>
71-
72+
<!-- Spring -->
7273
<dependency>
73-
<groupId>org.springframework.cloud</groupId>
74-
<artifactId>spring-cloud-starter-circuitbreaker-reactor-resilience4j</artifactId>
74+
<groupId>org.springframework</groupId>
75+
<artifactId>spring-web</artifactId>
7576
<optional>true</optional>
7677
</dependency>
7778

@@ -86,6 +87,20 @@
8687
<dependency>
8788
<groupId>io.github.microsphere-projects</groupId>
8889
<artifactId>microsphere-spring-test</artifactId>
90+
<scope>test</scope>
91+
</dependency>
92+
93+
<!-- Hibernate Validator -->
94+
<dependency>
95+
<groupId>org.hibernate.validator</groupId>
96+
<artifactId>hibernate-validator</artifactId>
97+
<scope>test</scope>
98+
</dependency>
99+
100+
<dependency>
101+
<groupId>org.apache.tomcat.embed</groupId>
102+
<artifactId>tomcat-embed-el</artifactId>
103+
<scope>test</scope>
89104
</dependency>
90105

91106
</dependencies>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package io.microsphere.spring.cloud.gateway.commons.annotation;
19+
20+
import io.microsphere.spring.cloud.gateway.commons.constants.CommonsPropertyConstants;
21+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
22+
import org.springframework.context.annotation.Conditional;
23+
24+
import java.lang.annotation.Documented;
25+
import java.lang.annotation.Retention;
26+
import java.lang.annotation.Target;
27+
28+
import static io.microsphere.spring.cloud.gateway.commons.constants.CommonsPropertyConstants.DEFAULT_MICROSPHERE_GATEWAY_ENABLED;
29+
import static io.microsphere.spring.cloud.gateway.commons.constants.CommonsPropertyConstants.MICROSPHERE_GATEWAY_ENABLED_PROPERTY_NAME;
30+
import static java.lang.annotation.ElementType.METHOD;
31+
import static java.lang.annotation.ElementType.TYPE;
32+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
33+
34+
/**
35+
* The conditional annotation meta-annotates {@link ConditionalOnProperty @ConditionalOnProperty} for
36+
* Microsphere Spring Cloud Gateway enabled.
37+
*
38+
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
39+
* @see Conditional
40+
* @see ConditionalOnProperty
41+
* @see CommonsPropertyConstants#MICROSPHERE_GATEWAY_ENABLED_PROPERTY_NAME
42+
* @since 1.0.0
43+
*/
44+
@Retention(RUNTIME)
45+
@Target({TYPE, METHOD})
46+
@Documented
47+
@ConditionalOnProperty(name = MICROSPHERE_GATEWAY_ENABLED_PROPERTY_NAME,
48+
havingValue = DEFAULT_MICROSPHERE_GATEWAY_ENABLED, matchIfMissing = true)
49+
public @interface ConditionalOnMicrosphereGatewayEnabled {
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package io.microsphere.spring.cloud.gateway.commons.annotation;
19+
20+
import io.microsphere.spring.cloud.gateway.commons.constants.CommonsPropertyConstants;
21+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
22+
import org.springframework.context.annotation.Conditional;
23+
24+
import java.lang.annotation.Documented;
25+
import java.lang.annotation.Retention;
26+
import java.lang.annotation.Target;
27+
28+
import static io.microsphere.spring.cloud.gateway.commons.constants.CommonsPropertyConstants.DEFAULT_MICROSPHERE_GATEWAY_ENABLED;
29+
import static io.microsphere.spring.cloud.gateway.commons.constants.CommonsPropertyConstants.MICROSPHERE_WEB_ENDPOINT_MAPPING_ENABLED_PROPERTY_NAME;
30+
import static java.lang.annotation.ElementType.METHOD;
31+
import static java.lang.annotation.ElementType.TYPE;
32+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
33+
34+
/**
35+
* The conditional annotation meta-annotates {@link ConditionalOnProperty @ConditionalOnProperty} for
36+
* Microsphere Spring Cloud Gateway enabled.
37+
*
38+
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
39+
* @see Conditional
40+
* @see ConditionalOnProperty
41+
* @see CommonsPropertyConstants#MICROSPHERE_GATEWAY_ENABLED_PROPERTY_NAME
42+
* @since 1.0.0
43+
*/
44+
@Retention(RUNTIME)
45+
@Target({TYPE, METHOD})
46+
@Documented
47+
@ConditionalOnMicrosphereGatewayEnabled
48+
@ConditionalOnProperty(name = MICROSPHERE_WEB_ENDPOINT_MAPPING_ENABLED_PROPERTY_NAME,
49+
havingValue = DEFAULT_MICROSPHERE_GATEWAY_ENABLED, matchIfMissing = true)
50+
public @interface ConditionalOnMicrosphereWebEndpointMappingEnabled {
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package io.microsphere.spring.cloud.gateway.commons.config;
19+
20+
import io.microsphere.annotation.Nullable;
21+
import io.microsphere.util.Utils;
22+
import org.springframework.boot.context.properties.bind.BindHandler;
23+
import org.springframework.boot.context.properties.bind.Bindable;
24+
import org.springframework.boot.context.properties.bind.Binder;
25+
import org.springframework.boot.context.properties.bind.validation.ValidationBindHandler;
26+
import org.springframework.core.env.Environment;
27+
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
28+
29+
import java.util.Map;
30+
31+
import static io.microsphere.spring.cloud.gateway.commons.constants.RouteConstants.WEB_ENDPOINT_KEY;
32+
import static org.springframework.boot.context.properties.bind.Bindable.of;
33+
import static org.springframework.boot.context.properties.bind.Binder.get;
34+
35+
/**
36+
* The utilities class for Configuration
37+
*
38+
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
39+
* @see WebEndpointConfig
40+
* @since 1.0.0
41+
*/
42+
public abstract class ConfigUtils implements Utils {
43+
44+
private static final BindHandler springValidatorBindHandler;
45+
46+
private static final Bindable<WebEndpointConfig> WEB_ENDPOINT_CONFIG_BINDABLE = of(WebEndpointConfig.class);
47+
48+
static {
49+
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
50+
validator.afterPropertiesSet();
51+
springValidatorBindHandler = new ValidationBindHandler(validator);
52+
}
53+
54+
/**
55+
* Get the {@link WebEndpointConfig} from the specified {@link Environment}
56+
*
57+
* @param environment the specified {@link Environment}
58+
* @param configPrefix the configuration prefix
59+
* @return If the configuration is not present , return <code>null</code>
60+
*/
61+
@Nullable
62+
public static WebEndpointConfig getWebEndpointConfig(Environment environment, String configPrefix) {
63+
Binder binder = get(environment, springValidatorBindHandler);
64+
return binder.bind(configPrefix, WEB_ENDPOINT_CONFIG_BINDABLE).orElse(null);
65+
}
66+
67+
/**
68+
* Get the {@link WebEndpointConfig} from the specified metadata
69+
*
70+
* @param metadata the specified {@link Map}
71+
* @return If the configuration is not present , return <code>null</code>
72+
*/
73+
@Nullable
74+
public static WebEndpointConfig getWebEndpointConfig(Map<String, Object> metadata) {
75+
Object webEndpoint = metadata.get(WEB_ENDPOINT_KEY);
76+
return webEndpoint instanceof WebEndpointConfig ? (WebEndpointConfig) webEndpoint : null;
77+
}
78+
79+
private ConfigUtils() {
80+
}
81+
}

0 commit comments

Comments
 (0)