-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat($Starter): provide exposing HTTP resources
- Loading branch information
Johnny Miller (锺俊)
committed
Dec 25, 2020
1 parent
629e066
commit 4f2ebdc
Showing
9 changed files
with
89 additions
and
3 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
23 changes: 23 additions & 0 deletions
23
...ain/java/com/jmsoftware/maf/common/domain/springbootstarter/HttpApiResourcesResponse.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,23 @@ | ||
package com.jmsoftware.maf.common.domain.springbootstarter; | ||
|
||
import com.google.common.collect.Lists; | ||
import lombok.Data; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Description: HttpApiResourcesResponse, change description here. | ||
* | ||
* @author 钟俊(zhongjun), email: zhongjun@toguide.cn, date: 12/25/2020 4:58 PM | ||
**/ | ||
@Data | ||
public class HttpApiResourcesResponse { | ||
private List<HttpApiResource> list = Lists.newLinkedList(); | ||
|
||
@Data | ||
public static class HttpApiResource { | ||
private RequestMethod method; | ||
private String urlPattern; | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
...a/com/jmsoftware/maf/springbootstarter/controller/HttpApiResourceRemoteApiController.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,47 @@ | ||
package com.jmsoftware.maf.springbootstarter.controller; | ||
|
||
import com.jmsoftware.maf.common.bean.ResponseBodyBean; | ||
import com.jmsoftware.maf.common.domain.springbootstarter.HttpApiResourcesResponse; | ||
import com.jmsoftware.maf.springbootstarter.configuration.MafConfiguration; | ||
import com.jmsoftware.maf.springbootstarter.helper.HttpApiScanHelper; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.val; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedList; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Description: HttpApiResourceRemoteApiController, change description here. | ||
* | ||
* @author 钟俊(zhongjun), email: zhongjun@toguide.cn, date: 12/25/2020 4:33 PM | ||
**/ | ||
@RestController | ||
@RequiredArgsConstructor | ||
@Api(tags = {"HTTP API Resource Remote API"}) | ||
public class HttpApiResourceRemoteApiController { | ||
private final MafConfiguration mafConfiguration; | ||
private final HttpApiScanHelper httpApiScanHelper; | ||
|
||
@GetMapping("/http-api-resources") | ||
@ApiOperation(value = "Get HTTP API resources", notes = "Get HTTP API resources (Remote)") | ||
public ResponseBodyBean<HttpApiResourcesResponse> getHttpApiResource() { | ||
val handlerMethodMap = httpApiScanHelper.scan(mafConfiguration.getIncludedPackageForHttpApiScan()); | ||
HttpApiResourcesResponse response = new HttpApiResourcesResponse(); | ||
handlerMethodMap.forEach((requestMappingInfo, handlerMethod) -> { | ||
val requestMethod = Optional.ofNullable( | ||
new ArrayList<>(requestMappingInfo.getMethodsCondition().getMethods()).get(0)) | ||
.orElseThrow(() -> new RuntimeException("Request method mustn't be null!")); | ||
val httpApiResource = new HttpApiResourcesResponse.HttpApiResource(); | ||
httpApiResource.setMethod(requestMethod); | ||
httpApiResource.setUrlPattern( | ||
new LinkedList<>(requestMappingInfo.getPatternsCondition().getPatterns()).get(0)); | ||
response.getList().add(httpApiResource); | ||
}); | ||
return ResponseBodyBean.ofSuccess(response); | ||
} | ||
} |