-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed639ba
commit 949bbd1
Showing
26 changed files
with
168 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
osc-service/osc-gateway-service/src/main/java/com/.DS_Store
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
osc-service/osc-gateway-service/src/main/java/com/zwc/.DS_Store
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
osc-service/osc-gateway-service/src/main/java/com/zwc/gateway/.DS_Store
Binary file not shown.
71 changes: 71 additions & 0 deletions
71
...e/osc-gateway-service/src/main/java/com/zwc/gateway/config/MySwaggerResourceProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.zwc.gateway.config; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.cloud.gateway.route.RouteLocator; | ||
import org.springframework.stereotype.Component; | ||
import springfox.documentation.swagger.web.SwaggerResource; | ||
import springfox.documentation.swagger.web.SwaggerResourcesProvider; | ||
|
||
import java.util.*; | ||
|
||
/** | ||
* @ClassName MySwaggerResourceProvider | ||
* @Desc TODO 聚合 Swagger | ||
* @Date 2020/1/26 5:36 PM | ||
* @Version 1.0 | ||
*/ | ||
@Component | ||
public class MySwaggerResourceProvider implements SwaggerResourcesProvider { | ||
|
||
/** | ||
* 特定服务名称后缀 | ||
*/ | ||
public static final String SERVICE_SUFFIX = "core"; | ||
|
||
/** | ||
* 固定地址 | ||
*/ | ||
public static final String FIXED_URL = "/v2/api-docs"; | ||
|
||
/** | ||
* 网关路由 | ||
*/ | ||
private final RouteLocator routeLocator; | ||
|
||
@Autowired(required = false) | ||
public MySwaggerResourceProvider(RouteLocator routeLocator) { | ||
this.routeLocator = routeLocator; | ||
} | ||
|
||
@Override | ||
public List<SwaggerResource> get() { | ||
// 返回结果 | ||
List<SwaggerResource> resources = new ArrayList<>(); | ||
// 所有路由 | ||
List<String> routeHosts = new ArrayList<>(); | ||
// 过滤并添加路由(只加载指定服务:如处理业务逻辑的服务) | ||
routeLocator.getRoutes().filter(route -> route.getUri().getHost() != null) | ||
.filter(route -> route.getUri().getHost().indexOf(SERVICE_SUFFIX.toUpperCase()) != -1) | ||
.subscribe(route -> routeHosts.add(route.getUri().getHost())); | ||
|
||
// 去重已添加的地址 | ||
Set<String> dealed = new HashSet<>(); | ||
// 遍历所有路由 | ||
routeHosts.forEach(instance -> { | ||
// 拼接地址,格式为:/ + 路由 + 固定地址 | ||
String url = "/" + instance + FIXED_URL; | ||
// 去重 | ||
if (!dealed.contains(url)) { | ||
dealed.add(url); | ||
SwaggerResource swaggerResource = new SwaggerResource(); | ||
swaggerResource.setUrl(url); | ||
swaggerResource.setName(instance); | ||
resources.add(swaggerResource); | ||
} | ||
}); | ||
// 返回 | ||
return resources; | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...c/gateway/hystrix/FallbackController.java → ...ontroller/hystrix/FallbackController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...y-service/src/main/java/com/zwc/gateway/controller/swagger/SwaggerResourceController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.zwc.gateway.controller.swagger; | ||
|
||
import com.zwc.gateway.config.MySwaggerResourceProvider; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import springfox.documentation.swagger.web.*; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @ClassName SwaggerResourceController | ||
* @Desc TODO 重写核心接口 | ||
* @Date 2020/1/26 6:38 PM | ||
* @Version 1.0 | ||
*/ | ||
@RestController | ||
@RequestMapping("/swagger-resources") | ||
public class SwaggerResourceController { | ||
|
||
private MySwaggerResourceProvider swaggerResourceProvider; | ||
|
||
@Autowired | ||
public SwaggerResourceController(MySwaggerResourceProvider swaggerResourceProvider) { | ||
this.swaggerResourceProvider = swaggerResourceProvider; | ||
} | ||
|
||
@RequestMapping(value = "/configuration/security") | ||
public ResponseEntity<SecurityConfiguration> securityConfiguration() { | ||
return new ResponseEntity<>(SecurityConfigurationBuilder.builder().build(), HttpStatus.OK); | ||
} | ||
|
||
@RequestMapping(value = "/configuration/ui") | ||
public ResponseEntity<UiConfiguration> uiConfiguration() { | ||
return new ResponseEntity<>(UiConfigurationBuilder.builder().build(), HttpStatus.OK); | ||
} | ||
|
||
@RequestMapping | ||
public ResponseEntity<List<SwaggerResource>> swaggerResources() { | ||
return new ResponseEntity<>(swaggerResourceProvider.get(), HttpStatus.OK); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.